Jelajahi Sumber

修复间隔相关bug

liling 1 tahun lalu
induk
melakukan
b2ddff0eaf

+ 4 - 4
service/controllers/busAdminController.go

@@ -570,9 +570,9 @@ func (c *BusAdminController) AddCheckArea() {
 		return
 	}
 	model_id, _ := c.GetInt("model_id")
-	area_type := c.GetString("area_type")
+	//area_type := c.GetString("area_type")
 	area_name := c.GetString("area_name")
-	if model_id == 0 || area_type == "" || area_name == "" {
+	if model_id == 0 || area_name == "" {
 		c.Data["json"] = c.ResultError("参数不能为空!")
 		c.ServeJSON()
 		return
@@ -580,7 +580,7 @@ func (c *BusAdminController) AddCheckArea() {
 	obj := new(bo.CheckAreaMgr)
 	obj.SetUserInfo(c.GetCurrentUserInfo())
 	obj.ScdId = id
-	lst, err := obj.Save(model_id, area_type, area_name)
+	lst, err := obj.Save(model_id, area_name)
 	if err != nil {
 		c.Data["json"] = c.ResultError(err.Error())
 		c.ServeJSON()
@@ -775,7 +775,7 @@ func (c *BusAdminController) SaveCheckAreaIedNoByAreaID() {
 		return
 	}
 	if ied_name == "" {
-		c.Data["json"] = c.ResultError("装置名称不能为空!")
+		c.Data["json"] = c.ResultError("装置名称不能为空!(如果是追加装置需要先保存后再设置)")
 		c.ServeJSON()
 		return
 	}

+ 64 - 24
service/models/bo/checktools_area.go

@@ -133,17 +133,25 @@ func (c *CheckAreaMgr) Init(scdid int64) {
 }
 
 //保存间隔
-func (c *CheckAreaMgr) Save(model_id int, area_type, area_name string) (int, error) {
+func (c *CheckAreaMgr) Save(model_id int, area_name string) (int, error) {
 	//判断间隔名称是否重复
 	db := orm.NewOrm()
 	rowset := []orm.Params{}
-	db.Raw("select id from t_data_check_area where scd_id=?", c.ScdId).Values(&rowset)
+	db.Raw("select id from t_data_check_area where scd_id=? and area_name=?", c.ScdId, area_name).Values(&rowset)
 	if len(rowset) > 0 {
 		return 0, errors.New("间隔名称" + area_name + "已存在")
 	}
+	modelMgr := new(SysCheckModelMgr)
+	modelMgr.Model.Id = model_id
+	modelInfo, err := modelMgr.One()
+	if err != nil {
+		return 0, err
+	}
+	areatype_codeinfo := new(Global).GetCodeInfoByID(tools.IsEmpty(modelInfo.AreaType))
+	area_type := tools.IsEmpty(areatype_codeinfo["code"])
 	cr := c.GetUserId()
 	paras := []interface{}{c.ScdId, area_name, area_type, model_id, cr}
-	r, err := db.Raw("insert into t_data_check_area(scd_id,area_name,area_type,model_id,cr)values(?,?,?,?,?)", paras).Exec()
+	r, err := db.Raw("insert into t_data_check_area(scd_id,area_name,area_type,model_id,cr,voltage_level)values(?,?,?,?,?,0)", paras).Exec()
 	sqllog := fmt.Sprintf("添加新间隔%s", area_name)
 	if err != nil {
 		logger.Logger.Error(err)
@@ -1549,11 +1557,16 @@ func (c *CheckAreaMgr) pT(modelid int, vol, iedtypes string, ieds map[string]orm
 					for _, in := range iedname {
 						tmpIednameParts := scdParseMgr.ParseIedName(in)
 						if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
+							if hasIedNameMap[in] == 1 {
+								break
+							}
+							hasIedNameMap[in] = 1
 							insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, ptype[0:1], ptype[1:]))
 							break
 						}
 					}
 				}
+				continue
 			}
 			//判断间隔是否需要包含本体保护装置
 			if strings.Contains(tyCode, "#0") {
@@ -1562,11 +1575,16 @@ func (c *CheckAreaMgr) pT(modelid int, vol, iedtypes string, ieds map[string]orm
 					for _, in := range iedname {
 						tmpIednameParts := scdParseMgr.ParseIedName(in)
 						if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
+							if hasIedNameMap[in] == 1 {
+								break
+							}
+							hasIedNameMap[in] = 1
 							insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, ptype[0:1], ptype[1:]))
 							break
 						}
 					}
 				}
+				continue
 			}
 			dlIeds := []orm.Params{}
 			imtcode := c.getIedTypeCode(modelid, tyCode)
@@ -1639,7 +1657,6 @@ func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm
 		if tools.IsEmpty(row["vol"]) != vol || tools.IsEmpty(row["ied_type"]) != iedCode[0:1] || tools.IsEmpty(row["p_type"]) != iedCode[1:] {
 			continue
 		}
-		pmIedName := ""
 		mmIedName := ""
 		pl_iedname := tools.IsEmpty(row["ied_name"])
 		if _, h := groupList[pl_iedname]; h {
@@ -1669,6 +1686,7 @@ func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm
 			logger.Logger.Error(err)
 			return
 		}
+		hasIedNameMap := map[string]int{}
 		ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
 		insvalues := []string{}
 		pmCode := c.getIedTypeCode(modelid, "PM")
@@ -1690,29 +1708,20 @@ func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm
 				continue
 			}
 			ptype := strings.Split(tyCode, "#")[0]
