Przeglądaj źródła

修改手动连线功能

liling 1 rok temu
rodzic
commit
e9a821949d

+ 0 - 9
service/models/bo/check_sys_model.go

@@ -152,12 +152,6 @@ func (c *SysCheckModelMgr) Save() (err error) {
 			lm.Model.ModelId = int(newid)
 			lm.SetUserInfo(c.GetUserInfo())
 			lm.Save()
-			if c.Model.RelationJson != "" {
-				m2 := new(SysCheckModelIedRelationMgr)
-				m2.SetUserInfo(c.GetUserInfo())
-				m2.Model.ModelId = int(newid)
-				//err = m2.Save(c.Model.RelationJson)
-			}
 		}
 		if err2 != nil {
 			err = err2
@@ -275,9 +269,6 @@ func (c *SysCheckModelMgr) Save() (err error) {
 						m1 := new(SysCheckModelIedFuncMgr)
 						m1.Model = T_data_model_func_def{ModelId: c.Model.Id, IedType: item}
 						m1.Delete()
-						bgm := new(SysCheckModelIedtypeGroupMgr)
-						bgm.Model = T_data_model_iedtype_group{ModelId: c.Model.Id}
-						bgm.Delete(item)
 					}
 				}
 			}

+ 34 - 7
service/models/bo/check_sysmodel_ied_func.go

