【修改地图数据缓存结构】【数据版本处理】
This commit is contained in:
parent
bd9542fd8d
commit
e0085c4513
@ -62,7 +62,7 @@ func (ms *IbpMs) collectStationIbpState(station *graphicData.Station) (*state.Pu
|
|||||||
}
|
}
|
||||||
sid := memory.GetMapElementId(station.Common)
|
sid := memory.GetMapElementId(station.Common)
|
||||||
stationUid := memory.QueryUidByMidAndComId(ms.mapId, sid, &graphicData.Station{})
|
stationUid := memory.QueryUidByMidAndComId(ms.mapId, sid, &graphicData.Station{})
|
||||||
ibpMapId, ibpStorage := memory.GetStorageIBPMapData(station.RefIbpMapCode)
|
ibpMapId, ibpStorage := memory.QueryGiDataByName[*graphicData.IBPGraphicStorage](station.RefIbpMapCode)
|
||||||
ibpUidsMap := memory.QueryUidStructure[*memory.IBPUidStructure](ibpMapId)
|
ibpUidsMap := memory.QueryUidStructure[*memory.IBPUidStructure](ibpMapId)
|
||||||
buttonStates, err := ms.collectIBPButtonState(stationUid, ibpUidsMap, ibpStorage.IbpButtons)
|
buttonStates, err := ms.collectIBPButtonState(stationUid, ibpUidsMap, ibpStorage.IbpButtons)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -72,8 +72,7 @@ func (p *PslMs) collectGateBoxPSLState(box *graphicData.GatedBox) (*state.Pushed
|
|||||||
mkx := component.MkxType.Get(mkxEntry)
|
mkx := component.MkxType.Get(mkxEntry)
|
||||||
var buttonStateArr []*state.ButtonState
|
var buttonStateArr []*state.ButtonState
|
||||||
if ok {
|
if ok {
|
||||||
pslMapId := memory.QueryGiId(box.RefGatedBoxMapCode)
|
_, pslStorage := memory.QueryGiDataByName[*graphicData.PslGraphicStorage](box.RefGatedBoxMapCode)
|
||||||
pslStorage := memory.QueryGiData[*graphicData.PslGraphicStorage](pslMapId)
|
|
||||||
btnUidMap := make(map[string]uint32, len(pslStorage.PslButtons))
|
btnUidMap := make(map[string]uint32, len(pslStorage.PslButtons))
|
||||||
for _, button := range pslStorage.PslButtons {
|
for _, button := range pslStorage.PslButtons {
|
||||||
btnUidMap[boxUid+"_"+button.Code] = memory.GetMapElementId(button.Common)
|
btnUidMap[boxUid+"_"+button.Code] = memory.GetMapElementId(button.Common)
|
||||||
|
@ -62,7 +62,7 @@ func ListQueryPublished(req *dto.PublishedListReqDto) []*dto.PublishedDto {
|
|||||||
// 项目启动时查询发布地图信息
|
// 项目启动时查询发布地图信息
|
||||||
func ListAllPublished() []*dto.PublishedDto {
|
func ListAllPublished() []*dto.PublishedDto {
|
||||||
p, pv := dbquery.Published, dbquery.PublishedVersion
|
p, pv := dbquery.Published, dbquery.PublishedVersion
|
||||||
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, pv.Proto).
|
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, pv.Proto, pv.Version).
|
||||||
LeftJoin(pv, p.DataID.EqCol(pv.ID)).
|
LeftJoin(pv, p.DataID.EqCol(pv.ID)).
|
||||||
Where(p.Status.Eq(1), p.Type.Neq(trainDataType)).Order(pv.PublishAt)
|
Where(p.Status.Eq(1), p.Type.Neq(trainDataType)).Order(pv.PublishAt)
|
||||||
var records []*dto.PublishedDto
|
var records []*dto.PublishedDto
|
||||||
@ -76,7 +76,7 @@ func ListAllPublished() []*dto.PublishedDto {
|
|||||||
// 查询详细信息
|
// 查询详细信息
|
||||||
func GetPublishedById(id int32) *dto.PublishedDto {
|
func GetPublishedById(id int32) *dto.PublishedDto {
|
||||||
p, pv := dbquery.Published, dbquery.PublishedVersion
|
p, pv := dbquery.Published, dbquery.PublishedVersion
|
||||||
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, pv.Proto).
|
where := p.Select(p.ID, p.Code.As("name"), p.Type, p.Category, pv.Proto, pv.Version).
|
||||||
LeftJoin(pv, p.DataID.EqCol(pv.ID)).
|
LeftJoin(pv, p.DataID.EqCol(pv.ID)).
|
||||||
Where(p.ID.Eq(id), p.Status.Eq(1))
|
Where(p.ID.Eq(id), p.Status.Eq(1))
|
||||||
var record dto.PublishedDto
|
var record dto.PublishedDto
|
||||||
|
@ -54,5 +54,6 @@ func getIbpUidByMapIdAndStationId(mapId int32, stationId uint32) (*IBPUidStructu
|
|||||||
if station.RefIbpMapCode == "" {
|
if station.RefIbpMapCode == "" {
|
||||||
return nil, fmt.Errorf("车站【%s】未关联IBP地图", station.StationName)
|
return nil, fmt.Errorf("车站【%s】未关联IBP地图", station.StationName)
|
||||||
}
|
}
|
||||||
return QueryUidStructure[*IBPUidStructure](QueryGiId(station.RefIbpMapCode)), nil
|
ibpMapId, _ := QueryGiDataByName[*graphicData.IBPGraphicStorage](station.RefIbpMapCode)
|
||||||
|
return QueryUidStructure[*IBPUidStructure](ibpMapId), nil
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,17 @@ import (
|
|||||||
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
|
"joylink.club/bj-rtsts-server/ts/protos/graphicData"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var giPublishData sync.Map
|
||||||
giTypeMap sync.Map
|
|
||||||
giNameMap sync.Map
|
type giStoreData struct {
|
||||||
giDataMap sync.Map
|
name string
|
||||||
)
|
giType graphicData.PictureType
|
||||||
|
message proto.Message
|
||||||
|
version int32
|
||||||
|
}
|
||||||
|
|
||||||
// 将发布的地图数据放入内存中
|
// 将发布的地图数据放入内存中
|
||||||
func PublishMapVerifyStructure(graphic *dto.PublishedDto) {
|
func PublishMapVerifyStructure(graphic *dto.PublishedDto) {
|
||||||
giTypeMap.Store(graphic.ID, graphicData.PictureType(graphic.Type))
|
|
||||||
giNameMap.Store(graphic.Name, graphic.ID)
|
|
||||||
var message proto.Message
|
var message proto.Message
|
||||||
switch graphicData.PictureType(graphic.Type) {
|
switch graphicData.PictureType(graphic.Type) {
|
||||||
case graphicData.PictureType_StationLayout:
|
case graphicData.PictureType_StationLayout:
|
||||||
@ -43,13 +44,18 @@ func PublishMapVerifyStructure(graphic *dto.PublishedDto) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(&dto.ErrorDto{Code: dto.LogicError, Message: fmt.Sprintf("[id:%d]proto数据反序列化失败:%s", graphic.ID, err)})
|
panic(&dto.ErrorDto{Code: dto.LogicError, Message: fmt.Sprintf("[id:%d]proto数据反序列化失败:%s", graphic.ID, err)})
|
||||||
}
|
}
|
||||||
giDataMap.Store(graphic.ID, message)
|
// 缓存数据
|
||||||
|
giPublishData.Store(graphic.ID, &giStoreData{
|
||||||
|
name: graphic.Name,
|
||||||
|
giType: graphicData.PictureType(graphic.Type),
|
||||||
|
message: message,
|
||||||
|
version: graphic.Version,
|
||||||
|
})
|
||||||
// 初始化地图结构
|
// 初始化地图结构
|
||||||
switch graphicData.PictureType(graphic.Type) {
|
switch graphicData.PictureType(graphic.Type) {
|
||||||
case graphicData.PictureType_StationLayout:
|
case graphicData.PictureType_StationLayout:
|
||||||
graphicStorage := message.(*graphicData.RtssGraphicStorage)
|
graphicStorage := message.(*graphicData.RtssGraphicStorage)
|
||||||
// 处理掉其他线路的设备
|
filterOtherLineDevice(graphicStorage) // 处理掉其他线路的设备
|
||||||
filterOtherLineDevice(graphicStorage)
|
|
||||||
giUidMap.Store(graphic.ID, initStationUid(graphicStorage))
|
giUidMap.Store(graphic.ID, initStationUid(graphicStorage))
|
||||||
case graphicData.PictureType_RelayCabinetLayout:
|
case graphicData.PictureType_RelayCabinetLayout:
|
||||||
graphicStorage := message.(*graphicData.RelayCabinetGraphicStorage)
|
graphicStorage := message.(*graphicData.RelayCabinetGraphicStorage)
|
||||||
@ -71,57 +77,67 @@ func GenerateElementUid(city, lineId string, stationIndexList []string, code str
|
|||||||
|
|
||||||
// 移除内存中的地图信息
|
// 移除内存中的地图信息
|
||||||
func DeleteMapVerifyStructure(mapId int32) {
|
func DeleteMapVerifyStructure(mapId int32) {
|
||||||
giTypeMap.Delete(mapId)
|
giPublishData.Delete(mapId)
|
||||||
giDataMap.Delete(mapId)
|
|
||||||
giUidMap.Delete(mapId)
|
giUidMap.Delete(mapId)
|
||||||
var name string
|
|
||||||
giNameMap.Range(func(key, value any) bool {
|
|
||||||
id := value.(int32)
|
|
||||||
if id == mapId {
|
|
||||||
name = key.(string)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
if name != "" {
|
|
||||||
giNameMap.Delete(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取地图类型
|
||||||
func QueryGiType(mapId int32) graphicData.PictureType {
|
func QueryGiType(mapId int32) graphicData.PictureType {
|
||||||
value, ok := giTypeMap.Load(mapId)
|
value, ok := giPublishData.Load(mapId)
|
||||||
if !ok {
|
if !ok {
|
||||||
graphic := service.GetPublishedById(mapId)
|
graphic := service.GetPublishedById(mapId)
|
||||||
PublishMapVerifyStructure(graphic)
|
PublishMapVerifyStructure(graphic)
|
||||||
return graphicData.PictureType(graphic.Type)
|
return graphicData.PictureType(graphic.Type)
|
||||||
}
|
}
|
||||||
return value.(graphicData.PictureType)
|
d, ok := value.(*giStoreData)
|
||||||
|
if !ok {
|
||||||
|
panic(sys_error.New(fmt.Sprintf("地图【%d】缓存数据结构错误", mapId)))
|
||||||
|
}
|
||||||
|
return d.giType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取地图版本
|
||||||
|
func QueryGiVersion(mapId int32) int32 {
|
||||||
|
value, ok := giPublishData.Load(mapId)
|
||||||
|
if !ok {
|
||||||
|
panic(sys_error.New(fmt.Sprintf("地图【%d】缓存数据丢失", mapId)))
|
||||||
|
}
|
||||||
|
d, ok := value.(*giStoreData)
|
||||||
|
if !ok {
|
||||||
|
panic(sys_error.New(fmt.Sprintf("地图【%d】缓存数据结构错误", mapId)))
|
||||||
|
}
|
||||||
|
return d.version
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据地图ID获取地图数据
|
||||||
func QueryGiData[T proto.Message](mapId int32) T {
|
func QueryGiData[T proto.Message](mapId int32) T {
|
||||||
value, _ := giDataMap.Load(mapId)
|
value, ok := giPublishData.Load(mapId)
|
||||||
return value.(T)
|
if !ok {
|
||||||
|
panic(sys_error.New(fmt.Sprintf("地图【%d】缓存数据丢失", mapId)))
|
||||||
|
}
|
||||||
|
d, ok := value.(*giStoreData)
|
||||||
|
if !ok {
|
||||||
|
panic(sys_error.New(fmt.Sprintf("地图【%d】缓存数据结构错误", mapId)))
|
||||||
|
}
|
||||||
|
return d.message.(T)
|
||||||
}
|
}
|
||||||
|
|
||||||
func QueryGiId(name string) int32 {
|
// 根据地图名称获取地图数据
|
||||||
value, _ := giNameMap.Load(name)
|
func QueryGiDataByName[T proto.Message](name string) (int32, T) {
|
||||||
return value.(int32)
|
var (
|
||||||
}
|
id int32
|
||||||
|
giData T
|
||||||
func GetStorageIBPMapData(mapCode string) (int32, *graphicData.IBPGraphicStorage) {
|
)
|
||||||
// 处理关联的IBP盘信息
|
giPublishData.Range(func(key, value any) bool {
|
||||||
if mapCode == "" {
|
d, _ := value.(*giStoreData)
|
||||||
return 0, nil
|
if d.name == name {
|
||||||
}
|
id = key.(int32)
|
||||||
ibpId, ok := giNameMap.Load(mapCode)
|
giData = d.message.(T)
|
||||||
if !ok {
|
return false
|
||||||
return 0, nil
|
}
|
||||||
}
|
return true
|
||||||
ibpMapData, ok := giDataMap.Load(ibpId)
|
})
|
||||||
if !ok {
|
return id, giData
|
||||||
return ibpId.(int32), nil
|
|
||||||
}
|
|
||||||
return ibpId.(int32), ibpMapData.(*graphicData.IBPGraphicStorage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换成统一坐标公里标
|
// 转换成统一坐标公里标
|
||||||
|
@ -515,11 +515,13 @@ func (s *VerifySimulation) EvnWorld() ecs.World {
|
|||||||
func (s *VerifySimulation) initRepository() error {
|
func (s *VerifySimulation) initRepository() error {
|
||||||
// 构建Repository
|
// 构建Repository
|
||||||
var mapIdStrSlice []string
|
var mapIdStrSlice []string
|
||||||
|
var mapVersion []string
|
||||||
for _, id := range s.MapIds {
|
for _, id := range s.MapIds {
|
||||||
mapIdStrSlice = append(mapIdStrSlice, strconv.Itoa(int(id)))
|
mapIdStrSlice = append(mapIdStrSlice, strconv.Itoa(int(id)))
|
||||||
|
mapVersion = append(mapVersion, strconv.Itoa(int(QueryGiVersion(id))))
|
||||||
}
|
}
|
||||||
repoId := strings.Join(mapIdStrSlice, "|")
|
repoId := strings.Join(mapIdStrSlice, "|")
|
||||||
repoVersion := "0.1"
|
repoVersion := strings.Join(mapVersion, ".")
|
||||||
repo := repository.FindRepository(repoId, repoVersion)
|
repo := repository.FindRepository(repoId, repoVersion)
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
protoRepo, err := buildProtoRepository(s.MapIds)
|
protoRepo, err := buildProtoRepository(s.MapIds)
|
||||||
@ -1150,8 +1152,7 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi
|
|||||||
PsdId: uidsMap.PsdIds[data.RefScreenDoor].Uid,
|
PsdId: uidsMap.PsdIds[data.RefScreenDoor].Uid,
|
||||||
}
|
}
|
||||||
repo.Mkxs = append(repo.Mkxs, mkx)
|
repo.Mkxs = append(repo.Mkxs, mkx)
|
||||||
pslMapId := QueryGiId(data.RefGatedBoxMapCode)
|
_, pslStorage := QueryGiDataByName[*graphicData.PslGraphicStorage](data.RefGatedBoxMapCode)
|
||||||
pslStorage := QueryGiData[*graphicData.PslGraphicStorage](pslMapId)
|
|
||||||
for _, button := range pslStorage.PslButtons {
|
for _, button := range pslStorage.PslButtons {
|
||||||
repoButton := &proto.Button{
|
repoButton := &proto.Button{
|
||||||
Id: boxUidInfo.Uid + "_" + button.Code,
|
Id: boxUidInfo.Uid + "_" + button.Code,
|
||||||
@ -1205,7 +1206,7 @@ func fillProtoRepository(repo *proto.Repository, storage *graphicData.RtssGraphi
|
|||||||
|
|
||||||
// 将IBP的设备关联到车站中
|
// 将IBP的设备关联到车站中
|
||||||
func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, ibpMapCode string) {
|
func handlerIBPDeviceToStation(station *proto.Station, repo *proto.Repository, ibpMapCode string) {
|
||||||
mapId, storage := GetStorageIBPMapData(ibpMapCode)
|
mapId, storage := QueryGiDataByName[*graphicData.IBPGraphicStorage](ibpMapCode)
|
||||||
if storage == nil {
|
if storage == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user