feat(mes/wms): 接驳台编码统一为GW点位码 + 签字模型改报检呼叫 + 台账续流修复 + 末级库位强校验(2026-12-01 终版整改)

【全系统 · 接驳台编码终版统一(12-01 用户拍板)】
- 新增 dockcode 包作为唯一真源:工位接驳台 = GW{工位号}{Z|Y}(Z=左/Y=右,工位1~10同一规则,废除左右互换),库房 = JBT21 不变
- 编码即海康 RCS 地图点位码:落库/界面/下发 RCS/读 PLC 传感器全用同一套;旧 DOCK01~20 全量废弃,系统内无第二套编号、无换算层
- dock 表去 side 字段;agv_task.target_dock、line_point、看板点位态与中文名、dockLabel 工具全部改 GW 规则
- 产线布局说明.md 同步终版(图纸名 GxZ/GxY 与 AGV 码 GWxZ/GWxY 一一对应;注明 RCS 图与主线流向图相差 180°,读图一律以 GW 码为准)

【MES · 签字模型二次重构(11-30 实测后定稿)】
- _OPERATOR 签字整体废除:工艺步骤删 needOperatorSign / needAudit / auditRole 字段,签字角色改 CALL(工人报检呼叫)+ INSPECTOR(检验员审核签)
- 呼叫时落步骤录入快照(stepValue/stepText/stepChecked/processId),供检验员查看与指纹比对;「待签任务」只认检验员签名步骤
- 「签字复核」(AuditPending 页面 + produce.audit 菜单 + 路由)整套删除

【MES · 台账续流根因修复(11-30 对账发现)】
- 流转目标「G6」与 line_point.point_no「6」对不上导致到位落账查不到、却先释放源位→工件从调度消失;新增 ledgerPointByTarget 归一
- settleDirect/settleInTransit 改为先占目标位、成功才释放源位;目标被占原样保留,工件进缓存位排队(实测 C2 排队不再丢件)

【WMS · 末级库位强校验与上架移库】
- 新增 LocationCascade 四级联动选择器(区/架/层/号,只从启用 level=4 节点派生);手工入库、半成品/成品入库、隔离库位一律四级必填且命中启用节点
- 新增上架/移库 relocate:只改四级库位与 updated_at,不动质量状态/数量/锁定量;不合格与锁定行同样允许移库;支持 ids 逐行指定或 scope 按物料+原库位整组搬
- MES 新增 WMS 自动回流库位配置(半成品/成品各一组末级库位,默认值 1区/1架/1层/1号,存 sys_config 可改)

【MES · 统一口径与工程整改】
- 新增 workpiece_location:工单详情工件列表/WIP/追溯三处共用位置判定(SCRAPPED→DONE→SEMI_STORED→在 StationNo→在途→待流转)
- 新增 workorder_close_warn:工单完工/取消时汇总各工位实物余料出一条预警,不阻断关单
- 分页下沉:新增 pagination 工具,同步失败台账(两端)改 Count+LIMIT/OFFSET 真分页,列表不再全量切片
- 全网对账/孤儿扫描(问题临时.md 第25/26节):10 类关系边断言实测,给出 8 条可重复巡检项

