From b3271b497adc0158e86bccbce581db9f805bd233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?walker-sheng=E2=80=9D?= Date: Fri, 5 Jul 2024 13:22:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E6=AE=B5=E9=81=93=E5=B2=94=E5=85=AC?= =?UTF-8?q?=E9=87=8C=E6=A0=87=E6=A8=A1=E5=9E=8B=E6=95=B0=E6=8D=AE=E6=9E=84?= =?UTF-8?q?=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/build_repo_example/main.go | 39 +++++++++++++++++++++++++++++- model/section.go | 12 ++++----- model/turnout.go | 24 +++++++++--------- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/example/build_repo_example/main.go b/example/build_repo_example/main.go index 4aa70e5..03cf613 100644 --- a/example/build_repo_example/main.go +++ b/example/build_repo_example/main.go @@ -11,7 +11,8 @@ import ( ) func main() { - slog.SetLogLoggerLevel(slog.LevelDebug) + // slog.SetLogLoggerLevel(slog.LevelDebug) + slog.SetLogLoggerLevel(slog.LevelInfo) repo1 := repository.NewRepository("test1") rtssGraphicStorage := data_proto.GetXian6STYG() dataMapping := repository.NewDataMapping("1", rtssGraphicStorage) @@ -67,6 +68,8 @@ func main() { } else { slog.Info("区段、道岔连接关系检查通过") } + // 构建区段、道岔公里标 + buildKilometerMark(dataMapping, repo1) // 构建link/linknode repo1.BuildLinks() // 检查link/linknode @@ -79,6 +82,40 @@ func main() { } } +// 构建区段、道岔公里标 +func buildKilometerMark(dataMapping *repository.DataMapping, repo1 *repository.Repository) { + for _, checkpoint := range dataMapping.AxleCountings { + if checkpoint.AxleCountingRef == nil || len(checkpoint.AxleCountingRef) == 0 { + repo1.BuildErrorInfos = append(repo1.BuildErrorInfos, fmt.Errorf("构建区段、道岔公里标错误:检测点[id=%d]未关联任何区段、道岔", checkpoint.Common.Id)) + } + for _, linkship := range checkpoint.AxleCountingRef { + slog.Info("区段检测点关联数据", "code", checkpoint.Code, "linkship", fmt.Sprintf("{type=%s, id=%d, port=%s}", linkship.DeviceType, linkship.Id, linkship.DevicePort)) + idmapping := dataMapping.IdMappingMap[linkship.Id] + if idmapping == nil { + repo1.BuildErrorInfos = append(repo1.BuildErrorInfos, fmt.Errorf("构建区段、道岔公里标错误:检测点[id=%d]关联的{type=%s,id=%d}不存在", checkpoint.Common.Id, linkship.DeviceType, linkship.Id)) + continue + } + if linkship.DeviceType == data_proto.RelatedRef_Section { + sectionModel := repo1.SectionMap[idmapping.Uid] + if sectionModel == nil { + panic(fmt.Errorf("构建区段、道岔公里标错误:检测点[id=%d]关联的区段模型[uid=%s]不存在", checkpoint.Common.Id, idmapping.Uid)) + } + sectionModel.(*modelimpl.Section).PaKm = model.NewKilometerMark(checkpoint.KilometerSystem.CoordinateSystem, convertKmDirection(checkpoint.KilometerSystem.Direction), checkpoint.KilometerSystem.Kilometer) + } + } + } +} + +func convertKmDirection(kddata data_proto.KilometerSystem_Direction) model.OperationDirection { + if kddata == data_proto.KilometerSystem_LEFT { + return model.OperationDirectionDown + } + if kddata == data_proto.KilometerSystem_RIGHT { + return model.OperationDirectionUp + } + panic(fmt.Errorf("未知的公里标方向类型: %v", kddata)) +} + func buildTurnoutRelationships(dataMapping *repository.DataMapping, repo1 *repository.Repository) { for _, turnout := range dataMapping.TurnoutDataMap { idmapping := dataMapping.IdMappingMap[turnout.Common.Id] diff --git a/model/section.go b/model/section.go index b37995f..705053a 100644 --- a/model/section.go +++ b/model/section.go @@ -4,14 +4,14 @@ package model type Section interface { TwoPortsPipeElement // 获取A端和B端的公里标 - GetPaKm() KilometerMark - GetPbKm() KilometerMark + GetPaKm() *KilometerMark + GetPbKm() *KilometerMark } type SectionImpl struct { *TwoPortsPipeElementImpl - PaKm KilometerMark - PbKm KilometerMark + PaKm *KilometerMark + PbKm *KilometerMark } var _ Section = (*SectionImpl)(nil) @@ -24,10 +24,10 @@ func NewSection(uid string) *SectionImpl { } } -func (s *SectionImpl) GetPaKm() KilometerMark { +func (s *SectionImpl) GetPaKm() *KilometerMark { return s.PaKm } -func (s *SectionImpl) GetPbKm() KilometerMark { +func (s *SectionImpl) GetPbKm() *KilometerMark { return s.PbKm } diff --git a/model/turnout.go b/model/turnout.go index b253cfa..2d997c7 100644 --- a/model/turnout.go +++ b/model/turnout.go @@ -8,23 +8,23 @@ import ( type Turnout interface { ThreePortsPipeElement // 获取道岔岔心公里标 - GetKm() KilometerMark + GetKm() *KilometerMark // 获取道岔A端公里标 - GetPaKm() KilometerMark + GetPaKm() *KilometerMark // 获取道岔B端公里标 - GetPbKm() KilometerMark + GetPbKm() *KilometerMark // 获取道岔C端公里标 - GetPcKm() KilometerMark + GetPcKm() *KilometerMark } var _ Turnout = (*TurnoutImpl)(nil) type TurnoutImpl struct { *ThreePortsPipeElementImpl - Km KilometerMark - PaKm KilometerMark - PbKm KilometerMark - PcKm KilometerMark + Km *KilometerMark + PaKm *KilometerMark + PbKm *KilometerMark + PcKm *KilometerMark } func NewTurnout(uid string) *TurnoutImpl { @@ -38,18 +38,18 @@ func NewTurnout(uid string) *TurnoutImpl { } } -func (t *TurnoutImpl) GetKm() KilometerMark { +func (t *TurnoutImpl) GetKm() *KilometerMark { return t.Km } -func (t *TurnoutImpl) GetPaKm() KilometerMark { +func (t *TurnoutImpl) GetPaKm() *KilometerMark { return t.PaKm } -func (t *TurnoutImpl) GetPbKm() KilometerMark { +func (t *TurnoutImpl) GetPbKm() *KilometerMark { return t.PbKm } -func (t *TurnoutImpl) GetPcKm() KilometerMark { +func (t *TurnoutImpl) GetPcKm() *KilometerMark { return t.PcKm }