44 lines
792 B
Go
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
|
|
}
|