调整model结构
This commit is contained in:
parent
1ef65d69f4
commit
9505fece91
@ -3,14 +3,24 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"joylink.club/rtsssimulation/repository"
|
||||
"joylink.club/rtsssimulation/repository/model"
|
||||
"joylink.club/rtsssimulation/repository/model/proto"
|
||||
)
|
||||
|
||||
var Repo *repository.Repository
|
||||
|
||||
func main() {
|
||||
link := model.NewLink("1")
|
||||
fmt.Println(link)
|
||||
|
||||
lp := model.NewLinkPort(&link, proto.Port_A)
|
||||
fmt.Println(lp)
|
||||
|
||||
Repo = repository.NewRepository("1" /* id */, "0.1" /* version */)
|
||||
section := model.NewPhysicalSection("s1")
|
||||
fmt.Println(section)
|
||||
Repo.AddPhysicalSection(section)
|
||||
fmt.Println(Repo)
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
// 检测点
|
||||
type CheckPoint struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
km proto.Kilometer
|
||||
t proto.CheckPointType //检测点类型
|
||||
|
@ -3,7 +3,7 @@ package model
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type PortedDevice interface {
|
||||
Model
|
||||
Identity
|
||||
|
||||
// 端口数量
|
||||
PortNum() int
|
||||
|
@ -3,14 +3,16 @@ package model
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type Link struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
aRelation LinkNodePort
|
||||
bRelation LinkNodePort
|
||||
}
|
||||
|
||||
var _ Identity = &Link{}
|
||||
|
||||
func NewLink(id string) Link {
|
||||
return Link{Model: modelInfo{id: id}}
|
||||
return Link{Identity: identity{id: id}}
|
||||
}
|
||||
|
||||
// link位置
|
||||
@ -46,7 +48,7 @@ func NewLinkPort(link *Link, port proto.Port) LinkPort {
|
||||
}
|
||||
}
|
||||
|
||||
func (lp LinkPort) Device() Model {
|
||||
func (lp LinkPort) Device() Identity {
|
||||
return lp.link
|
||||
}
|
||||
|
||||
@ -64,6 +66,6 @@ func NewLinkNodePort(node *LinkNode, port proto.Port) LinkNodePort {
|
||||
}
|
||||
}
|
||||
|
||||
func (lp LinkNodePort) Device() Model {
|
||||
func (lp LinkNodePort) Device() Identity {
|
||||
return lp.node
|
||||
}
|
||||
|
@ -2,31 +2,32 @@ package model
|
||||
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type Model interface {
|
||||
// 身份信息
|
||||
type Identity interface {
|
||||
Id() string
|
||||
}
|
||||
|
||||
// Model 模型公共属性
|
||||
type modelInfo struct {
|
||||
// 身份信息
|
||||
type identity struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func (m modelInfo) Id() string {
|
||||
func (m identity) Id() string {
|
||||
return m.id
|
||||
}
|
||||
|
||||
type Signal struct {
|
||||
Model
|
||||
Identity
|
||||
km proto.Kilometer
|
||||
}
|
||||
type Responder struct {
|
||||
Model
|
||||
Identity
|
||||
}
|
||||
type Slope struct {
|
||||
Model
|
||||
Identity
|
||||
devicePositions []*LinkPosition
|
||||
}
|
||||
|
||||
type Curve struct {
|
||||
Model
|
||||
Identity
|
||||
}
|
||||
|
@ -4,12 +4,34 @@ import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
// 物理区段
|
||||
type PhysicalSection struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
len int32 //长度 mm
|
||||
checkPoints []*CheckPoint //将此区段分隔出来的所有检测点
|
||||
// A/B端关联的设备端
|
||||
aRelation DevicePort
|
||||
bRelation DevicePort
|
||||
|
||||
// A/B/C端口关联的检测点
|
||||
aCheckPoint CheckPoint
|
||||
bCheckPoint CheckPoint
|
||||
|
||||
// 关联的设备
|
||||
devices []Identity
|
||||
}
|
||||
|
||||
func NewPhysicalSection(id string) *PhysicalSection {
|
||||
return &PhysicalSection{
|
||||
Identity: identity{id},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PhysicalSection) ARelation() DevicePort {
|
||||
return s.aRelation
|
||||
}
|
||||
|
||||
func (s *PhysicalSection) BRelation() DevicePort {
|
||||
return s.bRelation
|
||||
}
|
||||
|
||||
type PhysicalSectionPort struct {
|
||||
|
@ -3,12 +3,24 @@ package model
|
||||
import "joylink.club/rtsssimulation/repository/model/proto"
|
||||
|
||||
type Turnout struct {
|
||||
Model
|
||||
Identity
|
||||
|
||||
km proto.Kilometer
|
||||
aRelation DevicePort
|
||||
bRelation DevicePort
|
||||
cRelation DevicePort
|
||||
|
||||
// A/B/C端口关联的设备端口
|
||||
aDevicePort DevicePort
|
||||
bDevicePort DevicePort
|
||||
cDevicePort DevicePort
|
||||
|
||||
// A/B/C端口关联的检测点
|
||||
aCheckPoint CheckPoint
|
||||
bCheckPoint CheckPoint
|
||||
cCheckPoint CheckPoint
|
||||
|
||||
// A/B/C方向关联的设备
|
||||
aDevices []Identity
|
||||
bDevices []Identity
|
||||
cDevices []Identity
|
||||
}
|
||||
|
||||
type TurnoutPort struct {
|
||||
|
@ -5,6 +5,7 @@ import "joylink.club/rtsssimulation/repository/model"
|
||||
type Repository struct {
|
||||
id string
|
||||
version string
|
||||
modelMap map[string]model.Identity
|
||||
physicalSections []*model.PhysicalSection
|
||||
checkPoints []*model.CheckPoint
|
||||
turnouts []*model.Turnout
|
||||
@ -14,6 +15,29 @@ type Repository struct {
|
||||
curves []*model.Curve
|
||||
}
|
||||
|
||||
func NewRepository(id string, version string) *Repository {
|
||||
return &Repository{
|
||||
id: id,
|
||||
version: version,
|
||||
modelMap: make(map[string]model.Identity),
|
||||
physicalSections: make([]*model.PhysicalSection, 0),
|
||||
turnouts: make([]*model.Turnout, 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (repo *Repository) PhysicalSectionList() []*model.PhysicalSection {
|
||||
return repo.physicalSections
|
||||
}
|
||||
|
||||
func (repo *Repository) TurnoutList() []*model.Turnout {
|
||||
return repo.turnouts
|
||||
}
|
||||
|
||||
func (repo *Repository) AddPhysicalSection(section *model.PhysicalSection) {
|
||||
repo.physicalSections = append(repo.physicalSections, section)
|
||||
repo.modelMap[section.Id()] = section
|
||||
}
|
||||
|
||||
// func (r Repository) GetById(id string) (*model.Turnout, error) {
|
||||
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user