【文档】
- 产线布局说明.md 按 GW 编码终版重写;问题临时.md 新增 24.7 闭环实测、25 全网对账、26 补料→配送→报工人库闭环
This commit is contained in:
SunYF
2026-12-01 22:15:28 +08:00
parent f9eaebad28
commit f930a1325f
170 changed files with 8569 additions and 4431 deletions
+159 -58
View File
@@ -3,8 +3,11 @@ package logic
import (
"context"
"strconv"
"strings"
"bj_power_mes/common/dockcode"
"bj_power_mes/ent/alertrule"
"bj_power_mes/ent/materialrequest"
"bj_power_mes/ent/permission"
"bj_power_mes/ent/role"
"bj_power_mes/ent/station"
@@ -36,8 +39,8 @@ func (s *Service) Seed(ctx context.Context) error {
"produce.plc.monitor",
// 产线管理(块 E:4 tab,含工件位置纠正)与 AGV 配送(AGV 真源已在 MES):仅菜单权限
"produce.line.manage", "produce.agv", "produce.agv.manual",
// 产品工艺(产品级工艺定义,2026-10-09)+ 待审核签字
"produce.productprocess", "produce.audit",
// 产品工艺(产品级工艺定义,2026-10-09)
"produce.productprocess",
// 按钮级权限(块2)
"produce.workorder:add", "produce.workorder:edit", "produce.workorder:delete",
"produce.workorder:dailyplan", "produce.workorder:forcecomplete",
@@ -115,7 +118,6 @@ func (s *Service) Seed(ctx context.Context) error {
{"produce.shortage", "补料审批", "MENU", "/shortage"},
{"produce.loss", "损耗台账", "MENU", "/loss-ledger"},
{"produce.processcard", "生产流程卡", "MENU", "/process-card"},
{"produce.audit", "签字复核", "MENU", "/audit-pending"},
{"produce.product", "产品档案", "MENU", "/product-type"},
{"produce.quality", "质量检验", "MENU", "/quality"},
{"sys.inspect", "巡检终端", "MENU", "/inspect"},
@@ -286,6 +288,10 @@ func (s *Service) Seed(ctx context.Context) error {
// 一律补授 produce.agv.manual,避免拆码后菜单消失或接口 403(幂等)。
migrateSplitAgvManual(ctx, s)
// 3.9 接驳台/AGV 点位编码 GW 化迁移(2026-12-01 用户终版,幂等):
// 旧 DOCK01~20 编号全量废弃,存量库由 DOCK 码改 GW 码(DOCK 编号 = PLC 托盘传感器位序)。
migrateDockGwCodes(ctx, s)
// 4. 初始化产线工位(内置只读主数据);工艺流程/工艺步骤由用户在「工艺流程」页自建,不预置
seedStations(ctx, s)
// 5. 接驳台主数据(真源在 MES,2026-09-21 自 WMS 迁入;2026-10-17 块 E.2 起可在「产线管理」页维护)
@@ -364,37 +370,29 @@ func seedAlertRules(ctx context.Context, s *Service) {
}
}
// seedDocks 接驳台主数据:DOCK01~20 对应工位1~10(每工位2个,AGV 点位),JBT21 库房收货
// (2026-11-03 拍板 T7:库房接驳台代号统一 JBT21,与产线布局说明.md 一致)。
// seedDocks 接驳台主数据:工位1~10 各两台(GW{工位号}Z=左、GW{工位号}Y=右),另加 JBT21 库房接驳台。
// 编码即 AGV/RCS 地图点位码(2026-12-01 用户终版,旧 DOCK 编号全量废弃)。
// 一次性写入(仅当表为空时);2026-10-17 块 E.2 起「产线管理」页开放增/改/删/启停,seed 不再覆盖人工改动。
func seedDocks(ctx context.Context, s *Service) {
count, _ := s.ctx.EntClient.Dock.Query().Count(ctx)
if count > 0 {
return
}
for i := 1; i <= 20; i++ {
code := "DOCK" + pad2(i)
stationNo := (i + 1) / 2 // 每工位 2 个接驳台:工位1=DOCK01/02, 工位2=DOCK03/04 … 工位10=DOCK19/20
// side 左右互换(2026-11-03 拍板):工位 2/4/6/8/10(下排)左右名称互换——
// 偶数工位:奇数台(地图左)=GxR=right、偶数台(地图右)=GxL=left;
// 奇数工位维持:奇数台(地图左)=GxL=left。即 (i%2)==(stationNo%2) 为 left。
side := "right"
if i%2 == stationNo%2 {
side = "left"
for n := 1; n <= 10; n++ {
for _, side := range []string{"left", "right"} {
sideCn := "右"
if side == "left" {
sideCn = "左"
}
_, _ = s.ctx.EntClient.Dock.Create().
SetDockCode(AgvPointOf(n, side)).
SetName("工位" + strconv.Itoa(n) + sideCn + "接驳台").
SetDockType("line").
SetStationNo(n).
SetHasPallet(false).
SetStatus("ENABLED").
Save(ctx)
}
sideCn := "右"
if side == "left" {
sideCn = "左"
}
_, _ = s.ctx.EntClient.Dock.Create().
SetDockCode(code).
SetName("产线接驳台 " + code + "(工位" + strconv.Itoa(stationNo) + sideCn + ")").
SetDockType("line").
SetStationNo(stationNo).
SetSide(side).
SetHasPallet(false).
SetStatus("ENABLED").
Save(ctx)
}
_, _ = s.ctx.EntClient.Dock.Create().
SetDockCode("JBT21").
@@ -407,17 +405,13 @@ func seedDocks(ctx context.Context, s *Service) {
}
// seedAgvPoints AGV 点位真源(硬件内置):接驳台点位 position_code=dockCode、dock_id 强绑定;
// 另补纯 AGV 点位(is_dock=false)。
// 2026-11-13 拍板:改为【逐点位幂等补种】——原实现「表非空就整体跳过」会让后期新增的硬件点位
// 在存量库里永远进不来;现按 position_code 逐个判断,人工改动(启停/名称/锁定)不被覆盖。
// 2026-11-14 用户终版(三条澄清):dock(接驳台)与 agv_point(AGV 点位)本来就是分开的两张表,
// GW* 是 agv_point.position_code,即将来调用 AGV/RCS 接口时要传的点位参数;
// 产线布局说明.md 是对的、接驳台编码 DOCK01~20 / JBT21 一律不动,本函数只负责「对应上」:
// 另补纯 AGV 点位(is_dock=false)。逐点位幂等补种(2026-11-13 拍板),
// 人工改动(启停/名称/锁定)不被覆盖。
// 2026-12-01 用户终版:接驳台编码 = AGV/RCS 点位码(GW{工位号}{Z|Y} / JBT21),两张表存同一个码:
//
// ① 全量幂等补种 28 个点位(20 工位接驳台 GW* + JBT21 + 7 虚拟点位,见 agv_points.go);
// ② 每个 GW* 通过 dock_id 绑定到对应的 DOCK(2n-1)/DOCK(2n);
// ③ 历史点位(DOCK01~20 业务点位、待命/充电位、现场临时编码)一律保留,不删不改名
// —— 派车链路 targetDock 仍用 DOCK 编码,删了会断业务;也符合本轮红线「严禁乱改历史数据」。
// ② 每个接驳台点位通过 dock_id 绑定到同码的接驳台行;
// ③ 旧 DOCK01~20 点位不再存在。
func seedAgvPoints(ctx context.Context, s *Service) {
existing, _ := s.ctx.EntClient.AgvPoint.Query().All(ctx)
have := make(map[string]bool, len(existing))
@@ -441,44 +435,30 @@ func seedAgvPoints(ctx context.Context, s *Service) {
}
}
// 1) 接驳台索引:按 dockCode 取 id,供 GW* 点位绑定(dock 表本身不动)
// 1) 接驳台索引:按 dockCode 取 id(接驳台码即点位码)
dockID := map[string]int{}
if docks, err := s.ctx.EntClient.Dock.Query().All(ctx); err == nil {
for _, d := range docks {
dockID[d.DockCode] = d.ID
// 历史业务点位:position_code=dockCode,派车链路 targetDock 在用,保留原语义
name := d.Name
if name == "" {
name = "接驳台 " + d.DockCode
}
create(d.DockCode, name, true, d.ID)
}
}
// 2) 用户终版 28 个 AGV 传参点位:20 工位接驳台(GW*)+ JBT21 + 7 虚拟点位
// 2) 28 个 AGV 点位:20 工位接驳台(GW*)+ JBT21 + 7 虚拟点位
for _, p := range AgvAllPoints() {
id := 0
if p.DockSeq == 21 {
id = dockID[AgvStorePoint]
} else if p.DockSeq > 0 {
id = dockID["DOCK"+pad2(p.DockSeq)]
if p.IsDock {
id = dockID[p.Code]
}
create(p.Code, p.Name, p.IsDock, id)
}
// 3) 存量库「对应上」补正:GW1Z 等此前被误种成虚拟点位(is_dock=false、无 dock_id),
// 现补正为工位接驳台点位并绑定对应接驳台。只动 is_dock / dock_id / name,
// 不动 enabled / locked / locked_by / force_pick 等人工与运行态字段。
// 3) 存量库「对应上」补正:接驳台点位若 is_dock / dock_id / name 与主数据不一致则补正。
// 只动这三个字段,不动 enabled / locked / locked_by / force_pick 等人工与运行态字段。
for _, p := range AgvAllPoints() {
if !p.IsDock || p.DockSeq == 0 {
if !p.IsDock {
continue
}
id := 0
if p.DockSeq == 21 {
id = dockID[AgvStorePoint]
} else {
id = dockID["DOCK"+pad2(p.DockSeq)]
}
id := dockID[p.Code]
if id == 0 {
continue
}
@@ -506,6 +486,127 @@ func seedAgvPoints(ctx context.Context, s *Service) {
}
}
// migrateDockGwCodes 接驳台/AGV 点位编码 GW 化迁移(幂等,2026-12-01 用户终版)。
// 背景:旧 DOCK01~20 编号全量废弃,但该改造的数据迁移此前只在开发库手工执行过 SQL,
// migrate 子命令只做结构、seedDocks 只在空表写入、seedAgvPoints 只补缺不改名,
// 存量库(dock 主数据 / agv_point / agv_tasks / material_request.returnDock)不会被改写,
// 导致生产环境 AGV 点位管理残留 DOCK01~20、产线管理「传感器」列因编码对不上 PLC 位码整列显示「PLC 离线」。
// 映射:旧 DOCK 编号 = PLC 托盘传感器位序 1~20(与 plc/tcp.go 位序同源)→ dockcode.CodeOfSeq(位序);
// DOCK21 = 库房接驳台 → JBT21。历史留痕表(event_log 等)不改。
func migrateDockGwCodes(ctx context.Context, s *Service) {
gwOf := func(code string) string {
c := strings.ToUpper(strings.TrimSpace(code))
if !strings.HasPrefix(c, "DOCK") {
return ""
}
n, e := strconv.Atoi(c[4:])
if e != nil || n < 1 || n > 21 {
return ""
}
if n == 21 {
return dockcode.Store
}
return dockcode.CodeOfSeq(n)
}
nameOf := func(code string) string {
for _, def := range AgvAllPoints() {
if def.Code == code {
return def.Name
}
}
return dockcode.Label(code)
}
// 1) dock 主数据改码:DOCK 编号 → GW 码 + 名称 + 类型/工位号(类型与工位号按新码重派,纠正旧脏值)
docks, err := s.ctx.EntClient.Dock.Query().All(ctx)
if err != nil {
return
}
byCode := make(map[string]int, len(docks))
for _, d := range docks {
byCode[d.DockCode] = d.ID
}
for _, d := range docks {
target := gwOf(d.DockCode)
if target == "" || target == d.DockCode {
continue
}
if existID, ok := byCode[target]; ok && existID != d.ID {
// 目标码行已存在(异常残库):台账托盘状态并入目标行后删旧行,不留 DOCK 残码
_, _ = s.ctx.EntClient.Dock.UpdateOneID(existID).
SetHasPallet(d.HasPallet).SetPalletRef(d.PalletRef).Save(ctx)
_ = s.ctx.EntClient.Dock.DeleteOneID(d.ID).Exec(ctx)
continue
}
no, _, _ := dockcode.Parse(target)
upd := s.ctx.EntClient.Dock.UpdateOneID(d.ID).SetDockCode(target).SetName(dockcode.Label(target))
if no > 0 {
upd = upd.SetDockType("line").SetStationNo(no)
} else {
upd = upd.SetDockType("store").SetStationNo(0)
}
if _, err := upd.Save(ctx); err == nil {
delete(byCode, d.DockCode)
byCode[target] = d.ID
}
}
// 2) agv_point 点位改码/改绑/清理:目标点位已存在(seed 先行补种过)则删旧 DOCK 点位行;
// 否则改码改名,并按新码绑定 dock_id(硬件级强绑定)。
if points, err := s.ctx.EntClient.AgvPoint.Query().All(ctx); err == nil {
ptByCode := make(map[string]int, len(points))
for _, p := range points {
ptByCode[p.PositionCode] = p.ID
}
for _, p := range points {
target := gwOf(p.PositionCode)
if target == "" || target == p.PositionCode {
continue
}
if existID, ok := ptByCode[target]; ok && existID != p.ID {
_ = s.ctx.EntClient.AgvPoint.DeleteOneID(p.ID).Exec(ctx)
continue
}
upd := s.ctx.EntClient.AgvPoint.UpdateOneID(p.ID).SetPositionCode(target).SetName(nameOf(target))
if dockID, ok := byCode[target]; ok {
upd = upd.SetIsDock(true).SetDockID(dockID)
}
if _, err := upd.Save(ctx); err == nil {
delete(ptByCode, p.PositionCode)
ptByCode[target] = p.ID
}
}
}
// 3) agv_tasks 起点/终点改码(在途与历史任务的防撞/回显依据,必须同账)
if tasks, err := s.ctx.EntClient.AgvTask.Query().All(ctx); err == nil {
for _, t := range tasks {
src, tgt := gwOf(t.SourceDock), gwOf(t.TargetDock)
if src == "" && tgt == "" {
continue
}
upd := s.ctx.EntClient.AgvTask.UpdateOneID(t.ID)
if src != "" {
upd = upd.SetSourceDock(src)
}
if tgt != "" {
upd = upd.SetTargetDock(tgt)
}
_, _ = upd.Save(ctx)
}
}
// 4) material_request.returnDock 改码(退料 AGV 派车依据)
if reqs, err := s.ctx.EntClient.MaterialRequest.Query().
Where(materialrequest.ReturnDockHasPrefix("DOCK")).All(ctx); err == nil {
for _, r := range reqs {
if target := gwOf(r.ReturnDock); target != "" {
_ = s.ctx.EntClient.MaterialRequest.UpdateOneID(r.ID).SetReturnDock(target).Exec(ctx)
}
}
}
}
func seedStations(ctx context.Context, s *Service) {
// 工位是产线固定物理工位,一律「内置工位」:需连 PLC、按工位号顺序流转、不可改类型、不可删除、仅可改名,
// 属系统内置只读主数据(同 WMS 接驳台),故由种子初始化。12 个装配工位(1~10 带接驳台,11/12 产线末端无接驳台);