example repository构建
This commit is contained in:
parent
f66d826418
commit
5d8b8cf1ea
@ -2,32 +2,33 @@ package main
|
||||
|
||||
import (
|
||||
"joylink.club/rtss-core/example/data_proto"
|
||||
modelimpl "joylink.club/rtss-core/example/model_impl"
|
||||
"joylink.club/rtss-core/example/repository"
|
||||
"joylink.club/rtss-core/model"
|
||||
)
|
||||
|
||||
var (
|
||||
_stationMap = make(map[uint32]*data_proto.Station)
|
||||
_sectionMap = make(map[uint32]*data_proto.Section)
|
||||
_turnoutMap = make(map[uint32]*data_proto.Turnout)
|
||||
)
|
||||
|
||||
func main() {
|
||||
repo := repository.NewRepository("test1").(*repository.Repository)
|
||||
rtssGraphicStorage := data_proto.GetLineSytle1()
|
||||
// log.Println(rtssGraphicStorage.Stations)
|
||||
// log.Println(rtssGraphicStorage.Section)
|
||||
// log.Println(rtssGraphicStorage.Turnouts)
|
||||
for _, station := range rtssGraphicStorage.Stations {
|
||||
_stationMap[station.Common.Id] = station
|
||||
repo.StationDataMap[station.Common.Id] = station
|
||||
}
|
||||
for _, section := range rtssGraphicStorage.Section {
|
||||
if section.CentralizedStations == nil || len(section.CentralizedStations) == 0 || _stationMap[section.CentralizedStations[0]] == nil {
|
||||
belongStation := repo.SectionDataMap[section.CentralizedStations[0]]
|
||||
if section.CentralizedStations == nil || len(section.CentralizedStations) == 0 || repo.SectionDataMap[section.CentralizedStations[0]] == nil {
|
||||
continue
|
||||
}
|
||||
_sectionMap[section.Common.Id] = section
|
||||
model.NewSection(getSectionUid(section))
|
||||
repo.SectionDataMap[section.Common.Id] = section
|
||||
uid := getSectionUid(section, belongStation)
|
||||
repo.IpMapping = append(repo.IpMapping, repository.NewIdMapping(section.Common.Id, uid))
|
||||
sectionModel := model.NewSection(uid)
|
||||
repo.SectionMap[uid] = &modelimpl.Section{SectionImpl: sectionModel}
|
||||
}
|
||||
}
|
||||
|
||||
func getSectionUid(section *data_proto.Section) string {
|
||||
return _stationMap[section.CentralizedStations[0]].Code + "-" + section.Code
|
||||
func getSectionUid(section *data_proto.Section, belongStation *data_proto.Section) string {
|
||||
return belongStation.Code + "-" + section.Code
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package modelimpl
|
||||
import "joylink.club/rtss-core/model"
|
||||
|
||||
type Section struct {
|
||||
model.SectionImpl
|
||||
*model.SectionImpl
|
||||
}
|
||||
|
@ -1,24 +1,46 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"joylink.club/rtss-core/example/data_proto"
|
||||
modelimpl "joylink.club/rtss-core/example/model_impl"
|
||||
"joylink.club/rtss-core/model"
|
||||
"joylink.club/rtss-core/repo"
|
||||
)
|
||||
|
||||
// Id映射
|
||||
type IdMapping struct {
|
||||
GraphicId uint32
|
||||
Uid string
|
||||
}
|
||||
|
||||
func NewIdMapping(graphicId uint32, uid string) *IdMapping {
|
||||
return &IdMapping{
|
||||
GraphicId: graphicId,
|
||||
Uid: uid,
|
||||
}
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
id string
|
||||
stationMap map[string]*modelimpl.Station
|
||||
sectionMap map[string]*modelimpl.Section
|
||||
turnoutMap map[string]*modelimpl.Turnout
|
||||
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
|
||||
}
|
||||
|
||||
func NewRepository(id string) repo.Repo {
|
||||
return &Repository{
|
||||
id: id,
|
||||
stationMap: make(map[string]*modelimpl.Station),
|
||||
sectionMap: make(map[string]*modelimpl.Section),
|
||||
turnoutMap: make(map[string]*modelimpl.Turnout),
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,13 +49,13 @@ func (r *Repository) Id() string {
|
||||
}
|
||||
|
||||
func (r *Repository) GetStationByUid(uid string) model.Station {
|
||||
return r.stationMap[uid]
|
||||
return r.StationMap[uid]
|
||||
}
|
||||
|
||||
func (r *Repository) GetSectionByUid(uid string) model.Section {
|
||||
return r.sectionMap[uid]
|
||||
return r.SectionMap[uid]
|
||||
}
|
||||
|
||||
func (r *Repository) GetTurnoutByUid(uid string) model.Turnout {
|
||||
return r.turnoutMap[uid]
|
||||
return r.TurnoutMap[uid]
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ type LinkNode interface {
|
||||
PipeElement
|
||||
}
|
||||
|
||||
var _ Link = (*LinkImpl)(nil)
|
||||
var _ LinkNode = (*LinkNodeImpl)(nil)
|
||||
|
||||
type LinkImpl struct {
|
||||
uid string
|
||||
paLinkNode *PipeLink
|
||||
|
@ -12,7 +12,9 @@ type SectionImpl struct {
|
||||
pbPipeLink *PipeLink
|
||||
}
|
||||
|
||||
func NewSection(uid string) Section {
|
||||
var _ Section = (*SectionImpl)(nil)
|
||||
|
||||
func NewSection(uid string) *SectionImpl {
|
||||
return &SectionImpl{
|
||||
uid: uid,
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ type Station interface {
|
||||
IsCentralized() bool
|
||||
}
|
||||
|
||||
var _ Station = (*StationImpl)(nil)
|
||||
|
||||
type StationImpl struct {
|
||||
uid string
|
||||
centralized bool
|
||||
|
@ -8,6 +8,8 @@ type Turnout interface {
|
||||
PipeElement
|
||||
}
|
||||
|
||||
var _ Turnout = (*TurnoutImpl)(nil)
|
||||
|
||||
type TurnoutImpl struct {
|
||||
uid string
|
||||
paPipeLink *PipeLink
|
||||
@ -15,7 +17,7 @@ type TurnoutImpl struct {
|
||||
pcPipeLink *PipeLink
|
||||
}
|
||||
|
||||
func NewTurnout(uid string) Turnout {
|
||||
func NewTurnout(uid string) *TurnoutImpl {
|
||||
if strings.Trim(uid, " ") == "" {
|
||||
panic("Turnout uid is empty")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user