checktools_area.go 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859
  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_maping{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_maping{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_maping{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. db := orm.NewOrm()
  947. //获取当前站的各电压等级
  948. volRows := []orm.Params{}
  949. _, 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)
  950. if err != nil {
  951. logger.Logger.Error(err)
  952. return
  953. }
  954. if len(volRows) == 0 {
  955. logger.Logger.Error(errors.New("该scd未发现任何电压等级的装置"))
  956. return
  957. }
  958. volMap := map[string]string{}
  959. volMap["hight"] = tools.IsEmpty(volRows[0]["vol"]) //高压电压
  960. if len(volRows) == 2 {
  961. volMap["middle"] = ""
  962. volMap["low"] = volRows[1]["vol"].(string) //低压电压等级
  963. } else {
  964. volMap["middle"] = volRows[1]["vol"].(string) //中压电压等级
  965. volMap["low"] = volRows[len(volRows)-1]["vol"].(string) //低压电压等级
  966. }
  967. var getIedByDesc = func(iedinfo map[string]orm.Params, iedtpye string, desc string) ([]string, []string) {
  968. scdParseMgr := new(ScdParse)
  969. scdXmlObj, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
  970. r1 := []string{}
  971. r2 := []string{}
  972. for vn, row := range iedinfo {
  973. if strings.HasPrefix(vn, iedtpye) {
  974. v := tools.IsEmpty(row["ied_desc"])
  975. if v == "" {
  976. if scdXmlObj == nil {
  977. continue
  978. }
  979. scdNode := new(ScdNode)
  980. ied := scdNode.GetIed(scdXmlObj, "", vn)
  981. if ied == nil {
  982. continue
  983. }
  984. v = ied.Desc
  985. }
  986. if strings.Contains(v, desc) {
  987. r1 = append(r1, v)
  988. r2 = append(r2, vn)
  989. }
  990. }
  991. }
  992. return r1, r2
  993. }
  994. //判断是否将各电压等级的保护装置合并还是分开的间隔
  995. //如果存在高中低压的保护装置,则说明是分开的主变间隔
  996. //isMarge := true // 默认为合并的主变间隔
  997. ptCode := c.getIedTypeCode(modelid, "PT")
  998. for _, row := range ieds {
  999. if tools.IsEmpty(row["ied_type"]) != ptCode[0:1] || tools.IsEmpty(row["p_type"]) != ptCode[1:] {
  1000. continue
  1001. }
  1002. //判断主变保护是否是按电压等级分开配置的模型
  1003. /*
  1004. if strings.Contains(iedtypes, "PT#H") || strings.Contains(iedtypes, "PT#M") || strings.Contains(iedtypes, "PT#L") {
  1005. h, m, l := c.getIedListByVol("PT", ieds, volMap)
  1006. } else {
  1007. pl_iedname := tools.IsEmpty(row["ied_name"])
  1008. }
  1009. */
  1010. //pmIedName := ""
  1011. //mmIedName := ""
  1012. pl_iedname := tools.IsEmpty(row["ied_name"])
  1013. iednameParts := scdParseMgr.ParseIedName(pl_iedname)
  1014. //添加间隔数据
  1015. dbdata := T_data_check_area{
  1016. ModelId: modelid,
  1017. ScdId: c.ScdId,
  1018. AreaType: "T",
  1019. AreaName: tools.IsEmpty(row["area_name"]) + iednameParts[7],
  1020. }
  1021. newid, err := db.Insert(&dbdata)
  1022. if err != nil {
  1023. logger.Logger.Error(err)
  1024. return
  1025. }
  1026. ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
  1027. insvalues := []string{}
  1028. inAreaIedName := pl_iedname
  1029. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "T"))
  1030. //判断间隔是否需要包含差动装置
  1031. if strings.Contains(iedtypes, ptCode+"#C") {
  1032. _, iedname := getIedByDesc(ieds, ptCode, "差动")
  1033. if len(iedname) > 0 {
  1034. for _, in := range iedname {
  1035. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1036. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1037. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "P", "TC"))
  1038. break
  1039. }
  1040. }
  1041. }
  1042. }
  1043. //判断间隔是否需要包含本体保护装置
  1044. if strings.Contains(iedtypes, ptCode+"#0") {
  1045. _, iedname := getIedByDesc(ieds, ptCode, "本体")
  1046. if len(iedname) > 0 {
  1047. for _, in := range iedname {
  1048. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1049. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1050. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "P", "T0"))
  1051. break
  1052. }
  1053. }
  1054. }
  1055. }
  1056. //合智一体IMT/MIT,分高中低压
  1057. imtcode := c.getIedTypeCode(modelid, "IMT")
  1058. h, m, l := c.getIedListByVol(imtcode, ieds, volMap)
  1059. h = append(h, m...)
  1060. h = append(h, l...)
  1061. for _, r := range h {
  1062. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1063. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1064. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1065. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "IM", "T"))
  1066. }
  1067. }
  1068. imtcode = c.getIedTypeCode(modelid, "MIT")
  1069. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1070. h = append(h, m...)
  1071. h = append(h, l...)
  1072. for _, r := range h {
  1073. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1074. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1075. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1076. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "MI", "T"))
  1077. }
  1078. }
  1079. //母联智能终端IE需要分高中压,无低压侧
  1080. if HasAreaJ {
  1081. imtcode = c.getIedTypeCode(modelid, "IE")
  1082. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1083. for _, r := range h {
  1084. //高压侧,AB套必须与PT装置相同
  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, "I", "E"))
  1089. }
  1090. }
  1091. for _, r := range m {
  1092. //中压侧
  1093. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1094. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1095. lastChar := tmpIednameParts[7]
  1096. if tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || tmpIednameParts[7] == iednameParts[7]) {
  1097. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "E"))
  1098. }
  1099. }
  1100. }
  1101. //合并单元MT分高中低压侧;低压侧无关联母线合并单元MM
  1102. imtcode = c.getIedTypeCode(modelid, "MT")
  1103. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1104. h = append(h, m...)
  1105. h = append(h, l...)
  1106. for _, r := range h {
  1107. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1108. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1109. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1110. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "M", "T"))
  1111. }
  1112. }
  1113. //是否包含本体合并单元
  1114. if strings.Contains(iedtypes, imtcode+"#0") {
  1115. _, iedname := getIedByDesc(ieds, imtcode, "本体")
  1116. if len(iedname) > 0 {
  1117. for _, in := range iedname {
  1118. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1119. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1120. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "M", "T"))
  1121. break
  1122. }
  1123. }
  1124. }
  1125. }
  1126. //测控装置CT分高中低压侧,且可能是多套合并单元MT共用,既不分AB套
  1127. imtcode = c.getIedTypeCode(modelid, "CT")
  1128. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1129. h = append(h, m...)
  1130. h = append(h, l...)
  1131. for _, r := range h {
  1132. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1133. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1134. lastChar := tmpIednameParts[7]
  1135. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1136. //高中低压电压等级相同的
  1137. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1138. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "C", "T"))
  1139. }
  1140. }
  1141. //是否包含本体测控装置
  1142. if strings.Contains(iedtypes, imtcode+"#0") {
  1143. _, iedname := getIedByDesc(ieds, imtcode, "本体")
  1144. if len(iedname) > 0 {
  1145. for _, in := range iedname {
  1146. tmpIednameParts := scdParseMgr.ParseIedName(in)
  1147. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1148. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, in, "C", "T"))
  1149. break
  1150. }
  1151. }
  1152. }
  1153. }
  1154. //智能终端(IB:开关\IT:分支\IF:分段)分高中低压侧
  1155. imtcodeB := c.getIedTypeCode(modelid, "IB")
  1156. imtcodeT := c.getIedTypeCode(modelid, "IT")
  1157. imtcodeF := c.getIedTypeCode(modelid, "IF")
  1158. h, m, l = c.getIedListByVol(imtcodeB, ieds, volMap)
  1159. h = append(h, m...)
  1160. h = append(h, l...)
  1161. for _, r := range h {
  1162. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1163. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1164. lastChar := tmpIednameParts[7]
  1165. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1166. //高中低压电压等级相同的
  1167. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1168. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "B"))
  1169. }
  1170. }
  1171. //是否包含本体测控装置
  1172. if strings.Contains(iedtypes, imtcodeT+"#0") {
  1173. for n, row := range ieds {
  1174. if strings.HasPrefix(n, imtcodeT) || strings.HasPrefix(n, imtcodeB) || strings.HasPrefix(n, imtcodeF) {
  1175. ieddesc := tools.IsEmpty(row["ied_desc"])
  1176. if strings.Contains(ieddesc, "本体") {
  1177. tmpIednameParts := scdParseMgr.ParseIedName(n)
  1178. if tmpIednameParts[6] == iednameParts[6] && tmpIednameParts[7] == iednameParts[7] {
  1179. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, n, "I", "T"))
  1180. break
  1181. }
  1182. }
  1183. }
  1184. }
  1185. }
  1186. h, m, l = c.getIedListByVol(imtcodeT, ieds, volMap)
  1187. h = append(h, m...)
  1188. h = append(h, l...)
  1189. for _, r := range h {
  1190. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1191. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1192. lastChar := tmpIednameParts[7]
  1193. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1194. //高中低压电压等级相同的
  1195. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1196. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "T"))
  1197. }
  1198. }
  1199. h, m, l = c.getIedListByVol(imtcodeF, ieds, volMap)
  1200. h = append(h, m...)
  1201. h = append(h, l...)
  1202. for _, r := range h {
  1203. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1204. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1205. lastChar := tmpIednameParts[7]
  1206. tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
  1207. //高中低压电压等级相同的
  1208. if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1209. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "F"))
  1210. }
  1211. }
  1212. //母线保护PM及母线合并单元MM,可能是多套合并单元MT共用,既不分AB套;低压侧智能终端无关联母线保护
  1213. imtcode = c.getIedTypeCode(modelid, "PM")
  1214. h, m, l = c.getIedListByVol(imtcode, ieds, volMap)
  1215. for _, r := range h {
  1216. //高压侧,AB套必须与PT装置相同
  1217. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1218. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1219. lastChar := tmpIednameParts[7]
  1220. if tmpIednameParts[6] == iednameParts[6] && lastChar == iednameParts[7] {
  1221. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
  1222. //MM装置
  1223. mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
  1224. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
  1225. break
  1226. }
  1227. }
  1228. for _, r := range m {
  1229. //中压侧
  1230. inAreaIedName = tools.IsEmpty(r["ied_name"])
  1231. tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
  1232. lastChar := tmpIednameParts[7]
  1233. if tmpIednameParts[6] == iednameParts[6] && (lastChar == "" || lastChar == iednameParts[7]) {
  1234. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
  1235. //MM装置
  1236. mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
  1237. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
  1238. break
  1239. }
  1240. }
  1241. _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
  1242. if err != nil {
  1243. logger.Logger.Error(err)
  1244. return
  1245. }
  1246. }
  1247. }
  1248. //线路间隔分析
  1249. //vol:电压等级
  1250. func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm.Params) {
  1251. scdParseMgr := new(ScdParse)
  1252. scdNodeMgr := new(ScdNode)
  1253. db := orm.NewOrm()
  1254. scdXmlObj, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
  1255. iedCode := c.getIedTypeCode(modelid, "PL")
  1256. for _, row := range ieds {
  1257. if tools.IsEmpty(row["vol"]) != vol || tools.IsEmpty(row["ied_type"]) != iedCode[0:1] || tools.IsEmpty(row["p_type"]) != iedCode[1:] {
  1258. continue
  1259. }
  1260. pmIedName := ""
  1261. mmIedName := ""
  1262. pl_iedname := tools.IsEmpty(row["ied_name"])
  1263. iednameParts := scdParseMgr.ParseIedName(pl_iedname)
  1264. //添加间隔数据
  1265. dbdata := T_data_check_area{
  1266. ModelId: modelid,
  1267. ScdId: c.ScdId,
  1268. AreaType: "L",
  1269. AreaName: tools.IsEmpty(row["area_name"]) + iednameParts[7],
  1270. }
  1271. newid, err := db.Insert(&dbdata)
  1272. if err != nil {
  1273. logger.Logger.Error(err)
  1274. return
  1275. }
  1276. ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
  1277. insvalues := []string{}
  1278. pmCode := c.getIedTypeCode(modelid, "PM")
  1279. mmCode := c.getIedTypeCode(modelid, "MM")
  1280. clCode := c.getIedTypeCode(modelid, "CL")
  1281. for _, ty := range strings.Split(iedtypes, ",") {
  1282. inAreaIedName := ""
  1283. tyCode := c.getIedTypeCode(modelid, ty)
  1284. if tyCode == pmCode {
  1285. //母线保护和母线合并单元装置编号跟随变压器
  1286. //查找变压器编号
  1287. //1号变压器->2号变压器->3号
  1288. inAreaIedName = c.getPMName(iednameParts, ieds)
  1289. pmIedName = inAreaIedName
  1290. if mmIedName == "" {
  1291. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ty[0:1], ty[1:2]))
  1292. //pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1293. //使用PM装置的名称去定义MM的名称
  1294. tyCode = mmCode
  1295. inAreaIedName = c.getMMName(iednameParts, ieds, iednameParts[7])
  1296. mmIedName = inAreaIedName
  1297. }
  1298. } else if tyCode == mmCode {
  1299. if pmIedName != "" && mmIedName == "" {
  1300. //pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1301. //使用PM装置的名称去定义MM的名称
  1302. inAreaIedName = c.getMMName(iednameParts, ieds, iednameParts[7])
  1303. mmIedName = inAreaIedName
  1304. } else {
  1305. continue
  1306. }
  1307. } else if tyCode == "PLC" || tyCode == "PCL" {
  1308. //判断是否是保测一体的
  1309. if strings.Contains(iedtypes, "PLC") || strings.Contains(iedtypes, "PCL") {
  1310. no := []string{"PLC", "PCL", "PL"}
  1311. for _, n := range no {
  1312. plcIedName := n + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1313. if scdNodeMgr.GetIed(scdXmlObj, "", plcIedName) != nil {
  1314. inAreaIedName = plcIedName
  1315. break
  1316. }
  1317. }
  1318. }
  1319. } else {
  1320. inAreaIedName = tyCode + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1321. if tyCode == "IML" {
  1322. //查找IML装置是否存在,不存在就查找MIL开头装置做中合智一体装置
  1323. no := []string{"IML", "MIL"}
  1324. for _, n := range no {
  1325. milIedName := n + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1326. if scdNodeMgr.GetIed(scdXmlObj, "", milIedName) != nil {
  1327. inAreaIedName = milIedName
  1328. }
  1329. }
  1330. }
  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. //添加间隔数据
  1387. dbdata := T_data_check_area{
  1388. ModelId: modelid,
  1389. ScdId: c.ScdId,
  1390. AreaType: "J",
  1391. AreaName: tools.IsEmpty(row["area_name"]) + iednameParts[7],
  1392. }
  1393. newid, err := db.Insert(&dbdata)
  1394. if err != nil {
  1395. logger.Logger.Error(err)
  1396. return
  1397. }
  1398. ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
  1399. insvalues := []string{}
  1400. pmCode := c.getIedTypeCode(modelid, "PM")
  1401. mmCode := c.getIedTypeCode(modelid, "MM")
  1402. for _, ty := range strings.Split(iedtypes, ",") {
  1403. tyCode := c.getIedTypeCode(modelid, ty)
  1404. inAreaIedName := ""
  1405. if tyCode == pmCode {
  1406. //母线保护和母线合并单元装置编号跟随变压器
  1407. //查找变压器编号
  1408. //1号变压器->2号变压器->3号
  1409. inAreaIedName = c.getPMName(iednameParts, ieds)
  1410. pmIedName = inAreaIedName
  1411. if mmIedName == "" {
  1412. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:2]))
  1413. pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1414. //使用PM装置的名称去定义MM的名称
  1415. tyCode = "MM"
  1416. inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
  1417. mmIedName = inAreaIedName
  1418. }
  1419. } else if tyCode == mmCode {
  1420. if pmIedName != "" && mmIedName == "" {
  1421. pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
  1422. //使用PM装置的名称去定义MM的名称
  1423. inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
  1424. mmIedName = inAreaIedName
  1425. } else {
  1426. continue
  1427. }
  1428. } else {
  1429. tyCode = tyCode[0:1] + pjIed[1:2]
  1430. inAreaIedName = tyCode + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1431. //判断与基准保护装置相同套号的装置是否存在
  1432. if ieds[inAreaIedName] == nil {
  1433. //尝试去除套号
  1434. inAreaIedName = tyCode + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6]
  1435. }
  1436. }
  1437. insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, tyCode[0:1], tyCode[1:2]))
  1438. }
  1439. _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
  1440. if err != nil {
  1441. logger.Logger.Error(err)
  1442. return
  1443. }
  1444. }
  1445. }
  1446. //母联间隔装置关系检查
  1447. 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) {
  1448. modelidInt, _ := strconv.Atoi(modelid)
  1449. pjIed = c.getIedTypeCode(modelidInt, pjIed)
  1450. masterIed := new(node_attr.NIED)
  1451. findIedName := ""
  1452. for _, row2 := range area_ieds {
  1453. findIedName = tools.IsEmpty(row2["ied_name"])
  1454. if strings.HasPrefix(findIedName, pjIed) {
  1455. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1456. break
  1457. }
  1458. }
  1459. if masterIed == nil {
  1460. return
  1461. }
  1462. dealFromIed := map[string]int{}
  1463. for _, row := range ied_refs {
  1464. fromiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["from_ied_code"]))
  1465. toiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["to_ied_code"]))
  1466. reftype := tools.IsEmpty(row["in_type"])
  1467. tmpFromAreaIeds := []orm.Params{}
  1468. tmpToAreaIeds := []orm.Params{}
  1469. for _, row2 := range area_ieds {
  1470. findIedName = tools.IsEmpty(row2["ied_name"])
  1471. if strings.HasPrefix(findIedName, fromiedtype) {
  1472. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1473. if masterIed != nil {
  1474. tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
  1475. } else {
  1476. if dealFromIed[findIedName] == 0 {
  1477. parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
  1478. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1479. //检查未通过
  1480. scdNodeRule.AppendFcdaCheckResult(r)
  1481. }
  1482. dealFromIed[findIedName] = 1
  1483. }
  1484. }
  1485. if strings.HasPrefix(findIedName, toiedtype) {
  1486. tmpToAreaIeds = append(tmpToAreaIeds, row2)
  1487. }
  1488. }
  1489. if len(tmpFromAreaIeds) == 0 {
  1490. continue
  1491. }
  1492. if len(tmpToAreaIeds) == 0 {
  1493. parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, toiedtype)
  1494. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1495. //检查未通过
  1496. scdNodeRule.AppendFcdaCheckResult(r)
  1497. continue
  1498. }
  1499. toIedname := ""
  1500. for _, row2 := range tmpFromAreaIeds {
  1501. findIedName = tools.IsEmpty(row2["ied_name"])
  1502. hasToIedRef := false
  1503. hasToIed := false
  1504. for _, row3 := range tmpToAreaIeds {
  1505. toIedname = tools.IsEmpty(row3["ied_name"])
  1506. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", toIedname)
  1507. if masterIed != nil {
  1508. hasToIed = true
  1509. // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
  1510. inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
  1511. logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
  1512. if inout != nil {
  1513. outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
  1514. for _, ieditem := range outiedlist {
  1515. outiedname := ieditem["ref_ied_name"].(string)
  1516. if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
  1517. hasToIedRef = true
  1518. break
  1519. }
  1520. }
  1521. }
  1522. if !hasToIedRef {
  1523. parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
  1524. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1525. //检查未通过
  1526. scdNodeRule.AppendFcdaCheckResult(r)
  1527. }
  1528. }
  1529. }
  1530. if !hasToIed {
  1531. parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
  1532. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1533. //检查未通过
  1534. scdNodeRule.AppendFcdaCheckResult(r)
  1535. }
  1536. }
  1537. }
  1538. }
  1539. //线路间隔装置关系检查
  1540. 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) {
  1541. modelidInt, _ := strconv.Atoi(modelid)
  1542. plIed := c.getIedTypeCode(modelidInt, "PL")
  1543. masterIed := new(node_attr.NIED)
  1544. findIedName := ""
  1545. for _, row2 := range area_ieds {
  1546. findIedName = tools.IsEmpty(row2["ied_name"])
  1547. if strings.HasPrefix(findIedName, plIed) {
  1548. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1549. break
  1550. }
  1551. }
  1552. if masterIed == nil {
  1553. return
  1554. }
  1555. dealFromIed := map[string]int{}
  1556. for _, row := range ied_refs {
  1557. fromiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["from_ied_code"]))
  1558. toiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["to_ied_code"]))
  1559. reftype := tools.IsEmpty(row["in_type"])
  1560. tmpFromAreaIeds := []orm.Params{}
  1561. tmpToAreaIeds := []orm.Params{}
  1562. for _, row2 := range area_ieds {
  1563. findIedName = tools.IsEmpty(row2["ied_name"])
  1564. if strings.HasPrefix(findIedName, fromiedtype) {
  1565. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1566. if masterIed != nil {
  1567. tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
  1568. } else {
  1569. if dealFromIed[findIedName] == 0 {
  1570. parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
  1571. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1572. //检查未通过
  1573. scdNodeRule.AppendFcdaCheckResult(r)
  1574. }
  1575. dealFromIed[findIedName] = 1
  1576. }
  1577. }
  1578. if strings.HasPrefix(findIedName, toiedtype) {
  1579. tmpToAreaIeds = append(tmpToAreaIeds, row2)
  1580. }
  1581. }
  1582. if len(tmpFromAreaIeds) == 0 {
  1583. continue
  1584. }
  1585. if len(tmpToAreaIeds) == 0 {
  1586. parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, toiedtype)
  1587. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1588. //检查未通过
  1589. scdNodeRule.AppendFcdaCheckResult(r)
  1590. continue
  1591. }
  1592. toIedname := ""
  1593. for _, row2 := range tmpFromAreaIeds {
  1594. findIedName = tools.IsEmpty(row2["ied_name"])
  1595. hasToIedRef := false
  1596. hasToIed := false
  1597. for _, row3 := range tmpToAreaIeds {
  1598. toIedname = tools.IsEmpty(row3["ied_name"])
  1599. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", toIedname)
  1600. if masterIed != nil {
  1601. hasToIed = true
  1602. // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
  1603. inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
  1604. logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
  1605. if inout != nil {
  1606. outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
  1607. for _, ieditem := range outiedlist {
  1608. outiedname := ieditem["ref_ied_name"].(string)
  1609. if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
  1610. hasToIedRef = true
  1611. break
  1612. }
  1613. }
  1614. }
  1615. if !hasToIedRef {
  1616. parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
  1617. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1618. //检查未通过
  1619. scdNodeRule.AppendFcdaCheckResult(r)
  1620. }
  1621. }
  1622. }
  1623. if !hasToIed {
  1624. parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
  1625. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1626. //检查未通过
  1627. scdNodeRule.AppendFcdaCheckResult(r)
  1628. }
  1629. }
  1630. }
  1631. }
  1632. //变压器间隔装置关系检查
  1633. 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) {
  1634. masterIed := new(node_attr.NIED)
  1635. findIedName := ""
  1636. modelidInt, _ := strconv.Atoi(modelid)
  1637. ptIed := c.getIedTypeCode(modelidInt, "PT")
  1638. for _, row2 := range area_ieds {
  1639. findIedName = tools.IsEmpty(row2["ied_name"])
  1640. if strings.HasPrefix(findIedName, ptIed) {
  1641. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1642. break
  1643. }
  1644. }
  1645. if masterIed == nil {
  1646. return
  1647. }
  1648. scdParseMgr := new(ScdParse)
  1649. dealFromIed := map[string]int{}
  1650. for _, row := range ied_refs {
  1651. fromiedtype := c.getIedTypeCode(modelidInt, tools.IsEmpty(row["from_ied_code"]))
  1652. fromiedtype = strings.Split(fromiedtype, "#")[0] //去除后面的电压级别标识
  1653. toiedtype := strings.Split(c.getIedTypeCode(modelidInt, tools.IsEmpty(row["to_ied_code"])), "#")[0] //去除后面的电压级别标识
  1654. reftype := tools.IsEmpty(row["in_type"])
  1655. tmpFromAreaIeds := []orm.Params{}
  1656. tmpToAreaIeds := []orm.Params{}
  1657. for _, row2 := range area_ieds {
  1658. findIedName = tools.IsEmpty(row2["ied_name"])
  1659. if strings.HasPrefix(findIedName, fromiedtype) {
  1660. masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
  1661. if masterIed != nil {
  1662. tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
  1663. } else {
  1664. if dealFromIed[findIedName] == 0 {
  1665. parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
  1666. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1667. //检查未通过
  1668. scdNodeRule.AppendFcdaCheckResult(r)
  1669. }
  1670. dealFromIed[findIedName] = 1
  1671. }
  1672. }
  1673. if strings.HasPrefix(findIedName, toiedtype) {
  1674. tmpToAreaIeds = append(tmpToAreaIeds, row2)
  1675. }
  1676. }
  1677. if len(tmpFromAreaIeds) == 0 {
  1678. continue
  1679. }
  1680. if len(tmpToAreaIeds) == 0 {
  1681. logger.Logger.Debug(fmt.Sprintf("缺失类型关联装置 :%+v", row))
  1682. parse_result := fmt.Sprintf("间隔%s缺失类型为%s的%s信号装置", area_name, toiedtype, reftype)
  1683. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1684. //检查未通过
  1685. scdNodeRule.AppendFcdaCheckResult(r)
  1686. continue
  1687. }
  1688. toIedname := ""
  1689. for _, row2 := range tmpFromAreaIeds {
  1690. findIedName = tools.IsEmpty(row2["ied_name"])
  1691. hasToIedRef := false
  1692. hasToIed := false
  1693. t1 := fromiedtype + "->" + toiedtype
  1694. volLevel := "" //电压等级
  1695. 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" {
  1696. ps := scdParseMgr.ParseIedName(findIedName)
  1697. volLevel = ps[3] + ps[4]
  1698. }
  1699. hasSameVolIed := false
  1700. for _, row3 := range tmpToAreaIeds {
  1701. toIedname = tools.IsEmpty(row3["ied_name"])
  1702. if volLevel != "" {
  1703. ps := scdParseMgr.ParseIedName(toIedname)
  1704. if volLevel != ps[3]+ps[4] {
  1705. //排除不是同一电压等级的装置
  1706. continue
  1707. }
  1708. hasSameVolIed = true
  1709. }
  1710. if scdNodeMgr.GetIed(scdXmlObj, "", toIedname) != nil {
  1711. hasToIed = true
  1712. // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
  1713. inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
  1714. logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
  1715. if inout != nil {
  1716. outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
  1717. for _, ieditem := range outiedlist {
  1718. outiedname := ieditem["ref_ied_name"].(string)
  1719. if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
  1720. hasToIedRef = true
  1721. break
  1722. }
  1723. }
  1724. }
  1725. if !hasToIedRef {
  1726. parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
  1727. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1728. //检查未通过
  1729. scdNodeRule.AppendFcdaCheckResult(r)
  1730. }
  1731. }
  1732. if hasSameVolIed {
  1733. break
  1734. }
  1735. }
  1736. if toiedtype != ptIed {
  1737. if volLevel != "" && !hasSameVolIed {
  1738. parse_result := fmt.Sprintf("间隔%s的装置%s缺失同电压等级的关联类型%s装置", area_name, findIedName, toiedtype)
  1739. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1740. //检查未通过
  1741. scdNodeRule.AppendFcdaCheckResult(r)
  1742. } else if !hasToIed {
  1743. parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
  1744. r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
  1745. //检查未通过
  1746. scdNodeRule.AppendFcdaCheckResult(r)
  1747. }
  1748. }
  1749. }
  1750. }
  1751. }
  1752. //根据参考ied name找出应该关联PM装置
  1753. func (c *CheckAreaMgr) getPMName(iednameParts []string, ieds map[string]orm.Params) string {
  1754. //如果只有一个PM装置,则直接返回该 装置
  1755. pmLst := []string{}
  1756. for n, _ := range ieds {
  1757. if strings.HasPrefix(n, "PM") {
  1758. pmLst = append(pmLst, n)
  1759. }
  1760. }
  1761. if len(pmLst) == 1 {
  1762. return pmLst[0]
  1763. }
  1764. //暴力匹配
  1765. no := []string{"A", "B", "C", "D", "1", "2", "3", "4"}
  1766. for _, i := range no {
  1767. tmpIedName := "PM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + i + iednameParts[7]
  1768. iedObj := ieds[tmpIedName]
  1769. if iedObj != nil {
  1770. return tmpIedName
  1771. }
  1772. }
  1773. return ""
  1774. }
  1775. //根据参考ied name找出应该关联MM装置
  1776. func (c *CheckAreaMgr) getMMName(iednameParts []string, ieds map[string]orm.Params, ab string) string {
  1777. tmpIedName := "MM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + ab
  1778. if ieds[tmpIedName] == nil {
  1779. tmpIedName = "MM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
  1780. }
  1781. return tmpIedName
  1782. }
  1783. //根据当前设备列表,分析出电压等级(高、中、低)的设备列表
  1784. // CT测控、IT智能终端、MT合并单元需要判断是否是本体装置,是则将其归为主变高压侧
  1785. func (c *CheckAreaMgr) getIedListByVol(iedtype string, ieds map[string]orm.Params, vollevel map[string]string) (hightLst, middleLst, lowLst []orm.Params) {
  1786. tmpLst := map[string][]orm.Params{}
  1787. for _, v := range vollevel {
  1788. tmpLst[v] = []orm.Params{}
  1789. }
  1790. scdParseMgr := new(ScdParse)
  1791. for _, row := range ieds {
  1792. pl_iedname := tools.IsEmpty(row["ied_name"])
  1793. if pl_iedname[0:len(iedtype)] != iedtype {
  1794. continue
  1795. }
  1796. iednameParts := scdParseMgr.ParseIedName(pl_iedname)
  1797. volvalue := iednameParts[3] + iednameParts[4]
  1798. if tmpLst[volvalue] == nil {
  1799. tmpLst[volvalue] = []orm.Params{row}
  1800. } else {
  1801. tmpLst[volvalue] = append(tmpLst[volvalue], row)
  1802. }
  1803. }
  1804. return tmpLst[vollevel["hight"]], tmpLst[vollevel["middle"]], tmpLst[vollevel["low"]]
  1805. }
  1806. func (c *CheckAreaMgr) GetCheckResult(scdid int64) ([]orm.Params, error) {
  1807. db := orm.NewOrm()
  1808. rowset := []orm.Params{}
  1809. 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"
  1810. _, err := db.Raw(sql, scdid).Values(&rowset)
  1811. return rowset, err
  1812. }