check_sysmodel_ied_fcda_relation.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package bo
  2. import (
  3. "fmt"
  4. "scd_check_tools/logger"
  5. "scd_check_tools/models/enum"
  6. "github.com/astaxie/beego/orm"
  7. )
  8. //系统内置模型-装置功能点端子关系管理
  9. type T_data_model_fcda_ref struct {
  10. Id int `orm:"pk"`
  11. ModelId int // '模型ID' ,
  12. RelationRef int //
  13. FromIedCode string //
  14. ToIedCode string //
  15. FromFuncId int
  16. FromFcdaId int
  17. ToFuncId int
  18. ToFcdaId int
  19. Goosesv string
  20. Cr int // '创建人' ,
  21. Ct string `orm:"-"` // '创建时间' ,
  22. Ur int // '更新人' ,
  23. Ut string `orm:"-"` // '更新时间'
  24. }
  25. //内置检测模型-装置功能点端子管理
  26. type SysCheckModelFcdaRalationMgr struct {
  27. Model T_data_model_fcda_ref
  28. DeviceBaseModel
  29. }
  30. var sysCheckModel_iedFcdaRelationDesc = "内置检测模型-装置功能点端子关系管理"
  31. func init() {
  32. orm.RegisterModel(new(T_data_model_fcda_ref))
  33. }
  34. //保存检测模型装置功能信息
  35. func (c *SysCheckModelFcdaRalationMgr) Save() (err error) {
  36. dblog := new(SystemLog)
  37. dblog.SetUserInfo(c.GetUserInfo())
  38. dblog.Audittype = enum.AuditType_check_model
  39. dblog.Logtype = enum.LogType_Insert
  40. dblog.Eventtype = enum.OptEventType_Bus
  41. dblog.Eventlevel = enum.OptEventLevel_Hight
  42. db := orm.NewOrm()
  43. if c.Model.Id > 0 {
  44. //编辑
  45. _, err = db.Update(&c.Model)
  46. } else {
  47. //新增
  48. _, err = db.Insert(&c.Model)
  49. }
  50. if err != nil {
  51. logger.Logger.Error(err)
  52. dblog.Description = fmt.Sprintf("保存%s信息失败:%s,操作数据:%+v", sysCheckModel_iedFcdaRelationDesc, err.Error(), c.Model)
  53. dblog.Fail2()
  54. } else {
  55. dblog.Description = fmt.Sprintf("保存%s信息成功,操作数据:%+v", sysCheckModel_iedFcdaRelationDesc, c.Model)
  56. dblog.Success2()
  57. }
  58. return err
  59. }
  60. //根据model中指定的id删除
  61. func (c *SysCheckModelFcdaRalationMgr) Delete() (err error) {
  62. dblog := new(SystemLog)
  63. dblog.SetUserInfo(c.GetUserInfo())
  64. dblog.Audittype = enum.AuditType_check_model
  65. dblog.Logtype = enum.LogType_Delete
  66. dblog.Eventtype = enum.OptEventType_Bus
  67. dblog.Eventlevel = enum.OptEventLevel_Hight
  68. db := orm.NewOrm()
  69. if c.Model.FromFuncId > 0 {
  70. _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? and from_func_id=?", c.Model.ModelId, c.Model.FromFuncId).Exec()
  71. } else if c.Model.FromIedCode != "" {
  72. _, 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()
  73. } else if c.Model.ToIedCode != "" {
  74. _, 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()
  75. } else if c.Model.FromFuncId > 0 {
  76. _, 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()
  77. } else if c.Model.ToFuncId > 0 {
  78. _, 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()
  79. } else if c.Model.FromFcdaId > 0 {
  80. _, 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()
  81. } else if c.Model.ToFcdaId > 0 {
  82. _, 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()
  83. } else {
  84. _, err = db.Raw("delete from t_data_model_func_fcda where model_id=? ", c.Model.ModelId).Exec()
  85. }
  86. if err != nil {
  87. logger.Logger.Error(err)
  88. dblog.Description = fmt.Sprintf("删除%s(%d)失败:%s", sysCheckModel_iedFcdaRelationDesc, c.Model.ModelId, err.Error())
  89. dblog.Fail2()
  90. } else {
  91. dblog.Description = fmt.Sprintf("删除%s(%d)成功", sysCheckModel_iedFcdaRelationDesc, c.Model.ModelId)
  92. dblog.Success2()
  93. }
  94. return err
  95. }
  96. func (c *SysCheckModelFcdaRalationMgr) GetList() ([]orm.Params, error) {
  97. o := orm.NewOrm()
  98. sqlParamters := []interface{}{c.Model.ModelId, c.Model.FromFcdaId}
  99. sql := "select t.* from t_data_model_func_fcda t where t.model_id=? and t.from_fcda_id=?"
  100. rowset := []orm.Params{}
  101. _, err := o.Raw(sql, sqlParamters).Values(&rowset)
  102. if err != nil {
  103. logger.Logger.Error(err)
  104. }
  105. return rowset, err
  106. }