rts-sim-module/repository/repository_check.go

58 lines
2.0 KiB
Go

package repository
import (
"fmt"
"joylink.club/rtsssimulation/repository/model/proto"
)
// 对数据做基础检查
func baseCheck(source *proto.Repository) []string {
var errMsg []string
//区段
sectionMap := make(map[string]*proto.PhysicalSection)
for _, section := range source.PhysicalSections {
sectionMap[section.Id] = section
if len(section.TurnoutIds) == 0 && section.ADevicePort == nil && section.BDevicePort == nil {
errMsg = append(errMsg, fmt.Sprintf("区段[%s]缺少关联的道岔或区段", section.Id))
}
}
//道岔
turnoutMap := make(map[string]*proto.Turnout)
for _, turnout := range source.Turnouts {
turnoutMap[turnout.Id] = turnout
if turnout.Km == nil {
errMsg = append(errMsg, fmt.Sprintf("道岔[%s]缺少公里标", turnout.Id))
}
if turnout.ADevicePort == nil || turnout.BDevicePort == nil || turnout.CDevicePort == nil {
errMsg = append(errMsg, fmt.Sprintf("道岔[%s]缺少端口关联数据", turnout.Id))
}
}
//检测点
checkPointMap := make(map[string]*proto.CheckPoint)
for _, point := range source.CheckPoints {
checkPointMap[point.Id] = point
if point.Km == nil {
errMsg = append(errMsg, fmt.Sprintf("检测点[%s]缺少公里标", point.Id))
}
}
//信号机
for _, signal := range source.Signals {
if signal.Km == nil || signal.Km.CoordinateSystem == "" {
errMsg = append(errMsg, fmt.Sprintf("信号机[%s]缺少公里标", signal.Id))
}
if signal.SectionId == "" && signal.TurnoutPort == nil {
errMsg = append(errMsg, fmt.Sprintf("检测点[%s]缺少关联的区段或道岔", signal.Id))
}
}
//应答器
for _, transponder := range source.Transponders {
if transponder.Km == nil || transponder.Km.CoordinateSystem == "" {
errMsg = append(errMsg, fmt.Sprintf("应答器[%s]缺少公里标", transponder.Id))
}
if transponder.SectionId == "" && transponder.TurnoutPort == nil {
errMsg = append(errMsg, fmt.Sprintf("应答器[%s]缺少关联的区段或道岔", transponder.Id))
}
}
return errMsg
}