Ver Fonte

修改主变间隔装置获取及报表生成格式

liling há 1 ano atrás
pai
commit
00a41e84f6

+ 2 - 2
service/controllers/busAdminController.go

@@ -295,13 +295,13 @@ func (c *BusAdminController) SaveSysModelInfo() {
 		c.ServeJSON()
 		return
 	}
-	err := obj.Save()
+	model, err := obj.Save()
 	if err != nil {
 		c.Data["json"] = c.ResultError(err.Error())
 		c.ServeJSON()
 		return
 	}
-	c.Data["json"] = c.ResultOK("", 0)
+	c.Data["json"] = c.ResultOK(model, 0)
 	c.ServeJSON()
 }
 

+ 26 - 24
service/models/bo/check_sys_model.go

@@ -96,7 +96,7 @@ func (c *SysCheckModelMgr) ExistName(name string) (has bool, id int) {
 }
 
 //保存检测模型信息
-func (c *SysCheckModelMgr) Save() (err error) {
+func (c *SysCheckModelMgr) Save() (model T_data_model_defualt, err error) {
 	dblog := new(SystemLog)
 	dblog.SetUserInfo(c.GetUserInfo())
 	dblog.Audittype = enum.AuditType_check_model
@@ -107,7 +107,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 	if c.Model.Id == 0 {
 		h, _ := c.ExistName(c.Model.ModelName)
 		if h {
-			return errors.New("模型名称已存在")
+			return c.Model, errors.New("模型名称已存在")
 		}
 		if c.Model.IsSys == 0 {
 			c.Model.IsSys = 1
@@ -121,7 +121,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 				logger.Logger.Error(err)
 				dblog.Description = fmt.Sprintf("保存%s信息失败:%s,操作数据:%+v", sysCheckModelDesc, err.Error(), c.Model)
 				dblog.Fail2()
-				return err
+				return c.Model, err
 			}
 			if modelJson["nodes"] != nil {
 				nodes := modelJson["nodes"].([]interface{})
@@ -138,7 +138,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 					tmp := tools.IsEmpty(properties["ied_type"])
 					if arrayex.IndexOf(iedtypes, tmp) > 0 {
 						//装置类型重复了
-						return errors.New("装置类型" + tmp + "不能重复引用")
+						return c.Model, errors.New("装置类型" + tmp + "不能重复引用")
 					}
 					iedtypes = append(iedtypes, tmp)
 				}
@@ -162,12 +162,12 @@ func (c *SysCheckModelMgr) Save() (err error) {
 	} else {
 		tmpObj, err := c.One()
 		if err != nil {
-			return err
+			return c.Model, err
 		}
 		if c.Model.ModelName != "" {
 			h, oldid := c.ExistName(c.Model.ModelName)
 			if h && c.Model.Id != oldid {
-				return errors.New("模型名称已存在")
+				return c.Model, errors.New("模型名称已存在")
 			}
 		} else {
 			c.Model.ModelName = tmpObj.ModelName
@@ -228,7 +228,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 				logger.Logger.Error(err)
 				dblog.Description = fmt.Sprintf("保存%s信息失败:%s,操作数据:%+v", sysCheckModelDesc, err.Error(), c.Model)
 				dblog.Fail2()
-				return err
+				return c.Model, err
 			}
 			if modelJson["nodes"] != nil {
 				nodes := modelJson["nodes"].([]interface{})
@@ -248,7 +248,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 					tmp := tools.IsEmpty(properties["ied_type"])
 					if arrayex.IndexOf(iedtypes, tmp) > 0 {
 						//装置类型重复了
-						return errors.New("装置类型" + tmp + "不能重复引用")
+						return c.Model, errors.New("装置类型" + tmp + "不能重复引用")
 					}
 					iedtypes = append(iedtypes, tmp)
 				}
@@ -292,7 +292,7 @@ func (c *SysCheckModelMgr) Save() (err error) {
 		bgm.Model = T_data_model_iedtype_group{ModelId: c.Model.Id}
 		bgm.Save(c.Model.RelationJson)
 	}
-	return err
+	return c.Model, err
 }
 
 func (c *SysCheckModelMgr) One() (T_data_model_defualt, error) {
@@ -317,22 +317,24 @@ func (c *SysCheckModelMgr) UpdateIedType(oldiedtype, newiedtype string) error {
 	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()
-			db.Raw("update t_data_model_iedtype_group set children_type=? where model_id=? and children_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
+	/*
+		//判断修改的是否是分组的自定义装置类型
+		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()
+				db.Raw("update t_data_model_iedtype_group set children_type=? where model_id=? and children_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_mapping{ModelId: c.Model.Id}
 	mapping.Model.IedType = oldiedtype

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

@@ -226,6 +226,10 @@ func (c *SysCheckModelIedFuncMgr) Delete(onlyFunc ...bool) (err error) {
 }
 
 func (c *SysCheckModelIedFuncMgr) GetList(modelid int, iedType string) ([]orm.Params, error) {
+	mappresult := new(SysCheckModelIedtypeMappingMgr).GetMappingType(modelid, iedType)
+	if mappresult != "" {
+		iedType = mappresult
+	}
 	//获取装置分组信息
 	bgm := new(SysCheckModelIedtypeGroupMgr)
 	bgm.Model = T_data_model_iedtype_group{ModelId: modelid}
@@ -283,8 +287,8 @@ func (c *SysCheckModelIedFuncMgr) Imp(param map[string]interface{}) (bool, error
 	fcdaMgr := new(SysCheckModelIedFuncFcdaMgr)
 	fcdaMgr.Model.ModelId = modelId
 	//获取装置分组信息
-	bgm := new(SysCheckModelIedtypeGroupMgr)
-	bgm.Model = T_data_model_iedtype_group{ModelId: modelId}
+	//bgm := new(SysCheckModelIedtypeGroupMgr)
+	//bgm.Model = T_data_model_iedtype_group{ModelId: modelId}
 	//groupList := bgm.List()
 	autoRows := []T_data_model_func_def{}
 	for _, row := range datalist {

+ 10 - 6
service/models/bo/check_sysmodel_ied_func_fcda.go

@@ -132,8 +132,8 @@ func (c *SysCheckModelIedFuncFcdaMgr) AutoRelation(modelid int, relationrow []T_
 	fcdaMap := map[string]T_data_model_func_def{}
 	for _, row := range relationrow {
 		key := fmt.Sprintf("%s%s", row.IedType, row.FcdaName)
-		if row.FuncName == "额定延时" {
-			if strings.Index(row.FcdaName, "额定") > -1 || strings.Index(row.FcdaName, "延迟") > -1 || strings.Index(row.FcdaName, "延时") > -1 {
+		if strings.Index(row.FuncName, "额定延") > -1 {
+			if strings.Index(row.FcdaName, "额定") > -1 && (strings.Index(row.FcdaName, "延迟") > -1 || strings.Index(row.FcdaName, "延时") > -1) {
 				key = fmt.Sprintf("%s%s", row.IedType, "额定延时")
 			}
 		}
@@ -159,8 +159,8 @@ func (c *SysCheckModelIedFuncFcdaMgr) AutoRelation(modelid int, relationrow []T_
 			tmplst := strings.Split(row.ReceiveIedType, ",")
 			for _, item := range tmplst {
 				key := fmt.Sprintf("%s%s", item, row.FcdaName)
-				if row.FuncName == "额定延时" {
-					if strings.Index(row.FcdaName, "额定") > -1 || strings.Index(row.FcdaName, "延迟") > -1 || strings.Index(row.FcdaName, "延时") > -1 {
+				if strings.Index(row.FuncName, "额定延") > -1 {
+					if strings.Index(row.FcdaName, "额定") > -1 && (strings.Index(row.FcdaName, "延迟") > -1 || strings.Index(row.FcdaName, "延时") > -1) {
 						key = fmt.Sprintf("%s%s", item, "额定延时")
 					}
 				}
@@ -296,6 +296,10 @@ func (c *SysCheckModelIedFuncFcdaMgr) GetList(refIedtype string, funcids ...[]st
 	sqlParamters := []interface{}{c.Model.ModelId}
 	outsql := ""
 	desc := ""
+	mappresult := new(SysCheckModelIedtypeMappingMgr).GetMappingType(c.Model.ModelId, refIedtype)
+	if mappresult != "" {
+		refIedtype = mappresult
+	}
 	//获取装置分组信息
 	bgm := new(SysCheckModelIedtypeGroupMgr)
 	bgm.Model = T_data_model_iedtype_group{ModelId: c.Model.ModelId}
@@ -339,11 +343,11 @@ func (c *SysCheckModelIedFuncFcdaMgr) GetList(refIedtype string, funcids ...[]st
 	}
 	sql = sql + " order by " + desc + " t.id"
 	if c.Model.Inorout == "输出" {
-		sql = "select a.id,a.model_id,a.func_id,a.fcda_name,a.fcda_match_exp,a.svorgoose,a.inorout,ifnull(a.to_fcda_id,0) to_fcda_id,ifnull(ff1.fcda_name,'') to_fcda_name,ifnull(fd1.ied_type,'') to_ied_type from (" +
+		sql = "select a.id,a.model_id,a.func_id,a.func_name,a.fcda_name,a.fcda_match_exp,a.svorgoose,a.inorout,ifnull(a.to_fcda_id,0) to_fcda_id,ifnull(ff1.fcda_name,'') to_fcda_name,ifnull(fd1.ied_type,'') to_ied_type from (" +
 			sql + ") a left join t_data_model_func_fcda ff1 on a.to_fcda_id=ff1.id  LEFT JOIN (select f1.id,case when f2.ied_type is null then f1.ied_type else f2.ied_type end ied_type from  t_data_model_func_def f1 LEFT JOIN t_data_model_iedtype_group f2 on f1.ied_type=f2.children_type and f2.model_id=f1.model_id WHERE f1.model_id=?) fd1 on ff1.func_id=fd1.id"
 		sqlParamters = append(sqlParamters, c.Model.ModelId)
 	} else if c.Model.Inorout == "接收" {
-		sql = "select a.id,a.model_id,a.func_id,a.fcda_name,a.fcda_match_exp,a.svorgoose,a.inorout,ifnull(a.from_fcda_id,0) from_fcda_id,ifnull(ff1.fcda_name,'') from_fcda_name,ifnull(fd1.ied_type,'') from_ied_type from (" +
+		sql = "select a.id,a.model_id,a.func_id,a.func_name,a.fcda_name,a.fcda_match_exp,a.svorgoose,a.inorout,ifnull(a.from_fcda_id,0) from_fcda_id,ifnull(ff1.fcda_name,'') from_fcda_name,ifnull(fd1.ied_type,'') from_ied_type from (" +
 			sql + ") a left join t_data_model_func_fcda ff1 on a.from_fcda_id=ff1.id  LEFT JOIN (select f1.id,case when f2.ied_type is null then f1.ied_type else f2.ied_type end ied_type from  t_data_model_func_def f1 LEFT JOIN t_data_model_iedtype_group f2 on f1.ied_type=f2.children_type and f2.model_id=f1.model_id WHERE f1.model_id=?) fd1 on ff1.func_id=fd1.id"
 		sqlParamters = append(sqlParamters, c.Model.ModelId)
 	}

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

@@ -46,7 +46,7 @@ func (c *SysCheckModelIedtypeGroupMgr) Delete(iedtype ...string) {
 
 func (c *SysCheckModelIedtypeGroupMgr) Copy(new_modelid int) {
 	db := orm.NewOrm()
-	db.Raw("insert into t_data_model_iedtype_group(model_id,ied_type,children_type)select ?,ied_type,children_type from t_data_model_iedtype_group where model_id=?", new_modelid, c.Model.Id).Exec()
+	db.Raw("insert into t_data_model_iedtype_group(model_id,ied_type,children_type)select ?,ied_type,children_type from t_data_model_iedtype_group where model_id=?", new_modelid, c.Model.ModelId).Exec()
 }
 
 func (c *SysCheckModelIedtypeGroupMgr) Save(jsonstr string) {

+ 13 - 0
service/models/bo/check_sysmodel_iedtype_mapping.go

@@ -77,6 +77,19 @@ func (c *SysCheckModelIedtypeMappingMgr) Save() error {
 	return err
 }
 
+func (c *SysCheckModelIedtypeMappingMgr) GetMappingType(modelid int, iedtype string) string {
+	c.Model.ModelId = modelid
+	c.Model.IedType = iedtype
+	r := c.List()
+	if r == nil {
+		return ""
+	}
+	if v, h := r[iedtype]; h {
+		return v
+	}
+	return ""
+}
+
 func (c *SysCheckModelIedtypeMappingMgr) List() map[string]string {
 	if c.Model.ModelId == 0 {
 		return nil

+ 136 - 230
service/models/bo/checktools_area.go

@@ -622,6 +622,7 @@ func (c *CheckAreaMgr) CheckIedFcda() error {
 		//获取该间隔下该类型的装置
 		s1 := []orm.Params{}
 		_, err = db.Raw("select ied_name from t_data_check_area_ied where area_id=?", area_id).Values(&s1)
+		typeMappingMgr := new(SysCheckModelIedtypeMappingMgr)
 		//循环处理关联关系
 		for to_ied_type2, refrow := range funclist {
 			ts := strings.Split(to_ied_type2, ",")
@@ -630,6 +631,10 @@ func (c *CheckAreaMgr) CheckIedFcda() error {
 			if v, h := groupList[ied_type]; h {
 				ied_type = v
 			}
+			mappresult := typeMappingMgr.GetMappingType(modelid, ied_type)
+			if mappresult != "" {
+				ied_type = mappresult
+			}
 			ied_type, vol := getIedTypeAndVolCode(ied_type)
 			iedlst := filterAreaIeds(ied_type, vol, s1)
 			logger.Logger.Debug(fmt.Sprintf("正在检查装置类型:%s的装置(%+v)端子关系", ied_type, iedlst))
@@ -639,6 +644,10 @@ func (c *CheckAreaMgr) CheckIedFcda() error {
 			if v, h := groupList[fromiedcode]; h {
 				fromiedcode = v
 			}
+			mappresult = typeMappingMgr.GetMappingType(modelid, fromiedcode)
+			if mappresult != "" {
+				fromiedcode = mappresult
+			}
 			from_ied_type, vol2 := getIedTypeAndVolCode(fromiedcode)
 			outiedlist2 := filterAreaIeds(from_ied_type, vol2, s1)
 			for _, iedrow := range outiedlist2 {
@@ -668,11 +677,11 @@ func (c *CheckAreaMgr) CheckIedFcda() error {
 					}
 					logger.Logger.Debug(fmt.Sprintf("正在匹配装置%s与%s的端子关联关系", iedname, outiedname))
 					outIedObj := scdNodeMgr.GetIed(scdXmlObj, fmt.Sprintf("%d", c.ScdId), outiedname)
-					outIedObjDesc := ""
+					//outIedObjDesc := ""
 					if outIedObj == nil {
 						logger.Logger.Error(fmt.Sprintf("信号输出装置%s未找到!", outiedname))
 					} else {
-						outIedObjDesc = outIedObj.Desc
+						//outIedObjDesc = outIedObj.Desc
 					}
 					if iedObj == nil && outIedObj == nil {
 						continue
@@ -730,23 +739,24 @@ func (c *CheckAreaMgr) CheckIedFcda() error {
 								//检查未通过
 								scdNodeRule.AppendFcdaCheckResult(re)
 							}
-							if !fcda2Exist {
-								parse_result := fmt.Sprintf("间隔%s的装置%s缺失端子%s", area_name, outiedname, fcda_name)
-								re := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result,
-									"ied_name":      "",
-									"ied_desc":      "",
-									"out_ied_name":  outiedname,
-									"out_ied_desc":  outIedObjDesc,
-									"fcda_desc":     "",
-									"fcda_addr":     "",
-									"out_fcda_desc": fcda_name,
-									"out_fcda_addr": "",
-									"error_type":    "3",
+							/*
+								if !fcda2Exist {
+									parse_result := fmt.Sprintf("间隔%s的装置%s缺失端子%s", area_name, outiedname, fcda_name)
+									re := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result,
+										"ied_name":      "",
+										"ied_desc":      "",
+										"out_ied_name":  outiedname,
+										"out_ied_desc":  outIedObjDesc,
+										"fcda_desc":     "",
+										"fcda_addr":     "",
+										"out_fcda_desc": fcda_name,
+										"out_fcda_addr": "",
+										"error_type":    "3",
+									}
+									//检查未通过
+									scdNodeRule.AppendFcdaCheckResult(re)
 								}
-								//检查未通过
-								scdNodeRule.AppendFcdaCheckResult(re)
-							}
-
+							*/
 						} else {
 							//检查端子是否关联正确
 							if fcda2Exist && (extrefObj.LdInst != fcdaObj.LdInst ||
@@ -993,12 +1003,10 @@ func (c *CheckAreaMgr) ParseModelArea() {
 //根据默认装置类型获取其类型编码。如果没有自定义编码,则返回默认编码
 func (c *CheckAreaMgr) getIedTypeCode(modelid int, iedtype string) string {
 	mapptype := new(SysCheckModelIedtypeMappingMgr)
-	mapptype.Model = T_data_model_iedtype_mapping{ModelId: modelid}
-	mapptype.Model.IedType = iedtype
-	mappresult := mapptype.List()
+	mappresult := mapptype.GetMappingType(modelid, iedtype)
 	ptCode := iedtype
-	if len(mappresult) > 0 {
-		ptCode = mappresult[iedtype] //自定义主变保护编码
+	if mappresult != "" {
+		ptCode = mappresult //自定义主变保护编码
 	}
 	return ptCode
 }
@@ -1063,8 +1071,25 @@ func (c *CheckAreaMgr) pT(modelid int, iedtypes string, ieds map[string]orm.Para
 	}
 	//判断是否将各电压等级的保护装置合并还是分开的间隔
 	//如果存在高中低压的保护装置,则说明是分开的主变间隔
-	//isMarge := true // 默认为合并的主变间隔
 	ptCode := c.getIedTypeCode(modelid, "PT")
+	volValue := "" //电压等级值
+	if strings.Index(","+iedtypes+",", ","+ptCode+",") == -1 {
+		//判断主变保护是否是按电压等级分开配置的模型
+		h, m, l := c.getIedListByVol(ptCode, ieds, volMap)
+		if strings.Contains(iedtypes, ptCode+"#H") && len(h) > 0 {
+			//高压侧装置
+			volValue = "H"
+		} else if strings.Contains(iedtypes, ptCode+"#M") && len(m) > 0 {
+			volValue = "M"
+		} else if strings.Contains(iedtypes, ptCode+"#L") && len(l) > 0 {
+			volValue = "L"
+		}
+	}
+	pmCode := c.getIedTypeCode(modelid, "PM")
+	mmCode := c.getIedTypeCode(modelid, "MM")
+	ctCode := c.getIedTypeCode(modelid, "CT")
+	delPm := false
+	delMm := false
 	for _, row := range ieds {
 		if tools.IsEmpty(row["ied_type"]) != ptCode[0:1] || tools.IsEmpty(row["p_type"]) != ptCode[1:] {
 			continue
@@ -1073,16 +1098,6 @@ func (c *CheckAreaMgr) pT(modelid int, iedtypes string, ieds map[string]orm.Para
 			//装置如果是分组成员装置,则不用检测
 			continue
 		}
-		//判断主变保护是否是按电压等级分开配置的模型
-		/*
-			if strings.Contains(iedtypes, "PT#H") || strings.Contains(iedtypes, "PT#M") || strings.Contains(iedtypes, "PT#L") {
-				h, m, l := c.getIedListByVol("PT", ieds, volMap)
-			} else {
-				pl_iedname := tools.IsEmpty(row["ied_name"])
-			}
-		*/
-		//pmIedName := ""
-		//mmIedName := ""
 		pl_iedname := tools.IsEmpty(row["ied_name"])
 		iednameParts := scdParseMgr.ParseIedName(pl_iedname)
 		areadesc := tools.IsEmpty(row["ied_desc"])
@@ -1109,220 +1124,99 @@ func (c *CheckAreaMgr) pT(modelid int, iedtypes string, ieds map[string]orm.Para
 		}
 		ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
 		insvalues := []string{}
-		inAreaIedName := pl_iedname
-		insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "T"))
-		//判断间隔是否需要包含差动装置
-		if strings.Contains(iedtypes, ptCode+"#C") {
-			_, iedname := getIedByDesc(ieds, ptCode, "差动")
-			if len(iedname) > 0 {
-				for _, in := range iedname {
-					tmpIednameParts := scdParseMgr.ParseIedName(in)
-					if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "P", "TC"))
-						break
+		inAreaIedName := ""
+		//insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "T"))
+		for _, ty := range strings.Split(iedtypes, ",") {
+			inAreaIedName = ""
+			if _, h := groupList[ty]; h {
+				//装置如果是分组成员装置,则不用检测
+				continue
+			}
+			tyCode := c.getIedTypeCode(modelid, ty)
+			if _, h := groupList[tyCode]; h {
+				//装置如果是分组成员装置,则不用检测
+				continue
+			}
+			if tyCode[0:len(pmCode)] == pmCode {
+				//PM和MM最后处理
+				delPm = true
+				continue
+			}
+			if tyCode[0:len(mmCode)] == mmCode {
+				//PM和MM最后处理
+				delMm = true
+				continue
+			}
+			//判断间隔是否需要包含差动装置
+			if strings.Contains(tyCode, "#C") {
+				_, iedname := getIedByDesc(ieds, tyCode, "差动")
+				if len(iedname) > 0 {
+					for _, in := range iedname {
+						tmpIednameParts := scdParseMgr.ParseIedName(in)
+						if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
+							insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, tyCode[0:1], tyCode[1:]))
+							break
+						}
 					}
 				}
 			}
-		}
-		//判断间隔是否需要包含本体保护装置
-		if strings.Contains(iedtypes, ptCode+"#0") {
-			_, iedname := getIedByDesc(ieds, ptCode, "本体")
-			if len(iedname) > 0 {
-				for _, in := range iedname {
-					tmpIednameParts := scdParseMgr.ParseIedName(in)
-					if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "P", "T0"))
-						break
+			//判断间隔是否需要包含本体保护装置
+			if strings.Contains(tyCode, "#0") {
+				_, iedname := getIedByDesc(ieds, tyCode, "本体")
+				if len(iedname) > 0 {
+					for _, in := range iedname {
+						tmpIednameParts := scdParseMgr.ParseIedName(in)
+						if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
+							insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, tyCode[0:1], tyCode[1:]))
+							break
+						}
 					}
 				}
 			}
-		}
-		//合智一体IMT/MIT,分高中低压
-		imtcode := c.getIedTypeCode(modelid, "IMT")
-		h, m, l := c.getIedListByVol(imtcode, ieds, volMap)
-		h = append(h, m...)
-		h = append(h, l...)
-		for _, r := range h {
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "IM", "T"))
+			dlIeds := []orm.Params{}
+			imtcode := c.getIedTypeCode(modelid, tyCode)
+			h, m, l := c.getIedListByVol(imtcode, ieds, volMap)
+			//logger.Logger.Debug(fmt.Sprintf("tyCode:%s H:%+v,M:%+v,L:%+v", tyCode, h, m, l))
+			if volValue == "" || volValue == "H" {
+				dlIeds = append(dlIeds, h...)
 			}
-		}
-		imtcode = c.getIedTypeCode(modelid, "MIT")
-		h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
-		h = append(h, m...)
-		h = append(h, l...)
-		for _, r := range h {
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "MI", "T"))
+			if volValue == "" || volValue == "M" {
+				dlIeds = append(dlIeds, m...)
 			}
-		}
-		//母联智能终端IE需要分高中压,无低压侧
-		if HasAreaJ {
-			imtcode = c.getIedTypeCode(modelid, "IE")
-			h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
-			for _, r := range h {
-				//高压侧,AB套必须与PT装置相同
-				inAreaIedName = tools.IsEmpty(r["ied_name"])
-				tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-				if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-					insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "E"))
-				}
+			if volValue == "" || volValue == "L" {
+				dlIeds = append(dlIeds, l...)
 			}
