12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460 |
- package bo
- import (
- "errors"
- "fmt"
- "regexp"
- "scd_check_tools/logger"
- "scd_check_tools/models/enum"
- "scd_check_tools/models/node_attr"
- "scd_check_tools/tools"
- "strconv"
- "strings"
- "sync"
- "github.com/astaxie/beego/orm"
- )
- //检测时间隔管理
- type CheckAreaMgr struct {
- DeviceBaseModel
- //SCD文件ID
- ScdId int64
- //电压等级定义
- VoltageLevelDef map[string]int
- //设备类型定义
- DeviceTypeDef map[string]int
- CacheAreaID map[string]int64
- CacheAreaIDByIedNameNo map[string]int
- //检测模型列表
- CheckModelList []orm.Params
- //模型内装置关系定义
- CheckModelDef sync.Map
- CacheLock sync.RWMutex
- }
- type T_data_check_area struct {
- Id int64 `orm:"pk"`
- AreaName string
- ScdId int64
- VoltageLevel int
- AreaType string
- ModelId int
- Cr int // '创建人' ,
- Ct string `orm:"-"` // '创建时间' ,
- Ur int // '更新人' ,
- Ut string `orm:"-"` // '更新时间'
- }
- type t_data_check_area_ied struct {
- Id int64 `orm:"pk"`
- AreaId int64
- IedName string
- IedType string
- ScdId int64
- PType string
- Cr int // '创建人' ,
- Ct string `orm:"-"` // '创建时间' ,
- Ur int // '更新人' ,
- Ut string `orm:"-"` // '更新时间'
- }
- func init() {
- orm.RegisterModel(new(T_data_check_area))
- orm.RegisterModel(new(t_data_check_area_ied))
- }
- func (c *CheckAreaMgr) Init(scdid int64) {
- c.VoltageLevelDef = map[string]int{}
- c.DeviceTypeDef = map[string]int{}
- c.CacheAreaIDByIedNameNo = map[string]int{}
- c.CacheAreaID = map[string]int64{}
- c.CacheLock = sync.RWMutex{}
- c.ScdId = scdid
- db := orm.NewOrm()
- rowset := []orm.Params{}
- db.Raw("select * from global_const_code where parentcode=?", "voltage_level").Values(&rowset)
- for _, row := range rowset {
- vl := strings.ToLower(tools.IsEmpty(row["code"]))
- id, _ := strconv.ParseInt(tools.IsEmpty(row["id"]), 10, 32)
- c.VoltageLevelDef[strings.ReplaceAll(vl, "v_level_", "")] = int(id)
- }
- db.Raw("select * from global_const_code where parentcode=?", "device_type").Values(&rowset)
- for _, row := range rowset {
- vl := tools.IsEmpty(row["code"])
- c.DeviceTypeDef[vl] = 1
- }
- v, _ := GetSysParamValue("OtherIedNameList", "")
- otherIedNameList = map[string]bool{}
- if v != "" {
- vs := strings.Split(v, ",")
- for _, vv := range vs {
- otherIedNameList[vv] = true
- }
- }
- //先清除ied与间隔关联关系
- clearSql := "delete from t_data_check_area_ied where area_id in(select id from t_data_check_area where scd_id=?)"
- _, err := db.Raw(clearSql, c.ScdId).Exec()
- if err != nil {
- logger.Logger.Error(err, fmt.Sprintf("SQL:%s 参数:%+v", clearSql, []interface{}{c.ScdId}))
- }
- clearSql = "delete from t_data_check_area where scd_id=?"
- _, err = db.Raw(clearSql, c.ScdId).Exec()
- if err != nil {
- logger.Logger.Error(err, fmt.Sprintf("SQL:%s 参数:%+v", clearSql, []interface{}{c.ScdId}))
- }
- //获取当前scd信息中获取到对应的电压等级id
- /*
- scdMgr := new(ScdMgr)
- scdinfo, _ := scdMgr.One(fmt.Sprintf("%d", c.ScdId))
- stationid := tools.IsEmpty(scdinfo["station_id"])
- volid := 0
- if stationid != "" {
- basearea := new(BasicArea)
- stationonof, _ := basearea.One(stationid)
- volid = stationonof.AreaLevel
- }
- */
- tmplist, _ := new(SysCheckModelMgr).GetModelsByVolid()
- scdModels, _, _ := new(TaskMgr).GetModelsByScdID(c.ScdId)
- ms := map[string]interface{}{}
- for _, row := range scdModels {
- ms[tools.IsEmpty(row["model_id"])] = row
- }
- for _, row := range tmplist {
- modelid := tools.IsEmpty(row["id"])
- if ms[modelid] != nil {
- c.CheckModelList = append(c.CheckModelList, row)
- }
- }
- logger.Logger.Debug(fmt.Sprintf("任务的模型列表:%+v", c.CheckModelList))
- ms = nil
- tmplist = nil
- }
- //保存指定间隔所属的电压等级
- func (c *CheckAreaMgr) SetVoltageLevel(id string, voltagelevel int) error {
- db := orm.NewOrm()
- _, err := db.Raw("update t_data_check_area set voltage_level=? where id=?", voltagelevel, id).Exec()
- return err
- }
- //修改指定间隔的名称
- func (c *CheckAreaMgr) UpdateName(scdid int64, area_id int, name string) error {
- db := orm.NewOrm()
- areaM := T_data_check_area{Id: int64(area_id), ScdId: scdid}
- err := db.Read(&areaM)
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- areaM.AreaName = name
- _, err = db.Update(&areaM)
- if err != nil {
- logger.Logger.Error(err)
- }
- return err
- }
- //修改指定IED的所属间隔
- func (c *CheckAreaMgr) UpdateIedArea(scdid int64, iedname string, area_id int) error {
- db := orm.NewOrm()
- _, err := db.Raw("update t_data_check_area_ied set area_id=? where scd_id=? and ied_name=?", area_id, scdid, iedname).Exec()
- return err
- }
- //获取指定scd的间隔信息
- func (c *CheckAreaMgr) GetAreaList(scdid int64) ([]orm.Params, error) {
- db := orm.NewOrm()
- 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"
- rowset := []orm.Params{}
- _, err := db.Raw(sql, scdid).Values(&rowset)
- sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, []interface{}{scdid})
- if err != nil {
- logger.Logger.Error(err, sqllog)
- new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
- } else {
- new(SystemLog).Success(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
- }
- return rowset, nil
- }
- //获取指定scd和电压等级的间隔信息
- func (c *CheckAreaMgr) GetAreaListByVol(scdid int64, vl, linkstyleid int) ([]orm.Params, error) {
- db := orm.NewOrm()
- 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=? "
- params := []interface{}{scdid}
- if vl > 0 {
- sql = sql + " and t1.vol_id=? "
- params = append(params, vl)
- }
- if linkstyleid > 0 {
- sql = sql + " and t1.line_link_style=? "
- params = append(params, linkstyleid)
- }
- rowset := []orm.Params{}
- _, err := db.Raw(sql+" order by t1.vol_id,t1.line_link_style,t1.id", params).Values(&rowset)
- sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, []interface{}{scdid, vl})
- if err != nil {
- logger.Logger.Error(err, sqllog)
- new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
- } else {
- new(SystemLog).Success(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
- }
- return rowset, nil
- }
- //获取指定间隔下的IED列表
- func (c *CheckAreaMgr) GetIedList(scdid int64, areaid int) ([]orm.Params, error) {
- db := orm.NewOrm()
- 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 "
- sqlParamters := []interface{}{}
- sqlParamters = append(sqlParamters, scdid)
- if areaid > 0 {
- sql = sql + " and t1.area_id=?"
- sqlParamters = append(sqlParamters, areaid)
- }
- scdXmlObj, serr := new(ScdParse).GetScdXmlObjectBySCDID(tools.IsEmpty(scdid))
- if serr != nil {
- return nil, serr
- }
- if scdXmlObj == nil {
- return nil, errors.New("无效的SCD")
- }
- rowset := []orm.Params{}
- _, err := db.Raw(sql, sqlParamters).Values(&rowset)
- sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, sqlParamters)
- if err != nil {
- logger.Logger.Error(err, sqllog)
- new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
- } else {
- scdNode := new(ScdNode)
- for _, row := range rowset {
- iedid, _ := strconv.ParseInt(tools.IsEmpty(row["ied_name"]), 10, 64)
- iedObj := scdNode.GetIedByID(scdXmlObj, tools.IsEmpty(scdid), iedid)
- if iedObj == nil {
- continue
- }
- row["attr_name"] = iedObj.Name
- row["attr_desc"] = iedObj.Desc
- row["attr_config_version"] = iedObj.ConfigVersion
- row["attr_type"] = iedObj.Type
- row["attr_manufacturer"] = iedObj.Manufacturer
- row["ied_id"] = iedObj.NodeId
- }
- new(SystemLog).Success(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
- }
- return rowset, nil
- }
- //更新指定间隔下的装置定义
- func (c *CheckAreaMgr) UpdateIeds(scdid int64, areaid int, ieds string) error {
- db := orm.NewOrm()
- iedlist := strings.Split(ieds, ",")
- _, err := db.Raw("delete from t_data_check_area_ied where scd_id=? and area_id=?", scdid, areaid).Exec()
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- for _, row := range iedlist {
- _, err = db.Raw("insert into t_data_check_area_ied(scd_id,area_id,ied_name)values(?,?,?)", scdid, areaid, row).Exec()
- if err != nil {
- logger.Logger.Error(err)
- break
- }
- }
- return err
- }
- //获取指定SCD的IED类型列表
- func (c *CheckAreaMgr) GetIedTypeList(scdid int64) ([]orm.Params, error) {
- db := orm.NewOrm()
- 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 "
- sqlParamters := []interface{}{}
- rowset := []orm.Params{}
- sqlParamters = append(sqlParamters, scdid)
- _, err := db.Raw(sql, sqlParamters).Values(&rowset)
- sqllog := fmt.Sprintf("SQL:%s 参数:%+v", sql, sqlParamters)
- if err != nil {
- logger.Logger.Error(err, sqllog)
- new(SystemLog).Fail(enum.AuditType_scd_show, enum.LogType_Query, enum.OptEventType_Bus, enum.OptEventLevel_Low, sqllog, c.GetUserInfo())
- }
- return rowset, nil
- }
- func (c *CheckAreaMgr) One(id string) (interface{}, error) {
- db := orm.NewOrm()
- idInt, err := strconv.ParseInt(id, 10, 64)
- if err != nil {
- return nil, err
- }
- areaM := T_data_check_area{Id: idInt}
- err = db.Read(&areaM)
- if err == nil {
- return areaM, nil
- }
- return nil, err
- }
- //重置scd的间隔信息
- func (c *CheckAreaMgr) Reset() error {
- dbo := orm.NewOrm()
- dbo.Raw("delete from t_data_check_area where scd_id=?", c.ScdId).Exec()
- dbo.Raw("delete from t_data_check_area_ied where scd_id=?", c.ScdId).Exec()
- c.ParseModelArea()
- logdesc := fmt.Sprintf("重置SCD[%d]检测模型间隔成功", c.ScdId)
- new(SystemLog).Success(enum.AuditType_check_task, enum.LogType_bind, enum.OptEventType_Bus, enum.OptEventLevel_Mid, logdesc, c.GetUserInfo())
- return nil
- }
- var areaCheckInfo = sync.Map{}
- //获取解析模型需要的基础数据信息
- func (c *CheckAreaMgr) getAreaCheckInfo() (*node_attr.SCL, []orm.Params, string, error) {
- key := fmt.Sprintf("%d-checkinfo", c.ScdId)
- if v, h := areaCheckInfo.Load(key); h {
- v1 := v.([]interface{})
- return v1[0].(*node_attr.SCL), v1[1].([]orm.Params), v1[2].(string), nil
- }
- arealist := []orm.Params{}
- db := orm.NewOrm()
- _, err := db.Raw("select id,area_name,area_type,model_id from t_data_check_area where scd_id=?", c.ScdId).Values(&arealist)
- if err != nil {
- logger.Logger.Error(err)
- return nil, nil, "", err
- }
- scdNodeRule := new(ScdNodeRule)
- area_ruleid := ""
- area_ruleList, _, _ := scdNodeRule.GetDefList(map[string]interface{}{"check_name": "间隔装置与检查模型不符"}, 1, 1)
- if len(area_ruleList) > 0 {
- area_ruleid = tools.IsEmpty(area_ruleList[0]["id"])
- }
- if area_ruleid == "" {
- return nil, nil, "", errors.New(fmt.Sprintf("未定义间隔装置的检查规则“间隔装置与检查模型不符”"))
- }
- scdParseMgr := new(ScdParse)
- scdXmlObj, serr := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
- if serr != nil {
- return nil, nil, "", serr
- }
- if scdXmlObj == nil {
- return nil, nil, "", errors.New("无效的SCD")
- }
- areaCheckInfo.Store(key, []interface{}{scdXmlObj, arealist, area_ruleid})
- return scdXmlObj, arealist, area_ruleid, nil
- }
- //检测间隔装置关系正确性
- func (c *CheckAreaMgr) CheckAreaIedRelation() error {
- // 获取当前scd中需要检查的间隔
- scdXmlObj, arealist, area_ruleid, err := c.getAreaCheckInfo()
- db := orm.NewOrm()
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- if area_ruleid == "" {
- return errors.New(fmt.Sprintf("未定义间隔装置的检查规则“间隔装置与检查模型不符”"))
- }
- if scdXmlObj == nil {
- return errors.New("无效的SCD")
- }
- scdNodeRule := new(ScdNodeRule)
- scdNode := new(ScdNode)
- model_refs := map[string][]orm.Params{} //模型定义的装置关系定义
- area_ieds := map[string][]orm.Params{} //间隔下的装置列表
- iedRelationMgr := new(SysCheckModelIedRelationMgr)
- for _, row := range arealist {
- //获取间隔标准装置及关系
- modelid, _ := strconv.Atoi(tools.IsEmpty(row["model_id"]))
- //area_name := tools.IsEmpty(row["area_name"])
- //area_type := tools.IsEmpty(row["area_type"]) //间隔模型类型
- area_id := tools.IsEmpty(row["id"])
- s, err := iedRelationMgr.GetListByModelid(modelid)
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- if len(s) == 0 {
- return errors.New(fmt.Sprintf("模型%d还未配置装置关系", modelid))
- }
- model_refs[fmt.Sprintf("%d", modelid)] = s
- /*
- hasIeds := map[string]bool{}
- for _, row1 := range s {
- iedname := tools.IsEmpty(row1["from_ied_code"])
- if !hasIeds[iedname] {
- hasIeds[iedname] = true
- }
- iedname = tools.IsEmpty(row1["to_ied_code"])
- if !hasIeds[iedname] {
- hasIeds[iedname] = true
- }
- }
- */
- s1 := []orm.Params{}
- _, err = db.Raw("select ied_name from t_data_check_area_ied where area_id=?", area_id).Values(&s1)
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- if len(s) == 0 {
- return errors.New(fmt.Sprintf("间隔%s未发现任何装置", tools.IsEmpty(row["area_name"])))
- }
- area_ieds[area_id] = s1
- /*
- curIeds := map[string]string{}
- for _, row1 := range s1 {
- iedname := strings.Trim(tools.IsEmpty(row1["ied_name"]), " ")
- iedParts := scdParseMgr.ParseIedName(iedname)
- iedtype := iedParts[0] + iedParts[1] + iedParts[2]
- curIeds[iedtype] = iedname
- }
- for k, _ := range hasIeds {
- iedname := curIeds[k]
- if iedname == "" {
- parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, k)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r)
- } else {
- //判断装置是否存在
- if scdNode.GetIed(scdXmlObj, "", iedname) == nil {
- parse_result := fmt.Sprintf("间隔%s内装置%s未定义", area_name, iedname)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r)
- }
- }
- }*/
- }
- //装置关联关系分析
- //先分析母联间隔,如果没有选择母联间隔时,主变间隔中不包含母联终端装置
- HasAreaJ := false
- for _, row := range arealist {
- area_name := tools.IsEmpty(row["area_name"])
- areaCode := tools.IsEmpty(row["area_type"]) //间隔模型类型
- area_id := tools.IsEmpty(row["id"])
- if areaCode == "J" {
- HasAreaJ = true
- modelid := tools.IsEmpty(row["model_id"])
- c.cJ(scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PE", area_ruleid)
- c.cJ(scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PJ", area_ruleid)
- c.cJ(scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PK", area_ruleid)
- c.cJ(scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], "PF", area_ruleid)
- }
- }
- for _, row := range arealist {
- area_name := tools.IsEmpty(row["area_name"])
- areaCode := tools.IsEmpty(row["area_type"]) //间隔模型类型
- area_id := tools.IsEmpty(row["id"])
- modelid := tools.IsEmpty(row["model_id"])
- if areaCode == "J" {
- continue
- }
- if areaCode == "L" {
- //线路间隔
- c.cL(scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], area_ruleid)
- }
- if areaCode == "T" {
- //变压器齐间隔
- c.cT(scdXmlObj, scdNode, scdNodeRule, area_name, model_refs[modelid], area_ieds[area_id], area_ruleid, HasAreaJ)
- }
- }
- scdNodeRule.CheckFinish()
- scdNodeRule.Flush()
- return nil
- }
- //检测装置功能分析
- func (c *CheckAreaMgr) CheckIedFunc() error {
- return nil
- }
- //检测装置端子分析
- func (c *CheckAreaMgr) CheckIedFcda() error {
- scdXmlObj, arealist, area_ruleid, err := c.getAreaCheckInfo()
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- if area_ruleid == "" {
- return errors.New(fmt.Sprintf("未定义间隔装置的检查规则“间隔装置与检查模型不符”"))
- }
- if scdXmlObj == nil {
- return errors.New("无效的SCD")
- }
- db := orm.NewOrm()
- //获取当前站的各电压等级
- volRows := []orm.Params{}
- _, 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)
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- if len(volRows) == 0 {
- logger.Logger.Error(errors.New("该scd未发现任何电压等级的装置"))
- return errors.New("该scd未发现任何电压等级的装置")
- }
- volMap := map[string]string{}
- volMap["hight"] = tools.IsEmpty(volRows[0]["vol"]) //高压电压
- if len(volRows) == 2 {
- volMap["middle"] = ""
- volMap["low"] = volRows[1]["vol"].(string) //低压电压等级
- } else {
- volMap["middle"] = volRows[1]["vol"].(string) //中压电压等级
- volMap["low"] = volRows[len(volRows)-1]["vol"].(string) //低压电压等级
- }
- scdNodeRule := new(ScdNodeRule)
- scdNodeMgr := new(ScdNode)
- iedRelationMgr := new(SysCheckModelIedRelationMgr)
- for _, row := range arealist {
- //获取间隔标准装置及关系
- modelid, _ := strconv.Atoi(tools.IsEmpty(row["model_id"]))
- area_name := tools.IsEmpty(row["area_name"])
- //area_type := tools.IsEmpty(row["area_type"]) //间隔模型类型
- area_id := tools.IsEmpty(row["id"])
- s, err := iedRelationMgr.GetListByModelid(modelid)
- if err != nil {
- logger.Logger.Error(err)
- return err
- }
- if len(s) == 0 {
- return errors.New(fmt.Sprintf("模型%d还未配置装置关系", modelid))
- }
- //获取该间隔下该类型的装置
- s1 := []orm.Params{}
- _, err = db.Raw("select ied_name from t_data_check_area_ied where area_id=?", area_id).Values(&s1)
- //循环处理关联关系
- dealIedType := map[string]int{} //已处理过的装置类型
- for _, row2 := range s {
- ied_type := tools.IsEmpty(row2["ied_type"])
- if dealIedType[ied_type] > 0 {
- continue
- }
- //获取装置类型配置的端子列表
- fcdaMgr := new(SysCheckModelIedFuncFcdaMgr)
- funcMgr := new(SysCheckModelIedFuncMgr)
- funcMgr.Model = T_data_model_func_def{ModelId: modelid}
- funclist, _ := funcMgr.GetList(modelid, ied_type)
- if funclist == nil || len(funclist) == 0 {
- continue
- }
- tmp := strings.Split(ied_type, "#")
- ied_type = tmp[0]
- vol := ""
- if len(tmp) == 2 {
- vol = tmp[1] //电压级别
- }
- iedlst := []orm.Params{}
- if vol == "" {
- for _, r := range s1 {
- if strings.HasPrefix(tools.IsEmpty(r["ied_name"]), ied_type) {
- iedlst = append(iedlst, r)
- }
- }
- } else {
- tmpLst := map[string]orm.Params{}
- for _, r := range s1 {
- iedname := tools.IsEmpty(r["ied_name"])
- if strings.HasPrefix(iedname, ied_type) {
- tmpLst[iedname] = r
- }
- }
- h, m, l := c.getIedListByVol(ied_type, tmpLst, volMap)
- if vol == "H" {
- iedlst = h
- }
- if vol == "M" {
- iedlst = m
- }
- if vol == "L" {
- iedlst = l
- }
- }
- for _, ied := range iedlst {
- iedname := tools.IsEmpty(ied["ied_name"])
- iedObj := scdNodeMgr.GetIed(scdXmlObj, tools.IsEmpty(c.ScdId), iedname)
- if iedObj == nil {
- continue
- }
- fcdaObjList := []*node_attr.NFCDA{}
- for _, t1 := range iedObj.AccessPoint {
- if t1.Server == nil || len(t1.Server.LDevice) == 0 {
- continue
- }
- for _, ld := range t1.Server.LDevice {
- if ld.LN0 != nil {
- for _, t2 := range ld.LN0.DataSet {
- for _, t3 := range t2.FCDA {
- fcdaObjList = append(fcdaObjList, t3)
- }
- }
- }
- }
- }
- for _, row3 := range funclist {
- funcExist := false //设计的功能是否存在
- funcid, _ := strconv.Atoi(tools.IsEmpty(row3["id"]))
- fcdaMgr.Model = T_data_model_func_fcda{ModelId: modelid, FuncId: funcid}
- fcdalist, _ := fcdaMgr.GetList()
- if fcdalist != nil && len(fcdalist) > 0 {
- //判断端子是否存在
- for _, row4 := range fcdalist {
- fcda_name_match := tools.IsEmpty(row4["fcda_match_exp"])
- fcda_name := tools.IsEmpty(row4["fcda_name"])
- if fcda_name_match == "" {
- fcda_name_match = fcda_name
- }
- fcdaExist := false
- //获取端子FCDA描述
- if len(fcdaObjList) > 0 {
- for _, t4 := range fcdaObjList {
- re, _ := scdNodeRule.IedFcdaExist(iedname, t4.LdInst, t4.LnClass, t4.LnInst, t4.Prefix, t4.DoName, t4.DaName)
- if re == nil {
- continue
- }
- doi := re.(*node_attr.NDOI)
- desc := doi.Desc
- if fcda_name_match == desc {
- //完全匹配
- fcdaExist = true
- break
- }
- //正则匹配
- //fcda_name_match = strings.ReplaceAll(fcda_name_match)
- rexp := regexp.MustCompile(fcda_name_match)
- if rexp.FindString(desc) != "" {
- fcdaExist = true
- break
- }
- }
- }
- if fcdaExist {
- funcExist = true
- } else {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失虚端子%s", area_name, iedname, fcda_name)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r)
- }
- }
- }
- if !funcExist {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失功能%s", area_name, iedname, tools.IsEmpty(row3["func_name"]))
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r)
- }
- }
- }
- dealIedType[ied_type] = 1
- }
- }
- scdNodeRule.CheckFinish()
- scdNodeRule.Flush()
- return nil
- }
- //解析模型间隔
- func (c *CheckAreaMgr) ParseModelArea() {
- c.Init(c.ScdId)
- key := fmt.Sprintf("%d-checkinfo", c.ScdId)
- areaCheckInfo.Delete(key)
- // 取得当前scd所有ied及名称解析结果
- dbo := orm.NewOrm()
- 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"
- iedlst := []orm.Params{}
- _, err := dbo.Raw(sql, c.ScdId).Values(&iedlst)
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- logger.Logger.Debug(fmt.Sprintf("=====总装置数:%d", len(iedlst)))
- iedMap := map[string]orm.Params{}
- for _, r := range iedlst {
- iedMap[tools.IsEmpty(r["ied_name"])] = r
- }
- //先分析母联间隔,如果没有选择母联间隔时,主变间隔中不包含母联终端装置
- HasAreaJ := false
- for _, row := range c.CheckModelList {
- areaCode := tools.IsEmpty(row["area_type_code"])
- if areaCode == "J" {
- HasAreaJ = true
- modelid, _ := strconv.Atoi(tools.IsEmpty(row["id"]))
- //modelname := tools.IsEmpty(row["model_name"])
- iedtypes := tools.IsEmpty(row["ied_types"])
- volcode := strings.ReplaceAll(tools.IsEmpty(row["vol_code"]), "v_level_", "")
- c.pJ(modelid, volcode, iedtypes, iedMap, "PE")
- c.pJ(modelid, volcode, iedtypes, iedMap, "PJ")
- c.pJ(modelid, volcode, iedtypes, iedMap, "PK")
- c.pJ(modelid, volcode, iedtypes, iedMap, "PF")
- }
- }
- for _, row := range c.CheckModelList {
- //逐一分析模型定义
- modelid, _ := strconv.Atoi(tools.IsEmpty(row["id"]))
- modelname := tools.IsEmpty(row["model_name"])
- iedtypes := tools.IsEmpty(row["ied_types"])
- //模型对应的间隔代码
- /*
- S 站用变压器
- C 电容器
- B 断路器
- K 母分
- J 母联
- M 母线
- X 电抗器
- L 线路
- T 主变压器
- */
- areaCode := tools.IsEmpty(row["area_type_code"])
- //模型对应的电压等级
- //10:10KV 35:35KV 66:66KV 11:110KV 22:220KV 50:500KV 75:750KV 33:330KV T0:1000KV
- volcode := strings.ReplaceAll(tools.IsEmpty(row["vol_code"]), "v_level_", "")
- if modelname == "" || iedtypes == "" {
- continue
- }
- //母联间隔已经提前分析,如果没有母联间隔时,主变间隔中不包含母联终端装置
- if areaCode == "J" {
- continue
- }
- //获取模型内中装备关系定义
- //主变间隔分析:需要查站内该电压等级下的高中低压侧装置或者高低压装置组成一个间隔,以主变保护装置(PT)为起始
- if areaCode == "T" {
- c.pT(modelid, iedtypes, iedMap, HasAreaJ)
- }
- //线路保护间隔分析:以线路保护测控装置(PL)为开始分析
- if areaCode == "L" {
- c.pL(modelid, volcode, iedtypes, iedMap)
- }
- }
- }
- //变压器间隔分析
- func (c *CheckAreaMgr) pT(modelid int, iedtypes string, ieds map[string]orm.Params, HasAreaJ bool) {
- scdParseMgr := new(ScdParse)
- db := orm.NewOrm()
- //获取当前站的各电压等级
- volRows := []orm.Params{}
- _, 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)
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- if len(volRows) == 0 {
- logger.Logger.Error(errors.New("该scd未发现任何电压等级的装置"))
- return
- }
- volMap := map[string]string{}
- volMap["hight"] = tools.IsEmpty(volRows[0]["vol"]) //高压电压
- if len(volRows) == 2 {
- volMap["middle"] = ""
- volMap["low"] = volRows[1]["vol"].(string) //低压电压等级
- } else {
- volMap["middle"] = volRows[1]["vol"].(string) //中压电压等级
- volMap["low"] = volRows[len(volRows)-1]["vol"].(string) //低压电压等级
- }
- for _, row := range ieds {
- if tools.IsEmpty(row["ied_type"]) != "P" || tools.IsEmpty(row["p_type"]) != "T" {
- continue
- }
- //pmIedName := ""
- //mmIedName := ""
- pl_iedname := tools.IsEmpty(row["ied_name"])
- iednameParts := scdParseMgr.ParseIedName(pl_iedname)
- //添加间隔数据
- dbdata := T_data_check_area{
- ModelId: modelid,
- ScdId: c.ScdId,
- AreaType: "T",
- AreaName: tools.IsEmpty(row["area_name"]) + iednameParts[7],
- }
- newid, err := db.Insert(&dbdata)
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
- insvalues := []string{}
- inAreaIedName := pl_iedname
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "T"))
- //合智一体IMT/MIT,分高中低压
- h, m, l := c.getIedListByVol("IMT", ieds, volMap)
- h = append(h, m...)
- h = append(h, l...)
- for _, r := range h {
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- if lastChar == iednameParts[7] {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "IM", "T"))
- }
- }
- h, m, l = c.getIedListByVol("MIT", ieds, volMap)
- h = append(h, m...)
- h = append(h, l...)
- for _, r := range h {
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- if lastChar == iednameParts[7] {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "MI", "T"))
- }
- }
- //母联智能终端IE需要分高中压,无低压侧
- if HasAreaJ {
- h, m, l = c.getIedListByVol("IE", ieds, volMap)
- for _, r := range h {
- //高压侧,AB套必须与PT装置相同
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- if lastChar == iednameParts[7] {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "E"))
- }
- }
- for _, r := range m {
- //中压侧
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- if lastChar == "" || lastChar == iednameParts[7] {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "E"))
- }
- }
- }
- //合并单元MT分高中低压侧;低压侧无关联母线合并单元MM
- h, m, l = c.getIedListByVol("MT", ieds, volMap)
- h = append(h, m...)
- h = append(h, l...)
- for _, r := range h {
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- if lastChar == iednameParts[7] {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "M", "T"))
- }
- }
- //测控装置CT分高中低压侧,且可能是多套合并单元MT共用,既不分AB套
- h, m, l = c.getIedListByVol("CT", ieds, volMap)
- h = append(h, m...)
- h = append(h, l...)
- for _, r := range h {
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
- //高中低压电压等级相同的
- if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && (lastChar == "" || lastChar == iednameParts[7]) {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "C", "T"))
- }
- }
- //智能终端(IB:开关\IT:分支\IF:分段)分高中低压侧
- h, m, l = c.getIedListByVol("IB", ieds, volMap)
- h = append(h, m...)
- h = append(h, l...)
- for _, r := range h {
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
- //高中低压电压等级相同的
- if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && (lastChar == "" || lastChar == iednameParts[7]) {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "B"))
- }
- }
- h, m, l = c.getIedListByVol("IT", ieds, volMap)
- h = append(h, m...)
- h = append(h, l...)
- for _, r := range h {
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
- //高中低压电压等级相同的
- if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && (lastChar == "" || lastChar == iednameParts[7]) {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "T"))
- }
- }
- h, m, l = c.getIedListByVol("IF", ieds, volMap)
- h = append(h, m...)
- h = append(h, l...)
- for _, r := range h {
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- tmpVol := tmpIednameParts[3] + tmpIednameParts[4]
- //高中低压电压等级相同的
- if (tmpVol == volMap["low"] || tmpVol == volMap["middle"] || tmpVol == volMap["hight"]) && (lastChar == "" || lastChar == iednameParts[7]) {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "I", "F"))
- }
- }
- //母线保护PM及母线合并单元MM,可能是多套合并单元MT共用,既不分AB套;低压侧智能终端无关联母线保护
- h, m, l = c.getIedListByVol("PM", ieds, volMap)
- for _, r := range h {
- //高压侧,AB套必须与PT装置相同
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- if lastChar == iednameParts[7] {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
- //MM装置
- mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
- break
- }
- }
- for _, r := range m {
- //中压侧
- inAreaIedName = tools.IsEmpty(r["ied_name"])
- tmpIednameParts := scdParseMgr.ParseIedName(inAreaIedName)
- lastChar := tmpIednameParts[7]
- if lastChar == "" || lastChar == iednameParts[7] {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "P", "M"))
- //MM装置
- mmIedName := c.getMMName(tmpIednameParts, ieds, iednameParts[7])
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, mmIedName, "M", "M"))
- break
- }
- }
- _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- }
- }
- //线路间隔分析
- //vol:电压等级
- func (c *CheckAreaMgr) pL(modelid int, vol, iedtypes string, ieds map[string]orm.Params) {
- scdParseMgr := new(ScdParse)
- //scdNodeMgr := new(ScdNode)
- db := orm.NewOrm()
- //scdXmlObject, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
- for _, row := range ieds {
- if tools.IsEmpty(row["vol"]) != vol || tools.IsEmpty(row["ied_type"]) != "P" || tools.IsEmpty(row["p_type"]) != "L" {
- continue
- }
- pmIedName := ""
- mmIedName := ""
- pl_iedname := tools.IsEmpty(row["ied_name"])
- iednameParts := scdParseMgr.ParseIedName(pl_iedname)
- //添加间隔数据
- dbdata := T_data_check_area{
- ModelId: modelid,
- ScdId: c.ScdId,
- AreaType: "L",
- AreaName: tools.IsEmpty(row["area_name"]) + iednameParts[7],
- }
- newid, err := db.Insert(&dbdata)
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
- insvalues := []string{}
- for _, ty := range strings.Split(iedtypes, ",") {
- inAreaIedName := ""
- if ty == "PM" {
- //母线保护和母线合并单元装置编号跟随变压器
- //查找变压器编号
- //1号变压器->2号变压器->3号
- inAreaIedName = c.getPMName(iednameParts, ieds)
- pmIedName = inAreaIedName
- if mmIedName == "" {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ty[0:1], ty[1:2]))
- pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
- //使用PM装置的名称去定义MM的名称
- ty = "MM"
- inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
- mmIedName = inAreaIedName
- }
- } else if ty == "MM" {
- if pmIedName != "" && mmIedName == "" {
- pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
- //使用PM装置的名称去定义MM的名称
- inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
- mmIedName = inAreaIedName
- } else {
- continue
- }
- } else {
- inAreaIedName = ty + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
- }
- if strings.Index("ABCDE", iednameParts[7]) > -1 {
- //最后一位是字母则说明是AB套
- switch ty {
- case "CL":
- //测控装置,先判断是否分了AB套,没有标识(ied名称的最后一位是否是字母)则说明是多套共用装置
- clIedname := inAreaIedName + iednameParts[7]
- iedObj := ieds[inAreaIedName]
- if iedObj != nil {
- //当前测控装置也分了AB套
- inAreaIedName = clIedname
- }
- break
- default:
- break
- }
- }
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ty[0:1], ty[1:2]))
- }
- _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- //如果mm装置还未确定
- if mmIedName == "" {
- pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
- inAreaIedName := c.getMMName(pmIedNameParts, ieds, iednameParts[7])
- _, err = db.Raw(ins1 + fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, "M", "M")).Exec()
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- }
- }
- }
- //母联间隔分析
- func (c *CheckAreaMgr) pJ(modelid int, vol, iedtypes string, ieds map[string]orm.Params, pjIed string) {
- scdParseMgr := new(ScdParse)
- //scdNodeMgr := new(ScdNode)
- db := orm.NewOrm()
- //scdXmlObject, _ := scdParseMgr.GetScdXmlObjectBySCDID(tools.IsEmpty(c.ScdId))
- for _, row := range ieds {
- if tools.IsEmpty(row["vol"]) != vol || tools.IsEmpty(row["ied_type"]) != "P" || tools.IsEmpty(row["p_type"]) != pjIed[1:2] {
- continue
- }
- pmIedName := ""
- mmIedName := ""
- pl_iedname := tools.IsEmpty(row["ied_name"])
- iednameParts := scdParseMgr.ParseIedName(pl_iedname)
- //添加间隔数据
- dbdata := T_data_check_area{
- ModelId: modelid,
- ScdId: c.ScdId,
- AreaType: "J",
- AreaName: tools.IsEmpty(row["area_name"]) + iednameParts[7],
- }
- newid, err := db.Insert(&dbdata)
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- ins1 := "insert into t_data_check_area_ied(scd_id,area_id,ied_name,ied_type,p_type)values"
- insvalues := []string{}
- for _, ty := range strings.Split(iedtypes, ",") {
- inAreaIedName := ""
- if ty == "PM" {
- //母线保护和母线合并单元装置编号跟随变压器
- //查找变压器编号
- //1号变压器->2号变压器->3号
- inAreaIedName = c.getPMName(iednameParts, ieds)
- pmIedName = inAreaIedName
- if mmIedName == "" {
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ty[0:1], ty[1:2]))
- pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
- //使用PM装置的名称去定义MM的名称
- ty = "MM"
- inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
- mmIedName = inAreaIedName
- }
- } else if ty == "MM" {
- if pmIedName != "" && mmIedName == "" {
- pmIedNameParts := scdParseMgr.ParseIedName(pmIedName)
- //使用PM装置的名称去定义MM的名称
- inAreaIedName = c.getMMName(pmIedNameParts, ieds, iednameParts[7])
- mmIedName = inAreaIedName
- } else {
- continue
- }
- } else {
- ty = ty[0:1] + pjIed[1:2]
- inAreaIedName = ty + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
- //判断与基准保护装置相同套号的装置是否存在
- if ieds[inAreaIedName] == nil {
- //尝试去除套号
- inAreaIedName = ty + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6]
- }
- }
- insvalues = append(insvalues, fmt.Sprintf("(%d,%d,'%s','%s','%s')", c.ScdId, newid, inAreaIedName, ty[0:1], ty[1:2]))
- }
- _, err = db.Raw(ins1 + strings.Join(insvalues, ",")).Exec()
- if err != nil {
- logger.Logger.Error(err)
- return
- }
- }
- }
- //母联间隔装置关系检查
- func (c *CheckAreaMgr) cJ(scdXmlObj *node_attr.SCL, scdNodeMgr *ScdNode, scdNodeRule *ScdNodeRule, area_name string, ied_refs []orm.Params, area_ieds []orm.Params, pjIed, area_ruleid string) {
- masterIed := new(node_attr.NIED)
- findIedName := ""
- for _, row2 := range area_ieds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- if strings.HasPrefix(findIedName, pjIed) {
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
- break
- }
- }
- if masterIed == nil {
- return
- }
- dealFromIed := map[string]int{}
- for _, row := range ied_refs {
- fromiedtype := tools.IsEmpty(row["from_ied_code"])
- toiedtype := tools.IsEmpty(row["to_ied_code"])
- reftype := tools.IsEmpty(row["in_type"])
- tmpFromAreaIeds := []orm.Params{}
- tmpToAreaIeds := []orm.Params{}
- for _, row2 := range area_ieds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- if strings.HasPrefix(findIedName, fromiedtype) {
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
- if masterIed != nil {
- tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
- } else {
- if dealFromIed[findIedName] == 0 {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r)
- }
- dealFromIed[findIedName] = 1
- }
- }
- if strings.HasPrefix(findIedName, toiedtype) {
- tmpToAreaIeds = append(tmpToAreaIeds, row2)
- }
- }
- if len(tmpFromAreaIeds) == 0 {
- continue
- }
- if len(tmpToAreaIeds) == 0 {
- parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, toiedtype)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- continue
- }
- toIedname := ""
- for _, row2 := range tmpFromAreaIeds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- hasToIedRef := false
- hasToIed := false
- for _, row3 := range tmpToAreaIeds {
- toIedname = tools.IsEmpty(row3["ied_name"])
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", toIedname)
- if masterIed != nil {
- hasToIed = true
- // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
- inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
- logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
- if inout != nil {
- outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
- for _, ieditem := range outiedlist {
- outiedname := ieditem["ref_ied_name"].(string)
- if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
- hasToIedRef = true
- break
- }
- }
- }
- if !hasToIedRef {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- }
- }
- }
- if !hasToIed {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- }
- }
- }
- }
- //线路间隔装置关系检查
- func (c *CheckAreaMgr) cL(scdXmlObj *node_attr.SCL, scdNodeMgr *ScdNode, scdNodeRule *ScdNodeRule, area_name string, ied_refs []orm.Params, area_ieds []orm.Params, area_ruleid string) {
- masterIed := new(node_attr.NIED)
- findIedName := ""
- for _, row2 := range area_ieds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- if strings.HasPrefix(findIedName, "PL") {
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
- break
- }
- }
- if masterIed == nil {
- return
- }
- dealFromIed := map[string]int{}
- for _, row := range ied_refs {
- fromiedtype := tools.IsEmpty(row["from_ied_code"])
- toiedtype := tools.IsEmpty(row["to_ied_code"])
- reftype := tools.IsEmpty(row["in_type"])
- tmpFromAreaIeds := []orm.Params{}
- tmpToAreaIeds := []orm.Params{}
- for _, row2 := range area_ieds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- if strings.HasPrefix(findIedName, fromiedtype) {
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
- if masterIed != nil {
- tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
- } else {
- if dealFromIed[findIedName] == 0 {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r)
- }
- dealFromIed[findIedName] = 1
- }
- }
- if strings.HasPrefix(findIedName, toiedtype) {
- tmpToAreaIeds = append(tmpToAreaIeds, row2)
- }
- }
- if len(tmpFromAreaIeds) == 0 {
- continue
- }
- if len(tmpToAreaIeds) == 0 {
- parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, toiedtype)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- continue
- }
- toIedname := ""
- for _, row2 := range tmpFromAreaIeds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- hasToIedRef := false
- hasToIed := false
- for _, row3 := range tmpToAreaIeds {
- toIedname = tools.IsEmpty(row3["ied_name"])
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", toIedname)
- if masterIed != nil {
- hasToIed = true
- // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
- inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
- logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
- if inout != nil {
- outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
- for _, ieditem := range outiedlist {
- outiedname := ieditem["ref_ied_name"].(string)
- if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
- hasToIedRef = true
- break
- }
- }
- }
- if !hasToIedRef {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- }
- }
- }
- if !hasToIed {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- }
- }
- }
- }
- //变压器间隔装置关系检查
- func (c *CheckAreaMgr) cT(scdXmlObj *node_attr.SCL, scdNodeMgr *ScdNode, scdNodeRule *ScdNodeRule, area_name string, ied_refs []orm.Params, area_ieds []orm.Params, area_ruleid string, HasAreaJ bool) {
- masterIed := new(node_attr.NIED)
- findIedName := ""
- for _, row2 := range area_ieds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- if strings.HasPrefix(findIedName, "PT") {
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
- break
- }
- }
- if masterIed == nil {
- return
- }
- scdParseMgr := new(ScdParse)
- dealFromIed := map[string]int{}
- for _, row := range ied_refs {
- fromiedtype := tools.IsEmpty(row["from_ied_code"])
- fromiedtype = strings.Split(fromiedtype, "#")[0] //去除后面的电压级别标识
- toiedtype := strings.Split(tools.IsEmpty(row["to_ied_code"]), "#")[0] //去除后面的电压级别标识
- reftype := tools.IsEmpty(row["in_type"])
- tmpFromAreaIeds := []orm.Params{}
- tmpToAreaIeds := []orm.Params{}
- for _, row2 := range area_ieds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- if strings.HasPrefix(findIedName, fromiedtype) {
- masterIed = scdNodeMgr.GetIed(scdXmlObj, "", findIedName)
- if masterIed != nil {
- tmpFromAreaIeds = append(tmpFromAreaIeds, row2)
- } else {
- if dealFromIed[findIedName] == 0 {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失", area_name, findIedName)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r)
- }
- dealFromIed[findIedName] = 1
- }
- }
- if strings.HasPrefix(findIedName, toiedtype) {
- tmpToAreaIeds = append(tmpToAreaIeds, row2)
- }
- }
- if len(tmpFromAreaIeds) == 0 {
- continue
- }
- if len(tmpToAreaIeds) == 0 {
- logger.Logger.Debug(fmt.Sprintf("缺失类型关联装置 :%+v", row))
- parse_result := fmt.Sprintf("间隔%s缺失类型为%s的装置", area_name, toiedtype)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- continue
- }
- toIedname := ""
- for _, row2 := range tmpFromAreaIeds {
- findIedName = tools.IsEmpty(row2["ied_name"])
- hasToIedRef := false
- hasToIed := false
- t1 := fromiedtype + "->" + toiedtype
- volLevel := "" //电压等级
- 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" {
- ps := scdParseMgr.ParseIedName(findIedName)
- volLevel = ps[3] + ps[4]
- }
- hasSameVolIed := false
- for _, row3 := range tmpToAreaIeds {
- toIedname = tools.IsEmpty(row3["ied_name"])
- if volLevel != "" {
- ps := scdParseMgr.ParseIedName(toIedname)
- if volLevel != ps[3]+ps[4] {
- //排除不是同一电压等级的装置
- continue
- }
- hasSameVolIed = true
- }
- if scdNodeMgr.GetIed(scdXmlObj, "", toIedname) != nil {
- hasToIed = true
- // 获取该ied的输出(ref_type为0)装置,并从中检测是否存在toiedtype类型的装置
- inout, _ := scdNodeMgr.GetIedRelations(map[string]interface{}{"scd_id": c.ScdId, "ied_name": findIedName})
- logger.Logger.Debug(fmt.Sprintf("ied:%s refs:%+v", findIedName, inout))
- if inout != nil {
- outiedlist := inout[findIedName].(orm.Params)["list"].([]orm.Params)
- for _, ieditem := range outiedlist {
- outiedname := ieditem["ref_ied_name"].(string)
- if outiedname == toIedname && ieditem["ref_type"].(string) == "0" {
- hasToIedRef = true
- break
- }
- }
- }
- if !hasToIedRef {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失与装置%s的%s信号关联", area_name, findIedName, toIedname, reftype)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- }
- }
- if hasSameVolIed {
- break
- }
- }
- if toiedtype != "PT" {
- if volLevel != "" && !hasSameVolIed {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失同电压等级的关联类型%s装置", area_name, findIedName, toiedtype)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- } else if !hasToIed {
- parse_result := fmt.Sprintf("间隔%s的装置%s缺失关联装置%s", area_name, findIedName, toIedname)
- r := map[string]interface{}{"scdid": c.ScdId, "lineno": 0, "ruleid": area_ruleid, "nodeid": 0, "parse_result": parse_result}
- //检查未通过
- scdNodeRule.AppendPaseResult(r, masterIed)
- }
- }
- }
- }
- }
- //根据参考ied name找出应该关联PM装置
- func (c *CheckAreaMgr) getPMName(iednameParts []string, ieds map[string]orm.Params) string {
- tmpIedName := "PM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + "1" + iednameParts[7]
- iedObj := ieds[tmpIedName]
- if iedObj != nil {
- } else {
- tmpIedName = "PM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + "2" + iednameParts[7]
- iedObj = ieds[tmpIedName]
- if iedObj != nil {
- return tmpIedName
- }
- }
- return tmpIedName
- }
- //根据参考ied name找出应该关联MM装置
- func (c *CheckAreaMgr) getMMName(iednameParts []string, ieds map[string]orm.Params, ab string) string {
- tmpIedName := "MM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + ab
- if ieds[tmpIedName] == nil {
- tmpIedName = "MM" + iednameParts[3] + iednameParts[4] + iednameParts[5] + iednameParts[6] + iednameParts[7]
- }
- return tmpIedName
- }
- //根据当前设备列表,分析出电压等级(高、中、低)的设备列表
- // CT测控、IT智能终端、MT合并单元需要判断是否是本体装置,是则将其归为主变高压侧
- func (c *CheckAreaMgr) getIedListByVol(iedtype string, ieds map[string]orm.Params, vollevel map[string]string) (hightLst, middleLst, lowLst []orm.Params) {
- tmpLst := map[string][]orm.Params{}
- for _, v := range vollevel {
- tmpLst[v] = []orm.Params{}
- }
- scdParseMgr := new(ScdParse)
- for _, row := range ieds {
- pl_iedname := tools.IsEmpty(row["ied_name"])
- if pl_iedname[0:len(iedtype)] != iedtype {
- continue
- }
- iednameParts := scdParseMgr.ParseIedName(pl_iedname)
- volvalue := iednameParts[3] + iednameParts[4]
- if tmpLst[volvalue] == nil {
- tmpLst[volvalue] = []orm.Params{row}
- } else {
- tmpLst[volvalue] = append(tmpLst[volvalue], row)
- }
- }
- return tmpLst[vollevel["hight"]], tmpLst[vollevel["middle"]], tmpLst[vollevel["low"]]
- }
- //测试
- func (c *CheckAreaMgr) TestAppendNode(iedname string) {
- //t := t_scd_node_scl{NodeName: iedname}
- //c.AppendIedNode(&t)
- }
|