瀏覽代碼

实现母线间隔解析

liling 1 年之前
父節點
當前提交
fa4b99b060

+ 20 - 2
service/controllers/busAdminController.go

@@ -310,8 +310,10 @@ func (c *BusAdminController) SaveSysModelInfo() {
 // 	@Tags         业务管理服务
 // 	@Accept       x-www-form-urlencoded
 // 	@Produce      json
-//	@Param 	id 		formData   int  	true 	"模型ID"
-//	@Param 	newname formData   string  	true 	"新模型名称"
+//	@Param 	id 				formData   int  	true 	"被复制模型的ID"
+//	@Param 	newname 		formData   string  	true 	"新模型名称"
+//	@Param 	vol_id 			formData   int  	false 	"目标电压等级ID"
+//	@Param 	link_style_id 	formData   int	  	false 	"目标接线方式ID"
 // 	@Success     200    {object} ResultOK 成功
 // 	@Failure 	 500 	{object} ResultError  失败
 // @router /admin/sysmodel/saveas [post]
@@ -329,6 +331,22 @@ func (c *BusAdminController) CopySysModelByID() {
 	obj.Model = bo.T_data_model_defualt{Id: id}
 	obj.Model.Id = id
 	obj.Model.ModelName = new_name
+	//判断名称是否已存在
+	h, _ := obj.ExistName(new_name)
+	if h {
+		c.Data["json"] = c.ResultError("当前的模型名称已存在")
+		c.ServeJSON()
+		return
+	}
+	volid, _ := c.GetInt("vol_id")
+	linkid, _ := c.GetInt("link_style_id")
+	if volid > 0 {
+		obj.Model.VolId = volid
+	}
+	if linkid > 0 {
+		obj.Model.LineLinkStyle = linkid
+	}
+	obj.Model.IsSys = 1
 	err, newid := obj.Copy(id)
 	if err != nil {
 		c.Data["json"] = c.ResultError(err.Error())

+ 18 - 3
service/models/bo/check_sys_model.go

@@ -420,12 +420,27 @@ func (c *SysCheckModelMgr) Copy(modelid int) (error, int) {
 		return err, 0
 	}
 	if c.Model.ModelName != "" {
-		tmpM.ModelName = c.Model.ModelName + tmpM.ModelName
+		if c.Model.IsSys == 2 {
+			tmpM.ModelName = c.Model.ModelName + tmpM.ModelName
+		} else {
+			tmpM.ModelName = c.Model.ModelName
+		}
 	} else {
 		tmpM.ModelName = "[检测模型]" + tmpM.ModelName
 	}
+	if c.Model.VolId > 0 {
+		tmpM.VolId = c.Model.VolId
+	}
+	if c.Model.LineLinkStyle > 0 {
+		tmpM.LineLinkStyle = c.Model.LineLinkStyle
+	}
+	if c.Model.IsSys > 0 {
+		tmpM.IsSys = c.Model.IsSys
+	} else {
+		tmpM.IsSys = 2
+	}
 	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()
+	r, err := o.Raw(sql, []interface{}{tmpM.ModelName, tmpM.AreaType, tmpM.VolId, tmpM.LineLinkStyle, tmpM.IedTypes, tmpM.RelationJson, tmpM.IsSys, modelid}).Exec()
 	if err != nil {
 		logger.Logger.Error(err)
 		dblog.Description = fmt.Sprintf("复制%s%s失败:%s", sysCheckModelDesc, c.Model.ModelName, err.Error())
@@ -450,7 +465,7 @@ func (c *SysCheckModelMgr) Copy(modelid int) (error, int) {
 		bgm.Copy(int(newid))
 		//复制装置类型自定义信息
 		obj1 := new(SysCheckModelIedtypeMappingMgr)
-		obj1.Model = T_data_model_iedtype_mapping{ModelId: c.Model.Id}
+		obj1.Model = T_data_model_iedtype_mapping{ModelId: modelid}
 		obj1.Copy(int(newid))
 		//复制功能及端子信息
 		m3 := new(SysCheckModelIedFuncMgr)

+ 150 - 11
service/models/bo/checktools_area.go

@@ -1040,6 +1040,10 @@ func (c *CheckAreaMgr) ParseModelArea() {
 		if areaCode == "L" {
 			c.pL(modelid, volcode, iedtypes, iedMap)
 		}
+		//母线间隔分析:PM
+		if areaCode == "M" {
+			c.pM(modelid, volcode, iedtypes, iedMap)
+		}
 	}
 }
 
@@ -1175,6 +1179,11 @@ func (c *CheckAreaMgr) pT(modelid int, iedtypes string, ieds map[string]orm.Para
 				//装置如果是分组成员装置,则不用检测
 				continue
 			}
+			//判断是否指定的套别标识
+			abCode := c.getIedTypeABCode(ty)
+			if abCode != "" {
+				iednameParts[7] = abCode
+			}
 			tyCode := c.getIedTypeCode(modelid, ty)
 			if _, h := groupList[tyCode]; h {
 				//装置如果是分组成员装置,则不用检测
@@ -1190,11 +1199,6 @@ func (c *CheckAreaMgr) pT(modelid int, iedtypes string, ieds map[string]orm.Para
 				delMm = true
 				continue
 			}
-			//判断是否指定的套别标识
-			abCode := c.getIedTypeABCode(tyCode)
-			if abCode != "" {
-				iednameParts[7] = abCode
-			}
 			//判断间隔是否需要包含差动装置
 			if strings.Contains(tyCode, "#C") {
 				_, iedname := getIedByDesc(ieds, tyCode, "差动")
@@ -1329,15 +1333,15 @@ func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm
 				//装置如果是分组成员装置,则不用检测
 				continue
 			}
+			abCode := c.getIedTypeABCode(ty)
+			if abCode != "" {
+				iednameParts[7] = abCode
+			}
 			tyCode := c.getIedTypeCode(modelid, ty)
 			if _, h := groupList[tyCode]; h {
 				//装置如果是分组成员装置,则不用检测
 				continue
 			}
-			abCode := c.getIedTypeABCode(tyCode)
-			if abCode != "" {
-				iednameParts[7] = abCode
-			}
 			if tyCode == pmCode {
 				//母线保护和母线合并单元装置编号跟随变压器
 				//查找变压器编号
@@ -1446,6 +1450,10 @@ func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm
 		pmCode := c.getIedTypeCode(modelid, "PM")
 		mmCode := c.getIedTypeCode(modelid, "MM")
 		for _, ty := range strings.Split(iedtypes, ",") {
+			abCode := c.getIedTypeABCode(ty)
+			if abCode != "" {
+				iednameParts[7] = abCode
+			}
 			tyCode := c.getIedTypeCode(modelid, ty)
 			inAreaIedName := ""
 			if tyCode == pmCode {
@@ -1492,6 +1500,134 @@ func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm
 
 }
 
+//母线间隔装置提取
+func (c *CheckAreaMgr) pM(modelid int, vol, iedtypes string, ieds map[string]orm.Params) {
+	scdParseMgr := new(ScdParse)
+	scdNodeMgr := new(ScdNode)
+	db := orm.NewOrm()
+	//获取当前站的各电压等级
+	volRows := []orm.Params{}
+	_, err := db.Raw("select t.vol, CAST(REPLACE(UPPER(g.name),'KV','') as SIGNED) volname from t_area_ied_relation t,global_const_code g  where g.code=CONCAT('v_level_',t.vol) and g.parentcode='voltage_level' and  t.vol!=999 and t.scd_id=? GROUP BY t.vol ORDER BY volname desc", c.ScdId).Values(&volRows)
+	if err != nil {
+		logger.Logger.Error(err)
+		return
+	}
+	if len(volRows) == 0 {
+		logger.Logger.Error(errors.New("该scd未发现任何电压等级的装置"))
+		return
+	}
+	volMap := map[string]string{}
+	volMap["hight"] = tools.IsEmpty(volRows[0]["vol"]) //高压电压
+	if len(volRows) == 2 {
+		volMap["middle"] = ""
+		volMap["low"] = volRows[1]["vol"].(string) //低压电压等级
+	} else {
+		volMap["middle"] = volRows[1]["vol"].(string)           //中压电压等级
+		volMap["low"] = volRows[len(volRows)-1]["vol"].(string) //低压电压等级
+	}
+	//获取装置分组信息
+	bgm := new(SysCheckModelIedtypeGroupMgr)
+	bgm.Model = T_data_model_iedtype_group{ModelId: modelid}
+	groupList := bgm.List()
+	scdXmlObj, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
+	iedCode := c.getIedTypeCode(modelid, "PM")
+	for _, row := range ieds {
+		if tools.IsEmpty(row["vol"]) != vol || tools.IsEmpty(row["ied_type"]) != iedCode[0:1] || tools.IsEmpty(row["p_type"]) != iedCode[1:] {
+			continue
+		}
+		pl_iedname := tools.IsEmpty(row["ied_name"])
+		iednameParts := scdParseMgr.ParseIedName(pl_iedname)
+		areadesc := tools.IsEmpty(row["ied_desc"])
+		if areadesc == "" {
+			iedobj := scdNodeMgr.GetIed(scdXmlObj, "", pl_iedname)
+			if iedobj != nil {
+				areadesc = iedobj.Desc
+			} else {
+				areadesc = tools.IsEmpty(row["area_name"])
+			}
+		}
+		areadesc = strings.ReplaceAll(areadesc, "装置", "")
+		//添加间隔数据
+		dbdata := T_data_check_area{
+			ModelId:  modelid,
+			ScdId:    c.ScdId,
+			AreaType: "M",
+			AreaName: areadesc,
+		}
+		newid, err := db.Insert(&dbdata)
+		if err != nil {
+			logger.Logger.Error(err)
+			return
+		}
+		pmVol := "" //当前PM装置的电压等级
+		for volLevel, volValue := range volMap {
+			if volValue == iednameParts[3]+iednameParts[4] {
+				pmVol = volLevel
+				break
+			}
+		}
+		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")
+		for _, ty := range strings.Split(iedtypes, ",") {
+			inAreaIedName := ""
+			if _, h := groupList[ty]; h {
+				//装置如果是分组成员装置,则不用检测
+				continue
+			}
+			abCode := c.getIedTypeABCode(ty)
+			if abCode == "" {
+				//未特别指定套别时,采用主IED装置的套别
+				abCode = iednameParts[7]
+			}
+			tyCode := c.getIedTypeCode(modelid, ty)
+			if _, h := groupList[tyCode]; h {
+				//装置如果是分组成员装置,则不用检测
+				continue
+			}
+			if tyCode == mmCode {
+				//MM:母线合并单元
+				inAreaIedName = c.getMMName(iednameParts, ieds, abCode)
+				if inAreaIedName != "" {
+					insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:]))
+				}
+			} else {
+				//需要查找同电压等级的所有同类同套装置
+				h, m, l := c.getIedListByVol(tyCode, ieds, volMap, abCode)
+				logger.Logger.Debug(fmt.Sprintf("当前PM装置:%s 电压等级:%s 提取类型:%s 套别:%s h:%+v,m:%+v,l:%+v", pl_iedname, pmVol, tyCode, abCode, h, m, l))
+				switch pmVol {
+				case "hight":
+					for _, item := range h {
+						inAreaIedName = tools.IsEmpty(item["ied_name"])
+						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:]))
+					}
+					break
+				case "middle":
+					for _, item := range m {
+						inAreaIedName = tools.IsEmpty(item["ied_name"])
+						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:]))
+					}
+					break
+				case "low":
+					for _, item := range l {
+						inAreaIedName = tools.IsEmpty(item["ied_name"])
+						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:]))
+					}
+					break
+				}
+			}
+		}
+		if len(insvalues) == 0 {
+			continue
+		}
+		_, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
+		if err != nil {
+			logger.Logger.Error(err)
+			return
+		}
+	}
+}
+
 //母联间隔装置关系检查
 func (c *CheckAreaMgr) cJ(modelid string, scdXmlObj *node_attr.SCL, scdNodeMgr *ScdNode, scdNodeRule *ScdNodeRule, area_name string, ied_refs []orm.Params, area_ieds []orm.Params, pjIed, area_ruleid string) {
 	modelidInt, _ := strconv.Atoi(modelid)
@@ -1939,7 +2075,10 @@ func (c *CheckAreaMgr) getMMName(iednameParts []string, ieds map[string]orm.Para
 		return mmLst[0]
 	}
 	for _, n := range mmLst {
-		if strings.HasSuffix(n, ab) {
+		if ab != "" && strings.HasSuffix(n, ab) {
+			return n
+		}
+		if ab == "" && strings.HasSuffix(n, iednameParts[5]+iednameParts[6]) {
 			return n
 		}
 	}
@@ -1951,7 +2090,7 @@ func (c *CheckAreaMgr) getIedTypeABCode(iedtype string) string {
 	if strings.Index(iedtype, "-") > 0 {
 		return strings.Split(iedtype, "-")[1]
 	}
-	return iedtype
+	return ""
 }
 
 //根据当前设备列表,分析出电压等级(高、中、低)的设备列表

+ 1 - 1
service/models/bo/scd_mgr.go

@@ -1762,7 +1762,7 @@ func (c *ScdMgr) GetDoiCdcInfo(scdXmlObj *node_attr.SCL, scdid int64, doiObj *no
 	tmpdata, _ := GlobalNodeMap.Load(scdid)
 	nodeCacheMap := tmpdata.(map[int64]NodeCacheMap)
 	lnnode := nodeCacheMap[nodeCacheMap[doiObj.NodeId].ParentNodeId]
-	lnType := lnnode.ObjAddr.(*node_attr.NLNode).LnType
+	lnType := lnnode.ObjAddr.(*node_attr.NLN).LnType
 	if lnnodetpye, h := mapTargetLNodeType[lnType]; h {
 		for _, doitem := range lnnodetpye.DO {
 			if doitem.Name == doiObj.Name {

+ 1 - 0
service/models/bo/task_model.go

@@ -73,6 +73,7 @@ func (c *TaskModelMgr) Save(modelids []string) (err error) {
 			//将选择的系统模型复制为检测模型
 			m1.Model.ModelName = fmt.Sprintf("[%d]", c.Model.TaskId) //生成不唯一的模型名称,规则:检测任务id作为复制源模型的名称前缀
 			tmpid, _ := strconv.Atoi(ids)
+			m1.Model.IsSys = 2
 			err, newid := m1.Copy(tmpid)
 			if err != nil {
 				logger.Logger.Error(err)

+ 15 - 1
service/static/swagger/swagger.json

@@ -1040,7 +1040,7 @@
                     {
                         "in": "formData",
                         "name": "id",
-                        "description": "模型ID",
+                        "description": "被复制模型ID",
                         "required": true,
                         "type": "integer",
                         "format": "int64"
@@ -1051,6 +1051,20 @@
                         "description": "新模型名称",
                         "required": true,
                         "type": "string"
+                    },
+                    {
+                        "in": "formData",
+                        "name": "vol_id",
+                        "description": "目标电压等级ID",
+                        "type": "integer",
+                        "format": "int64"
+                    },
+                    {
+                        "in": "formData",
+                        "name": "link_style_id",
+                        "description": "目标接线方式ID",
+                        "type": "integer",
+                        "format": "int64"
                     }
                 ],
                 "responses": {

+ 11 - 1
service/static/swagger/swagger.yml

@@ -715,7 +715,7 @@ paths:
       parameters:
       - in: formData
         name: id
-        description: 模型ID
+        description: 被复制模型ID
         required: true
         type: integer
         format: int64
@@ -724,6 +724,16 @@ paths:
         description: 新模型名称
         required: true
         type: string
+      - in: formData
+        name: vol_id
+        description: 目标电压等级ID
+        type: integer
+        format: int64
+      - in: formData
+        name: link_style_id
+        description: 目标接线方式ID
+        type: integer
+        format: int64
       responses:
         "200":
           description: 成功

+ 15 - 1
service/swagger/swagger.json

@@ -1040,7 +1040,7 @@
                     {
                         "in": "formData",
                         "name": "id",
-                        "description": "模型ID",
+                        "description": "被复制模型ID",
                         "required": true,
                         "type": "integer",
                         "format": "int64"
@@ -1051,6 +1051,20 @@
                         "description": "新模型名称",
                         "required": true,
                         "type": "string"
+                    },
+                    {
+                        "in": "formData",
+                        "name": "vol_id",
+                        "description": "目标电压等级ID",
+                        "type": "integer",
+                        "format": "int64"
+                    },
+                    {
+                        "in": "formData",
+                        "name": "link_style_id",
+                        "description": "目标接线方式ID",
+                        "type": "integer",
+                        "format": "int64"
                     }
                 ],
                 "responses": {

+ 11 - 1
service/swagger/swagger.yml

@@ -715,7 +715,7 @@ paths:
       parameters:
       - in: formData
         name: id
-        description: 模型ID
+        description: 被复制模型ID
         required: true
         type: integer
         format: int64
@@ -724,6 +724,16 @@ paths:
         description: 新模型名称
         required: true
         type: string
+      - in: formData
+        name: vol_id
+        description: 目标电压等级ID
+        type: integer
+        format: int64
+      - in: formData
+        name: link_style_id
+        description: 目标接线方式ID
+        type: integer
+        format: int64
       responses:
         "200":
           description: 成功