check_sysmodel_ied_fcda_relation.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package bo
  2. import (
  3. "fmt"
  4. "scd_check_tools/logger"
  5. "scd_check_tools/models/enum"
  6. "scd_check_tools/tools"
  7. "strings"
  8. "github.com/astaxie/beego/orm"
  9. )
  10. //系统内置模型-装置功能点端子关系管理
  11. type T_data_model_fcda_ref struct {
  12. Id int `orm:"pk"`
  13. ModelId int // '模型ID' ,
  14. RelationRef int //
  15. FromIedCode string //
  16. ToIedCode string //
  17. FromFuncId int
  18. FromFcdaId int
  19. ToFuncId int
  20. ToFcdaId int
  21. Goosesv string
  22. Cr int // '创建人' ,
  23. Ct string `orm:"-"` // '创建时间' ,
  24. Ur int // '更新人' ,
  25. Ut string `orm:"-"` // '更新时间'
  26. }
  27. //内置检测模型-装置功能点端子管理
  28. type SysCheckModelFcdaRalationMgr struct {
  29. Model T_data_model_fcda_ref
  30. DeviceBaseModel
  31. }
  32. var sysCheckModel_iedFcdaRelationDesc = "内置检测模型-装置功能点端子关系管理"
  33. func init() {
  34. orm.RegisterModel(new(T_data_model_fcda_ref))
  35. }
  36. //保存检测模型装置功能信息
  37. func (c *SysCheckModelFcdaRalationMgr) Save() (err error) {
  38. dblog := new(SystemLog)
  39. dblog.SetUserInfo(c.GetUserInfo())
  40. dblog.Audittype = enum.AuditType_check_model
  41. dblog.Logtype = enum.LogType_Insert
  42. dblog.Eventtype = enum.OptEventType_Bus
  43. dblog.Eventlevel = enum.OptEventLevel_Hight
  44. db := orm.NewOrm()
  45. if c.Model.Id > 0 {
  46. //编辑
  47. _, err = db.Update(&c.Model)
  48. } else {
  49. //新增
  50. _, err = db.Insert(&c.Model)
  51. }
  52. if err != nil {
  53. logger.Logger.Error(err)
  54. dblog.Description = fmt.Sprintf("保存%s信息失败:%s,操作数据:%+v", sysCheckModel_iedFcdaRelationDesc, err.Error(), c.Model)
  55. dblog.Fail2()
  56. } else {
  57. dblog.Description = fmt.Sprintf("保存%s信息成功,操作数据:%+v", sysCheckModel_iedFcdaRelationDesc, c.Model)
  58. dblog.Success2()
  59. }
  60. return err
  61. }
  62. //根据model中指定的id删除
  63. func (c *SysCheckModelFcdaRalationMgr) Delete() (err error) {
  64. dblog := new(SystemLog)
  65. dblog.SetUserInfo(c.GetUserInfo())
  66. dblog.Audittype = enum.AuditType_check_model
  67. dblog.Logtype = enum.LogType_Delete
  68. dblog.Eventtype = enum.OptEventType_Bus
  69. dblog.Eventlevel = enum.OptEventLevel_Hight
  70. db := orm.NewOrm()
  71. if c.Model.FromFcdaId > 0 {
  72. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and (from_fcda_id=? or to_fcda_id=?) and to_ied_code=? and goosesv=?", c.Model.ModelId, c.Model.FromFcdaId, c.Model.FromFcdaId, c.Model.ToIedCode, c.Model.Goosesv).Exec()
  73. } else if c.Model.ToFcdaId > 0 {
  74. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and (from_fcda_id=? or to_fcda_id=?)", c.Model.ModelId, c.Model.ToFcdaId, c.Model.ToFcdaId).Exec()
  75. } else if c.Model.FromFuncId > 0 {
  76. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and from_func_id=?", c.Model.ModelId, c.Model.FromFuncId).Exec()
  77. } else if c.Model.FromIedCode != "" {
  78. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and (from_ied_code=? or to_ied_code=?)", c.Model.ModelId, c.Model.FromIedCode, c.Model.FromIedCode).Exec()
  79. } else if c.Model.ToIedCode != "" {
  80. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and (from_ied_code=? or to_ied_code=?)", c.Model.ModelId, c.Model.ToIedCode, c.Model.ToIedCode).Exec()
  81. } else if c.Model.FromFuncId > 0 {
  82. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and (from_func_id=? or to_func_id=?)", c.Model.ModelId, c.Model.FromFuncId, c.Model.FromFuncId).Exec()
  83. } else if c.Model.ToFuncId > 0 {
  84. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and (from_func_id=? or to_func_id=?)", c.Model.ModelId, c.Model.ToFuncId, c.Model.ToFuncId).Exec()
  85. } else {
  86. _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? ", c.Model.ModelId).Exec()
  87. }
  88. if err != nil {
  89. logger.Logger.Error(err)
  90. dblog.Description = fmt.Sprintf("删除%s(%d)失败:%s", sysCheckModel_iedFcdaRelationDesc, c.Model.ModelId, err.Error())
  91. dblog.Fail2()
  92. } else {
  93. dblog.Description = fmt.Sprintf("删除%s(%d)成功", sysCheckModel_iedFcdaRelationDesc, c.Model.ModelId)
  94. dblog.Success2()
  95. }
  96. return err
  97. }
  98. func (c *SysCheckModelFcdaRalationMgr) GetList() ([]orm.Params, error) {
  99. o := orm.NewOrm()
  100. sqlParamters := []interface{}{c.Model.ModelId, c.Model.FromFcdaId}
  101. sql := "select t.* from t_data_model_fcda_ref t where t.model_id=? and t.from_fcda_id=?"
  102. if c.Model.ToIedCode != "" {
  103. sql = sql + " and t.to_ied_code=?"
  104. sqlParamters = append(sqlParamters, c.Model.ToIedCode)
  105. }
  106. if c.Model.Goosesv != "" {
  107. sql = sql + " and t.goosesv=?"
  108. sqlParamters = append(sqlParamters, c.Model.Goosesv)
  109. }
  110. rowset := []orm.Params{}
  111. _, err := o.Raw(sql, sqlParamters).Values(&rowset)
  112. if err != nil {
  113. logger.Logger.Error(err)
  114. }
  115. return rowset, err
  116. }
  117. func (c *SysCheckModelFcdaRalationMgr) GetModelAllFcdaRef() (map[string][]orm.Params, error) {
  118. db := orm.NewOrm()
  119. sql := "select r1.*,f1.fcda_name from_fcda_name,f1.fcda_match_exp from_fcda_match_exp,f2.fcda_name to_fcda_name,f2.fcda_match_exp to_fcda_match_exp from t_data_model_fcda_ref r1 left join t_data_model_func_fcda f1 on r1.from_fcda_id=f1.id left join t_data_model_func_fcda f2 on r1.to_fcda_id=f2.id where r1.model_id=? "
  120. rowset := []orm.Params{}
  121. sqlParamters := []interface{}{c.Model.ModelId}
  122. _, err := db.Raw(sql, sqlParamters).Values(&rowset)
  123. if err != nil {
  124. logger.Logger.Error(err)
  125. return nil, err
  126. }
  127. result := map[string][]orm.Params{}
  128. for _, row := range rowset {
  129. toiedcode := tools.IsEmpty(row["to_ied_code"])
  130. extref_name_exp := strings.ReplaceAll(tools.IsEmpty(row["to_fcda_match_exp"]), "/", "|")
  131. if extref_name_exp == "" {
  132. extref_name_exp = tools.IsEmpty(row["to_fcda_name"])
  133. }
  134. row["to_fcda_match_exp"] = extref_name_exp
  135. fcda_name_exp := strings.ReplaceAll(tools.IsEmpty(row["from_fcda_match_exp"]), "/", "|")
  136. if fcda_name_exp == "" {
  137. fcda_name_exp = tools.IsEmpty(row["from_fcda_name"])
  138. }
  139. row["from_fcda_match_exp"] = fcda_name_exp
  140. if result[toiedcode] == nil {
  141. result[toiedcode] = []orm.Params{}
  142. }
  143. result[toiedcode] = append(result[toiedcode], row)
  144. }
  145. logger.Logger.Debug(fmt.Sprintf("=====模型%d所有的端子关联关系=====\n%+v", c.Model.ModelId, result))
  146. return result, err
  147. }