-			for _, r := range m {
-				//中压侧
+			for _, r := range dlIeds {
 				inAreaIedName = tools.IsEmpty(r["ied_name"])
 				tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-				lastChar := tmpIednameParts[7]
-				if tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || tmpIednameParts[7] == iednameParts[7]) {
-					insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "E"))
-				}
-			}
-		}
-		//合并单元MT分高中低压侧;低压侧无关联母线合并单元MM
-		imtcode = c.getIedTypeCode(modelid, "MT")
-		h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
-		h = append(h, m...)
-		h = append(h, l...)
-		for _, r := range h {
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "M", "T"))
-			}
-		}
-		//是否包含本体合并单元
-		if strings.Contains(iedtypes, imtcode+"#0") {
-			_, iedname := getIedByDesc(ieds, imtcode, "本体")
-			if len(iedname) > 0 {
-				for _, in := range iedname {
-					tmpIednameParts := scdParseMgr.ParseIedName(in)
-					if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "M", "T"))
-						break
+				if tyCode[0:len(ctCode)] == ctCode {
+					//CT单独处理。它可能不分AB套
+					lastChar := tmpIednameParts[7]
+					if tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
+						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:]))
 					}
-				}
-			}
-		}
-		//测控装置CT分高中低压侧,且可能是多套合并单元MT共用,既不分AB套
-		imtcode = c.getIedTypeCode(modelid, "CT")
-		h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
-		h = append(h, m...)
-		h = append(h, l...)
-		for _, r := range h {
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			lastChar := tmpIednameParts[7]
-			tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
-			//高中低压电压等级相同的
-			if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "C", "T"))
-			}
-		}
-		//是否包含本体测控装置
-		if strings.Contains(iedtypes, imtcode+"#0") {
-			_, iedname := getIedByDesc(ieds, imtcode, "本体")
-			if len(iedname) > 0 {
-				for _, in := range iedname {
-					tmpIednameParts := scdParseMgr.ParseIedName(in)
+				} else {
 					if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "C", "T"))
-						break
+						insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:]))
 					}
 				}
 			}
 		}
