rts-sim-module/modelrepo/model_impl/uid.go
walker c4bc8c640f 重构singleton组件及相关方法接口
调整repo目录结构和命名
初步开始重构仿真实体加载
2023-12-28 16:49:28 +08:00

44 lines
792 B
Go

package modelimpl
import (
"fmt"
"strings"
)
// 城轨uid
type CgUid struct {
// 城市
city string
// 线路
line string
// 设备编号
codes []string
// codestr
codestr string
// uid
idstr string
}
func NewCgUid(city string, line string, codes ...string) *CgUid {
if city == "" || line == "" {
panic(fmt.Errorf("创建城轨uid错误: 城市、线路、车站不能为空 city=%s, line=%s", city, line))
}
l := len(codes)
if l == 0 {
panic(fmt.Errorf("创建城轨uid错误: codes不能为空"))
}
codestr := strings.Join(codes, "_")
elems := []string{city, line, codestr}
uid := strings.Join(elems, "_")
return &CgUid{
city: city,
line: line,
codes: codes,
codestr: codestr,
idstr: uid,
}
}
func (u *CgUid) Id() string {
return u.idstr
}