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
+106 -126
View File
@@ -8,9 +8,9 @@ import (
"strconv"
"strings"
"github.com/jung-kurt/gofpdf"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/svc"
"github.com/jung-kurt/gofpdf"
)
const (
@@ -100,7 +100,6 @@ func buildCardsPdf(ctx context.Context, svcCtx *svc.ServiceContext, nos, sns []s
pdf.AddPage()
}
first = false
pdf.AddPage()
renderWorkOrderCardPdf(pdf, card)
}
for _, sn := range sns {
@@ -112,7 +111,6 @@ func buildCardsPdf(ctx context.Context, svcCtx *svc.ServiceContext, nos, sns []s
pdf.AddPage()
}
first = false
pdf.AddPage()
renderSnTraceCardPdf(pdf, card)
}
if first {
@@ -257,162 +255,144 @@ func drawRow(pdf *gofpdf.Fpdf, y float64, widths []float64, cells []string, isHe
return y + rowH
}
// pdfBlockFlags 四张子表的显示开关(2026-12-01 用户拍板):工艺没配置的块不绘制。
// 判断依据是「工艺里配没配」(工单级),不是「当前有没有数据」;单台追溯卡全开。
type pdfBlockFlags struct {
Torque bool
Sign bool
Material bool
}
var pdfAllBlocks = pdfBlockFlags{Torque: true, Sign: true, Material: true}
// drawProductTables 绘制一台成品的四张子表;工单主卡与单台追溯卡共用,保证导出结构一致。
func drawProductTables(pdf *gofpdf.Fpdf, y float64, p *woProduct, flags pdfBlockFlags) float64 {
// ① 工序实绩
y = pdfHeading(pdf, y, "1. 工序实绩")
stepRows := make([][]string, 0, len(p.Steps))
for _, s := range p.Steps {
stepRows = append(stepRows, []string{
strconv.Itoa(s.Seq), s.ProcessName, s.StationNo, s.StartAt, s.EndAt, s.Operator,
s.SelfCheck, s.Inspector, s.Conclusion, s.Remark, s.InspectedAt, s.Status,
})
}
y = drawTable(pdf, y, []float64{8, 26, 10, 20, 20, 18, 12, 14, 10, 20, 20, 8},
[]string{"序号", "工艺", "工位", "开始", "结束", "操作人", "工人自检", "检验员", "结论", "检验意见", "检验时间", "状态"}, stepRows)
// ② 用料清单(工艺没配物料分账 → 不绘制)
if flags.Material {
y = pdfHeading(pdf, y, "2. 用料清单")
matRows := make([][]string, 0, len(p.Materials))
for _, m := range p.Materials {
matRows = append(matRows, []string{
m.MaterialCode, m.MaterialName, m.MaterialType, m.Spec, m.Unit,
m.SnOrBatch, strconv.Itoa(m.Qty), m.StationNo, m.Operator, m.BindAt,
})
}
y = drawTable(pdf, y, []float64{24, 26, 14, 22, 10, 30, 8, 14, 20, 18},
[]string{"图号", "名称", "类型", "规格", "单位", "物料SN或批次号", "数量", "装配工位", "装配人", "装配时间"}, matRows)
}
// ③ 拧紧数据(工艺没配拧紧步骤 → 不绘制)
if flags.Torque {
y = pdfHeading(pdf, y, "3. 拧紧数据")
torqueRows := make([][]string, 0, len(p.Torques))
for _, t := range p.Torques {
torqueRows = append(torqueRows, []string{t.ScrewNo, t.Torque, t.Angle, "设备判 " + t.Result, t.Operator, t.Time})
}
y = drawTable(pdf, y, []float64{22, 26, 22, 26, 24, 66},
[]string{"螺丝点", "扭矩", "角度", "设备判定", "操作人", "时间"}, torqueRows)
}
// ④ 签字明细(未撤销;工艺没配签字步骤 → 不绘制)
if flags.Sign {
y = pdfHeading(pdf, y, "4. 签字明细(未撤销)")
signRows := make([][]string, 0, len(p.Signs))
for _, s := range p.Signs {
signRows = append(signRows, []string{
s.ProcessName, s.StepName, s.SelfCheck, s.SelfCheckAt, s.Inspector,
s.Conclusion, s.Remark, s.SignedAt, strconv.Itoa(s.Round),
})
}
y = drawTable(pdf, y, []float64{24, 20, 12, 22, 18, 12, 28, 34, 16},
[]string{"工艺", "步骤", "工人自检", "自检时间", "检验员", "结论", "意见", "签字时间", "轮次"}, signRows)
}
return y
}
// ---------- 工单主卡 PDF ----------
func renderWorkOrderCardPdf(pdf *gofpdf.Fpdf, c *workOrderCard) {
y := pdfMargin
y = pdfTitle(pdf, y, "生产流程卡(工单维度)")
y = pdfTitle(pdf, y, "生产流程卡 · 工件明细")
y = pdfHeading(pdf, y, "一、工单汇总")
y = metaKV(pdf, y, [][2]string{
{"工单号", c.WorkOrderNo}, {"产品型号", c.ProductCode}, {"产品名称", c.ProductName},
{"图号", c.DrawingNo}, {"计划数", strconv.Itoa(c.PlanQty)}, {"完成数", strconv.Itoa(c.FinishedNum)},
{"状态", c.Status}, {"不合格数", strconv.Itoa(c.FailNum)},
}, 4)
y = metaKV(pdf, y, [][2]string{
{"计划开始", c.PlanStart}, {"计划完成", c.PlanEnd}, {"实际开始", c.ActualStart},
{"实际完成", c.CompletedAt}, {"实际结束", c.ActualFinish}, {"生成时间", c.GeneratedAt},
{"不良数", strconv.Itoa(c.FailNum)}, {"用料合计", strconv.Itoa(c.MaterialTotal)},
{"状态", c.Status}, {"实际开始", c.ActualStart}, {"实际完成", c.ActualFinish},
{"生成时间", c.GeneratedAt},
}, 3)
y = pdfHeading(pdf, y, "一、工艺实绩")
widths := []float64{12, 34, 14, 16, 28, 28, 24, 16, 18}
rows := [][]string{}
for _, s := range c.ProcessSteps {
rows = append(rows, []string{
strconv.Itoa(s.Seq), s.ProcessName, s.StationNo, s.CollectCN,
s.ActualStart, s.ActualEnd, s.Operators, s.Status, s.Auditor,
})
}
y = drawTable(pdf, y, widths, []string{"序号", "工艺", "工位", "采集", "实绩开始", "实绩结束", "操作人", "状态", "审核人"}, rows)
y = pdfHeading(pdf, y, "二、用料清单 · 序列号=是(逐件追溯)")
swidths := []float64{28, 38, 16, 28, 12, 28, 10, 14, 16}
srows := [][]string{}
for _, m := range c.SerialMaterials {
srows = append(srows, []string{
m.MaterialCode, m.MaterialName, m.MaterialType, m.Spec, m.Unit,
strings.Join(m.SnList, " "), strconv.Itoa(m.Qty), m.StationNo, m.Operator,
})
}
y = drawTable(pdf, y, swidths, []string{"图号", "名称", "类型", "规格", "单位", "物料SN", "数量", "装配工位", "装配人"}, srows)
y = pdfHeading(pdf, y, "三、用料清单 · 序列号=否(按批追溯)")
bwidths := []float64{28, 38, 16, 28, 12, 20, 10, 14, 16}
brows := [][]string{}
for _, m := range c.BatchMaterials {
brows = append(brows, []string{
m.MaterialCode, m.MaterialName, m.MaterialType, m.Spec, m.Unit,
m.BatchNo, strconv.Itoa(m.Qty), m.StationNo, m.Operator,
})
}
y = drawTable(pdf, y, bwidths, []string{"图号", "名称", "类型", "规格", "单位", "批次号", "数量", "装配工位", "装配人"}, brows)
y = pdfHeading(pdf, y, "四、成品明细")
pwidths := []float64{60, 30, 88}
prows := [][]string{}
for _, p := range c.Products {
prows = append(prows, []string{p.Sn, p.Status, p.DoneAt})
}
y = drawTable(pdf, y, pwidths, []string{"SN", "状态", "完工时间"}, prows)
y = pdfHeading(pdf, y, "五、签字确认")
// 签字汇总:已排除撤销记录、按人去重,不再把返工重签算成次数。
sign := [][2]string{}
if c.Signs.Operator != nil {
sign = append(sign, [2]string{"操作工", c.Signs.Operator.Names + "(" + strconv.Itoa(c.Signs.Operator.Count) + "次,最近 " + c.Signs.Operator.LatestTime + ")"})
sign = append(sign, [2]string{"操作工", c.Signs.Operator.Names + "(" + strconv.Itoa(c.Signs.Operator.Count) + "人,最近 " + c.Signs.Operator.LatestTime + ")"})
} else {
sign = append(sign, [2]string{"操作工", "待签"})
}
if c.Signs.Inspector != nil {
sign = append(sign, [2]string{"检验员", c.Signs.Inspector.Names + "(" + strconv.Itoa(c.Signs.Inspector.Count) + "次,最近 " + c.Signs.Inspector.LatestTime + ")"})
sign = append(sign, [2]string{"检验员", c.Signs.Inspector.Names + "(" + strconv.Itoa(c.Signs.Inspector.Count) + "人,最近 " + c.Signs.Inspector.LatestTime + ")"})
} else {
sign = append(sign, [2]string{"检验员", "待签"})
}
if c.Signs.Auditor != nil {
sign = append(sign, [2]string{"审核人", c.Signs.Auditor.Names + "(" + strconv.Itoa(c.Signs.Auditor.Count) + "次,最近 " + c.Signs.Auditor.LatestTime + ")"})
} else {
sign = append(sign, [2]string{"审核人", "待签"})
}
sign = append(sign, [2]string{"批准人", "手签"})
y = metaKV(pdf, y, sign, 1)
y = pdfHeading(pdf, y, "二、工件明细(按成品 SN 逐台)")
if len(c.Products) == 0 {
y = metaKV(pdf, y, [][2]string{{"提示", "暂无成品记录"}}, 1)
}
// 每台强制分页:一台一页,四张子表在页内按需续页。
for i := range c.Products {
p := &c.Products[i]
pdf.AddPage()
y = pdfMargin
y = pdfTitle(pdf, y, "成品 SN:"+p.Sn)
y = metaKV(pdf, y, [][2]string{
{"状态", p.Status}, {"当前工序", p.CurrentProcess},
{"已完成工序", strconv.Itoa(p.DoneCount) + "/" + strconv.Itoa(p.TotalCount)},
{"用料条数", strconv.Itoa(p.MaterialCount)}, {"检验结论", p.InspectionResult},
{"完工时间", p.DoneAt},
}, 3)
y = drawProductTables(pdf, y, p, pdfBlockFlags{
Torque: c.HasTorqueConfig, Sign: c.HasSignConfig, Material: c.HasMaterialConfig,
})
_ = y
}
}
// ---------- 成品 SN 追溯卡 PDF ----------
func renderSnTraceCardPdf(pdf *gofpdf.Fpdf, c *snTraceCard) {
y := pdfMargin
y = pdfTitle(pdf, y, "成品追溯卡(SN 维度)")
y = pdfTitle(pdf, y, "成品追溯卡 · 工件明细")
y = metaKV(pdf, y, [][2]string{
{"SN", c.Sn}, {"工单号", c.WorkOrderNo}, {"产品型号", c.ProductCode},
{"状态", c.Status}, {"完工时间", c.DoneAt}, {"生成时间", c.GeneratedAt},
{"当前工序", c.CurrentProcess}, {"已完成工序", strconv.Itoa(c.DoneCount) + "/" + strconv.Itoa(c.TotalCount)},
{"用料条数", strconv.Itoa(c.MaterialCount)}, {"检验结论", c.InspectionResult},
}, 3)
y = pdfHeading(pdf, y, "一、工艺实绩")
widths := []float64{14, 14, 38, 28, 28, 22, 16, 16}
rows := [][]string{}
for _, s := range c.Processes {
rows = append(rows, []string{
strconv.Itoa(s.FlowId), s.StationNo, s.ProcessName, s.StartAt, s.EndAt,
s.Operator, s.Status, s.Result,
})
}
y = drawTable(pdf, y, widths, []string{"产线", "工位", "工艺", "开始", "结束", "操作人", "状态", "结果"}, rows)
y = pdfHeading(pdf, y, "二、用料清单 · 序列号=是")
swidths := []float64{28, 38, 16, 28, 12, 28, 10, 14, 16}
srows := [][]string{}
for _, m := range c.SerialMaterials {
srows = append(srows, []string{
m.MaterialCode, m.MaterialName, m.MaterialType, m.Spec, m.Unit,
strings.Join(m.SnList, " "), strconv.Itoa(m.Qty), m.StationNo, m.Operator,
})
}
y = drawTable(pdf, y, swidths, []string{"图号", "名称", "类型", "规格", "单位", "物料SN", "数量", "装配工位", "装配人"}, srows)
y = pdfHeading(pdf, y, "三、用料清单 · 序列号=否")
bwidths := []float64{28, 38, 16, 28, 12, 20, 10, 14, 16}
brows := [][]string{}
for _, m := range c.BatchMaterials {
brows = append(brows, []string{
m.MaterialCode, m.MaterialName, m.MaterialType, m.Spec, m.Unit,
m.BatchNo, strconv.Itoa(m.Qty), m.StationNo, m.Operator,
})
}
y = drawTable(pdf, y, bwidths, []string{"图号", "名称", "类型", "规格", "单位", "批次号", "数量", "装配工位", "装配人"}, brows)
if len(c.TorqueRows) > 0 {
y = pdfHeading(pdf, y, "四、拧紧数据")
twidths := []float64{24, 28, 24, 24, 24, 48}
trows := [][]string{}
for _, t := range c.TorqueRows {
trows = append(trows, []string{t.ScrewNo, t.Torque, t.Angle, "设备判 " + t.Result, t.Operator, t.Time})
}
y = drawTable(pdf, y, twidths, []string{"螺丝点", "扭矩", "角度", "判定", "操作人", "时间"}, trows)
}
// 单台卡与工单主卡 products[] 使用同一套四张子表;单台卡不受工艺配置标志约束,四块全开。
p := &woProduct{Steps: c.Steps, Materials: c.Materials, Torques: c.Torques, Signs: c.SignRows}
y = drawProductTables(pdf, y, p, pdfAllBlocks)
if len(c.SkipRows) > 0 {
y = pdfHeading(pdf, y, "五、人工跳过(设备未连接)")
srows := [][]string{}
y = pdfHeading(pdf, y, "5. 人工跳过(设备未连接)")
srows := make([][]string, 0, len(c.SkipRows))
for _, s := range c.SkipRows {
srows = append(srows, []string{s.StepName, s.Reason, s.Operator, s.Time})
}
y = drawTable(pdf, y, []float64{40, 76, 24, 40}, []string{"拧紧步骤", "跳过原因", "操作人", "时间"}, srows)
y = drawTable(pdf, y, []float64{40, 76, 24, 46}, []string{"拧紧步骤", "跳过原因", "操作人", "时间"}, srows)
}
y = pdfHeading(pdf, y, "六、签字确认")
sign := [][2]string{}
if c.Signs.Operator != nil {
sign = append(sign, [2]string{"操作工", c.Signs.Operator.Names})
} else {
sign = append(sign, [2]string{"操作工", "待签"})
}
if c.Signs.Inspector != nil {
sign = append(sign, [2]string{"检验员", c.Signs.Inspector.Names})
} else {
sign = append(sign, [2]string{"检验员", "待签"})
}
if c.Signs.Auditor != nil {
sign = append(sign, [2]string{"审核人", c.Signs.Auditor.Names})
} else {
sign = append(sign, [2]string{"审核人", "待签"})
}
sign = append(sign, [2]string{"批准人", "手签"})
y = metaKV(pdf, y, sign, 1)
_ = y
}