|
@@ -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)
|