-		//智能终端(IB:开关\IT:分支\IF:分段)分高中低压侧
-		imtcodeB := c.getIedTypeCode(modelid, "IB")
-		imtcodeT := c.getIedTypeCode(modelid, "IT")
-		imtcodeF := c.getIedTypeCode(modelid, "IF")
-		h, m, l = c.getIedListByVol(imtcodeB, ieds, volMap)
-		h = append(h, m...)
-		h = append(h, l...)
-		for _, r := range h {
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			lastChar := tmpIednameParts[7]
-			tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
-			//高中低压电压等级相同的
-			if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "B"))
-			}
-		}
-		//是否包含本体测控装置
-		if strings.Contains(iedtypes, imtcodeT+"#0") {
-			for n, row := range ieds {
-				if strings.HasPrefix(n, imtcodeT) || strings.HasPrefix(n, imtcodeB) || strings.HasPrefix(n, imtcodeF) {
-					ieddesc := tools.IsEmpty(row["ied_desc"])
-					if strings.Contains(ieddesc, "本体") {
-						tmpIednameParts := scdParseMgr.ParseIedName(n)
-						if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
-							insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, n, "I", "T"))
-							break
-						}
-					}
-				}
-			}
-		}
-		h, m, l = c.getIedListByVol(imtcodeT, ieds, volMap)
-		h = append(h, m...)
-		h = append(h, l...)
-		for _, r := range h {
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			lastChar := tmpIednameParts[7]
-			tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
-			//高中低压电压等级相同的
-			if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "T"))
-			}
-		}
-		h, m, l = c.getIedListByVol(imtcodeF, ieds, volMap)
-		h = append(h, m...)
-		h = append(h, l...)
-		for _, r := range h {
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			lastChar := tmpIednameParts[7]
-			tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
-			//高中低压电压等级相同的
-			if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "F"))
-			}
-		}
-		//母线保护PM及母线合并单元MM,可能是多套合并单元MT共用,既不分AB套;低压侧智能终端无关联母线保护
-		imtcode = c.getIedTypeCode(modelid, "PM")
-		h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
-		for _, r := range h {
-			//高压侧,AB套必须与PT装置相同
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			lastChar := tmpIednameParts[7]
-			if tmpIednameParts[6] == iednameParts[6] && lastChar == iednameParts[7] {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
-				//MM装置
-				mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
-				break
+		//最后处理PM和MM
+		inAreaIedName = c.getPMName(iednameParts, ieds)
+		if delPm && inAreaIedName != "" {
+			insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
+			//pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
+			//使用PM装置的名称去定义MM的名称
+			inAreaIedName = c.getMMName(iednameParts, ieds, iednameParts[7])
+			if delMm && inAreaIedName != "" {
+				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "M", "M"))
 			}
 		}
