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