2023-09-21 16:28:13 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-12-05 13:54:49 +08:00
|
|
|
|
2023-09-21 16:28:13 +08:00
|
|
|
"joylink.club/rtsssimulation/repository/model/proto"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 对数据做基础检查
|
|
|
|
func baseCheck(source *proto.Repository) []string {
|
|
|
|
var errMsg []string
|
2024-01-29 14:42:09 +08:00
|
|
|
uidMap := make(map[string]bool)
|
2023-09-21 16:28:13 +08:00
|
|
|
//区段
|
|
|
|
for _, section := range source.PhysicalSections {
|
2024-01-29 14:42:09 +08:00
|
|
|
if uidMap[section.Id] {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", section.Id))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uidMap[section.Id] = true
|
2023-09-21 16:28:13 +08:00
|
|
|
if len(section.TurnoutIds) == 0 && section.ADevicePort == nil && section.BDevicePort == nil {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("区段[%s]缺少关联的道岔或区段", section.Id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//道岔
|
|
|
|
for _, turnout := range source.Turnouts {
|
2024-01-29 14:42:09 +08:00
|
|
|
if uidMap[turnout.Id] {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", turnout.Id))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uidMap[turnout.Id] = true
|
2023-09-21 16:28:13 +08:00
|
|
|
if turnout.Km == nil {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("道岔[%s]缺少公里标", turnout.Id))
|
|
|
|
}
|
2023-12-05 13:54:49 +08:00
|
|
|
// 如果缺少所有关联设备则报错
|
|
|
|
if turnout.ADevicePort == nil && turnout.BDevicePort == nil && turnout.CDevicePort == nil {
|
2023-09-21 16:28:13 +08:00
|
|
|
errMsg = append(errMsg, fmt.Sprintf("道岔[%s]缺少端口关联数据", turnout.Id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//检测点
|
|
|
|
for _, point := range source.CheckPoints {
|
2024-01-29 14:42:09 +08:00
|
|
|
if uidMap[point.Id] {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", point.Id))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uidMap[point.Id] = true
|
2023-09-21 16:28:13 +08:00
|
|
|
if point.Km == nil {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("检测点[%s]缺少公里标", point.Id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//信号机
|
|
|
|
for _, signal := range source.Signals {
|
2024-01-29 14:42:09 +08:00
|
|
|
if uidMap[signal.Id] {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", signal.Id))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uidMap[signal.Id] = true
|
2023-09-25 14:38:13 +08:00
|
|
|
if signal.Km == nil || signal.Km.CoordinateSystem == "" {
|
2023-09-21 16:28:13 +08:00
|
|
|
errMsg = append(errMsg, fmt.Sprintf("信号机[%s]缺少公里标", signal.Id))
|
|
|
|
}
|
|
|
|
if signal.SectionId == "" && signal.TurnoutPort == nil {
|
2023-12-07 14:44:31 +08:00
|
|
|
errMsg = append(errMsg, fmt.Sprintf("信号机[%s]缺少关联的区段或道岔", signal.Id))
|
2023-09-21 16:28:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//应答器
|
|
|
|
for _, transponder := range source.Transponders {
|
2024-01-29 14:42:09 +08:00
|
|
|
if uidMap[transponder.Id] {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("uid[%s]重复", transponder.Id))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
uidMap[transponder.Id] = true
|
2023-09-25 14:38:13 +08:00
|
|
|
if transponder.Km == nil || transponder.Km.CoordinateSystem == "" {
|
2023-09-21 16:28:13 +08:00
|
|
|
errMsg = append(errMsg, fmt.Sprintf("应答器[%s]缺少公里标", transponder.Id))
|
|
|
|
}
|
|
|
|
if transponder.SectionId == "" && transponder.TurnoutPort == nil {
|
|
|
|
errMsg = append(errMsg, fmt.Sprintf("应答器[%s]缺少关联的区段或道岔", transponder.Id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errMsg
|
|
|
|
}
|