|
|
@@ -5,6 +5,7 @@ import (
|
|
|
"encoding/xml"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "scd_check_tools/arrayex"
|
|
|
"scd_check_tools/logger"
|
|
|
"scd_check_tools/models/enum"
|
|
|
"scd_check_tools/tools"
|
|
|
@@ -24,7 +25,8 @@ type T_data_model_defualt struct {
|
|
|
LineLinkStyle int // '接线方式' ,
|
|
|
IedTypes string // '包含的装置类型' ,
|
|
|
RelationJson string // '关系定义内容' ,
|
|
|
- IsSys int //是否内置模型 1 内置 2 自定义
|
|
|
+ IsSys int //是否内置模型。1 系统内置模型 2 任务检测模型
|
|
|
+ FromModelId int //非系统内置模型时的参照模型ID。is_sys为2时有效
|
|
|
Cr int // '创建人' ,
|
|
|
Ct string `orm:"-"` // '创建时间' ,
|
|
|
Ur int // '更新人' ,
|
|
|
@@ -163,6 +165,9 @@ func (c *SysCheckModelMgr) Save() (err error) {
|
|
|
if c.Model.IsSys == 0 {
|
|
|
c.Model.IsSys = tmpObj.IsSys
|
|
|
}
|
|
|
+ if c.Model.FromModelId == 0 {
|
|
|
+ c.Model.FromModelId = tmpObj.FromModelId
|
|
|
+ }
|
|
|
|
|
|
if c.Model.RelationJson != "" {
|
|
|
// 解析出模型需要的装置类型
|
|
|
@@ -191,21 +196,17 @@ func (c *SysCheckModelMgr) Save() (err error) {
|
|
|
dblog.Fail2()
|
|
|
return err
|
|
|
}
|
|
|
- /*
|
|
|
- if nodes.Nodes != nil && len(nodes.Nodes) > 0 {
|
|
|
- iedtypes := []string{}
|
|
|
- for _, ritem := range nodes.Nodes {
|
|
|
- iedtypes = append(iedtypes, ritem.Properties.IedType)
|
|
|
- }
|
|
|
- c.Model.IedTypes = strings.Join(iedtypes, ",")
|
|
|
- }
|
|
|
- */
|
|
|
if modelJson["nodes"] != nil {
|
|
|
nodes := modelJson["nodes"].([]interface{})
|
|
|
iedtypes := []string{}
|
|
|
for _, ritem := range nodes {
|
|
|
properties := ritem.(map[string]interface{})["properties"].(map[string]interface{})
|
|
|
- iedtypes = append(iedtypes, tools.IsEmpty(properties["ied_type"]))
|
|
|
+ tmp := tools.IsEmpty(properties["ied_type"])
|
|
|
+ if arrayex.IndexOf(iedtypes, tmp) > 0 {
|
|
|
+ //装置类型重复了
|
|
|
+ return errors.New("装置类型" + tmp + "不能重复引用")
|
|
|
+ }
|
|
|
+ iedtypes = append(iedtypes, tmp)
|
|
|
}
|
|
|
c.Model.IedTypes = strings.Join(iedtypes, ",")
|
|
|
}
|
|
|
@@ -220,6 +221,19 @@ func (c *SysCheckModelMgr) Save() (err error) {
|
|
|
c.Model.Cr = tmpObj.Cr
|
|
|
c.Model.Ur, _ = strconv.Atoi(c.GetUserId())
|
|
|
_, err = db.Update(&c.Model)
|
|
|
+ if err != nil {
|
|
|
+ //对比装置类型是否有变动.如果有减少则,需要同步删除减少装置类型的相关数据
|
|
|
+ oldTypes := strings.Split(tmpObj.IedTypes, ",")
|
|
|
+ newTypes := "," + c.Model.IedTypes + ","
|
|
|
+ for _, item := range oldTypes {
|
|
|
+ if strings.Index(newTypes, ","+item+",") == -1 {
|
|
|
+ //当前装置类型item被删除:删除该装置类型原来的功能定义等
|
|
|
+ m1 := new(SysCheckModelIedFuncMgr)
|
|
|
+ m1.Model = T_data_model_func_def{ModelId: c.Model.Id, IedType: item}
|
|
|
+ m1.Delete()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if err != nil {
|
|
|
@@ -283,7 +297,7 @@ func (c *SysCheckModelMgr) Delete() (err error) {
|
|
|
}
|
|
|
|
|
|
//复制模型
|
|
|
-func (c *SysCheckModelMgr) Copy(newmodelname string) (error, int) {
|
|
|
+func (c *SysCheckModelMgr) Copy(modelid int) (error, int) {
|
|
|
dblog := new(SystemLog)
|
|
|
dblog.SetUserInfo(c.GetUserInfo())
|
|
|
dblog.Audittype = enum.AuditType_check_model
|
|
|
@@ -291,9 +305,19 @@ func (c *SysCheckModelMgr) Copy(newmodelname string) (error, int) {
|
|
|
dblog.Eventtype = enum.OptEventType_Bus
|
|
|
dblog.Eventlevel = enum.OptEventLevel_Low
|
|
|
o := orm.NewOrm()
|
|
|
- o.Read(&c.Model)
|
|
|
- sql := "insert into t_data_model_defualt(model_name,area_type,vol_id,line_link_style,ied_types,relation_json,is_sys)values(?,?,?,?,?,?,?)"
|
|
|
- r, err := o.Raw(sql, []interface{}{newmodelname, c.Model.AreaType, c.Model.VolId, c.Model.LineLinkStyle, c.Model.IedTypes, c.Model.RelationJson, 2}).Exec()
|
|
|
+ tmpM := T_data_model_defualt{Id: modelid}
|
|
|
+ err := o.Read(&tmpM)
|
|
|
+ if err != nil {
|
|
|
+ logger.Logger.Error(err)
|
|
|
+ return err, 0
|
|
|
+ }
|
|
|
+ if c.Model.ModelName != "" {
|
|
|
+ tmpM.ModelName = c.Model.ModelName + tmpM.ModelName
|
|
|
+ } else {
|
|
|
+ tmpM.ModelName = "[检测模型]" + tmpM.ModelName
|
|
|
+ }
|
|
|
+ sql := "insert into t_data_model_defualt(model_name,area_type,vol_id,line_link_style,ied_types,relation_json,is_sys,from_model_id)values(?,?,?,?,?,?,?,?)"
|
|
|
+ r, err := o.Raw(sql, []interface{}{tmpM.ModelName, tmpM.AreaType, tmpM.VolId, tmpM.LineLinkStyle, tmpM.IedTypes, tmpM.RelationJson, 2, modelid}).Exec()
|
|
|
if err != nil {
|
|
|
logger.Logger.Error(err)
|
|
|
dblog.Description = fmt.Sprintf("复制%s%s失败:%s", sysCheckModelDesc, c.Model.ModelName, err.Error())
|
|
|
@@ -302,7 +326,7 @@ func (c *SysCheckModelMgr) Copy(newmodelname string) (error, int) {
|
|
|
} else {
|
|
|
m2 := new(SysCheckModelIedRelationMgr)
|
|
|
m2.SetUserInfo(c.GetUserInfo())
|
|
|
- m2.Model.ModelId = c.Model.Id
|
|
|
+ m2.Model = T_data_model_relation_def{ModelId: modelid}
|
|
|
newid, _ := r.LastInsertId()
|
|
|
err, _ = m2.Copy(int(newid))
|
|
|
if err != nil {
|
|
|
@@ -312,19 +336,34 @@ func (c *SysCheckModelMgr) Copy(newmodelname string) (error, int) {
|
|
|
dblog.Fail2()
|
|
|
return err, 0
|
|
|
}
|
|
|
+ //复制功能及端子信息
|
|
|
+ m3 := new(SysCheckModelIedFuncMgr)
|
|
|
+ m3.SetUserInfo(c.GetUserInfo())
|
|
|
+ err = m3.Copy(tmpM.Id, int(newid))
|
|
|
+ if err != nil {
|
|
|
+ c.Model.Id = int(newid)
|
|
|
+ c.Delete()
|
|
|
+ m2.Model.ModelId = int(newid)
|
|
|
+ m2.Delete()
|
|
|
+ dblog.Description = fmt.Sprintf("复制%s%s失败:%s", sysCheckModelDesc, c.Model.ModelName, err.Error())
|
|
|
+ dblog.Fail2()
|
|
|
+ return err, 0
|
|
|
+ }
|
|
|
dblog.Description = fmt.Sprintf("复制%s%s成功", sysCheckModelDesc, c.Model.ModelName)
|
|
|
dblog.Success2()
|
|
|
- id, _ := r.LastInsertId()
|
|
|
- return nil, int(id)
|
|
|
+ return nil, int(newid)
|
|
|
}
|
|
|
- return nil, 0
|
|
|
}
|
|
|
|
|
|
//获取指定电压等级下的所有模型
|
|
|
-func (c *SysCheckModelMgr) GetModelsByVolid() ([]orm.Params, error) {
|
|
|
+func (c *SysCheckModelMgr) GetModelsByVolid(is_sys ...int) ([]orm.Params, error) {
|
|
|
o := orm.NewOrm()
|
|
|
- sqlParamters := []interface{}{}
|
|
|
- sql := "select t.id, t.model_name,t.area_type,c.code area_type_code,c.name area_type_name ,t.ied_types,t.is_sys ,c1.`code` vol_code,c1.`name` vol_name from t_data_model_defualt t INNER JOIN global_const_code c on c.id=t.area_type and c.parentcode='area_type' INNER JOIN global_const_code c1 on t.vol_id=c1.id and c1.parentcode='voltage_level' "
|
|
|
+ s := 1
|
|
|
+ if len(is_sys) > 0 {
|
|
|
+ s = is_sys[0]
|
|
|
+ }
|
|
|
+ sqlParamters := []interface{}{s}
|
|
|
+ sql := "select t.id, t.model_name,t.area_type,c.code area_type_code,c.name area_type_name ,t.ied_types,t.is_sys ,c1.`code` vol_code,c1.`name` vol_name from t_data_model_defualt t INNER JOIN global_const_code c on c.id=t.area_type and c.parentcode='area_type' INNER JOIN global_const_code c1 on t.vol_id=c1.id and c1.parentcode='voltage_level' where t.is_sys=? "
|
|
|
rowset := []orm.Params{}
|
|
|
_, err := o.Raw(sql, sqlParamters).Values(&rowset)
|
|
|
if err != nil {
|