【仿真消息处理逻辑】
This commit is contained in:
parent
399daa147f
commit
bf2118e10e
|
@ -34,7 +34,7 @@ func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
|||
// 初始化地图信息
|
||||
initPublishMapInfo()
|
||||
apiproto.RegisterMsgServer(&apiproto.SimulationServer{})
|
||||
apiproto.RegisterMsgServer(&apiproto.MemoryChangeServer{})
|
||||
apiproto.RegisterMsgServer(&apiproto.MemoryChangeServer{SimulationMap: make(map[string]*state.SimulationStatus)})
|
||||
}
|
||||
|
||||
func initPublishMapInfo() {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
type MemoryChangeServer struct {
|
||||
simulationMap map[string]*state.SimulationStatus
|
||||
SimulationMap map[string]*state.SimulationStatus
|
||||
}
|
||||
|
||||
// 返回通道格式
|
||||
|
@ -25,9 +25,9 @@ func (t *MemoryChangeServer) getInterval() time.Duration {
|
|||
|
||||
// 返回所有数据
|
||||
func (t *MemoryChangeServer) allMsgData(params map[string]string) []byte {
|
||||
arr := make([]*state.SimulationStatus, len(t.simulationMap))
|
||||
arr := make([]*state.SimulationStatus, len(t.SimulationMap))
|
||||
i := 0
|
||||
for _, v := range t.simulationMap {
|
||||
for _, v := range t.SimulationMap {
|
||||
arr[i] = v
|
||||
i++
|
||||
}
|
||||
|
@ -47,18 +47,24 @@ func (t *MemoryChangeServer) onTick() []TopicMsg {
|
|||
allSim := make(map[string]bool)
|
||||
for _, v := range simArr {
|
||||
allSim[v.SimulationId] = true
|
||||
if t.simulationMap[v.SimulationId] == nil {
|
||||
if t.SimulationMap[v.SimulationId] == nil {
|
||||
status := &state.SimulationStatus{SimulationId: v.SimulationId, MapId: v.MapId, ProjectId: v.ProjectId}
|
||||
t.simulationMap[v.SimulationId] = status
|
||||
t.SimulationMap[v.SimulationId] = status
|
||||
addArr = append(addArr, status)
|
||||
}
|
||||
}
|
||||
// 已经移除的仿真
|
||||
for k, v := range t.simulationMap {
|
||||
for k, v := range t.SimulationMap {
|
||||
if !allSim[k] {
|
||||
delArr = append(delArr, v)
|
||||
}
|
||||
}
|
||||
// 删除已替换仿真主键
|
||||
if len(delArr) > 0 {
|
||||
for _, v := range delArr {
|
||||
delete(t.SimulationMap, v.SimulationId)
|
||||
}
|
||||
}
|
||||
if len(addArr) == 0 && len(delArr) == 0 {
|
||||
return []TopicMsg{}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue