考虑repo只提供抽象接口,具体实现由应用层实现

This commit is contained in:
walker 2023-12-27 15:51:28 +08:00
parent 75723b31e6
commit 1e71d51feb
10 changed files with 232 additions and 64 deletions

View File

@ -463,9 +463,9 @@ message Lamp {
//
message DeviceEcc {
//
//
Model.Type deviceType = 1;
//
//
string deviceCode = 2;
//
repeated Ecc ecc = 3;

View File

@ -7,7 +7,6 @@ import (
"strings"
"joylink.club/rtsssimulation/repo/dto"
"joylink.club/rtsssimulation/repo/model"
)
// 城轨uid
@ -58,10 +57,10 @@ type idMap struct {
// 元素id
Eid uint32
// 唯一id
Uid model.Uid
Uid *CgUid
}
func NewIdMap(did string, eid uint32, uid model.Uid) *idMap {
func NewIdMap(did string, eid uint32, uid *CgUid) *idMap {
return &idMap{
Did: did,
Eid: eid,

View File

@ -1,57 +0,0 @@
package model
type ModelType string
const (
// 车站
MT_Station ModelType = "Station"
// 站台
MT_Stand ModelType = "Stand"
// 屏蔽门
MT_PSD ModelType = "PSD"
// Link
MT_Link ModelType = "Link"
// 区段
MT_Section ModelType = "Section"
// 道岔
MT_Turnout ModelType = "Turnout"
// 信号机
MT_Signal ModelType = "Signal"
// 应答器
MT_Balise ModelType = "Balise"
)
type Uid interface {
Id() string
// 设备原始编号
Code() string
}
// 模型接口
type Model interface {
// Unique id,唯一id
Uid() Uid
// 模型类型
Type() ModelType
}
// Link
type Link interface {
Model
}
// 物理区段(实际检测区段,一般区段两端点,道岔区段为3-4个端点)
type PhysicalSection interface {
Model
Code() string
}
// 道岔
type Turnout interface {
Model
}
// 关联的端口关系
type AssociatedPort interface {
Port() string
}

34
repo/model/common.go Normal file
View File

@ -0,0 +1,34 @@
package model
type ModelType string
const (
// 车站
ModelType_Station ModelType = "Station"
// 站台
ModelType_Stand ModelType = "Stand"
// 屏蔽门
ModelType_PSD ModelType = "PSD"
// Link
ModelType_Link ModelType = "Link"
// 区段
ModelType_Section ModelType = "Section"
// 道岔
ModelType_Turnout ModelType = "Turnout"
// 信号机
ModelType_Signal ModelType = "Signal"
// 应答器
ModelType_Balise ModelType = "Balise"
)
type Uid interface {
Id() string
}
// 模型接口
type Model interface {
// Unique id,唯一id
Uid() Uid
// 模型类型
Type() ModelType
}

View File

@ -35,7 +35,7 @@ func (l *Link) Uid() string {
}
func (l *Link) Type() model.ModelType {
return model.MT_Link
return model.ModelType_Link
}
// link偏移

View File

@ -25,7 +25,7 @@ func (s *PhysicalSection) Uid() string {
}
func (s *PhysicalSection) Type() model.ModelType {
return model.MT_Section
return model.ModelType_Section
}
func (s *PhysicalSection) Code() string {

141
repo/model/link.go Normal file
View File

@ -0,0 +1,141 @@
package model
import "log/slog"
// link端口
type Link_Port int
const (
LinkPort_A Link_Port = -1
LinkPort_B Link_Port = 1
)
// Link
type Link interface {
Model
// Link总长度
Length() int64
// 获取端口A关联的道岔
GetPaTurnout() Turnout
// 获取端口B关联的道岔
GetPbTurnout() Turnout
// 下一个link及端口
// port - 当前link端口
// tpos - 当前道岔位置
Next(port Link_Port, tpos TurnoutPosition) *LinkPort
}
type LinkPort struct {
link Link
port Link_Port
}
func NewLinkPort(link Link, port Link_Port) *LinkPort {
return &LinkPort{
link: link,
port: port,
}
}
// link偏移位置
// 默认linkA端口偏移为0从A到B为增大从B到A为减小
type LinkOffset struct {
link Link
offset int64 // 偏移坐标,link相当于一个一维坐标系,以端口A为原点
}
// 创建link偏移位置,若offset超出link长度则返回nil
func NewLinkOffset(link Link, offset int64) *LinkOffset {
if offset < 0 || offset > link.Length() {
return nil
}
return &LinkOffset{
link: link,
offset: offset,
}
}
func (l *LinkOffset) Link() Link {
return l.link
}
func (l *LinkOffset) Offset() int64 {
return l.offset
}
// link偏移范围
type LinkRange struct {
link Link
start int64
end int64
}
func NewLinkRange(link Link, a int64, b int64) *LinkRange {
if a < 0 || a > link.Length() {
slog.Error("创建link偏移范围失败: 超出link长度范围", slog.Int64("a", a))
return nil
} else if b < 0 || b > link.Length() {
slog.Error("创建link偏移范围失败: 超出link长度范围", slog.Int64("b", b))
return nil
}
var start int64
var end int64
if a > b {
start = b
end = a
} else {
start = a
end = b
}
return &LinkRange{
link: link,
start: start,
end: end,
}
}
// 是否相交
func (l *LinkRange) IsIntersect(other *LinkRange) bool {
if l.link != other.link {
return false
}
if l.start > other.end || other.start > l.end {
return false
}
return true
}
// 是否相交
func (l *LinkRange) IsIntersect2(a, b int64) bool {
var start int64
var end int64
if a > b {
start = b
end = a
} else {
start = a
end = b
}
if start > l.end || end < l.start {
return false
}
return true
}
// 是否在范围内
func (l *LinkRange) IsInRange(lo *LinkOffset) bool {
if lo.link != l.link {
return false
}
if lo.offset < l.start || lo.offset > l.end {
return false
}
return true
}
// 偏移坐标是否在范围内
func (l *LinkRange) IsInRange2(offset int64) bool {
if offset < l.start || offset > l.end {
return false
}
return true
}

9
repo/model/section.go Normal file
View File

@ -0,0 +1,9 @@
package model
// 物理区段(实际检测区段)
type PhysicalSection interface {
Model
Code() string
// 所在Link范围
LinkRanges() []*LinkRange
}

10
repo/model/station.go Normal file
View File

@ -0,0 +1,10 @@
package model
// 车站
type Station interface {
Model
// 车站名
Name() string
// 是否设备集中站
IsEcs() bool
}

32
repo/model/turnout.go Normal file
View File

@ -0,0 +1,32 @@
package model
// 道岔位置
type TurnoutPosition int
const (
// 失表
TPos_Lost TurnoutPosition = 0
// 定位
TPos_DW TurnoutPosition = 1
// 反位
TPos_FW TurnoutPosition = 2
)
type Turnout_Port int
const (
TurnoutPort_A Turnout_Port = 0
TurnoutPort_B Turnout_Port = 1
TurnoutPort_C Turnout_Port = 2
)
// 道岔
type Turnout interface {
Model
// 获取A方向连接的link端口
GetALinkPort() *LinkPort
// 获取B方向连接的link端口
GetBLinkPort() *LinkPort
// 获取C方向连接的link端口
GetCLinkPort() *LinkPort
}