Browse Source

修改部分BUG

liling 1 year ago
parent
commit
229fd22929

+ 27 - 10
service/models/bo/check_sys_model.go

@@ -126,7 +126,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 				for _, ritem := range nodes {
 					ritem2 := ritem.(map[string]interface{})
 					nodetype := tools.IsEmpty(ritem2["type"])
-					if nodetype == "group" {
+					if nodetype == "my-group" {
 						properties := ritem2["properties"].(map[string]interface{})
 						iedtypes = append(iedtypes, tools.IsEmpty(properties["ied_type"]))
 						continue
@@ -145,16 +145,13 @@ func (c *SysCheckModelMgr) Save() (err error) {
 		}
 		newid, err2 := db.Insert(&c.Model)
 		if err2 == nil {
+			c.Model.Id = int(newid)
 			//添加接线方式与模型关系
 			lm := new(LinkStyleModelMgr)
 			lm.Model.LinkstyleId = c.Model.LineLinkStyle
 			lm.Model.ModelId = int(newid)
 			lm.SetUserInfo(c.GetUserInfo())
 			lm.Save()
-			//保存装置分组
-			bgm := new(SysCheckModelIedtypeGroupMgr)
-			bgm.Model = T_data_model_iedtype_group{ModelId: int(newid)}
-			bgm.Save(c.Model.RelationJson)
 			if c.Model.RelationJson != "" {
 				m2 := new(SysCheckModelIedRelationMgr)
 				m2.SetUserInfo(c.GetUserInfo())
@@ -240,7 +237,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 				for _, ritem := range nodes {
 					ritem2 := ritem.(map[string]interface{})
 					nodetype := tools.IsEmpty(ritem2["type"])
-					if nodetype == "group" {
+					if nodetype == "my-group" {
 						//装置分组
 						properties := ritem2["properties"].(map[string]interface{})
 						tmp := tools.IsEmpty(properties["ied_type"])
@@ -293,6 +290,10 @@ func (c *SysCheckModelMgr) Save() (err error) {
 	} else {
 		dblog.Description = fmt.Sprintf("保存%s信息成功,操作数据:%+v", sysCheckModelDesc, c.Model)
 		dblog.Success2()
+		//保存装置分组
+		bgm := new(SysCheckModelIedtypeGroupMgr)
+		bgm.Model = T_data_model_iedtype_group{ModelId: c.Model.Id}
+		bgm.Save(c.Model.RelationJson)
 	}
 	return err
 }
@@ -312,14 +313,30 @@ func (c *SysCheckModelMgr) One() (T_data_model_defualt, error) {
 
 //更新指定模型中的指定装置类型编码
 func (c *SysCheckModelMgr) UpdateIedType(oldiedtype, newiedtype string) error {
+	c.Model, _ = c.One()
 	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
+	//判断修改的是否是分组的自定义装置类型
+	groupMapping := new(SysCheckModelIedtypeGroupMgr)
+	groupMapping.Model = T_data_model_iedtype_group{ModelId: c.Model.Id}
+	rowset := groupMapping.List()
+	for _, g := range rowset {
+		if g == oldiedtype {
+			db := orm.NewOrm()
+			db.Raw("update t_data_model_relation_def set from_ied_code=? where model_id=? and from_ied_code=?", newiedtype, c.Model.Id, oldiedtype).Exec()
+			db.Raw("update t_data_model_relation_def set to_ied_code=? where model_id=? and to_ied_code=?", newiedtype, c.Model.Id, oldiedtype).Exec()
+			db.Raw("update t_data_model_iedtype_group set ied_type=? where model_id=? and ied_type=?", newiedtype, c.Model.Id, oldiedtype).Exec()
+			dblog.Description = fmt.Sprintf("设置%s%s装置类型编码(%s->%s)成功", sysCheckModelDesc, c.Model.ModelName, oldiedtype, newiedtype)
+			dblog.Success2()
+			return nil
+		}
+	}
 	mapping := new(SysCheckModelIedtypeMappingMgr)
-	mapping.Model = T_data_model_iedtype_maping{ModelId: c.Model.Id}
+	mapping.Model = T_data_model_iedtype_mapping{ModelId: c.Model.Id}
 	mapping.Model.IedType = oldiedtype
 	mapping.Model.MappingIedType = newiedtype
 	err := mapping.Save()
@@ -336,7 +353,7 @@ func (c *SysCheckModelMgr) UpdateIedType(oldiedtype, newiedtype string) error {
 //获取指定装置类型的自定义类型编码
 func (c *SysCheckModelMgr) GetIedtypeMapping(iedtype string) string {
 	mapping := new(SysCheckModelIedtypeMappingMgr)
-	mapping.Model = T_data_model_iedtype_maping{ModelId: c.Model.Id}
+	mapping.Model = T_data_model_iedtype_mapping{ModelId: c.Model.Id}
 	mapping.Model.IedType = iedtype
 	re := mapping.List()
 	if len(re) == 0 {
@@ -379,7 +396,7 @@ func (c *SysCheckModelMgr) Delete() (err error) {
 		bgm.Model = T_data_model_iedtype_group{ModelId: c.Model.Id}
 		bgm.Delete()
 		obj1 := new(SysCheckModelIedtypeMappingMgr)
-		obj1.Model = T_data_model_iedtype_maping{ModelId: c.Model.Id}
+		obj1.Model = T_data_model_iedtype_mapping{ModelId: c.Model.Id}
 		obj1.Delete()
 		dblog.Description = fmt.Sprintf("删除%s%s成功", sysCheckModelDesc, c.Model.ModelName)
 		dblog.Success2()
@@ -433,7 +450,7 @@ func (c *SysCheckModelMgr) Copy(modelid int) (error, int) {
 		bgm.Copy(int(newid))
 		//复制装置类型自定义信息
 		obj1 := new(SysCheckModelIedtypeMappingMgr)
-		obj1.Model = T_data_model_iedtype_maping{ModelId: c.Model.Id}
+		obj1.Model = T_data_model_iedtype_mapping{ModelId: c.Model.Id}
 		obj1.Copy(int(newid))
 		//复制功能及端子信息
 		m3 := new(SysCheckModelIedFuncMgr)

+ 2 - 2
service/models/bo/check_sysmodel_ied_func.go

@@ -300,11 +300,11 @@ func (c *SysCheckModelIedFuncMgr) Imp(param map[string]interface{}) (bool, error
 		if svorgoose == "" {
 			return false, errors.New(fmt.Sprintf("第%d行:信号类型不能为空", i))
 		}
-		inorout := strings.ReplaceAll(row[7], ",", ",")
+		inorout := strings.ReplaceAll(strings.ReplaceAll(row[7], "&", ","), ",", ",")
 		if inorout == "" {
 			return false, errors.New(fmt.Sprintf("第%d行:信号方向不能为空", i))
 		}
-		receive_ied_type := strings.ReplaceAll(row[8], ",", ",") //对侧接收装置类型
+		receive_ied_type := strings.ReplaceAll(strings.ReplaceAll(row[8], "&", ","), ",", ",") //对侧接收装置类型
 		funckey := fmt.Sprintf("%d%s%s", modelId, ied_type, func_name)
 		func_id = funcMap[funckey]
 		if func_id == 0 {

+ 6 - 2
service/models/bo/check_sysmodel_ied_relation.go

@@ -82,7 +82,9 @@ func (c *SysCheckModelIedRelationMgr) Save(nodes map[string]interface{}) (err er
 			item := tmpMap[sourceied].(map[string]interface{})
 			newm.FromIedCode = tools.IsEmpty(item["properties"].(map[string]interface{})["ied_type"])
 			newIedTypes[newm.FromIedCode] = newm.FromIedCode
-			newm.FromIedName = tools.IsEmpty(item["text"].(map[string]interface{})["value"])
+			if item["text"] != nil {
+				newm.FromIedName = tools.IsEmpty(item["text"].(map[string]interface{})["value"])
+			}
 			if isSv == "" {
 				newm.InType = "GOOSE"
 			} else {
@@ -91,7 +93,9 @@ func (c *SysCheckModelIedRelationMgr) Save(nodes map[string]interface{}) (err er
 			item = tmpMap[targetied].(map[string]interface{})
 			newm.ToIedCode = tools.IsEmpty(item["properties"].(map[string]interface{})["ied_type"])
 			newIedTypes[newm.ToIedCode] = newm.ToIedCode
-			newm.ToIedName = tools.IsEmpty(item["text"].(map[string]interface{})["value"])
+			if item["text"] != nil {
+				newm.ToIedName = tools.IsEmpty(item["text"].(map[string]interface{})["value"])
+			}
 			_, err = db.Insert(&newm)
 			if err != nil {
 				logger.Logger.Error(err)

+ 15 - 10
service/models/bo/check_sysmodel_iedtype_group.go

@@ -58,6 +58,7 @@ func (c *SysCheckModelIedtypeGroupMgr) Save(jsonstr string) {
 	if err != nil {
 		return
 	}
+	c.Delete()
 	if modelJson["nodes"] != nil {
 		db := orm.NewOrm()
 		nodes := modelJson["nodes"].([]interface{})
@@ -65,7 +66,7 @@ func (c *SysCheckModelIedtypeGroupMgr) Save(jsonstr string) {
 		for _, ritem := range nodes {
 			ritem2 := ritem.(map[string]interface{})
 			nodetype := tools.IsEmpty(ritem2["type"])
-			if nodetype != "group" {
+			if nodetype != "my-group" {
 				continue
 			}
 			childrens := ritem2["children"]
@@ -77,37 +78,41 @@ func (c *SysCheckModelIedtypeGroupMgr) Save(jsonstr string) {
 			if gtype == "" {
 				continue
 			}
-			for _, ci := range childrens.([]string) {
-				groupIedTypes[ci] = gtype
+			for _, ci := range childrens.([]interface{}) {
+				groupIedTypes[tools.IsEmpty(ci)] = gtype
 			}
 		}
 		for _, ritem := range nodes {
 			ritem2 := ritem.(map[string]interface{})
 			nodetype := tools.IsEmpty(ritem2["type"])
-			if nodetype == "group" {
+			if nodetype == "my-group" {
 				continue
 			}
-			properties := ritem.(map[string]interface{})["properties"].(map[string]interface{})
+			nodeid := tools.IsEmpty(ritem2["id"])
+			if groupIedTypes[nodeid] == "" {
+				continue
+			}
+			properties := ritem2["properties"].(map[string]interface{})
 			iedtype := tools.IsEmpty(properties["ied_type"])
-			if iedtype == "" || groupIedTypes[iedtype] == "" {
+			if iedtype == "" {
 				continue
 			}
-			db.Raw("insert into t_data_model_iedtype_group(model_id,ied_type,children_type)values(?,?,?)", c.Model.ModelId, groupIedTypes[iedtype], iedtype).Exec()
+			db.Raw("insert into t_data_model_iedtype_group(model_id,ied_type,children_type)values(?,?,?)", c.Model.ModelId, groupIedTypes[nodeid], iedtype).Exec()
 		}
 	}
 }
 
 func (c *SysCheckModelIedtypeGroupMgr) List() map[string]string {
+	result := map[string]string{}
 	if c.Model.ModelId == 0 {
-		return nil
+		return result
 	}
-	result := map[string]string{}
 	db := orm.NewOrm()
 	rowset := []orm.Params{}
 	_, err := db.Raw("select ied_type,children_type from t_data_model_iedtype_group where model_id=?", c.Model.ModelId).Values(&rowset)
 	if err != nil {
 		logger.Logger.Error(err)
-		return nil
+		return result
 	} else {
 		for _, row := range rowset {
 			result[tools.IsEmpty(row["children_type"])] = tools.IsEmpty(row["ied_type"])

+ 7 - 4
service/models/bo/check_sysmodel_iedtype_mapping.go

@@ -11,7 +11,7 @@ import (
 
 var mapps = sync.Map{}
 
-type T_data_model_iedtype_maping struct {
+type T_data_model_iedtype_mapping struct {
 	Id             int `orm:"pk"`
 	ModelId        int // '模型ID' ,
 	IedType        string
@@ -20,12 +20,12 @@ type T_data_model_iedtype_maping struct {
 
 //内置检测模型-装置分组管理
 type SysCheckModelIedtypeMappingMgr struct {
-	Model T_data_model_iedtype_maping
+	Model T_data_model_iedtype_mapping
 	DeviceBaseModel
 }
 
 func init() {
-	orm.RegisterModel(new(T_data_model_iedtype_maping))
+	orm.RegisterModel(new(T_data_model_iedtype_mapping))
 }
 
 func (c *SysCheckModelIedtypeMappingMgr) Delete() {
@@ -61,6 +61,9 @@ func (c *SysCheckModelIedtypeMappingMgr) Copy(new_modelid int) {
 }
 
 func (c *SysCheckModelIedtypeMappingMgr) Save() error {
+	mapps.Delete(fmt.Sprintf("%d", c.Model.ModelId))
+	key := fmt.Sprintf("%d%s", c.Model.ModelId, c.Model.IedType)
+	mapps.Delete(key)
 	db := orm.NewOrm()
 	if c.Model.Id > 0 {
 		_, err := db.Update(&c.Model)
@@ -97,7 +100,7 @@ func (c *SysCheckModelIedtypeMappingMgr) List() map[string]string {
 		return nil
 	} else {
 		for _, row := range rowset {
-			result[tools.IsEmpty(row["ied_type"])] = tools.IsEmpty(row["mapping_type"])
+			result[tools.IsEmpty(row["ied_type"])] = tools.IsEmpty(row["mapping_ied_type"])
 		}
 		mapps.Store(key, result)
 	}

+ 3 - 3
service/models/bo/checktools_area.go

@@ -881,7 +881,7 @@ func (c *CheckAreaMgr) ParseModelArea() {
 			//modelname := tools.IsEmpty(row["model_name"])
 			iedtypes := tools.IsEmpty(row["ied_types"])
 			mapptype := new(SysCheckModelIedtypeMappingMgr)
-			mapptype.Model = T_data_model_iedtype_maping{ModelId: modelid}
+			mapptype.Model = T_data_model_iedtype_mapping{ModelId: modelid}
 			mappresult := mapptype.List()
 			if len(mappresult) > 0 {
 				tmp := []string{}
@@ -931,7 +931,7 @@ func (c *CheckAreaMgr) ParseModelArea() {
 		}
 		//获取模型中的自定义装置类型编码
 		mapptype := new(SysCheckModelIedtypeMappingMgr)
-		mapptype.Model = T_data_model_iedtype_maping{ModelId: modelid}
+		mapptype.Model = T_data_model_iedtype_mapping{ModelId: modelid}
 		mappresult := mapptype.List()
 		if len(mappresult) > 0 {
 			tmp := []string{}
@@ -959,7 +959,7 @@ func (c *CheckAreaMgr) ParseModelArea() {
 //根据默认装置类型获取其类型编码。如果没有自定义编码,则返回默认编码
 func (c *CheckAreaMgr) getIedTypeCode(modelid int, iedtype string) string {
 	mapptype := new(SysCheckModelIedtypeMappingMgr)
-	mapptype.Model = T_data_model_iedtype_maping{ModelId: modelid}
+	mapptype.Model = T_data_model_iedtype_mapping{ModelId: modelid}
 	mapptype.Model.IedType = iedtype
 	mappresult := mapptype.List()
 	ptCode := iedtype