Files
bj_power/bj_power_mes/common/dockcode/dockcode.go
T

118 lines
3.1 KiB
Go
Raw Normal View History

// Package dockcode 接驳台(工位接驳台 / 库房接驳台)编码的唯一真源。
//
// 2026-12-01 用户终版:
// - 工位接驳台编码 = GW{工位号}{Z|Y},Z=左、Y=右,工位 1~10 统一规则,不做左右互换;
// - 库房接驳台 = JBT21(不变);
// - 该编码就是海康 RCS 地图点位码:落库、界面显示、下发 RCS、读 PLC 传感器全部用它,
// 旧 DOCK01~20 编号已全量废弃,系统内不存在第二套编号,也不存在任何换算层。
//
// 接驳台序号(PLC 托盘传感器位序 1~20,对应点表「工位N后接驳台1/2」):
// 奇数工位 1=左(Z)、2=右(Y);偶数工位 1=右(Y)、2=左(Z)。物理位 = MB900.0 起顺排。
//
// 运行时不用正则:固定前缀/后缀一律走前缀判断与切片解析。
package dockcode
import (
"strconv"
"strings"
)
// Store 库房接驳台编码(唯一允许人工派车的接驳台点位)。
const Store = "JBT21"
// Station 工位接驳台编码:工位号 1~10 + 左右 → GW{no}{Z|Y};非法入参返回空串。
func Station(no int, left bool) string {
if no < 1 || no > 10 {
return ""
}
suffix := "Y"
if left {
suffix = "Z"
}
return "GW" + strconv.Itoa(no) + suffix
}
// Parse 解析工位接驳台编码:GW{1..10}{Z|Y} → 工位号、是否左台。非本格式 ok=false。
func Parse(code string) (no int, left bool, ok bool) {
c := strings.ToUpper(strings.TrimSpace(code))
if len(c) < 4 || c[0] != 'G' || c[1] != 'W' {
return 0, false, false
}
last := c[len(c)-1]
if last != 'Z' && last != 'Y' {
return 0, false, false
}
n, err := strconv.Atoi(c[2 : len(c)-1])
if err != nil || n < 1 || n > 10 {
return 0, false, false
}
return n, last == 'Z', true
}
// IsStation 是否工位接驳台编码。
func IsStation(code string) bool {
_, _, ok := Parse(code)
return ok
}
// Side 左右:left / right;非工位接驳台(含 JBT21、虚拟点)返回空串。
func Side(code string) string {
_, left, ok := Parse(code)
if !ok {
return ""
}
if left {
return "left"
}
return "right"
}
// SideCn 左右中文:左 / 右;非工位接驳台返回空串。
func SideCn(code string) string {
switch Side(code) {
case "left":
return "左"
case "right":
return "右"
}
return ""
}
// Seq 接驳台序号 1~20(PLC 托盘传感器位序);非工位接驳台返回 0。
func Seq(code string) int {
n, left, ok := Parse(code)
if !ok {
return 0
}
firstLeft := n%2 == 1 // 奇数工位的接驳台1 是左台
if left == firstLeft {
return 2*n - 1
}
return 2 * n
}
// CodeOfSeq 接驳台序号 1~20 → 编码;越界返回空串。
func CodeOfSeq(seq int) string {
if seq < 1 || seq > 20 {
return ""
}
n := (seq + 1) / 2
firstLeft := n%2 == 1
return Station(n, (seq%2 == 1) == firstLeft)
}
// Label 中文显示名:工位N左 / 工位N右 / 库房接驳台;其它编码原样返回。
func Label(code string) string {
c := strings.ToUpper(strings.TrimSpace(code))
if c == Store {
return "库房接驳台"
}
if n, left, ok := Parse(c); ok {
if left {
return "工位" + strconv.Itoa(n) + "左"
}
return "工位" + strconv.Itoa(n) + "右"
}
return code
}