123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package bo
- import (
- "fmt"
- "scd_check_tools/logger"
- "scd_check_tools/models/enum"
- "github.com/astaxie/beego/orm"
- )
- //系统内置模型-装置功能点端子关系管理
- type T_data_model_fcda_ref struct {
- Id int `orm:"pk"`
- ModelId int // '模型ID' ,
- RelationRef int //
- FromIedCode string //
- ToIedCode string //
- FromFuncId int
- FromFcdaId int
- ToFuncId int
- ToFcdaId int
- Goosesv string
- Cr int // '创建人' ,
- Ct string `orm:"-"` // '创建时间' ,
- Ur int // '更新人' ,
- Ut string `orm:"-"` // '更新时间'
- }
- //内置检测模型-装置功能点端子管理
- type SysCheckModelFcdaRalationMgr struct {
- Model T_data_model_fcda_ref
- DeviceBaseModel
- }
- var sysCheckModel_iedFcdaRelationDesc = "内置检测模型-装置功能点端子关系管理"
- func init() {
- orm.RegisterModel(new(T_data_model_fcda_ref))
- }
- //保存检测模型装置功能信息
- func (c *SysCheckModelFcdaRalationMgr) Save() (err error) {
- dblog := new(SystemLog)
- dblog.SetUserInfo(c.GetUserInfo())
- dblog.Audittype = enum.AuditType_check_model
- dblog.Logtype = enum.LogType_Insert
- dblog.Eventtype = enum.OptEventType_Bus
- dblog.Eventlevel = enum.OptEventLevel_Hight
- db := orm.NewOrm()
- if c.Model.Id > 0 {
- //编辑
- _, err = db.Update(&c.Model)
- } else {
- //新增
- _, err = db.Insert(&c.Model)
- }
- if err != nil {
- logger.Logger.Error(err)
- dblog.Description = fmt.Sprintf("保存%s信息失败:%s,操作数据:%+v", sysCheckModel_iedFcdaRelationDesc, err.Error(), c.Model)
- dblog.Fail2()
- } else {
- dblog.Description = fmt.Sprintf("保存%s信息成功,操作数据:%+v", sysCheckModel_iedFcdaRelationDesc, c.Model)
- dblog.Success2()
- }
- return err
- }
- //根据model中指定的id删除
- func (c *SysCheckModelFcdaRalationMgr) Delete() (err error) {
- dblog := new(SystemLog)
- dblog.SetUserInfo(c.GetUserInfo())
- dblog.Audittype = enum.AuditType_check_model
- dblog.Logtype = enum.LogType_Delete
- dblog.Eventtype = enum.OptEventType_Bus
- dblog.Eventlevel = enum.OptEventLevel_Hight
- db := orm.NewOrm()
- if c.Model.FromFuncId > 0 {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and from_func_id=?", c.Model.ModelId, c.Model.FromFuncId).Exec()
- } else if c.Model.FromIedCode != "" {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and (from_ied_code=? or to_ied_code=?)", c.Model.ModelId, c.Model.FromIedCode, c.Model.FromIedCode).Exec()
- } else if c.Model.ToIedCode != "" {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and (from_ied_code=? or to_ied_code=?)", c.Model.ModelId, c.Model.ToIedCode, c.Model.ToIedCode).Exec()
- } else if c.Model.FromFuncId > 0 {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and (from_func_id=? or to_func_id=?)", c.Model.ModelId, c.Model.FromFuncId, c.Model.FromFuncId).Exec()
- } else if c.Model.ToFuncId > 0 {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and (from_func_id=? or to_func_id=?)", c.Model.ModelId, c.Model.ToFuncId, c.Model.ToFuncId).Exec()
- } else if c.Model.FromFcdaId > 0 {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and (from_fcda_id=? or to_fcda_id=?)", c.Model.ModelId, c.Model.FromFcdaId, c.Model.FromFcdaId).Exec()
- } else if c.Model.ToFcdaId > 0 {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and (from_fcda_id=? or to_fcda_id=?)", c.Model.ModelId, c.Model.ToFcdaId, c.Model.ToFcdaId).Exec()
- } else {
- _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? ", c.Model.ModelId).Exec()
- }
- if err != nil {
- logger.Logger.Error(err)
- dblog.Description = fmt.Sprintf("删除%s(%d)失败:%s", sysCheckModel_iedFcdaRelationDesc, c.Model.ModelId, err.Error())
- dblog.Fail2()
- } else {
- dblog.Description = fmt.Sprintf("删除%s(%d)成功", sysCheckModel_iedFcdaRelationDesc, c.Model.ModelId)
- dblog.Success2()
- }
- return err
- }
- func (c *SysCheckModelFcdaRalationMgr) GetList() ([]orm.Params, error) {
- o := orm.NewOrm()
- sqlParamters := []interface{}{c.Model.ModelId, c.Model.FromFcdaId}
- sql := "select t.* from t_data_model_func_fcda t where t.model_id=? and t.from_fcda_id=?"
- rowset := []orm.Params{}
- _, err := o.Raw(sql, sqlParamters).Values(&rowset)
- if err != nil {
- logger.Logger.Error(err)
- }
- return rowset, err
- }
|