checktools_area.go 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869
  1. package bo
  2. import (
  3. "errors"
  4. "fmt"
  5. "regexp"
  6. "scd_check_tools/logger"
  7. "scd_check_tools/models/enum"
  8. "scd_check_tools/models/node_attr"
  9. "scd_check_tools/tools"
  10. "strconv"
  11. "strings"
  12. "sync"
  13. "github.com/astaxie/beego/orm"
  14. )
  15. //检测时间隔管理
  16. type CheckAreaMgr struct {
  17. DeviceBaseModel
  18. //SCD文件ID
  19. ScdId int64
  20. //电压等级定义
  21. VoltageLevelDef map[string]int
  22. //设备类型定义
  23. DeviceTypeDef map[string]int
  24. CacheAreaID map[string]int64
  25. CacheAreaIDByIedNameNo map[string]int
  26. //检测模型列表
  27. CheckModelList []orm.Params
  28. //模型内装置关系定义
  29. CheckModelDef sync.Map
  30. CacheLock sync.RWMutex
  31. }
  32. type T_data_check_area struct {
  33. Id int64 `orm:"pk"`
  34. AreaName string
  35. ScdId int64
  36. VoltageLevel int
  37. AreaType string
  38. ModelId int
  39. Cr int // '创建人' ,
  40. Ct string `orm:"-"` // '创建时间' ,
  41. Ur int // '更新人' ,
  42. Ut string `orm:"-"` // '更新时间'
  43. }
  44. type t_data_check_area_ied struct {
  45. Id int64 `orm:"pk"`
  46. AreaId int64
  47. IedName string
  48. IedType string
  49. ScdId int64
  50. PType string
  51. Cr int // '创建人' ,
  52. Ct string `orm:"-"` // '创建时间' ,
  53. Ur int // '更新人' ,
  54. Ut string `orm:"-"` // '更新时间'
  55. }
  56. func init() {
  57. orm.RegisterModel(new(T_data_check_area))
  58. orm.RegisterModel(new(t_data_check_area_ied))
  59. }
  60. func (c *CheckAreaMgr) Init(scdid int64) {
  61. c.VoltageLevelDef = map[string]int{}
  62. c.DeviceTypeDef = map[string]int{}
  63. c.CacheAreaIDByIedNameNo = map[string]int{}
  64. c.CacheAreaID = map[string]int64{}
  65. c.CacheLock = sync.RWMutex{}
  66. c.ScdId = scdid
  67. db := orm.NewOrm()
  68. rowset := []orm.Params{}
  69. db.Raw("select * from global_const_code where parentcode=?", "voltage_level").Values(&rowset)
  70. for _, row := range rowset {
  71. vl := strings.ToLower(tools.IsEmpty(row["code"]))
  72. id, _ := strconv.ParseInt(tools.IsEmpty(row["id"]), 10, 32)
  73. c.VoltageLevelDef[strings.ReplaceAll(vl, "v_level_", "")] = int(id)
  74. }
  75. db.Raw("select * from global_const_code where parentcode=?", "device_type").Values(&rowset)
  76. for _, row := range rowset {
  77. vl := tools.IsEmpty(row["code"])
  78. c.DeviceTypeDef[vl] = 1
  79. }
  80. v, _ := GetSysParamValue("OtherIedNameList", "")
  81. otherIedNameList = map[string]bool{}
  82. if v != "" {
  83. vs := strings.Split(v, ",")
  84. for _, vv := range vs {
  85. otherIedNameList[vv] = true
  86. }
  87. }
  88. //先清除ied与间隔关联关系
  89. clearSql := "delete from t_data_check_area_ied where area_id in(select id from t_data_check_area where scd_id=?)"
  90. _, err := db.Raw(clearSql, c.ScdId).Exec()
  91. if err != nil {
  92. logger.Logger.Error(err, fmt.Sprintf("SQL:%s 参数:%+v", clearSql, []interface{}{c.ScdId}))
  93. }
  94. clearSql = "delete from t_data_check_area where scd_id=?"
  95. _, err = db.Raw(clearSql, c.ScdId).Exec()
  96. if err != nil {
  97. logger.Logger.Error(err, fmt.Sprintf("SQL:%s 参数:%+v", clearSql, []interface{}{c.ScdId}))
  98. }
  99. //获取当前scd信息中获取到对应的电压等级id
  100. /*
  101. scdMgr := new(ScdMgr)
  102. scdinfo, _ := scdMgr.One(fmt.Sprintf("%d", c.ScdId))
  103. stationid := tools.IsEmpty(scdinfo["station_id"])
  104. volid := 0
  105. if stationid != "" {
  106. basearea := new(BasicArea)
  107. stationonof, _ := basearea.One(stationid)
  108. volid = stationonof.AreaLevel
  109. }
  110. */
  111. tmplist, _ := new(SysCheckModelMgr).GetModelsByVolid(2)
  112. scdModels, _, _ := new(TaskMgr).GetModelsByScdID(c.ScdId)
  113. ms := map[string]interface{}{}
  114. for _, row := range scdModels {
  115. ms[tools.IsEmpty(row["model_id"])] = row
  116. }
  117. for _, row := range tmplist {
  118. modelid := tools.IsEmpty(row["id"])
  119. if ms[modelid] != nil {
  120. c.CheckModelList = append(c.CheckModelList, row)
  121. }
  122. }
  123. logger.Logger.Debug(fmt.Sprintf("任务的模型列表:%+v", c.CheckModelList))
  124. ms = nil
  125. tmplist = nil
  126. }
  127. //保存指定间隔所属的电压等级
  128. func (c *CheckAreaMgr) SetVoltageLevel(id string, voltagelevel int) error {
  129. db := orm.NewOrm()
  130. _, err := db.Raw("update t_data_check_area set voltage_level=? where id=?", voltagelevel, id).Exec()
  131. return err
  132. }
  133. //修改指定间隔的名称
  134. func (c *CheckAreaMgr) UpdateName(scdid int64, area_id int, name string) error {
  135. db := orm.NewOrm()
  136. areaM := T_data_check_area{Id: int64(area_id), ScdId: scdid}
  137. err := db.Read(&areaM)
  138. if err != nil {
  139. logger.Logger.Error(err)
  140. return err
  141. }
  142. areaM.AreaName = name
  143. _, err = db.Update(&areaM)
  144. if err != nil {
  145. logger.Logger.Error(err)
  146. }
  147. return err
  148. }
  149. //修改指定IED的所属间隔
  150. func (c *CheckAreaMgr) UpdateIedArea(scdid int64, iedname string, area_id int) error {
  151. db := orm.NewOrm()
  152. _, err := db.Raw("update t_data_check_area_ied set area_id=? where scd_id=? and ied_name=?", area_id, scdid, iedname).Exec()
  153. return err
  154. }
  155. //获取指定scd的间隔信息
  156. func (c *CheckAreaMgr) GetAreaList(scdid int64) ([]orm.Params, error) {
  157. db := orm.NewOrm()
  158. sql := "select t.*,(select count(1) from t_data_check_area_ied where area_id=t.id) iedcount from t_data_check_area t where t.scd_id=? order by t.name"
  159. rowset := []orm.Params{}
  160. _, err := db.Raw(sql, scdid).Values(&rowset)
  161. sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, []interface{}{scdid})
  162. if err != nil {
  163. logger.Logger.Error(err, sqllog)
  164. new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
  165. } else {
  166. new(SystemLog).Success(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
  167. }
  168. return rowset, nil
  169. }
  170. //获取指定scd和电压等级的间隔信息
  171. func (c *CheckAreaMgr) GetAreaListByVol(scdid int64, vl, linkstyleid int) ([]orm.Params, error) {
  172. db := orm.NewOrm()
  173. sql := "select t1.id model_id, t1.model_name,t1.vol_id,g1.name vol_name,t1.line_link_style,ls.name,t.id area_id, t.area_name,t.ut,t.ur from t_data_check_area t right join t_data_model_defualt t1 on t.model_id=t1.id left join t_data_link_style ls on t1.line_link_style=ls.id left join global_const_code g1 on t1.vol_id=g1.id and g1.parentcode='voltage_level' where t.scd_id=? "
  174. params := []interface{}{scdid}
  175. if vl > 0 {
  176. sql = sql + " and t1.vol_id=? "
  177. params = append(params, vl)
  178. }
  179. if linkstyleid > 0 {
  180. sql = sql + " and t1.line_link_style=? "
  181. params = append(params, linkstyleid)
  182. }
  183. rowset := []orm.Params{}
  184. _, err := db.Raw(sql+" order by t1.vol_id,t1.line_link_style,t1.id", params).Values(&rowset)
  185. sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, []interface{}{scdid, vl})
  186. if err != nil {
  187. logger.Logger.Error(err, sqllog)
  188. new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
  189. } else {
  190. new(SystemLog).Success(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
  191. }
  192. return rowset, nil
  193. }
  194. //获取指定间隔下的IED列表
  195. func (c *CheckAreaMgr) GetIedList(scdid int64, areaid int) ([]orm.Params, error) {
  196. db := orm.NewOrm()
  197. sql := "select t1.* from t_data_check_area t,t_data_check_area_ied t1 where t.scd_id=? and t.id=t1.area_id "
  198. sqlParamters := []interface{}{}
  199. sqlParamters = append(sqlParamters, scdid)
  200. if areaid > 0 {
  201. sql = sql + " and t1.area_id=?"
  202. sqlParamters = append(sqlParamters, areaid)
  203. }
  204. scdXmlObj, serr := new(ScdParse).GetScdXmlObjectBySCDID(tools.IsEmpty(scdid))
  205. if serr != nil {
  206. return nil, serr
  207. }
  208. if scdXmlObj == nil {
  209. return nil, errors.New("无效的SCD")
  210. }
  211. rowset := []orm.Params{}
  212. _, err := db.Raw(sql, sqlParamters).Values(&rowset)
  213. sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, sqlParamters)
  214. if err != nil {
  215. logger.Logger.Error(err, sqllog)
  216. new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
  217. } else {
  218. scdNode := new(ScdNode)
  219. for i, row := range rowset {
  220. iedObj := scdNode.GetIed(scdXmlObj, tools.IsEmpty(scdid), tools.IsEmpty(row["ied_name"]))
  221. if iedObj == nil {
  222. continue
  223. }
  224. rowset[i]["attr_name"] = iedObj.Name
  225. rowset[i]["attr_desc"] = iedObj.Desc
  226. rowset[i]["attr_config_version"] = iedObj.ConfigVersion
  227. rowset[i]["attr_type"] = iedObj.Type
  228. rowset[i]["attr_manufacturer"] = iedObj.Manufacturer
  229. rowset[i]["ied_id"] = iedObj.NodeId
  230. }
  231. new(SystemLog).Success(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
  232. }
  233. return rowset, nil
  234. }
  235. //更新指定间隔下的装置定义
  236. func (c *CheckAreaMgr) UpdateIeds(scdid int64, areaid int, ieds string) error {
  237. db := orm.NewOrm()
  238. iedlist := strings.Split(ieds, ",")
  239. _, err := db.Raw("delete from t_data_check_area_ied where scd_id=? and area_id=?", scdid, areaid).Exec()
  240. if err != nil {
  241. logger.Logger.Error(err)
  242. return err
  243. }
  244. for _, row := range iedlist {
  245. _, err = db.Raw("insert into t_data_check_area_ied(scd_id,area_id,ied_name)values(?,?,?)", scdid, areaid, row).Exec()
  246. if err != nil {
  247. logger.Logger.Error(err)
  248. break
  249. }
  250. }
  251. return err
  252. }
  253. //获取指定SCD的IED类型列表
  254. func (c *CheckAreaMgr) GetIedTypeList(scdid int64) ([]orm.Params, error) {
  255. db := orm.NewOrm()
  256. sql := "select t2.* from t_data_check_area_ied t1,global_const_code t2 where t1.scd_id=? and t1.ied_type=t2.code and t2.parentcode='device_type' group by t1.ied_type "
  257. sqlParamters := []interface{}{}
  258. rowset := []orm.Params{}
  259. sqlParamters = append(sqlParamters, scdid)
  260. _, err := db.Raw(sql, sqlParamters).Values(&rowset)
  261. sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, sqlParamters)
  262. if err != nil {
  263. logger.Logger.Error(err, sqllog)
  264. new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
  265. }
  266. return rowset, nil
  267. }
  268. func (c *CheckAreaMgr) One(id string) (interface{}, error) {
  269. db := orm.NewOrm()
  270. idInt, err := strconv.ParseInt(id, 10, 64)
  271. if err != nil {
  272. return nil, err
  273. }
  274. areaM := T_data_check_area{Id: idInt}
  275. err = db.Read(&areaM)
  276. if err == nil {
  277. return areaM, nil
  278. }
  279. return nil, err
  280. }
  281. //重置scd的间隔信息
  282. func (c *CheckAreaMgr) Reset() error {
  283. dbo := orm.NewOrm()
  284. dbo.Raw("delete from t_data_check_area where scd_id=?", c.ScdId).Exec()
  285. dbo.Raw("delete from t_data_check_area_ied where scd_id=?", c.ScdId).Exec()
  286. c.ParseModelArea()
  287. logdesc := fmt.Sprintf("重置SCD[%d]检测模型间隔成功", c.ScdId)
  288. new(SystemLog).Success(enum.AuditType_check_task, enum.LogType_bind, enum.OptEventType_Bus, enum.OptEventLevel_Mid, logdesc, c.GetUserInfo())
  289. return nil
  290. }
  291. var areaCheckInfo = sync.Map{}
  292. //获取解析模型需要的基础数据信息
  293. func (c *CheckAreaMgr) getAreaCheckInfo() (*node_attr.SCL, []orm.Params, string, error) {
  294. key := fmt.Sprintf("%d-checkinfo", c.ScdId)
  295. if v, h := areaCheckInfo.Load(key); h {
  296. v1 := v.([]interface{})
  297. return v1[0].(*node_attr.SCL), v1[1].([]orm.Params), v1[2].(string), nil
  298. }
  299. arealist := []orm.Params{}
  300. db := orm.NewOrm()
  301. _, err := db.Raw("select id,area_name,area_type,model_id from t_data_check_area where scd_id=?", c.ScdId).Values(&arealist)
  302. if err != nil {
  303. logger.Logger.Error(err)
  304. return nil, nil, "", err
  305. }
  306. scdNodeRule := new(ScdNodeRule)
  307. area_ruleid := ""
  308. area_ruleList, _, _ := scdNodeRule.GetDefList(map[string]interface{}{"check_name": "间隔装置与检查模型不符"}, 1, 1)
  309. if len(area_ruleList) > 0 {
  310. area_ruleid = tools.IsEmpty(area_ruleList[0]["id"])
  311. }
  312. if area_ruleid == "" {
  313. return nil, nil, "", errors.New(fmt.Sprintf("未定义间隔装置的检查规则“间隔装置与检查模型不符”"))
  314. }
  315. scdParseMgr := new(ScdParse)
  316. scdXmlObj, serr := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
  317. if serr != nil {
  318. return nil, nil, "", serr
  319. }
  320. if scdXmlObj == nil {
  321. return nil, nil, "", errors.New("无效的SCD")
  322. }
  323. areaCheckInfo.Store(key, []interface{}{scdXmlObj, arealist, area_ruleid})
  324. return scdXmlObj, arealist, area_ruleid, nil
  325. }
  326. //检测装置端子分析:检测间隔装置关系正确性(已废弃)
  327. func (c *CheckAreaMgr) CheckAreaIedRelation() error {
  328. // 获取当前scd中需要检查的间隔
  329. scdXmlObj, arealist, area_ruleid, err := c.getAreaCheckInfo()
  330. db := orm.NewOrm()
  331. if err != nil {
  332. logger.Logger.Error(err)
  333. return err
  334. }
  335. if area_ruleid == "" {
  336. return errors.New(fmt.Sprintf("未定义间隔装置的检查规则“间隔装置与检查模型不符”"))
  337. }
  338. if scdXmlObj == nil {
  339. return errors.New("无效的SCD")
  340. }
  341. scdNodeRule := new(ScdNodeRule)
  342. scdNode := new(ScdNode)
  343. model_refs := map[string][]orm.Params{} //模型定义的装置关系定义
  344. area_ieds := map[string][]orm.Params{} //间隔下的装置列表
  345. iedRelationMgr := new(SysCheckModelIedRelationMgr)
  346. for _, row := range arealist {
  347. //获取间隔标准装置及关系
  348. modelid, _ := strconv.Atoi(tools.IsEmpty(row["model_id"]))
  349. //area_name := tools.IsEmpty(row["area_name"])
  350. //area_type := tools.IsEmpty(row["area_type"]) //间隔模型类型
  351. area_id := tools.IsEmpty(row["id"])
  352. s, err := iedRelationMgr.GetListByModelid(modelid)
  353. if err != nil {
  354. logger.Logger.Error(err)
  355. return err
  356. }
  357. if len(s) == 0 {
  358. return errors.New(fmt.Sprintf("模型%d还未配置装置关系", modelid))
  359. }
  360. model_refs[fmt.Sprintf("%d", modelid)] = s
  361. /*
  362. hasIeds := map[string]bool{}
  363. for _, row1 := range s {
  364. iedname := tools.IsEmpty(row1["from_ied_code"])
  365. if !hasIeds[iedname] {
  366. hasIeds[iedname] = true
  367. }
  368. iedname = tools.IsEmpty(row1["to_ied_code"])
  369. if !hasIeds[iedname] {
  370. hasIeds[iedname] = true
  371. }
  372. }
  373. */
  374. s1 := []orm.Params{}
  375. _, err = db.Raw("select ied_name from t_data_check_area_ied where area_id=?", area_id).Values(&s1)
  376. if err != nil {
  377. logger.Logger.Error(err)
  378. return err
  379. }
  380. if len(s) == 0 {
  381. return errors.New(fmt.Sprintf("间隔%s未发现任何装置", tools.IsEmpty(row["area_name"])))
  382. }
  383. area_ieds[area_id] = s1
  384. }
  385. //装置关联关系分析
  386. //先分析母联间隔,如果没有选择母联间隔时,主变间隔中不包含母联终端装置
  387. HasAreaJ := false
  388. for _, row := range arealist {
  389. area_name := tools.IsEmpty(row["area_name"])
  390. areaCode := tools.IsEmpty(row["area_type"]) //间隔模型类型
  391. area_id := tools.IsEmpty(row["id"])
  392. if areaCode == "J" {
  393. HasAreaJ = true
  394. modelid := tools.IsEmpty(row["model_id"])
  395. c.cJ(modelid, scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PE", area_ruleid)
  396. c.cJ(modelid, scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PJ", area_ruleid)
  397. c.cJ(modelid, scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PK", area_ruleid)
  398. c.cJ(modelid, scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PF", area_ruleid)
  399. }
  400. }
  401. for _, row := range arealist {
  402. area_name := tools.IsEmpty(row["area_name"])
  403. areaCode := tools.IsEmpty(row["area_type"]) //间隔模型类型
  404. area_id := tools.IsEmpty(row["id"])
  405. modelid := tools.IsEmpty(row["model_id"])
  406. if areaCode == "J" {
  407. continue
  408. }
  409. if areaCode == "L" {
  410. //线路间隔
  411. c.cL(modelid, scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], area_ruleid)
  412. }
  413. if areaCode == "T" {
  414. //变压器齐间隔
  415. c.cT(modelid, scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], area_ruleid, HasAreaJ)
  416. }
  417. }
  418. scdNodeRule.CheckFinish()
  419. scdNodeRule.Flush()
  420. return nil
  421. }
  422. //检测装置功能分析
  423. func (c *CheckAreaMgr) CheckIedFunc() error {
  424. return nil
  425. }
  426. //检测装置端子分析
  427. func (c *CheckAreaMgr) CheckIedFcda() error {
  428. scdXmlObj, arealist, area_ruleid, err := c.getAreaCheckInfo()
  429. if err != nil {
  430. logger.Logger.Error(err)
  431. return err
  432. }
  433. if area_ruleid == "" {
  434. return errors.New(fmt.Sprintf("未定义间隔装置的检查规则“间隔装置与检查模型不符”"))
  435. }
  436. if scdXmlObj == nil {
  437. return errors.New("无效的SCD")
  438. }
  439. db := orm.NewOrm()
  440. //获取当前站的各电压等级
  441. volRows := []orm.Params{}
  442. _, 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)
  443. if err != nil {
  444. logger.Logger.Error(err)
  445. return err
  446. }
  447. if len(volRows) == 0 {
  448. logger.Logger.Error(errors.New("该scd未发现任何电压等级的装置"))
  449. return errors.New("该scd未发现任何电压等级的装置")
  450. }
  451. volMap := map[string]string{}
  452. volMap["hight"] = tools.IsEmpty(volRows[0]["vol"]) //高压电压
  453. if len(volRows) == 2 {
  454. volMap["middle"] = ""
  455. volMap["low"] = volRows[1]["vol"].(string) //低压电压等级
  456. } else {
  457. volMap["middle"] = volRows[1]["vol"].(string) //中压电压等级
  458. volMap["low"] = volRows[len(volRows)-1]["vol"].(string) //低压电压等级
  459. }
  460. scdNodeRule := new(ScdNodeRule)
  461. scdNodeMgr := new(ScdNode)
  462. //当前装置的所有信号接收端子列表
  463. var getIedExtRefs = func(iedname string) map[string]*node_attr.NExtRef {
  464. iedObj := scdNodeMgr.GetIed(scdXmlObj, tools.IsEmpty(c.ScdId), iedname)
  465. if iedObj == nil {
  466. return nil
  467. }
  468. fcdaObjList := map[string]*node_attr.NExtRef{}
  469. for _, t1 := range iedObj.AccessPoint {
  470. if t1.Server == nil || len(t1.Server.LDevice) == 0 {
  471. continue
  472. }
  473. for _, ld := range t1.Server.LDevice {
  474. if ld.LN0 != nil && ld.LN0.Inputs != nil {
  475. for _, t2 := range ld.LN0.Inputs.ExtRef {
  476. doi := scdNodeRule.IedIntAddrExist(iedname, t2.IntAddr)
  477. if doi == nil {
  478. continue
  479. }
  480. fcdaObjList[doi.(*node_attr.NDOI).Desc] = t2
  481. }
  482. }
  483. for _, ln := range ld.LN {
  484. if ln.Inputs == nil {
  485. continue
  486. }
  487. for _, t2 := range ln.Inputs.ExtRef {
  488. doi := scdNodeRule.IedIntAddrExist(iedname, t2.IntAddr)
  489. if doi == nil {
  490. continue
  491. }
  492. fcdaObjList[doi.(*node_attr.NDOI).Desc] = t2
  493. }
  494. }
  495. }
  496. }
  497. return fcdaObjList
  498. }
  499. //当前装置的所有信号发送端子列表
  500. var getIedFcdas = func(iedname string) map[string]*node_attr.NFCDA {
  501. iedObj := scdNodeMgr.GetIed(scdXmlObj, tools.IsEmpty(c.ScdId), iedname)
  502. if iedObj == nil {
  503. return nil
  504. }
  505. fcdaObjList := map[string]*node_attr.NFCDA{}
  506. for _, t1 := range iedObj.AccessPoint {
  507. if t1.Server == nil || len(t1.Server.LDevice) == 0 {
  508. continue
  509. }
  510. for _, ld := range t1.Server.LDevice {
  511. if ld.LN0 != nil && len(ld.LN0.DataSet) > 0 {
  512. for _, t2 := range ld.LN0.DataSet {
  513. for _, t3 := range t2.FCDA {
  514. re, _ := scdNodeRule.IedFcdaExist(iedname, t3.LdInst, t3.LnClass, t3.LnInst, t3.Prefix, t3.DoName, t3.DaName)
  515. if re == nil {
  516. continue
  517. }
  518. doi := re.(*node_attr.NDOI)
  519. fcdaObjList[doi.Desc] = t3
  520. }
  521. }
  522. }
  523. }
  524. }
  525. return fcdaObjList
  526. }
  527. //从装置类型code中解析出类型代码和电压等级
  528. var getIedTypeAndVolCode = func(ied_type string) (string, string) {
  529. tmp := strings.Split(ied_type, "#")
  530. ied_type = tmp[0]
  531. vol := ""
  532. if len(tmp) == 2 {
  533. vol = tmp[1] //电压级别
  534. }
  535. return ied_type, vol
  536. }
  537. //从间隔装置中过滤出指定类型的IED
  538. var filterAreaIeds = func(ied_type, volLevelCode string, s1 []orm.Params) []orm.Params {
  539. iedlst := []orm.Params{}
  540. if volLevelCode == "" || (volLevelCode != "H" && volLevelCode != "M" && volLevelCode != "L") {
  541. for _, r := range s1 {
  542. if strings.HasPrefix(tools.IsEmpty(r["ied_name"]), ied_type) {
  543. iedlst = append(iedlst, r)
  544. }
  545. }
  546. } else {
  547. tmpLst := map[string]orm.Params{}
  548. for _, r := range s1 {
  549. iedname := tools.IsEmpty(r["ied_name"])
  550. if strings.HasPrefix(iedname, ied_type) {
  551. tmpLst[iedname] = r
  552. }
  553. }
  554. h, m, l := c.getIedListByVol(ied_type, tmpLst, volMap)
  555. if volLevelCode == "H" {
  556. iedlst = h
  557. }
  558. if volLevelCode == "M" {
  559. iedlst = m
  560. }
  561. if volLevelCode == "L" {
  562. iedlst = l
  563. }
  564. }
  565. return iedlst
  566. }
  567. //iedRelationMgr := new(SysCheckModelIedRelationMgr)
  568. for _, row := range arealist {
  569. //获取间隔标准装置及关系
  570. modelid, _ := strconv.Atoi(tools.IsEmpty(row["model_id"]))
  571. area_name := tools.IsEmpty(row["area_name"])
  572. //area_type := tools.IsEmpty(row["area_type"]) //间隔模型类型
  573. area_id := tools.IsEmpty(row["id"])
  574. //获取该间隔模型配置的所有端子关系列表
  575. tmpMgr := new(SysCheckModelFcdaRalationMgr)
  576. tmpMgr.Model.ModelId = modelid
  577. funclist, _ := tmpMgr.GetModelAllFcdaRef()
  578. if funclist == nil {
  579. continue
  580. }
  581. if len(funclist) == 0 {
  582. logger.Logger.Error(errors.New(fmt.Sprintf("模型%d还未配置装置关系", modelid)))
  583. continue
  584. }
  585. //获取该间隔下该类型的装置
  586. s1 := []orm.Params{}
  587. _, err = db.Raw("select ied_name from t_data_check_area_ied where area_id=?", area_id).Values(&s1)
  588. //循环处理关联关系
  589. for ied_type2, fromrowlist := range funclist {
  590. ied_type := c.getIedTypeCode(modelid, ied_type2)
  591. //找出信号输出装置
  592. outiedlist := map[string][]orm.Params{}
  593. for _, r := range fromrowlist {
  594. fromiedcode := c.getIedTypeCode(modelid, tools.IsEmpty(r["from_ied_code"]))
  595. ied_type, vol := getIedTypeAndVolCode(fromiedcode)
  596. outiedlist2 := filterAreaIeds(ied_type, vol, s1)
  597. for _, iedrow := range outiedlist2 {
  598. iedname := tools.IsEmpty(iedrow["ied_name"])
  599. if outiedlist[iedname] == nil {
  600. outiedlist[iedname] = []orm.Params{}
  601. }
  602. outiedlist[iedname] = append(outiedlist[iedname], r)
  603. }
  604. }
  605. if len(outiedlist) == 0 {
  606. continue
  607. }
  608. ied_type, vol := getIedTypeAndVolCode(ied_type)
  609. iedlst := filterAreaIeds(ied_type, vol, s1)
  610. for _, ied := range iedlst {
  611. iedname := tools.IsEmpty(ied["ied_name"])
  612. iedObj := scdNodeMgr.GetIed(scdXmlObj, fmt.Sprintf("%d", c.ScdId), iedname)
  613. iedObjDesc := ""
  614. if iedObj != nil {
  615. iedObjDesc = iedObj.Desc
  616. } else {
  617. logger.Logger.Error(fmt.Sprintf("信号接收装置%s未找到!", iedname))
  618. }
  619. extreflist := getIedExtRefs(iedname)
  620. for outiedname, refrow := range outiedlist {
  621. outIedObj := scdNodeMgr.GetIed(scdXmlObj, fmt.Sprintf("%d", c.ScdId), outiedname)
  622. outIedObjDesc := ""
  623. if outIedObj == nil {
  624. logger.Logger.Error(fmt.Sprintf("信号输出装置%s未找到!", outiedname))
  625. } else {
  626. outIedObjDesc = outIedObj.Desc
  627. }
  628. if iedObj == nil && outIedObj == nil {
  629. continue
  630. }
  631. outiedFcdaList := getIedFcdas(outiedname) //输入装置的信号输出端子
  632. //检查是否有错误和缺失的端子
  633. hasYaoXinFunc := false //是否具备遥信功能
  634. for _, r := range refrow {
  635. //判断装置是否具备遥信功能,具备时需要单独处理遥信类端子
  636. //遥信类端子处理规则:以scd中实际配置为准,通过检查装置双方的端子名称是否完全一致,以及是否有缺失和多余的遥信端子
  637. if strings.Contains(tools.IsEmpty(r["to_func_name"]), "遥信") || strings.Contains(tools.IsEmpty(r["from_func_name"]), "遥信") {
  638. hasYaoXinFunc = true
  639. }
  640. extref_name := tools.IsEmpty(r["to_fcda_name"])
  641. fcda_name := tools.IsEmpty(r["from_fcda_name"])
  642. extref_name_exp := tools.IsEmpty(r["to_fcda_match_exp"])
  643. fcda_name_exp := tools.IsEmpty(r["from_fcda_match_exp"])
  644. funcExist := false //设计的功能是否存在
  645. extrefObj := new(node_attr.NExtRef)
  646. for desc, item := range extreflist {
  647. rex, err := regexp.Compile(extref_name_exp)
  648. if err != nil {
  649. logger.Logger.Error(err, "无效的正则表达式:"+extref_name_exp)
  650. return err
  651. }
  652. if rex.MatchString(desc) {
  653. funcExist = true
  654. extrefObj = item
  655. break
  656. }
  657. }
  658. if !funcExist {
  659. parse_result := fmt.Sprintf("间隔%s的装置%s缺失端子%s", area_name, iedname, extref_name)
  660. re := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result,
  661. "ied_name": iedname,
  662. "ied_desc": iedObjDesc,
  663. "out_ied_name": outiedname,
  664. "out_ied_desc": outIedObjDesc,
  665. "fcda_desc": extref_name,
  666. "fcda_addr": "",
  667. "out_fcda_desc": fcda_name,
  668. "out_fcda_addr": "",
  669. "error_type": "3",
  670. }
  671. //检查未通过
  672. scdNodeRule.AppendFcdaCheckResult(re)
  673. } else {
  674. //检查端子是否关联正确
  675. fcda2Exist := false
  676. fcdaObj := new(node_attr.NFCDA)
  677. for desc, item := range outiedFcdaList {
  678. rex, err := regexp.Compile(fcda_name_exp)
  679. if err != nil {
  680. logger.Logger.Error(err, "无效的正则表达式:"+fcda_name_exp)
  681. return err
  682. }
  683. if rex.MatchString(desc) {
  684. fcda2Exist = true
  685. fcdaObj = item
  686. break
  687. }
  688. }
  689. if fcda2Exist && (extrefObj.LdInst != fcdaObj.LdInst ||
  690. extrefObj.LnInst != fcdaObj.LnInst ||
  691. extrefObj.LnClass != fcdaObj.LnClass ||
  692. extrefObj.Prefix != fcdaObj.Prefix ||
  693. extrefObj.DoName != fcdaObj.DoName) {
  694. //不正确
  695. iedObj := scdNodeMgr.GetIed(scdXmlObj, fmt.Sprintf("%d", c.ScdId), iedname)
  696. outIedObj := scdNodeMgr.GetIed(scdXmlObj, fmt.Sprintf("%d", c.ScdId), outiedname)
  697. parse_result := fmt.Sprintf("间隔%s的装置%s端子%s与装置%s端子%s关联错误", area_name, iedname, extref_name, outiedname, fcda_name)
  698. daname := ""
  699. if fcdaObj.DaName != "" {
  700. daname = "." + fcdaObj.DaName
  701. }
  702. re := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result,
  703. "ied_name": iedname,
  704. "ied_desc": iedObj.Desc,
  705. "out_ied_name": outiedname,
  706. "out_ied_desc": outIedObj.Desc,
  707. "fcda_desc": extref_name,
  708. "fcda_addr": extrefObj.IntAddr,
  709. "out_fcda_desc": fcda_name,
  710. "out_fcda_addr": fmt.Sprintf("%s/%s%s%s.%s%s", fcdaObj.LdInst, fcdaObj.Prefix, fcdaObj.LnClass, fcdaObj.LnInst, fcdaObj.DoName, daname),
  711. "error_type": "2",
  712. }
  713. //检查未通过
  714. scdNodeRule.AppendFcdaCheckResult(re)
  715. }
  716. }
  717. }
  718. //检查是否有多余(SCD中有不存在于设计中)的端子
  719. for extrefdesc, r := range extreflist { //scd中的端子关系
  720. extref_name := ""
  721. fcda_name := ""
  722. isHave := false
  723. for _, r1 := range refrow { //设计的端子关系
  724. if strings.Contains(tools.IsEmpty(r1["to_func_name"]), "遥信") || strings.Contains(tools.IsEmpty(r1["from_func_name"]), "遥信") {
  725. hasYaoXinFunc = true
  726. }
  727. extref_name_exp := tools.IsEmpty(r1["to_fcda_match_exp"])
  728. rex, err := regexp.Compile(extref_name_exp)
  729. if err != nil {
  730. logger.Logger.Error(err)
  731. return err
  732. }
  733. if rex.MatchString(extrefdesc) {
  734. //端子存在
  735. isHave = true
  736. break
  737. }
  738. }
  739. if !isHave {
  740. parse_result := fmt.Sprintf("间隔%s的装置%s端子%s在设计中不存在", area_name, iedname, extref_name)
  741. daname := ""
  742. if r.DaName != "" {
  743. daname = "." + r.DaName
  744. }
  745. doi := scdNodeRule.IedIntAddrExist(iedname, r.IntAddr)
  746. if doi != nil {
  747. extref_name = doi.(*node_attr.NDOI).Desc
  748. }
  749. doi, _ = scdNodeRule.IedFcdaExist(outiedname, r.LdInst, r.LnClass, r.LnInst, r.Prefix, r.DoName, "")
  750. if doi != nil {
  751. fcda_name = doi.(*node_attr.NDOI).Desc
  752. }
  753. re := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result,
  754. "ied_name": iedname,
  755. "ied_desc": iedObj.Desc,
  756. "out_ied_name": outiedname,
  757. "out_ied_desc": outIedObj.Desc,
  758. "fcda_desc": extref_name,
  759. "fcda_addr": r.IntAddr,
  760. "out_fcda_desc": fcda_name,
  761. "out_fcda_addr": fmt.Sprintf("%s/%s%s%s.%s%s", r.LdInst, r.Prefix, r.LnClass, r.LnInst, r.DoName, daname),
  762. "error_type": "1",
  763. }
  764. //检查未通过
  765. scdNodeRule.AppendFcdaCheckResult(re)
  766. }
  767. }
  768. if hasYaoXinFunc {
  769. //遥信端子检查:仅根据scd实际配置检查其双方端子的doi名称是否相同
  770. scdMgr := new(ScdMgr)
  771. yx := scdMgr.GetYxExtref(scdXmlObj, c.ScdId, iedname)
  772. if len(yx) > 0 {
  773. for extref, doiDesc := range yx {
  774. if extref.IedName != outiedname {
  775. //非当前输入装置的,不处理
  776. continue
  777. }
  778. daname := ""
  779. if extref.DaName != "" {
  780. daname = "." + extref.DaName
  781. }
  782. //获取输出端端子名称
  783. outFcdaDoi, _ := scdNodeRule.IedFcdaExist(extref.IedName, extref.LdInst, extref.LnClass, extref.LnInst, extref.Prefix, extref.DoName, extref.DaName)
  784. if outFcdaDoi == nil {
  785. //端子缺失
  786. parse_result := fmt.Sprintf("间隔%s的装置%s端子%s的关联端子不存在", area_name, iedname, doiDesc)
  787. re := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result,
  788. "ied_name": iedname,
  789. "ied_desc": iedObj.Desc,
  790. "out_ied_name": outiedname,
  791. "out_ied_desc": outIedObj.Desc,
  792. "fcda_desc": doiDesc,
  793. "fcda_addr": extref.IntAddr,
  794. "out_fcda_desc": "",
  795. "out_fcda_addr": fmt.Sprintf("%s/%s%s%s.%s%s", extref.LdInst, extref.Prefix, extref.LnClass, extref.LnInst, extref.DoName, daname),
  796. "error_type": "3",
  797. }
  798. //检查未通过
  799. scdNodeRule.AppendFcdaCheckResult(re)
  800. } else if outFcdaDoi.(*node_attr.NDOI).Desc != doiDesc {
  801. //关联错误
  802. parse_result := fmt.Sprintf("间隔%s的装置%s端子%s与装置%s端子%s名称不匹配", area_name, iedname, doiDesc, outiedname, outFcdaDoi.(*node_attr.NDOI).Desc)
  803. re := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result,
  804. "ied_name": iedname,
  805. "ied_desc": iedObj.Desc,
  806. "out_ied_name": outiedname,
  807. "out_ied_desc": outIedObj.Desc,
  808. "fcda_desc": doiDesc,
  809. "fcda_addr": extref.IntAddr,
  810. "out_fcda_desc": outFcdaDoi.(*node_attr.NDOI).Desc,
  811. "out_fcda_addr": fmt.Sprintf("%s/%s%s%s.%s%s", extref.LdInst, extref.Prefix, extref.LnClass, extref.LnInst, extref.DoName, daname),
  812. "error_type": "2",
  813. }
  814. //检查未通过
  815. scdNodeRule.AppendFcdaCheckResult(re)
  816. }
  817. }
  818. }
  819. }
  820. }
  821. }
  822. }
  823. }
  824. scdNodeRule.CheckFinish()
  825. scdNodeRule.Flush()
  826. return nil
  827. }
  828. //解析模型间隔。根据模型定义解析出间隔中的装置
  829. func (c *CheckAreaMgr) ParseModelArea() {
  830. c.Init(c.ScdId)
  831. key := fmt.Sprintf("%d-checkinfo", c.ScdId)
  832. areaCheckInfo.Delete(key)
  833. // 取得当前scd所有ied及名称解析结果
  834. dbo := orm.NewOrm()
  835. sql := "select t.*,t1.name area_name from t_area_ied_relation t,t_substation_area t1 where t.area_id=t1.id and t.scd_id=? order by t.p_type"
  836. iedlst := []orm.Params{}
  837. _, err := dbo.Raw(sql, c.ScdId).Values(&iedlst)
  838. if err != nil {
  839. logger.Logger.Error(err)
  840. return
  841. }
  842. logger.Logger.Debug(fmt.Sprintf("=====总装置数:%d", len(iedlst)))
  843. iedMap := map[string]orm.Params{}
  844. for _, r := range iedlst {
  845. iedMap[tools.IsEmpty(r["ied_name"])] = r
  846. }
  847. //先分析母联间隔,如果没有选择母联间隔时,主变间隔中不包含母联终端装置
  848. HasAreaJ := false
  849. for _, row := range c.CheckModelList {
  850. areaCode := tools.IsEmpty(row["area_type_code"])
  851. if areaCode == "J" {
  852. HasAreaJ = true
  853. modelid, _ := strconv.Atoi(tools.IsEmpty(row["id"]))
  854. //modelname := tools.IsEmpty(row["model_name"])
  855. iedtypes := tools.IsEmpty(row["ied_types"])
  856. mapptype := new(SysCheckModelIedtypeMappingMgr)
  857. mapptype.Model = T_data_model_iedtype_mapping{ModelId: modelid}
  858. mappresult := mapptype.List()
  859. if len(mappresult) > 0 {
  860. tmp := []string{}
  861. for _, r := range strings.Split(iedtypes, ",") {
  862. if mappresult[r] != "" {
  863. tmp = append(tmp, mappresult[r])
  864. } else {
  865. tmp = append(tmp, r)
  866. }
  867. }
  868. iedtypes = strings.Join(tmp, ",")
  869. }
  870. volcode := strings.ReplaceAll(tools.IsEmpty(row["vol_code"]), "v_level_", "")
  871. c.pJ(modelid, volcode, iedtypes, iedMap, "PE")
  872. c.pJ(modelid, volcode, iedtypes, iedMap, "PJ")
  873. c.pJ(modelid, volcode, iedtypes, iedMap, "PK")
  874. c.pJ(modelid, volcode, iedtypes, iedMap, "PF")
  875. }
  876. }
  877. for _, row := range c.CheckModelList {
  878. //逐一分析模型定义
  879. modelid, _ := strconv.Atoi(tools.IsEmpty(row["id"]))
  880. modelname := tools.IsEmpty(row["model_name"])
  881. iedtypes := tools.IsEmpty(row["ied_types"])
  882. //模型对应的间隔代码
  883. /*
  884. S 站用变压器
  885. C 电容器
  886. B 断路器
  887. K 母分
  888. J 母联
  889. M 母线
  890. X 电抗器
  891. L 线路
  892. T 主变压器
  893. */
  894. areaCode := tools.IsEmpty(row["area_type_code"])
  895. //模型对应的电压等级
  896. //10:10KV 35:35KV 66:66KV 11:110KV 22:220KV 50:500KV 75:750KV 33:330KV T0:1000KV
  897. volcode := strings.ReplaceAll(tools.IsEmpty(row["vol_code"]), "v_level_", "")
  898. if modelname == "" || iedtypes == "" {
  899. continue
  900. }
  901. //母联间隔已经提前分析,如果没有母联间隔时,主变间隔中不包含母联终端装置
  902. if areaCode == "J" {
  903. continue
  904. }
  905. //获取模型中的自定义装置类型编码
  906. mapptype := new(SysCheckModelIedtypeMappingMgr)
  907. mapptype.Model = T_data_model_iedtype_mapping{ModelId: modelid}
  908. mappresult := mapptype.List()
  909. if len(mappresult) > 0 {
  910. tmp := []string{}
  911. for _, r := range strings.Split(iedtypes, ",") {
  912. if mappresult[r] != "" {
  913. tmp = append(tmp, mappresult[r])
  914. } else {
  915. tmp = append(tmp, r)
  916. }
  917. }
  918. iedtypes = strings.Join(tmp, ",")
  919. }
  920. //获取模型内中装备关系定义
  921. //主变间隔分析:需要查站内该电压等级下的高中低压侧装置或者高低压装置组成一个间隔,以主变保护装置(PT)为起始
  922. if areaCode == "T" {
  923. c.pT(modelid, iedtypes, iedMap, HasAreaJ)
  924. }
  925. //线路保护间隔分析:以线路保护测控装置(PL)为开始分析
  926. if areaCode == "L" {
  927. c.pL(modelid, volcode, iedtypes, iedMap)
  928. }
  929. }
  930. }
  931. //根据默认装置类型获取其类型编码。如果没有自定义编码,则返回默认编码
  932. func (c *CheckAreaMgr) getIedTypeCode(modelid int, iedtype string) string {
  933. mapptype := new(SysCheckModelIedtypeMappingMgr)
  934. mapptype.Model = T_data_model_iedtype_mapping{ModelId: modelid}
  935. mapptype.Model.IedType = iedtype
  936. mappresult := mapptype.List()
  937. ptCode := iedtype
  938. if len(mappresult) > 0 {
  939. ptCode = mappresult[iedtype] //自定义主变保护编码
  940. }
  941. return ptCode
  942. }
  943. //变压器间隔分析
  944. func (c *CheckAreaMgr) pT(modelid int, iedtypes string, ieds map[string]orm.Params, HasAreaJ bool) {
  945. scdParseMgr := new(ScdParse)
  946. scdNodeMgr := new(ScdNode)
  947. db := orm.NewOrm()
  948. scdXmlObj, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
  949. //获取当前站的各电压等级
  950. volRows := []orm.Params{}
  951. _, 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)
  952. if err != nil {
  953. logger.Logger.Error(err)
  954. return
  955. }
  956. if len(volRows) == 0 {
  957. logger.Logger.Error(errors.New("该scd未发现任何电压等级的装置"))
  958. return
  959. }
  960. volMap := map[string]string{}
  961. volMap["hight"] = tools.IsEmpty(volRows[0]["vol"]) //高压电压
  962. if len(volRows) == 2 {
  963. volMap["middle"] = ""
  964. volMap["low"] = volRows[1]["vol"].(string) //低压电压等级
  965. } else {
  966. volMap["middle"] = volRows[1]["vol"].(string) //中压电压等级
  967. volMap["low"] = volRows[len(volRows)-1]["vol"].(string) //低压电压等级
  968. }
  969. var getIedByDesc = func(iedinfo map[string]orm.Params, iedtpye string, desc string) ([]string, []string) {
  970. scdParseMgr := new(ScdParse)
  971. scdXmlObj, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
  972. r1 := []string{}
  973. r2 := []string{}
  974. for vn, row := range iedinfo {
  975. if strings.HasPrefix(vn, iedtpye) {
  976. v := tools.IsEmpty(row["ied_desc"])
  977. if v == "" {
  978. if scdXmlObj == nil {
  979. continue
  980. }
  981. scdNode := new(ScdNode)
  982. ied := scdNode.GetIed(scdXmlObj, "", vn)
  983. if ied == nil {
  984. continue
  985. }
  986. v = ied.Desc
  987. }
  988. if strings.Contains(v, desc) {
  989. r1 = append(r1, v)
  990. r2 = append(r2, vn)
  991. }
  992. }
  993. }
  994. return r1, r2
  995. }
  996. //判断是否将各电压等级的保护装置合并还是分开的间隔
  997. //如果存在高中低压的保护装置,则说明是分开的主变间隔
  998. //isMarge := true // 默认为合并的主变间隔
  999. ptCode := c.getIedTypeCode(modelid, "PT")
  1000. for _, row := range ieds {
  1001. if tools.IsEmpty(row["ied_type"]) != ptCode[0:1] || tools.IsEmpty(row["p_type"]) != ptCode[1:] {
  1002. continue
  1003. }
  1004. //判断主变保护是否是按电压等级分开配置的模型
  1005. /*
  1006. if strings.Contains(iedtypes, "PT#H") || strings.Contains(iedtypes, "PT#M") || strings.Contains(iedtypes, "PT#L") {
  1007. h, m, l := c.getIedListByVol("PT", ieds, volMap)
  1008. } else {
  1009. pl_iedname := tools.IsEmpty(row["ied_name"])
  1010. }
  1011. */
  1012. //pmIedName := ""
  1013. //mmIedName := ""
  1014. pl_iedname := tools.IsEmpty(row["ied_name"])
  1015. iednameParts := scdParseMgr.ParseIedName(pl_iedname)
  1016. areadesc := tools.IsEmpty(row["ied_desc"])
  1017. if areadesc == "" {
  1018. iedobj := scdNodeMgr.GetIed(scdXmlObj, "", pl_iedname)
  1019. if iedobj != nil {
  1020. areadesc = iedobj.Desc
  1021. } else {
  1022. areadesc = tools.IsEmpty(row["area_name"])
  1023. }
  1024. }
  1025. areadesc = strings.ReplaceAll(areadesc, "装置", "")
  1026. //添加间隔数据
  1027. dbdata := T_data_check_area{
  1028. ModelId: modelid,
  1029. ScdId: c.ScdId,
  1030. AreaType: "T",
  1031. AreaName: areadesc + iednameParts[7],
  1032. }
  1033. newid, err := db.Insert(&dbdata)
  1034. if err != nil {
  1035. logger.Logger.Error(err)
  1036. return
  1037. }
  1038. ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
  1039. insvalues := []string{}
  1040. inAreaIedName := pl_iedname
  1041. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "T"))
  1042. //判断间隔是否需要包含差动装置
  1043. if strings.Contains(iedtypes, ptCode+"#C") {
  1044. _, iedname := getIedByDesc(ieds, ptCode, "差动")
  1045. if len(iedname) > 0 {
  1046. for _, in := range iedname {
  1047. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1048. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1049. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "P", "TC"))
  1050. break
  1051. }
  1052. }
  1053. }
  1054. }
  1055. //判断间隔是否需要包含本体保护装置
  1056. if strings.Contains(iedtypes, ptCode+"#0") {
  1057. _, iedname := getIedByDesc(ieds, ptCode, "本体")
  1058. if len(iedname) > 0 {
  1059. for _, in := range iedname {
  1060. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1061. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1062. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "P", "T0"))
  1063. break
  1064. }
  1065. }
  1066. }
  1067. }
  1068. //合智一体IMT/MIT,分高中低压
  1069. imtcode := c.getIedTypeCode(modelid, "IMT")
  1070. h, m, l := c.getIedListByVol(imtcode, ieds, volMap)
  1071. h = append(h, m...)
  1072. h = append(h, l...)
  1073. for _, r := range h {
  1074. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1075. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1076. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1077. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "IM", "T"))
  1078. }
  1079. }
  1080. imtcode = c.getIedTypeCode(modelid, "MIT")
  1081. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1082. h = append(h, m...)
  1083. h = append(h, l...)
  1084. for _, r := range h {
  1085. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1086. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1087. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1088. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "MI", "T"))
  1089. }
  1090. }
  1091. //母联智能终端IE需要分高中压,无低压侧
  1092. if HasAreaJ {
  1093. imtcode = c.getIedTypeCode(modelid, "IE")
  1094. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1095. for _, r := range h {
  1096. //高压侧,AB套必须与PT装置相同
  1097. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1098. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1099. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1100. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "E"))
  1101. }
  1102. }
  1103. for _, r := range m {
  1104. //中压侧
  1105. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1106. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1107. lastChar := tmpIednameParts[7]
  1108. if tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || tmpIednameParts[7] == iednameParts[7]) {
  1109. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "E"))
  1110. }
  1111. }
  1112. }
  1113. //合并单元MT分高中低压侧;低压侧无关联母线合并单元MM
  1114. imtcode = c.getIedTypeCode(modelid, "MT")
  1115. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1116. h = append(h, m...)
  1117. h = append(h, l...)
  1118. for _, r := range h {
  1119. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1120. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1121. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1122. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "M", "T"))
  1123. }
  1124. }
  1125. //是否包含本体合并单元
  1126. if strings.Contains(iedtypes, imtcode+"#0") {
  1127. _, iedname := getIedByDesc(ieds, imtcode, "本体")
  1128. if len(iedname) > 0 {
  1129. for _, in := range iedname {
  1130. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1131. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1132. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "M", "T"))
  1133. break
  1134. }
  1135. }
  1136. }
  1137. }
  1138. //测控装置CT分高中低压侧,且可能是多套合并单元MT共用,既不分AB套
  1139. imtcode = c.getIedTypeCode(modelid, "CT")
  1140. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1141. h = append(h, m...)
  1142. h = append(h, l...)
  1143. for _, r := range h {
  1144. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1145. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1146. lastChar := tmpIednameParts[7]
  1147. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1148. //高中低压电压等级相同的
  1149. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1150. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "C", "T"))
  1151. }
  1152. }
  1153. //是否包含本体测控装置
  1154. if strings.Contains(iedtypes, imtcode+"#0") {
  1155. _, iedname := getIedByDesc(ieds, imtcode, "本体")
  1156. if len(iedname) > 0 {
  1157. for _, in := range iedname {
  1158. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1159. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1160. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "C", "T"))
  1161. break
  1162. }
  1163. }
  1164. }
  1165. }
  1166. //智能终端(IB:开关\IT:分支\IF:分段)分高中低压侧
  1167. imtcodeB := c.getIedTypeCode(modelid, "IB")
  1168. imtcodeT := c.getIedTypeCode(modelid, "IT")
  1169. imtcodeF := c.getIedTypeCode(modelid, "IF")
  1170. h, m, l = c.getIedListByVol(imtcodeB, ieds, volMap)
  1171. h = append(h, m...)
  1172. h = append(h, l...)
  1173. for _, r := range h {
  1174. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1175. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1176. lastChar := tmpIednameParts[7]
  1177. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1178. //高中低压电压等级相同的
  1179. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1180. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "B"))
  1181. }
  1182. }
  1183. //是否包含本体测控装置
  1184. if strings.Contains(iedtypes, imtcodeT+"#0") {
  1185. for n, row := range ieds {
  1186. if strings.HasPrefix(n, imtcodeT) || strings.HasPrefix(n, imtcodeB) || strings.HasPrefix(n, imtcodeF) {
  1187. ieddesc := tools.IsEmpty(row["ied_desc"])
  1188. if strings.Contains(ieddesc, "本体") {
  1189. tmpIednameParts := scdParseMgr.ParseIedName(n)
  1190. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1191. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, n, "I", "T"))
  1192. break
  1193. }
  1194. }
  1195. }
  1196. }
  1197. }
  1198. h, m, l = c.getIedListByVol(imtcodeT, ieds, volMap)
  1199. h = append(h, m...)
  1200. h = append(h, l...)
  1201. for _, r := range h {
  1202. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1203. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1204. lastChar := tmpIednameParts[7]
  1205. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1206. //高中低压电压等级相同的
  1207. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1208. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "T"))
  1209. }
  1210. }
  1211. h, m, l = c.getIedListByVol(imtcodeF, ieds, volMap)
  1212. h = append(h, m...)
  1213. h = append(h, l...)
  1214. for _, r := range h {
  1215. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1216. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1217. lastChar := tmpIednameParts[7]
  1218. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1219. //高中低压电压等级相同的
  1220. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1221. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "F"))
  1222. }
  1223. }
  1224. //母线保护PM及母线合并单元MM,可能是多套合并单元MT共用,既不分AB套;低压侧智能终端无关联母线保护
  1225. imtcode = c.getIedTypeCode(modelid, "PM")
  1226. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1227. for _, r := range h {
  1228. //高压侧,AB套必须与PT装置相同
  1229. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1230. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1231. lastChar := tmpIednameParts[7]
  1232. if tmpIednameParts[6] == iednameParts[6] && lastChar == iednameParts[7] {
  1233. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
  1234. //MM装置
  1235. mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
  1236. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
  1237. break
  1238. }
  1239. }
  1240. for _, r := range m {
  1241. //中压侧
  1242. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1243. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1244. lastChar := tmpIednameParts[7]
  1245. if tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1246. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
  1247. //MM装置
  1248. mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
  1249. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
  1250. break
  1251. }
  1252. }
  1253. _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
  1254. if err != nil {
  1255. logger.Logger.Error(err)
  1256. return
  1257. }
  1258. }
  1259. }
  1260. //线路间隔分析
  1261. //vol:电压等级
  1262. func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm.Params) {
  1263. scdParseMgr := new(ScdParse)
  1264. scdNodeMgr := new(ScdNode)
  1265. db := orm.NewOrm()
  1266. scdXmlObj, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
  1267. iedCode := c.getIedTypeCode(modelid, "PL")
  1268. for _, row := range ieds {
  1269. if tools.IsEmpty(row["vol"]) != vol || tools.IsEmpty(row["ied_type"]) != iedCode[0:1] || tools.IsEmpty(row["p_type"]) != iedCode[1:] {
  1270. continue
  1271. }
  1272. pmIedName := ""
  1273. mmIedName := ""
  1274. pl_iedname := tools.IsEmpty(row["ied_name"])
  1275. iednameParts := scdParseMgr.ParseIedName(pl_iedname)
  1276. areadesc := tools.IsEmpty(row["ied_desc"])
  1277. if areadesc == "" {
  1278. iedobj := scdNodeMgr.GetIed(scdXmlObj, "", pl_iedname)
  1279. if iedobj != nil {
  1280. areadesc = iedobj.Desc
  1281. } else {
  1282. areadesc = tools.IsEmpty(row["area_name"])
  1283. }
  1284. }
  1285. areadesc = strings.ReplaceAll(areadesc, "装置", "")
  1286. //添加间隔数据
  1287. dbdata := T_data_check_area{
  1288. ModelId: modelid,
  1289. ScdId: c.ScdId,
  1290. AreaType: "L",
  1291. AreaName: areadesc + iednameParts[7],
  1292. }
  1293. newid, err := db.Insert(&dbdata)
  1294. if err != nil {
  1295. logger.Logger.Error(err)
  1296. return
  1297. }
  1298. ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
  1299. insvalues := []string{}
  1300. pmCode := c.getIedTypeCode(modelid, "PM")
  1301. mmCode := c.getIedTypeCode(modelid, "MM")
  1302. clCode := c.getIedTypeCode(modelid, "CL")
  1303. for _, ty := range strings.Split(iedtypes, ",") {
  1304. inAreaIedName := ""
  1305. tyCode := c.getIedTypeCode(modelid, ty)
  1306. if tyCode == pmCode {
  1307. //母线保护和母线合并单元装置编号跟随变压器
  1308. //查找变压器编号
  1309. //1号变压器->2号变压器->3号
  1310. inAreaIedName = c.getPMName(iednameParts, ieds)
  1311. pmIedName = inAreaIedName
  1312. if mmIedName == "" {
  1313. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ty[0:1], ty[1:2]))
  1314. //pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1315. //使用PM装置的名称去定义MM的名称
  1316. tyCode = mmCode
  1317. inAreaIedName = c.getMMName(iednameParts, ieds, iednameParts[7])
  1318. mmIedName = inAreaIedName
  1319. }
  1320. } else if tyCode == mmCode {
  1321. if pmIedName != "" && mmIedName == "" {
  1322. //pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1323. //使用PM装置的名称去定义MM的名称
  1324. inAreaIedName = c.getMMName(iednameParts, ieds, iednameParts[7])
  1325. mmIedName = inAreaIedName
  1326. } else {
  1327. continue
  1328. }
  1329. } else {
  1330. inAreaIedName = tyCode + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1331. }
  1332. if strings.Index("ABCDE", iednameParts[7]) > -1 {
  1333. //最后一位是字母则说明是AB套
  1334. switch tyCode {
  1335. case clCode:
  1336. if strings.Contains(iedtypes, "PLC") || strings.Contains(iedtypes, "PCL") {
  1337. //不处理CL装置
  1338. } else {
  1339. //测控装置,先判断是否分了AB套,没有标识(ied名称的最后一位是否是字母)则说明是多套共用装置
  1340. clIedname := inAreaIedName + iednameParts[7]
  1341. iedObj := ieds[inAreaIedName]
  1342. if iedObj != nil {
  1343. //当前测控装置也分了AB套
  1344. inAreaIedName = clIedname
  1345. }
  1346. }
  1347. break
  1348. default:
  1349. break
  1350. }
  1351. }
  1352. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:]))
  1353. }
  1354. _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
  1355. if err != nil {
  1356. logger.Logger.Error(err)
  1357. return
  1358. }
  1359. //如果mm装置还未确定
  1360. if mmIedName == "" {
  1361. //pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1362. inAreaIedName := c.getMMName(iednameParts, ieds, iednameParts[7])
  1363. _, err = db.Raw(ins1 + fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "M", "M")).Exec()
  1364. if err != nil {
  1365. logger.Logger.Error(err)
  1366. return
  1367. }
  1368. }
  1369. }
  1370. }
  1371. //母联间隔分析
  1372. func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm.Params, pjIed string) {
  1373. scdParseMgr := new(ScdParse)
  1374. scdNodeMgr := new(ScdNode)
  1375. db := orm.NewOrm()
  1376. pjIed = c.getIedTypeCode(modelid, pjIed)
  1377. scdXmlObject, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
  1378. for _, row := range ieds {
  1379. if tools.IsEmpty(row["vol"]) != vol || tools.IsEmpty(row["ied_type"]) != pjIed[0:1] || tools.IsEmpty(row["p_type"]) != pjIed[1:2] {
  1380. continue
  1381. }
  1382. pmIedName := ""
  1383. mmIedName := ""
  1384. pl_iedname := tools.IsEmpty(row["ied_name"])
  1385. iednameParts := scdParseMgr.ParseIedName(pl_iedname)
  1386. areadesc := tools.IsEmpty(row["ied_desc"])
  1387. if areadesc == "" {
  1388. iedobj := scdNodeMgr.GetIed(scdXmlObject, "", pl_iedname)
  1389. if iedobj != nil {
  1390. areadesc = iedobj.Desc
  1391. } else {
  1392. areadesc = tools.IsEmpty(row["area_name"])
  1393. }
  1394. }
  1395. areadesc = strings.ReplaceAll(areadesc, "装置", "")
  1396. //添加间隔数据
  1397. dbdata := T_data_check_area{
  1398. ModelId: modelid,
  1399. ScdId: c.ScdId,
  1400. AreaType: "J",
  1401. AreaName: areadesc + iednameParts[7],
  1402. }
  1403. newid, err := db.Insert(&dbdata)
  1404. if err != nil {
  1405. logger.Logger.Error(err)
  1406. return
  1407. }
  1408. ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
  1409. insvalues := []string{}
  1410. pmCode := c.getIedTypeCode(modelid, "PM")
  1411. mmCode := c.getIedTypeCode(modelid, "MM")
  1412. for _, ty := range strings.Split(iedtypes, ",") {
  1413. tyCode := c.getIedTypeCode(modelid, ty)
  1414. inAreaIedName := ""
  1415. if tyCode == pmCode {
  1416. //母线保护和母线合并单元装置编号跟随变压器
  1417. //查找变压器编号
  1418. //1号变压器->2号变压器->3号
  1419. inAreaIedName = c.getPMName(iednameParts, ieds)
  1420. pmIedName = inAreaIedName
  1421. if mmIedName == "" {
  1422. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:2]))
  1423. pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1424. //使用PM装置的名称去定义MM的名称
  1425. tyCode = "MM"
  1426. inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
  1427. mmIedName = inAreaIedName
  1428. }
  1429. } else if tyCode == mmCode {
  1430. if pmIedName != "" && mmIedName == "" {
  1431. pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1432. //使用PM装置的名称去定义MM的名称
  1433. inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
  1434. mmIedName = inAreaIedName
  1435. } else {
  1436. continue
  1437. }
  1438. } else {
  1439. tyCode = tyCode[0:1] + pjIed[1:2]
  1440. inAreaIedName = tyCode + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1441. //判断与基准保护装置相同套号的装置是否存在
  1442. if ieds[inAreaIedName] == nil {
  1443. //尝试去除套号
  1444. inAreaIedName = tyCode + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6]
  1445. }
  1446. }
  1447. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:2]))
  1448. }
  1449. _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
  1450. if err != nil {
  1451. logger.Logger.Error(err)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. //母联间隔装置关系检查
  1457. 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) {
  1458. modelidInt, _ := strconv.Atoi(modelid)
  1459. pjIed = c.getIedTypeCode(modelidInt, pjIed)
  1460. masterIed := new(node_attr.NIED)
  1461. findIedName := ""
  1462. for _, row2 := range area_ieds {
  1463. findIedName = tools.IsEmpty(row2["ied_name"])
  1464. if strings.HasPrefix(findIedName, pjIed) {
  1465. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1466. break
  1467. }
  1468. }
  1469. if masterIed == nil {
  1470. return
  1471. }
  1472. dealFromIed := map[string]int{}
  1473. for _, row := range ied_refs {
  1474. fromiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["from_ied_code"]))
  1475. toiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["to_ied_code"]))
  1476. reftype := tools.IsEmpty(row["in_type"])
  1477. tmpFromAreaIeds := []orm.Params{}
  1478. tmpToAreaIeds := []orm.Params{}
  1479. for _, row2 := range area_ieds {
  1480. findIedName = tools.IsEmpty(row2["ied_name"])
  1481. if strings.HasPrefix(findIedName, fromiedtype) {
  1482. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1483. if masterIed != nil {
  1484. tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
  1485. } else {
  1486. if dealFromIed[findIedName] == 0 {
  1487. parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
  1488. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1489. //检查未通过
  1490. scdNodeRule.AppendFcdaCheckResult(r)
  1491. }
  1492. dealFromIed[findIedName] = 1
  1493. }
  1494. }
  1495. if strings.HasPrefix(findIedName, toiedtype) {
  1496. tmpToAreaIeds = append(tmpToAreaIeds, row2)
  1497. }
  1498. }
  1499. if len(tmpFromAreaIeds) == 0 {
  1500. continue
  1501. }
  1502. if len(tmpToAreaIeds) == 0 {
  1503. parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, toiedtype)
  1504. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1505. //检查未通过
  1506. scdNodeRule.AppendFcdaCheckResult(r)
  1507. continue
  1508. }
  1509. toIedname := ""
  1510. for _, row2 := range tmpFromAreaIeds {
  1511. findIedName = tools.IsEmpty(row2["ied_name"])
  1512. hasToIedRef := false
  1513. hasToIed := false
  1514. for _, row3 := range tmpToAreaIeds {
  1515. toIedname = tools.IsEmpty(row3["ied_name"])
  1516. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", toIedname)
  1517. if masterIed != nil {
  1518. hasToIed = true
  1519. // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
  1520. inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
  1521. logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
  1522. if inout != nil {
  1523. outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
  1524. for _, ieditem := range outiedlist {
  1525. outiedname := ieditem["ref_ied_name"].(string)
  1526. if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
  1527. hasToIedRef = true
  1528. break
  1529. }
  1530. }
  1531. }
  1532. if !hasToIedRef {
  1533. parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
  1534. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1535. //检查未通过
  1536. scdNodeRule.AppendFcdaCheckResult(r)
  1537. }
  1538. }
  1539. }
  1540. if !hasToIed {
  1541. parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
  1542. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1543. //检查未通过
  1544. scdNodeRule.AppendFcdaCheckResult(r)
  1545. }
  1546. }
  1547. }
  1548. }
  1549. //线路间隔装置关系检查
  1550. func (c *CheckAreaMgr) cL(modelid string, scdXmlObj *node_attr.SCL, scdNodeMgr *ScdNode, scdNodeRule *ScdNodeRule, area_name string, ied_refs []orm.Params, area_ieds []orm.Params, area_ruleid string) {
  1551. modelidInt, _ := strconv.Atoi(modelid)
  1552. plIed := c.getIedTypeCode(modelidInt, "PL")
  1553. masterIed := new(node_attr.NIED)
  1554. findIedName := ""
  1555. for _, row2 := range area_ieds {
  1556. findIedName = tools.IsEmpty(row2["ied_name"])
  1557. if strings.HasPrefix(findIedName, plIed) {
  1558. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1559. break
  1560. }
  1561. }
  1562. if masterIed == nil {
  1563. return
  1564. }
  1565. dealFromIed := map[string]int{}
  1566. for _, row := range ied_refs {
  1567. fromiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["from_ied_code"]))
  1568. toiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["to_ied_code"]))
  1569. reftype := tools.IsEmpty(row["in_type"])
  1570. tmpFromAreaIeds := []orm.Params{}
  1571. tmpToAreaIeds := []orm.Params{}
  1572. for _, row2 := range area_ieds {
  1573. findIedName = tools.IsEmpty(row2["ied_name"])
  1574. if strings.HasPrefix(findIedName, fromiedtype) {
  1575. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1576. if masterIed != nil {
  1577. tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
  1578. } else {
  1579. if dealFromIed[findIedName] == 0 {
  1580. parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
  1581. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1582. //检查未通过
  1583. scdNodeRule.AppendFcdaCheckResult(r)
  1584. }
  1585. dealFromIed[findIedName] = 1
  1586. }
  1587. }
  1588. if strings.HasPrefix(findIedName, toiedtype) {
  1589. tmpToAreaIeds = append(tmpToAreaIeds, row2)
  1590. }
  1591. }
  1592. if len(tmpFromAreaIeds) == 0 {
  1593. continue
  1594. }
  1595. if len(tmpToAreaIeds) == 0 {
  1596. parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, toiedtype)
  1597. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1598. //检查未通过
  1599. scdNodeRule.AppendFcdaCheckResult(r)
  1600. continue
  1601. }
  1602. toIedname := ""
  1603. for _, row2 := range tmpFromAreaIeds {
  1604. findIedName = tools.IsEmpty(row2["ied_name"])
  1605. hasToIedRef := false
  1606. hasToIed := false
  1607. for _, row3 := range tmpToAreaIeds {
  1608. toIedname = tools.IsEmpty(row3["ied_name"])
  1609. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", toIedname)
  1610. if masterIed != nil {
  1611. hasToIed = true
  1612. // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
  1613. inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
  1614. logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
  1615. if inout != nil {
  1616. outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
  1617. for _, ieditem := range outiedlist {
  1618. outiedname := ieditem["ref_ied_name"].(string)
  1619. if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
  1620. hasToIedRef = true
  1621. break
  1622. }
  1623. }
  1624. }
  1625. if !hasToIedRef {
  1626. parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
  1627. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1628. //检查未通过
  1629. scdNodeRule.AppendFcdaCheckResult(r)
  1630. }
  1631. }
  1632. }
  1633. if !hasToIed {
  1634. parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
  1635. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1636. //检查未通过
  1637. scdNodeRule.AppendFcdaCheckResult(r)
  1638. }
  1639. }
  1640. }
  1641. }
  1642. //变压器间隔装置关系检查
  1643. func (c *CheckAreaMgr) cT(modelid string, scdXmlObj *node_attr.SCL, scdNodeMgr *ScdNode, scdNodeRule *ScdNodeRule, area_name string, ied_refs []orm.Params, area_ieds []orm.Params, area_ruleid string, HasAreaJ bool) {
  1644. masterIed := new(node_attr.NIED)
  1645. findIedName := ""
  1646. modelidInt, _ := strconv.Atoi(modelid)
  1647. ptIed := c.getIedTypeCode(modelidInt, "PT")
  1648. for _, row2 := range area_ieds {
  1649. findIedName = tools.IsEmpty(row2["ied_name"])
  1650. if strings.HasPrefix(findIedName, ptIed) {
  1651. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1652. break
  1653. }
  1654. }
  1655. if masterIed == nil {
  1656. return
  1657. }
  1658. scdParseMgr := new(ScdParse)
  1659. dealFromIed := map[string]int{}
  1660. for _, row := range ied_refs {
  1661. fromiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["from_ied_code"]))
  1662. fromiedtype = strings.Split(fromiedtype, "#")[0] //去除后面的电压级别标识
  1663. toiedtype := strings.Split(c.getIedTypeCode(modelidInt, tools.IsEmpty(row["to_ied_code"])), "#")[0] //去除后面的电压级别标识
  1664. reftype := tools.IsEmpty(row["in_type"])
  1665. tmpFromAreaIeds := []orm.Params{}
  1666. tmpToAreaIeds := []orm.Params{}
  1667. for _, row2 := range area_ieds {
  1668. findIedName = tools.IsEmpty(row2["ied_name"])
  1669. if strings.HasPrefix(findIedName, fromiedtype) {
  1670. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1671. if masterIed != nil {
  1672. tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
  1673. } else {
  1674. if dealFromIed[findIedName] == 0 {
  1675. parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
  1676. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1677. //检查未通过
  1678. scdNodeRule.AppendFcdaCheckResult(r)
  1679. }
  1680. dealFromIed[findIedName] = 1
  1681. }
  1682. }
  1683. if strings.HasPrefix(findIedName, toiedtype) {
  1684. tmpToAreaIeds = append(tmpToAreaIeds, row2)
  1685. }
  1686. }
  1687. if len(tmpFromAreaIeds) == 0 {
  1688. continue
  1689. }
  1690. if len(tmpToAreaIeds) == 0 {
  1691. logger.Logger.Debug(fmt.Sprintf("缺失类型关联装置 :%+v", row))
  1692. parse_result := fmt.Sprintf("间隔%s缺失类型为%s的%s信号装置", area_name, toiedtype, reftype)
  1693. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1694. //检查未通过
  1695. scdNodeRule.AppendFcdaCheckResult(r)
  1696. continue
  1697. }
  1698. toIedname := ""
  1699. for _, row2 := range tmpFromAreaIeds {
  1700. findIedName = tools.IsEmpty(row2["ied_name"])
  1701. hasToIedRef := false
  1702. hasToIed := false
  1703. t1 := fromiedtype + "->" + toiedtype
  1704. volLevel := "" //电压等级
  1705. if t1 == "CT->IT" || t1 == "IT->CT" || t1 == "CT->IB" || t1 == "IB->CT" || t1 == "MM->MT" || t1 == "PM->IB" || t1 == "IB->PM" || t1 == "PM->IT" || t1 == "IT->PM" {
  1706. ps := scdParseMgr.ParseIedName(findIedName)
  1707. volLevel = ps[3] + ps[4]
  1708. }
  1709. hasSameVolIed := false
  1710. for _, row3 := range tmpToAreaIeds {
  1711. toIedname = tools.IsEmpty(row3["ied_name"])
  1712. if volLevel != "" {
  1713. ps := scdParseMgr.ParseIedName(toIedname)
  1714. if volLevel != ps[3]+ps[4] {
  1715. //排除不是同一电压等级的装置
  1716. continue
  1717. }
  1718. hasSameVolIed = true
  1719. }
  1720. if scdNodeMgr.GetIed(scdXmlObj, "", toIedname) != nil {
  1721. hasToIed = true
  1722. // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
  1723. inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
  1724. logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
  1725. if inout != nil {
  1726. outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
  1727. for _, ieditem := range outiedlist {
  1728. outiedname := ieditem["ref_ied_name"].(string)
  1729. if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
  1730. hasToIedRef = true
  1731. break
  1732. }
  1733. }
  1734. }
  1735. if !hasToIedRef {
  1736. parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
  1737. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1738. //检查未通过
  1739. scdNodeRule.AppendFcdaCheckResult(r)
  1740. }
  1741. }
  1742. if hasSameVolIed {
  1743. break
  1744. }
  1745. }
  1746. if toiedtype != ptIed {
  1747. if volLevel != "" && !hasSameVolIed {
  1748. parse_result := fmt.Sprintf("间隔%s的装置%s缺失同电压等级的关联类型%s装置", area_name, findIedName, toiedtype)
  1749. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1750. //检查未通过
  1751. scdNodeRule.AppendFcdaCheckResult(r)
  1752. } else if !hasToIed {
  1753. parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
  1754. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1755. //检查未通过
  1756. scdNodeRule.AppendFcdaCheckResult(r)
  1757. }
  1758. }
  1759. }
  1760. }
  1761. }
  1762. //根据参考ied name找出应该关联PM装置
  1763. func (c *CheckAreaMgr) getPMName(iednameParts []string, ieds map[string]orm.Params) string {
  1764. //如果只有一个PM装置,则直接返回该 装置
  1765. pmLst := []string{}
  1766. for n, _ := range ieds {
  1767. if strings.HasPrefix(n, "PM") {
  1768. pmLst = append(pmLst, n)
  1769. }
  1770. }
  1771. if len(pmLst) == 1 {
  1772. return pmLst[0]
  1773. }
  1774. //暴力匹配
  1775. no := []string{"A", "B", "C", "D", "1", "2", "3", "4"}
  1776. for _, i := range no {
  1777. tmpIedName := "PM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + i + iednameParts[7]
  1778. iedObj := ieds[tmpIedName]
  1779. if iedObj != nil {
  1780. return tmpIedName
  1781. }
  1782. }
  1783. return ""
  1784. }
  1785. //根据参考ied name找出应该关联MM装置
  1786. func (c *CheckAreaMgr) getMMName(iednameParts []string, ieds map[string]orm.Params, ab string) string {
  1787. tmpIedName := "MM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + ab
  1788. if ieds[tmpIedName] == nil {
  1789. tmpIedName = "MM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1790. }
  1791. return tmpIedName
  1792. }
  1793. //根据当前设备列表,分析出电压等级(高、中、低)的设备列表
  1794. // CT测控、IT智能终端、MT合并单元需要判断是否是本体装置,是则将其归为主变高压侧
  1795. func (c *CheckAreaMgr) getIedListByVol(iedtype string, ieds map[string]orm.Params, vollevel map[string]string) (hightLst, middleLst, lowLst []orm.Params) {
  1796. tmpLst := map[string][]orm.Params{}
  1797. for _, v := range vollevel {
  1798. tmpLst[v] = []orm.Params{}
  1799. }
  1800. scdParseMgr := new(ScdParse)
  1801. for _, row := range ieds {
  1802. pl_iedname := tools.IsEmpty(row["ied_name"])
  1803. if pl_iedname[0:len(iedtype)] != iedtype {
  1804. continue
  1805. }
  1806. iednameParts := scdParseMgr.ParseIedName(pl_iedname)
  1807. volvalue := iednameParts[3] + iednameParts[4]
  1808. if tmpLst[volvalue] == nil {
  1809. tmpLst[volvalue] = []orm.Params{row}
  1810. } else {
  1811. tmpLst[volvalue] = append(tmpLst[volvalue], row)
  1812. }
  1813. }
  1814. return tmpLst[vollevel["hight"]], tmpLst[vollevel["middle"]], tmpLst[vollevel["low"]]
  1815. }
  1816. func (c *CheckAreaMgr) GetCheckResult(scdid int64) ([]orm.Params, error) {
  1817. db := orm.NewOrm()
  1818. rowset := []orm.Params{}
  1819. 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"
  1820. _, err := db.Raw(sql, scdid).Values(&rowset)
  1821. return rowset, err
  1822. }