调整repo定义

城轨和国铁分开
This commit is contained in:
walker 2023-12-27 13:04:19 +08:00
parent 07248c0fec
commit 1101edd1d3
6 changed files with 821 additions and 1029 deletions

View File

@ -4,17 +4,13 @@ package message;
option go_package = "./repo/dto"; option go_package = "./repo/dto";
message Repo { //
message CgRepo {
string id = 1; string id = 1;
oneof data { // 线
CGData cgData = 2; repeated Line lines = 2;
GTData gtData = 3; // (IBP/PSL/MKX等),线
} repeated JKP jkps = 3;
}
//
message GTData {
} }
// (Train Running Direction) // (Train Running Direction)
@ -25,14 +21,6 @@ enum TRD {
Downward = 1; Downward = 1;
} }
//
message CGData {
// 线
repeated Line lines = 1;
// (IBP/PSL/MKX等),线
repeated JKP jkps = 2;
}
// 线 // 线
message Line { message Line {
// //
@ -179,11 +167,12 @@ message DevidingPoint {
// id // id
repeated uint32 ecsIds = 6; repeated uint32 ecsIds = 6;
} }
//
message Device { //
// message Model {
//
enum Type { enum Type {
// //
Unknown = 0; Unknown = 0;
// //
Section = 1; Section = 1;
@ -192,39 +181,32 @@ message Device {
// //
Signal = 3; Signal = 3;
} }
// () // id
enum Port {
A = 0;
B = 1;
C = 2;
}
// id
uint32 id = 1; uint32 id = 1;
// //
Type type = 2; Type type = 2;
} }
// //
message SectionPort { message SectionPort {
// enum Type {
enum SectionType {
//
Section = 0;
//
Turnout = 1;
}
//
enum PortType {
A = 0; A = 0;
B = 1; B = 1;
C = 2; C = 2;
} }
//
// enum ElementType {
// //
// Section = 0;
// //
// Turnout = 1;
// }
// //
SectionType type = 1; Model.Type type = 1;
// / id // / id
uint32 id = 2; uint32 id = 2;
// //
PortType port = 3; Type port = 3;
} }
// //
message Signal { message Signal {
@ -272,6 +254,8 @@ message Signal {
Model model = 3; Model model = 3;
// id // id
uint32 ecsId = 4; uint32 ecsId = 4;
// ()
TRD trd = 5;
} }
// //
message Turnout { message Turnout {
@ -318,6 +302,8 @@ message Section {
SectionPort bsp = 5; SectionPort bsp = 5;
// id // id
uint32 ecsId = 6; uint32 ecsId = 6;
// ()
TRD trd = 7;
} }
// //
message Psd { message Psd {
@ -478,7 +464,7 @@ message Lamp {
// //
message DeviceEcc { message DeviceEcc {
// //
Device.Type deviceType = 1; Model.Type deviceType = 1;
// //
string deviceCode = 2; string deviceCode = 2;
// //

View File

@ -2,7 +2,7 @@ package repo
import "joylink.club/rtsssimulation/repo/model" import "joylink.club/rtsssimulation/repo/model"
type Repo interface { type CgRepo interface {
// 模型仓库id // 模型仓库id
Id() string Id() string
// 通过uid查询模型对象 // 通过uid查询模型对象

File diff suppressed because it is too large Load Diff

View File

@ -122,20 +122,9 @@ func (m *IdMapping) checkUidAndAdd(idmap *idMap) (existed *idMap, uidExisted boo
return return
} }
// 构建id映射
func BuildIdMapping(msgs *dto.Repo, errRecord *ErrorRecord) *IdMapping {
if cg := msgs.GetCgData(); cg != nil {
return BuildCgIdMapping(cg, errRecord)
} else if gt := msgs.GetGtData(); gt != nil {
return BuildGtIdMapping(gt)
}
errRecord.AddError("构建id映射表错误: 没有数据")
return nil
}
// 构建城轨id映射 // 构建城轨id映射
func BuildCgIdMapping(cg *dto.CGData, errRecord *ErrorRecord) *IdMapping { func BuildIdMapping(msgs *dto.CgRepo, errRecord *ErrorRecord) *IdMapping {
if cg == nil { if msgs == nil {
errRecord.AddError("构建城轨id映射表错误: 未关联任何数据") errRecord.AddError("构建城轨id映射表错误: 未关联任何数据")
return nil return nil
} }
@ -144,14 +133,14 @@ func BuildCgIdMapping(cg *dto.CGData, errRecord *ErrorRecord) *IdMapping {
uidMap: make(map[string]*idMap), uidMap: make(map[string]*idMap),
} }
lineSet := make(map[string]struct{}) lineSet := make(map[string]struct{})
for _, l := range cg.Lines { for _, l := range msgs.Lines {
if _, ok := lineSet[l.City+l.LineId]; ok { if _, ok := lineSet[l.City+l.LineId]; ok {
errRecord.AddError(fmt.Sprintf("构建城轨id映射表错误: 线路重复:%s_%s", l.City, l.LineId)) errRecord.AddError(fmt.Sprintf("构建城轨id映射表错误: 线路重复:%s_%s", l.City, l.LineId))
return nil return nil
} }
lineSet[l.City+l.LineId] = struct{}{} lineSet[l.City+l.LineId] = struct{}{}
} }
for _, line := range cg.Lines { for _, line := range msgs.Lines {
buildXhbz(idMapping, line, errRecord) buildXhbz(idMapping, line, errRecord)
if errRecord.HasError() { if errRecord.HasError() {
return nil return nil
@ -221,7 +210,7 @@ func buildXhbz(idMapping *IdMapping, line *dto.Line, errRecord *ErrorRecord) {
} }
} }
// 物理区段 // 物理区段
for _, ps := range xhbz.PhysicalSections { for _, ps := range xhbz.Sections {
eid := ps.Id eid := ps.Id
if checkFieldEmpty(did, eid, ps.Code, errPrefix, "物理区段编号", errRecord) { if checkFieldEmpty(did, eid, ps.Code, errPrefix, "物理区段编号", errRecord) {
continue continue
@ -478,7 +467,3 @@ func checkRepeatOrAddIdMap(idm *idMap, idMapping *IdMapping, prefix string, errR
} }
return return
} }
func BuildGtIdMapping(gt *dto.GTData) *IdMapping {
panic("未实现")
}

View File

@ -7,16 +7,16 @@ import (
) )
type repoManager struct { type repoManager struct {
repoMap map[string]Repo repoMap map[string]CgRepo
lock sync.Mutex lock sync.Mutex
} }
var defaultManager = &repoManager{ var defaultManager = &repoManager{
repoMap: make(map[string]Repo), repoMap: make(map[string]CgRepo),
} }
// 获取或构建模型仓库 // 获取或构建模型仓库
func GetOrBuildRepo(id string, dc func(errRecord *ErrorRecord) *dto.Repo) (Repo, *ErrorRecord) { func GetOrBuildRepo(id string, dc func(errRecord *ErrorRecord) *dto.CgRepo) (CgRepo, *ErrorRecord) {
manager := defaultManager manager := defaultManager
manager.lock.Lock() manager.lock.Lock()
defer manager.lock.Unlock() defer manager.lock.Unlock()

View File

@ -15,7 +15,7 @@ type repo struct {
turnoutMap map[string]*impl.Turnout // 道岔map,key为uid turnoutMap map[string]*impl.Turnout // 道岔map,key为uid
} }
func BuildFrom(msgs *dto.Repo) (Repo, *ErrorRecord) { func BuildFrom(msgs *dto.CgRepo) (CgRepo, *ErrorRecord) {
errRecord := NewErrorRecord() errRecord := NewErrorRecord()
idMapping := BuildIdMapping(msgs, errRecord) idMapping := BuildIdMapping(msgs, errRecord)
if errRecord.HasError() { if errRecord.HasError() {