调整repo包名

This commit is contained in:
walker 2023-12-27 15:59:46 +08:00
parent 3b4a017b3d
commit 7b80d6e736
18 changed files with 94 additions and 105 deletions

View File

@ -6,7 +6,7 @@ import (
"strconv"
"strings"
"joylink.club/rtsssimulation/repo/dto"
"joylink.club/rtsssimulation/cgrepo/dto"
)
// 城轨uid

33
cgrepo/manage.go Normal file
View File

@ -0,0 +1,33 @@
package repo
// type repoManager struct {
// repoMap map[string]CgRepo
// lock sync.Mutex
// }
// var defaultManager = &repoManager{
// repoMap: make(map[string]CgRepo),
// }
// // 获取或构建模型仓库
// func GetOrBuildRepo(id string, dc func(errRecord *ErrorRecord) *dto.CgRepo) (CgRepo, *ErrorRecord) {
// manager := defaultManager
// manager.lock.Lock()
// defer manager.lock.Unlock()
// r, ok := manager.repoMap[id]
// errRecord := NewErrorRecord()
// if !ok {
// // 所需protobuf数据转换
// msgs := dc(errRecord)
// // 数据转换出错直接返回
// if errRecord.HasError() {
// return nil, errRecord
// }
// // 构建模型Repo
// r, errRecord = BuildFrom(msgs)
// if r != nil {
// manager.repoMap[id] = r
// }
// }
// return r, errRecord
// }

View File

@ -4,8 +4,8 @@ import (
"fmt"
"sync/atomic"
"joylink.club/rtsssimulation/repo/dto"
"joylink.club/rtsssimulation/repo/model"
"joylink.club/rtsssimulation/cgrepo/dto"
"joylink.club/rtsssimulation/cgrepo/model"
)
// link生成uid基础值

View File

@ -1,7 +1,7 @@
package impl
import (
"joylink.club/rtsssimulation/repo/model"
"joylink.club/rtsssimulation/cgrepo/model"
)
type PhysicalSection struct {

View File

@ -1,6 +1,6 @@
package impl
import "joylink.club/rtsssimulation/repo/model"
import "joylink.club/rtsssimulation/cgrepo/model"
type Turnout struct {
uid string

56
cgrepo/repo.go Normal file
View File

@ -0,0 +1,56 @@
package repo
import "joylink.club/rtsssimulation/cgrepo/model"
type CgRepo interface {
// 模型仓库id
Id() string
// 获取所有道岔
Turnouts() []model.Turnout
// 通过uid查询模型对象
FindByUid(uid string) model.Model
}
type IdMap interface {
// 获取数据元素id
DeId() string
// 获取uid
Uid() string
}
// type repo struct {
// id string
// idMapping *IdMapping // id映射
// modelMap map[string]model.Model // 模型map,key为uid
// linkMap map[string]*impl.Link // 链路map,key为uid
// physicalSectionMap map[string]*impl.PhysicalSection // 物理区段map,key为uid
// turnoutMap map[string]*impl.Turnout // 道岔map,key为uid
// }
// func BuildFrom(msgs *dto.CgRepo) (CgRepo, *ErrorRecord) {
// errRecord := NewErrorRecord()
// idMapping := BuildIdMapping(msgs, errRecord)
// if errRecord.HasError() {
// return nil, errRecord
// }
// repo := &repo{
// id: msgs.Id,
// idMapping: idMapping,
// modelMap: make(map[string]model.Model, 1024),
// linkMap: make(map[string]*impl.Link, 256),
// physicalSectionMap: make(map[string]*impl.PhysicalSection, 256),
// turnoutMap: make(map[string]*impl.Turnout, 128),
// }
// return repo, errRecord
// }
// // 模型仓库id
// func (r *repo) Id() string {
// return r.id
// }
// // 通过uid查询模型对象
// func (r *repo) FindByUid(uid string) model.Model {
// return nil
// }

View File

@ -1,17 +0,0 @@
package repo
import "joylink.club/rtsssimulation/repo/model"
type CgRepo interface {
// 模型仓库id
Id() string
// 通过uid查询模型对象
FindByUid(uid string) model.Model
}
type IdMap interface {
// 获取数据元素id
DeId() string
// 获取uid
Uid() string
}

View File

@ -1,39 +0,0 @@
package repo
import (
"sync"
"joylink.club/rtsssimulation/repo/dto"
)
type repoManager struct {
repoMap map[string]CgRepo
lock sync.Mutex
}
var defaultManager = &repoManager{
repoMap: make(map[string]CgRepo),
}
// 获取或构建模型仓库
func GetOrBuildRepo(id string, dc func(errRecord *ErrorRecord) *dto.CgRepo) (CgRepo, *ErrorRecord) {
manager := defaultManager
manager.lock.Lock()
defer manager.lock.Unlock()
r, ok := manager.repoMap[id]
errRecord := NewErrorRecord()
if !ok {
// 所需protobuf数据转换
msgs := dc(errRecord)
// 数据转换出错直接返回
if errRecord.HasError() {
return nil, errRecord
}
// 构建模型Repo
r, errRecord = BuildFrom(msgs)
if r != nil {
manager.repoMap[id] = r
}
}
return r, errRecord
}

View File

@ -1,44 +0,0 @@
package repo
import (
"joylink.club/rtsssimulation/repo/dto"
"joylink.club/rtsssimulation/repo/model"
"joylink.club/rtsssimulation/repo/model/impl"
)
type repo struct {
id string
idMapping *IdMapping // id映射
modelMap map[string]model.Model // 模型map,key为uid
linkMap map[string]*impl.Link // 链路map,key为uid
physicalSectionMap map[string]*impl.PhysicalSection // 物理区段map,key为uid
turnoutMap map[string]*impl.Turnout // 道岔map,key为uid
}
func BuildFrom(msgs *dto.CgRepo) (CgRepo, *ErrorRecord) {
errRecord := NewErrorRecord()
idMapping := BuildIdMapping(msgs, errRecord)
if errRecord.HasError() {
return nil, errRecord
}
repo := &repo{
id: msgs.Id,
idMapping: idMapping,
modelMap: make(map[string]model.Model, 1024),
linkMap: make(map[string]*impl.Link, 256),
physicalSectionMap: make(map[string]*impl.PhysicalSection, 256),
turnoutMap: make(map[string]*impl.Turnout, 128),
}
return repo, errRecord
}
// 模型仓库id
func (r *repo) Id() string {
return r.id
}
// 通过uid查询模型对象
func (r *repo) FindByUid(uid string) model.Model {
return nil
}