80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package repository
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
)
|
|
|
|
// 对数据做基础检查
|
|
func baseCheck(source *proto.Repository) []string {
|
|
var errMsg []string
|
|
uidMap := make(map[string]bool)
|
|
//区段
|
|
for _, section := range source.PhysicalSections {
|
|
if uidMap[section.Id] {
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", section.Id))
|
|
continue
|
|
}
|
|
uidMap[section.Id] = true
|
|
if len(section.TurnoutIds) == 0 && section.ADevicePort == nil && section.BDevicePort == nil {
|
|
errMsg = append(errMsg, fmt.Sprintf("区段[%s]缺少关联的道岔或区段", section.Id))
|
|
}
|
|
}
|
|
//道岔
|
|
for _, turnout := range source.Turnouts {
|
|
if uidMap[turnout.Id] {
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", turnout.Id))
|
|
continue
|
|
}
|
|
uidMap[turnout.Id] = true
|
|
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))
|
|
}
|
|
}
|
|
//检测点
|
|
for _, point := range source.CheckPoints {
|
|
if uidMap[point.Id] {
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", point.Id))
|
|
continue
|
|
}
|
|
uidMap[point.Id] = true
|
|
if point.Km == nil {
|
|
errMsg = append(errMsg, fmt.Sprintf("检测点[%s]缺少公里标", point.Id))
|
|
}
|
|
}
|
|
//信号机
|
|
for _, signal := range source.Signals {
|
|
if uidMap[signal.Id] {
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", signal.Id))
|
|
continue
|
|
}
|
|
uidMap[signal.Id] = true
|
|
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 uidMap[transponder.Id] {
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", transponder.Id))
|
|
continue
|
|
}
|
|
uidMap[transponder.Id] = true
|
|
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
|
|
}
|