2023-07-31 08:41:42 +08:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2023-08-01 14:54:11 +08:00
|
|
|
"sync"
|
2023-07-31 08:41:42 +08:00
|
|
|
|
2023-08-01 14:54:11 +08:00
|
|
|
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
|
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
2023-07-31 08:41:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// 仿真存储集合
|
2023-08-01 14:54:11 +08:00
|
|
|
var simulationMap sync.Map
|
2023-07-31 08:41:42 +08:00
|
|
|
|
|
|
|
// 创建仿真对象
|
2023-08-01 14:54:11 +08:00
|
|
|
func CreateSimulation(mapId int32) string {
|
2023-07-31 08:41:42 +08:00
|
|
|
simulationId := createSimulationId(mapId)
|
2023-08-01 14:54:11 +08:00
|
|
|
_, e := simulationMap.Load(simulationId)
|
|
|
|
if !e {
|
|
|
|
verifySimulation := memory.CreateSimulation(mapId, simulationId)
|
|
|
|
simulationMap.Store(simulationId, verifySimulation)
|
2023-07-31 08:41:42 +08:00
|
|
|
}
|
|
|
|
return simulationId
|
|
|
|
}
|
|
|
|
|
|
|
|
// 删除仿真对象
|
|
|
|
func DestroySimulation(simulationId string) {
|
2023-08-01 14:54:11 +08:00
|
|
|
simulationMap.Delete(simulationId)
|
2023-07-31 08:41:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 创建时生成仿真Id
|
2023-08-01 14:54:11 +08:00
|
|
|
func createSimulationId(mapId int32) string {
|
|
|
|
return strconv.Itoa(int(mapId))
|
2023-07-31 08:41:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 获取仿真列表
|
2023-08-01 14:54:11 +08:00
|
|
|
func ListAllSimulations() []*dto.SimulationInfoRepDto {
|
|
|
|
simArr := []*dto.SimulationInfoRepDto{}
|
|
|
|
simulationMap.Range(func(k, v any) bool {
|
|
|
|
s := v.(*memory.VerifySimulation)
|
|
|
|
simArr = append(simArr, &dto.SimulationInfoRepDto{
|
|
|
|
SimulationId: s.SimulationId,
|
|
|
|
MapId: strconv.Itoa(int(s.MapId)),
|
|
|
|
})
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
return simArr
|
2023-07-31 08:41:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 根据仿真id查找仿真实例
|
2023-08-01 14:54:11 +08:00
|
|
|
func FindSimulation(simulationId string) *memory.VerifySimulation {
|
|
|
|
m, e := simulationMap.Load(simulationId)
|
|
|
|
if e {
|
|
|
|
return m.(*memory.VerifySimulation)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取普通仿真数组
|
|
|
|
func GetSimulationArr() []*memory.VerifySimulation {
|
|
|
|
result := []*memory.VerifySimulation{}
|
|
|
|
simulationMap.Range(func(k, v any) bool {
|
|
|
|
result = append(result, v.(*memory.VerifySimulation))
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
return result
|
2023-07-31 08:41:42 +08:00
|
|
|
}
|