-		for _, r := range m {
-			//中压侧
-			inAreaIedName = tools.IsEmpty(r["ied_name"])
-			tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
-			lastChar := tmpIednameParts[7]
-			if tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
-				//MM装置
-				mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
-				insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
-				break
-			}
+		//写数据库
+		if len(insvalues) > 0 {
+			_, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
 		}
-		_, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
 		if err != nil {
 			logger.Logger.Error(err)
 			return
@@ -1995,10 +1889,11 @@ func (c *CheckAreaMgr) getIedListByVol(iedtype string, ieds map[string]orm.Param
 	for _, v := range vollevel {
 		tmpLst[v] = []orm.Params{}
 	}
+	it := strings.Split(iedtype, "#")
 	scdParseMgr := new(ScdParse)
 	for _, row := range ieds {
 		pl_iedname := tools.IsEmpty(row["ied_name"])
-		if pl_iedname[0:len(iedtype)] != iedtype {
+		if pl_iedname[0:len(it[0])] != it[0] {
 			continue
 		}
 		iednameParts := scdParseMgr.ParseIedName(pl_iedname)
@@ -2009,13 +1904,24 @@ func (c *CheckAreaMgr) getIedListByVol(iedtype string, ieds map[string]orm.Param
 			tmpLst[volvalue] = append(tmpLst[volvalue], row)
 		}
 	}
+	if len(it) > 1 {
+		if it[1] == "H" {
+			return tmpLst[vollevel["hight"]], []orm.Params{}, []orm.Params{}
+		}
+		if it[1] == "M" {
+			return []orm.Params{}, tmpLst[vollevel["middle"]], []orm.Params{}
+		}
+		if it[1] == "L" {
+			return []orm.Params{}, []orm.Params{}, tmpLst[vollevel["low"]]
+		}
+	}
 	return tmpLst[vollevel["hight"]], tmpLst[vollevel["middle"]], tmpLst[vollevel["low"]]
 }
 
 func (c *CheckAreaMgr) GetCheckResult(scdid int64) ([]orm.Params, error) {
 	db := orm.NewOrm()
 	rowset := []orm.Params{}
-	sql := "select *,case error_type when 1 then '多余' when 2 then '错误' when 3 then '缺失' else '其他' end error_type_desc from t_scd_fcda_check_result where scd_id=? order by ied_name"
+	sql := "select *,case error_type when 1 then '多余' when 2 then '错误' when 3 then '缺失' else '其他' end error_type_desc from t_scd_fcda_check_result where scd_id=? order by ied_name,out_ied_name,error_type"
 	_, err := db.Raw(sql, scdid).Values(&rowset)
 	return rowset, err
 }

+ 14 - 0
service/models/bo/global_code.go

@@ -281,6 +281,13 @@ func (t *Global) GetCodeInfoByID(id string) orm.Params {
 	r, _ := global.GoCahce.Get(key)
 	if r != nil {
 		return r.(orm.Params)
+	} else {
+		lst := []orm.Params{}
+		orm.NewOrm().Raw("select * from global_const_code where id=?", id).Values(&lst)
+		if len(lst) > 0 {
+			global.GoCahce.Set(key, lst[0], -1)
+			return lst[0]
+		}
 	}
 	return nil
 }
@@ -290,6 +297,13 @@ func (t *Global) GetCodeInfoByCode(pcode, code string) orm.Params {
 	r, _ := global.GoCahce.Get(key)
 	if r != nil {
 		return r.(orm.Params)
+	} else {
+		lst := []orm.Params{}
+		orm.NewOrm().Raw("select * from global_const_code where code=? and parentcode=?", code, pcode).Values(&lst)
+		if len(lst) > 0 {
+			global.GoCahce.Set(key, lst[0], -1)
+			return lst[0]
+		}
 	}
 	return nil
 }

+ 0 - 3
service/models/bo/task.go

@@ -256,9 +256,6 @@ func (c *TaskMgr) Save() (id int, err error) {
 		if oldinfo.State == 1 {
 			return 0, errors.New("任务正在检测中,不允许编辑")
 		}
-		if oldinfo.State == 2 {
-			return 0, errors.New("任务已检测完成,不允许编辑")
-		}
 		c.Model.StartTime = oldinfo.StartTime
 		c.Model.EndTime = oldinfo.EndTime
 		c.Model.State = oldinfo.State

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

@@ -64,13 +64,18 @@ func (c *TaskModelMgr) Save(modelids []string) (err error) {
 		}
 	}
 	for _, ids := range modelids {
+		if ids == "" {
+			continue
+		}
 		//判断是否新增了模型
 		if arrayex.IndexOf(oldModels, ids) == -1 {
+			logger.Logger.Debug(fmt.Sprintf("正在从模型%s复制新模型", ids))
 			//将选择的系统模型复制为检测模型
 			m1.Model.ModelName = fmt.Sprintf("[%d]", c.Model.TaskId) //生成不唯一的模型名称,规则:检测任务id作为复制源模型的名称前缀
 			tmpid, _ := strconv.Atoi(ids)
 			err, newid := m1.Copy(tmpid)
 			if err != nil {
+				logger.Logger.Error(err)
 				break
 			}
 			if newid == 0 {

+ 12 - 4
service/models/bo/task_report.go

@@ -339,7 +339,7 @@ func (c *TaskReportMgr) ToWord(taskinfo T_data_task) (path string, err error) {
 		logger.Logger.Error(err)
 		return "", err
 	}
-	c.setCaption(sheet_fcda, fmt.Sprintf("%s-端子校验结果", scdName), 6)
+	c.setCaption(sheet_fcda, fmt.Sprintf("%s-端子校验结果", scdName), 5)
 	//汇总结果
 	scdFileName := ""
 	if sdcXmlObj.Header != nil {
@@ -432,21 +432,29 @@ func (c *TaskReportMgr) ToWord(taskinfo T_data_task) (path string, err error) {
 	cellNo := 1
 
 	for _, row := range result {
-		nowIedName := fmt.Sprintf("%s:%s", tools.IsEmpty(row["ied_name"]), tools.IsEmpty(row["ied_desc"]))
+		if tools.IsEmpty(row["ied_name"]) == "" {
+			continue
+		}
+		nowIedName := fmt.Sprintf("%s", tools.IsEmpty(row["ied_name"]))
 		if lastIedName == "" || lastIedName != nowIedName {
 			lastIedName = nowIedName
-			c.setCaption(sheet_fcda, lastIedName, 6)
+			c.setCaption(sheet_fcda, lastIedName+":"+tools.IsEmpty(row["ied_desc"]), 6)
 			c.addCellValue(sheet_fcda, []string{"序号", "外部IED", "发送信号", "本IED", "接收信号", "结论"})
 			cellNo = 1
 		}
+		outied := tools.IsEmpty(row["out_ied_name"])
+		if outied != "" {
+			outied = fmt.Sprintf("%s:%s", tools.IsEmpty(row["out_ied_name"]), tools.IsEmpty(row["out_ied_desc"]))
+		}
 		c.addCellValue(sheet_fcda, []string{
 			fmt.Sprintf("%d", cellNo),
-			fmt.Sprintf("%s:%s", tools.IsEmpty(row["out_ied_name"]), tools.IsEmpty(row["out_ied_desc"])),
+			outied,
 			fmt.Sprintf("%s\n%s", tools.IsEmpty(row["out_fcda_desc"]), tools.IsEmpty(row["out_fcda_addr"])),
 			fmt.Sprintf("%s:%s", tools.IsEmpty(row["ied_name"]), tools.IsEmpty(row["ied_desc"])),
 			fmt.Sprintf("%s\n%s", tools.IsEmpty(row["fcda_desc"]), tools.IsEmpty(row["fcda_addr"])),
 			tools.IsEmpty(row["error_type_desc"]),
 		})
+		sheet_fcda.SetColWidth(cellNo, cellNo, 30) //单元格宽度
 		cellNo = cellNo + 1
 	}
 	err = file.Save(reportFN)