-			if tyCode == pmCode {
+			if ptype == pmCode {
 				//母线保护和母线合并单元装置编号跟随变压器
 				//查找变压器编号
 				//1号变压器->2号变压器->3号
 				inAreaIedName = c.getPMName(iednameParts, ieds)
-				pmIedName = inAreaIedName
-				if mmIedName == "" {
-					insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:2]))
-					//pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
-					//使用PM装置的名称去定义MM的名称
-					tyCode = mmCode
-					inAreaIedName = c.getMMName(iednameParts, ieds, iednameParts[7])
-					mmIedName = inAreaIedName
-				}
-			} else if tyCode == mmCode {
-				if pmIedName != "" && mmIedName == "" {
-					//pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
-					//使用PM装置的名称去定义MM的名称
-					inAreaIedName = c.getMMName(iednameParts, ieds, iednameParts[7])
-					mmIedName = inAreaIedName
-				} else {
+				if hasIedNameMap[inAreaIedName] == 1 {
 					continue
 				}
+				hasIedNameMap[inAreaIedName] = 1
+				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:2]))
+				continue
+			} else if ptype == mmCode {
+				//最后处理
+				continue
 			} else {
 				inAreaIedName = ptype + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
 			}
@@ -1734,6 +1743,10 @@ func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm
 					break
 				}
 			}
+			if hasIedNameMap[inAreaIedName] == 1 {
+				continue
+			}
+			hasIedNameMap[inAreaIedName] = 1
 			insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:]))
 		}
 		_, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
@@ -1791,6 +1804,7 @@ func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm
 			logger.Logger.Error(err)
 			return
 		}
+		hasIedNameMap := map[string]int{}
 		ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
 		insvalues := []string{}
 		pmCode := c.getIedTypeCode(modelid, "PM")
@@ -1803,13 +1817,17 @@ func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm
 			tyCode := c.getIedTypeCode(modelid, ty)
 			ptype := strings.Split(tyCode, "#")[0]
 			inAreaIedName := ""
-			if tyCode == pmCode {
+			if ptype == pmCode {
 				//母线保护和母线合并单元装置编号跟随变压器
 				//查找变压器编号
 				//1号变压器->2号变压器->3号
 				inAreaIedName = c.getPMName(iednameParts, ieds)
 				pmIedName = inAreaIedName
 				if mmIedName == "" {
+					if hasIedNameMap[inAreaIedName] == 1 {
+						continue
+					}
+					hasIedNameMap[inAreaIedName] = 1
 					insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:]))
 					pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
 					//使用PM装置的名称去定义MM的名称
@@ -1817,7 +1835,7 @@ func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm
 					inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
 					mmIedName = inAreaIedName
 				}
-			} else if tyCode == mmCode {
+			} else if ptype == mmCode {
 				if pmIedName != "" && mmIedName == "" {
 					pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
 					//使用PM装置的名称去定义MM的名称
@@ -1834,6 +1852,10 @@ func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm
 					inAreaIedName = ptype + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6]
 				}
 			}
+			if hasIedNameMap[inAreaIedName] == 1 {
+				continue
+			}
+			hasIedNameMap[inAreaIedName] = 1
 			insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:]))
 		}
 		_, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
@@ -1912,6 +1934,7 @@ func (c *CheckAreaMgr) pM(modelid int, vol, iedtypes string, ieds map[string]orm
 				break
 			}
 		}
+		hasIedNameMap := map[string]int{}
 		ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
 		insvalues := []string{}
 		mmCode := c.getIedTypeCode(modelid, "MM")
@@ -1936,6 +1959,10 @@ func (c *CheckAreaMgr) pM(modelid int, vol, iedtypes string, ieds map[string]orm
 				//MM:母线合并单元
 				inAreaIedName = c.getMMName(iednameParts, ieds, abCode)
 				if inAreaIedName != "" {
+					if hasIedNameMap[inAreaIedName] == 1 {
+						continue
+					}
+					hasIedNameMap[inAreaIedName] = 1
 					insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:]))
 				}
 			} else {
@@ -1946,18 +1973,30 @@ func (c *CheckAreaMgr) pM(modelid int, vol, iedtypes string, ieds map[string]orm
 				case "hight":
 					for _, item := range h {
 						inAreaIedName = tools.IsEmpty(item["ied_name"])
+						if hasIedNameMap[inAreaIedName] == 1 {
+							continue
+						}
+						hasIedNameMap[inAreaIedName] = 1
 						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:]))
 					}
 					break
 				case "middle":
 					for _, item := range m {
 						inAreaIedName = tools.IsEmpty(item["ied_name"])
+						if hasIedNameMap[inAreaIedName] == 1 {
+							continue
+						}
+						hasIedNameMap[inAreaIedName] = 1
 						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:]))
 					}
 					break
 				case "low":
 					for _, item := range l {
 						inAreaIedName = tools.IsEmpty(item["ied_name"])
+						if hasIedNameMap[inAreaIedName] == 1 {
+							continue
+						}
+						hasIedNameMap[inAreaIedName] = 1
 						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ptype[0:1], ptype[1:]))
 					}
 					break
@@ -2429,7 +2468,8 @@ func (c *CheckAreaMgr) getMMName(iednameParts []string, ieds map[string]orm.Para
 			return n
 		}
 	}
-	return ""
+	//理论上的装置名称
+	return "MM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + ab
 }
 
 //获取装置编码中的套别代码(A、B..)