@@ -226,9 +226,25 @@ func (c *SysCheckModelIedFuncMgr) Delete(onlyFunc ...bool) (err error) {
 }
 
 func (c *SysCheckModelIedFuncMgr) GetList(modelid int, iedType string) ([]orm.Params, error) {
+	//获取装置分组信息
+	bgm := new(SysCheckModelIedtypeGroupMgr)
+	bgm.Model = T_data_model_iedtype_group{ModelId: modelid}
+	groupList := bgm.List()
+	tmpAry := []string{}
+	if len(groupList) > 0 {
+		//判断是否是获取的分组装置,是则需要将子装置所有功能返回
+		for k, v := range groupList {
+			if v == iedType {
+				tmpAry = append(tmpAry, k)
+			}
+		}
+		if len(tmpAry) > 0 {
+			iedType = strings.Join(tmpAry, "','")
+		}
+	}
 	o := orm.NewOrm()
-	sqlParamters := []interface{}{modelid, iedType}
-	sql := "select t.* from t_data_model_func_def t where t.model_id=? and ied_type=?"
+	sqlParamters := []interface{}{modelid}
+	sql := "select t.* from t_data_model_func_def t where t.model_id=? and ied_type in('" + iedType + "')"
 	rowset := []orm.Params{}
 	_, err := o.Raw(sql, sqlParamters).Values(&rowset)
 	if err != nil {
@@ -269,17 +285,19 @@ func (c *SysCheckModelIedFuncMgr) Imp(param map[string]interface{}) (bool, error
 	//获取装置分组信息
 	bgm := new(SysCheckModelIedtypeGroupMgr)
 	bgm.Model = T_data_model_iedtype_group{ModelId: modelId}
-	groupList := bgm.List()
+	//groupList := bgm.List()
 	autoRows := []T_data_model_func_def{}
 	for _, row := range datalist {
 		ied_type := strings.ToUpper(row[2])
 		if ied_type == "" {
 			return false, errors.New(fmt.Sprintf("第%d行:装置类型编码不能为空", i))
 		}
-		//判断装置类型是否是合并分组类型,如PLC由PL+CL合并
-		if groupList != nil && groupList[ied_type] != "" {
-			ied_type = groupList[ied_type]
-		}
+		/*
+			//判断装置类型是否是合并分组类型,如PLC由PL+CL合并
+			if groupList != nil && groupList[ied_type] != "" {
+				ied_type = groupList[ied_type]
+			}
+		*/
 		if !strings.Contains(modelInfoIedTypes, ","+ied_type+",") {
 			//模型中未发现该装置类型
 			continue
@@ -305,6 +323,15 @@ func (c *SysCheckModelIedFuncMgr) Imp(param map[string]interface{}) (bool, error
 			return false, errors.New(fmt.Sprintf("第%d行:信号方向不能为空", i))
 		}
 		receive_ied_type := strings.ReplaceAll(strings.ReplaceAll(row[8], "&", ","), ",", ",") //对侧接收装置类型
+		/*
+			tmpAry := strings.Split(receive_ied_type, ",")
+			for i, item := range tmpAry {
+				if groupList != nil && groupList[item] != "" {
+					tmpAry[i] = groupList[item]
+				}
+			}
+			receive_ied_type = strings.Join(tmpAry, ",")
+		*/
 		funckey := fmt.Sprintf("%d%s%s", modelId, ied_type, func_name)
 		func_id = funcMap[funckey]
 		if func_id == 0 {

+ 46 - 20
service/models/bo/check_sysmodel_ied_func_fcda.go

@@ -49,13 +49,15 @@ func (c *SysCheckModelIedFuncFcdaMgr) Save() (id int, err error) {
 	dblog.Eventtype = enum.OptEventType_Bus
 	dblog.Eventlevel = enum.OptEventLevel_Hight
 	db := orm.NewOrm()
-	hasName, _, err := c.Exist()
-	if err != nil {
-		return 0, err
-	}
-	if hasName {
-		return 0, errors.New("端子名称[" + c.Model.FcdaName + "]已存在")
-	}
+	/*
+		hasName, _, err := c.Exist()
+		if err != nil {
+			return 0, err
+		}
+		if hasName {
+			return 0, errors.New("端子名称[" + c.Model.FcdaName + "]已存在")
+		}
+	*/
 	newid := int64(0)
 	if c.Model.Id > 0 {
 		//编辑
@@ -142,16 +144,18 @@ func (c *SysCheckModelIedFuncFcdaMgr) AutoRelation(modelid int, relationrow []T_
 	bgm.Model = T_data_model_iedtype_group{ModelId: modelid}
 	groupList := bgm.List()
 	var getRealIedCode = func(ied_type string, groupList map[string]string) string {
-		if groupList != nil && groupList[ied_type] != "" {
-			ied_type = groupList[ied_type]
-		}
+		/*
+			if groupList != nil && groupList[ied_type] != "" {
+				ied_type = groupList[ied_type]
+			}
+		*/
 		return ied_type
 	}
 	fr := new(SysCheckModelFcdaRalationMgr)
 	fr.Model = T_data_model_fcda_ref{ModelId: modelid}
 	noMatchList := map[string][]interface{}{} //未完全匹配的列表
 	for i, row := range relationrow {
-		if row.ReceiveIedType != "" {
+		if row.ReceiveIedType != "" && strings.Index(row.Inorout, "输出") > -1 {
 			tmplst := strings.Split(row.ReceiveIedType, ",")
 			for _, item := range tmplst {
 				key := fmt.Sprintf("%s%s", item, row.FcdaName)
@@ -171,7 +175,7 @@ func (c *SysCheckModelIedFuncFcdaMgr) AutoRelation(modelid int, relationrow []T_
 					fr.Save()
 				} else {
 					//未完全匹配到端子时,查找其接收端的对侧装置为当前装置的端子
-					k := row.IedType + "," + item
+					k := getRealIedCode(row.IedType, groupList) + "," + getRealIedCode(item, groupList)
 					if _, h := noMatchList[k]; !h {
 						tmp := map[string]interface{}{"no": i, "fromrow": row}
 						noMatchList[k] = []interface{}{tmp}
@@ -188,17 +192,21 @@ func (c *SysCheckModelIedFuncFcdaMgr) AutoRelation(modelid int, relationrow []T_
 		subNo := 0 //相差的行数
 		fromrow := T_data_model_func_def{}
 		for i, row := range relationrow {
-			if row.IedType == ks[1] && strings.Index(row.ReceiveIedType, ks[0]) > -1 {
+			outIedType := getRealIedCode(row.IedType, groupList)
+			receiveIedType := getRealIedCode(row.ReceiveIedType, groupList)
+			if outIedType == ks[1] && strings.Index(receiveIedType, ks[0]) > -1 {
 				tmp := obj[0].(map[string]interface{})
 				no, _ := tmp["no"].(int)
 				subNo = no - i //相差的行数
 				break
 			}
 		}
+		logger.Logger.Debug(fmt.Sprintf("未建立关系的装置:%s,间隔行数:%d", iedtype, subNo))
 		for _, item := range obj {
 			item2 := item.(map[string]interface{})
 			rowno := item2["no"].(int) - subNo
-			if rowno < 0 || rowno > len(relationrow) {
+			if rowno < 0 || rowno > len(relationrow)-1 {
+				logger.Logger.Debug(fmt.Sprintf("建立关系异常数据:%+v", item))
 				return
 			}
 			fromrow = item2["fromrow"].(T_data_model_func_def)
@@ -288,14 +296,30 @@ func (c *SysCheckModelIedFuncFcdaMgr) GetList(refIedtype string, funcids ...[]st
 	sqlParamters := []interface{}{c.Model.ModelId}
 	outsql := ""
 	desc := ""
+	//获取装置分组信息
+	bgm := new(SysCheckModelIedtypeGroupMgr)
+	bgm.Model = T_data_model_iedtype_group{ModelId: c.Model.ModelId}
+	groupList := bgm.List()
+	tmpAry := []string{}
+	if len(groupList) > 0 {
+		for k, v := range groupList {
+			if v == refIedtype {
+				tmpAry = append(tmpAry, k)
+			}
+		}
+		if len(tmpAry) > 0 {
+			tmpAry = append(tmpAry, refIedtype) //包含分组编码本身
+			refIedtype = strings.Join(tmpAry, "','")
+		}
+	}
 	if c.Model.Inorout == "接收" {
-		outsql = ",(select from_fcda_id from t_data_model_fcda_ref where model_id=? and to_fcda_id=t.id and to_func_id=t1.id and from_ied_code=?) from_fcda_id"
-		sqlParamters = append(sqlParamters, refIedtype, c.Model.ModelId)
+		outsql = ",(select GROUP_CONCAT(from_fcda_id) from_fcda_id from t_data_model_fcda_ref where model_id=? and to_fcda_id=t.id and to_func_id=t1.id and from_ied_code in ('" + refIedtype + "')) from_fcda_id"
+		sqlParamters = append(sqlParamters, c.Model.ModelId)
 		desc = " from_fcda_id," //已有关联关系的端子排在前面
 	}
 	if c.Model.Inorout == "输出" {
-		outsql = ",(select to_fcda_id from t_data_model_fcda_ref where model_id=? and from_fcda_id=t.id and from_func_id=t1.id and to_ied_code=?) to_fcda_id"
-		sqlParamters = append(sqlParamters, refIedtype, c.Model.ModelId)
+		outsql = ",(select GROUP_CONCAT(to_fcda_id) to_fcda_id from t_data_model_fcda_ref where model_id=? and from_fcda_id=t.id and from_func_id=t1.id and to_ied_code in ('" + refIedtype + "')) to_fcda_id"
+		sqlParamters = append(sqlParamters, c.Model.ModelId)
 	}
 	sql := "select t.*,t1.func_name" + outsql + " from t_data_model_func_fcda t,t_data_model_func_def t1 where t1.id=t.func_id and t.model_id=? "
 	if c.Model.FuncId > 0 {
@@ -316,10 +340,12 @@ 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 + ") a left join t_data_model_func_fcda ff1 on a.to_fcda_id=ff1.id  LEFT JOIN t_data_model_func_def fd1 on ff1.func_id=fd1.id"
+			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 + ") a left join t_data_model_func_fcda ff1 on a.from_fcda_id=ff1.id  LEFT JOIN t_data_model_func_def fd1 on ff1.func_id=fd1.id"
+			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)
 	}
 	rowset := []orm.Params{}
 	_, err := o.Raw(sql, sqlParamters).Values(&rowset)