rtss-core/example/repository/repo.go

62 lines
1.5 KiB
Go
Raw Normal View History

2024-06-19 19:29:46 +08:00
package repository
import (
2024-06-24 18:20:11 +08:00
"joylink.club/rtss-core/example/data_proto"
2024-06-19 19:29:46 +08:00
modelimpl "joylink.club/rtss-core/example/model_impl"
"joylink.club/rtss-core/model"
"joylink.club/rtss-core/repo"
)
2024-06-24 18:20:11 +08:00
// Id映射
type IdMapping struct {
GraphicId uint32
Uid string
}
func NewIdMapping(graphicId uint32, uid string) *IdMapping {
return &IdMapping{
GraphicId: graphicId,
Uid: uid,
}
}
2024-06-19 19:29:46 +08:00
type Repository struct {
2024-06-24 18:20:11 +08:00
id string
StationDataMap map[uint32]*data_proto.Station
SectionDataMap map[uint32]*data_proto.Section
TurnoutDataMap map[uint32]*data_proto.Turnout
IpMapping []*IdMapping
StationMap map[string]*modelimpl.Station
SectionMap map[string]*modelimpl.Section
TurnoutMap map[string]*modelimpl.Turnout
2024-06-19 19:29:46 +08:00
}
func NewRepository(id string) repo.Repo {
return &Repository{
2024-06-24 18:20:11 +08:00
id: id,
StationDataMap: make(map[uint32]*data_proto.Station),
SectionDataMap: make(map[uint32]*data_proto.Section),
TurnoutDataMap: make(map[uint32]*data_proto.Turnout),
IpMapping: make([]*IdMapping, 0),
StationMap: make(map[string]*modelimpl.Station),
SectionMap: make(map[string]*modelimpl.Section),
TurnoutMap: make(map[string]*modelimpl.Turnout),
2024-06-19 19:29:46 +08:00
}
}
func (r *Repository) Id() string {
return r.id
}
func (r *Repository) GetStationByUid(uid string) model.Station {
2024-06-24 18:20:11 +08:00
return r.StationMap[uid]
2024-06-19 19:29:46 +08:00
}
func (r *Repository) GetSectionByUid(uid string) model.Section {
2024-06-24 18:20:11 +08:00
return r.SectionMap[uid]
2024-06-19 19:29:46 +08:00
}
func (r *Repository) GetTurnoutByUid(uid string) model.Turnout {
2024-06-24 18:20:11 +08:00
return r.TurnoutMap[uid]
2024-06-19 19:29:46 +08:00
}