Files
bj_power/bj_power_mes/internal/logic/processseq.go
T
SunYF 672cd23329 feat: 新增多类功能并优化现有流程
1. 工序工位支持0号上线位,更新解析逻辑与注释
2. 物料清单模块重命名为产品物料清单并优化文案
3. WMS与工位端新增用户/角色详情抽屉组件
4. 工单模块新增自动生成工单号、工位分组选择器
5. 日排产支持批量生成与详情查看
6. 工单列表重构操作菜单与表单优化
2026-09-18 13:54:30 +08:00

62 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package logic
import (
"errors"
"sort"
"strconv"
"strings"
)
// FullProcessSeq 全部 12 个工位的完整组合(按顺序执行)
const FullProcessSeq = "1,2,3,4,5,6,7,8,9,10,11,12"
// ProcessSeqMaxStation 工位组合允许的最大工位号(工位主数据可自行扩展,故放宽上限)。
const ProcessSeqMaxStation = 999
// ParseProcessSeq 解析工位组合字符串为升序去重的工位码列表。
// 唯一格式:逗号分隔 "1,3,5" / "10,11,12"。传送带不回走,故组合天然按工位号升序执行。
// 工位号取值 0..ProcessSeqMaxStation0/13 为虚拟上线/下线位(不连 PLC、仅记录),工位主数据可扩展到 14、15…。
func ParseProcessSeq(s string) []int {
s = strings.TrimSpace(s)
if s == "" {
return nil
}
seen := map[int]bool{}
out := make([]int, 0, 12)
for _, p := range strings.Split(s, ",") {
p = strings.TrimSpace(p)
if p == "" {
continue
}
n, err := strconv.Atoi(p)
if err != nil || n < 0 || n > ProcessSeqMaxStation || seen[n] {
continue
}
seen[n] = true
out = append(out, n)
}
sort.Ints(out)
return out
}
// NormalizeProcessSeq 规范化:解析后重排为逗号分隔升序,非法/空返回空串。
func NormalizeProcessSeq(s string) string {
codes := ParseProcessSeq(s)
if len(codes) == 0 {
return ""
}
parts := make([]string, len(codes))
for i, c := range codes {
parts[i] = strconv.Itoa(c)
}
return strings.Join(parts, ",")
}
// ValidateProcessSeq 校验工位组合:非空、按工位号升序执行(工位号上限见 ProcessSeqMaxStation)。
func ValidateProcessSeq(s string) error {
if len(ParseProcessSeq(s)) == 0 {
return errors.New("工位组合不能为空,请至少选择一个工位")
}
return nil
}