package entity import ( "fmt" "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" ) // 创建信号机故障报警仪实体 func NewSFAEntity(w ecs.World, station *repository.Station) error { data := GetWorldData(w) repo := data.Repo for _, de := range station.DeviceEcc() { if de.DeviceType == proto.DeviceType_DeviceType_SignalFaultAlarm { var dsbj *ecs.Entry for _, ecg := range de.Egs { if ecg.Code == "LS" { if len(ecg.ComponentIds) == 1 { relay := repo.FindById(ecg.ComponentIds[0]) if relay == nil { return fmt.Errorf("信号机故障报警仪构建错误: 找不到id=%s的继电器", ecg.ComponentIds[0]) } dsbj = NewRelayEntity(w, relay.(*repository.Relay), data.EntityMap) } } } entry := w.Entry(w.Create(component.SFATag, component.SFAEccType)) component.SFAEccType.Set(entry, &component.SFAEcc{ DSBJ: dsbj, }) } } return nil } // 创建断路器实体 func NewDLQEntity(w ecs.World, station *repository.Station) error { data := GetWorldData(w) repo := data.Repo for _, de := range station.DeviceEcc() { if de.DeviceType == proto.DeviceType_DeviceType_Breakers { var rsbj *ecs.Entry for _, ecg := range de.Egs { if ecg.Code == "LS" { if len(ecg.ComponentIds) == 1 { relay := repo.FindById(ecg.ComponentIds[0]) if relay == nil { return fmt.Errorf("断路器实体构建错误: 找不到id=%s的继电器", ecg.ComponentIds[0]) } rsbj = NewRelayEntity(w, relay.(*repository.Relay), data.EntityMap) } } } entry := w.Entry(w.Create(component.DLQTag, component.DLQEccType)) component.DLQEccType.Set(entry, &component.DLQEcc{ RSBJ: rsbj, }) } } return nil } // 创建电源屏实体 func NewDYPEntity(w ecs.World, station *repository.Station) error { data := GetWorldData(w) repo := data.Repo for _, de := range station.DeviceEcc() { if de.DeviceType == proto.DeviceType_DeviceType_PowerScreen { var zdyj *ecs.Entry var fdyj *ecs.Entry var dybj *ecs.Entry for _, ecg := range de.Egs { if ecg.Code == "LS" { if len(ecg.ComponentIds) == 3 { for _, id := range ecg.ComponentIds { d := repo.FindById(id) if d == nil { return fmt.Errorf("电源屏实体构建错误: 找不到id=%s的继电器", ecg.ComponentIds[0]) } if d.Type() == proto.DeviceType_DeviceType_Relay { relay := d.(*repository.Relay) if relay.Code() == "ZDYJ" { zdyj = NewRelayEntity(w, relay, data.EntityMap) } else if relay.Code() == "FDYJ" { fdyj = NewRelayEntity(w, relay, data.EntityMap) } else if relay.Code() == "DYBJ" { dybj = NewRelayEntity(w, relay, data.EntityMap) } else { return fmt.Errorf("电源屏实体构建错误: 未知的继电器编码'%s'", relay.Code()) } } else { return fmt.Errorf("电源屏实体构建错误: id=%s的设备不是继电器", ecg.ComponentIds[0]) } } } } } entry := w.Entry(w.Create(component.DYPTag, component.DYPEccType)) component.DYPEccType.Set(entry, &component.DYPEcc{ ZDYJ: zdyj, FDYJ: fdyj, DYBJ: dybj, }) } } return nil }