123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- package bo
- import (
- "fmt"
- "scd_check_tools/logger"
- "scd_check_tools/models/enum"
- "scd_check_tools/tools"
- "strings"
- "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.FromFcdaId > 0 && c.Model.ToFcdaId > 0 {
- _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and from_fcda_id=? and to_fcda_id=?", c.Model.ModelId, c.Model.FromFcdaId, c.Model.ToFcdaId).Exec()
- } else if c.Model.FromFcdaId > 0 {
- _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and from_fcda_id=? and to_ied_code=? and goosesv=?", c.Model.ModelId, c.Model.FromFcdaId, c.Model.ToIedCode, c.Model.Goosesv).Exec()
- } else if c.Model.ToFcdaId > 0 {
- _, err = db.Raw("delete from t_data_model_fcda_ref where model_id=? and to_fcda_id=? and to_ied_code=?", c.Model.ModelId, c.Model.ToFcdaId, c.Model.FromIedCode).Exec()
- } else if c.Model.FromFuncId > 0 {
- _, err = db.Raw("delete from t_data_model_fcda_ref 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_fcda_ref 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_fcda_ref 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_fcda_ref 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_fcda_ref where model_id=? and (from_func_id=? or to_func_id=?)", c.Model.ModelId, c.Model.ToFuncId, c.Model.ToFuncId).Exec()
- } else {
- _, err = db.Raw("delete from t_data_model_fcda_ref 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_fcda_ref t where t.model_id=? and t.from_fcda_id=?"
- if c.Model.ToIedCode != "" {
- sql = sql + " and t.to_ied_code=?"
- sqlParamters = append(sqlParamters, c.Model.ToIedCode)
- }
- if c.Model.Goosesv != "" {
- sql = sql + " and t.goosesv=?"
- sqlParamters = append(sqlParamters, c.Model.Goosesv)
- }
- rowset := []orm.Params{}
- _, err := o.Raw(sql, sqlParamters).Values(&rowset)
- if err != nil {
- logger.Logger.Error(err)
- }
- return rowset, err
- }
- func (c *SysCheckModelFcdaRalationMgr) GetModelAllFcdaRef() (map[string][]orm.Params, error) {
- //获取当前模型的装置类型关联
- refmgr := new(SysCheckModelIedRelationMgr)
- refLst, _ := refmgr.GetListByModelid(c.Model.ModelId)
- if refLst == nil || len(refLst) == 0 {
- return map[string][]orm.Params{}, nil
- }
- refMap := map[string]string{}
- for _, r := range refLst {
- key := fmt.Sprintf("%s,%s", tools.IsEmpty(r["to_ied_code"]), tools.IsEmpty(r["from_ied_code"]))
- refMap[key] = tools.IsEmpty(r["in_type"])
- }
- db := orm.NewOrm()
- sql := "select r1.*,(select func_name from t_data_model_func_def where id=f1.func_id) from_func_name,(select func_name from t_data_model_func_def where id=f2.func_id) to_func_name,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=? "
- rowset := []orm.Params{}
- sqlParamters := []interface{}{c.Model.ModelId}
- _, err := db.Raw(sql, sqlParamters).Values(&rowset)
- if err != nil {
- logger.Logger.Error(err)
- return nil, err
- }
- //获取装置分组信息
- bgm := new(SysCheckModelIedtypeGroupMgr)
- bgm.Model = T_data_model_iedtype_group{ModelId: c.Model.ModelId}
- groupList := bgm.List()
- result := map[string][]orm.Params{}
- for _, row := range rowset {
- tc := tools.IsEmpty(row["to_ied_code"])
- fc := tools.IsEmpty(row["from_ied_code"])
- goosesv := tools.IsEmpty(row["goosesv"])
- if v, h := groupList[tc]; h {
- tc = v
- }
- if v, h := groupList[fc]; h {
- fc = v
- }
- key := fmt.Sprintf("%s,%s", tc, fc)
- if v, h := refMap[key]; !h || v != goosesv {
- //装置类型之间没有建立连接关系
- continue
- }
- extref_name_exp := tools.IsEmpty(row["to_fcda_match_exp"])
- if extref_name_exp == "" {
- extref_name_exp = tools.IsEmpty(row["to_fcda_name"])
- }
- fcda_name_exp := tools.IsEmpty(row["from_fcda_match_exp"])
- if fcda_name_exp == "" {
- fcda_name_exp = tools.IsEmpty(row["from_fcda_name"])
- }
- t1 := []string{extref_name_exp, fcda_name_exp}
- //中文字符替换
- for i, exp := range t1 {
- if strings.Index(exp, "/") > -1 {
- exp = strings.ReplaceAll(exp, "/", "|")
- }
- if strings.Index(exp, "-") > -1 {
- exp = strings.ReplaceAll(exp, "-", "\\-")
- }
- if strings.Index(exp, "|") > -1 {
- exp = strings.ReplaceAll(exp, "|", "|")
- }
- if strings.Index(exp, ",") > -1 {
- exp = strings.ReplaceAll(exp, ",", ",")
- }
- if strings.Index(exp, "(") > -1 {
- exp = strings.ReplaceAll(exp, "(", "(")
- }
- if strings.Index(exp, ")") > -1 {
- exp = strings.ReplaceAll(exp, ")", ")")
- }
- if strings.Index(exp, "【") > -1 {
- exp = strings.ReplaceAll(exp, "【", "[")
- }
- if strings.Index(exp, "】") > -1 {
- exp = strings.ReplaceAll(exp, "】", "]")
- }
- if strings.Index(exp, "{") > -1 {
- exp = strings.ReplaceAll(exp, "{", "{")
- }
- if strings.Index(exp, "}") > -1 {
- exp = strings.ReplaceAll(exp, "}", "}")
- }
- t1[i] = exp
- }
- row["to_fcda_match_exp"] = t1[0]
- row["from_fcda_match_exp"] = t1[1]
- if result[key] == nil {
- result[key] = []orm.Params{}
- }
- result[key] = append(result[key], row)
- }
- //logger.Logger.Debug(fmt.Sprintf("=====模型%d所有的端子关联关系=====\n%+v", c.Model.ModelId, result))
- return result, err
- }
|