feat: 同步失败台账双向可重试 + 拧紧枪按工位配置 + 虚拟工位体系 + 去Redis与文档口径对齐
- 同步失败台账:MES/WMS 双端新增台账与页面,跨系统通知失败落台账、人工重试或标记已处理,不自动重传;重试前先判对端终态;叫料、配送、出库回写失败提示指向台账;补幂等建表脚本与菜单权限。 - 拧紧枪:新增按工位配置页,展示控制器地址与三把枪通道号(仅供查看,不参与采集校验);「允许手填」由全局开关改为每工位开关,关闭时校验该工位已配控制器;终端启动/登录上报配置并按本工位拉取,扭矩手填框按本工位置灰;补全局值迁移到各工位的脚本。 - 工位体系:终端未配置工位号时登录页可选(含虚拟工位),固定工位模式保留;虚拟/线下位不叫料、不退料、不作转产目标,未采集绑定放行并说明原因;叫料期望接驳台改为选填。 - AGV与出库:补「出库单已送达」回写;空车回充、接驳台传感器失联、配送状态更新失败均落预警或留痕并提示人工核对;人工出库不引入送达状态;出库单支持目标工位/接驳台并扩展导出列。 - 基础设施:看板缓存由Redis改为MES进程内实现,文档与启动脚本同步去Redis;扫码监听支持多地址、端口被占自动降级;PLC对账与工位报警在MES不可达时降级放行并留日志。 - 文档与帮助:案例与部署手册按实测订正(工位绑定、菜单名称、补料由班组长代提、菜单覆盖对照、虚拟工位);迁移脚本改为本地即时执行并登记7个已执行脚本;三端页面帮助改为「业务/操作/影响范围/后果」四要素。 - 测试:新增独立Go模块,按三个业务场景做真实HTTP与真实写库的流水测试,含运行报告。
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/dock"
|
||||
"bj_power_mes/ent/flowmaterial"
|
||||
"bj_power_mes/ent/workpiece"
|
||||
"bj_power_mes/ent/workpiecebind"
|
||||
@@ -193,13 +194,64 @@ func (s *Service) applyBinds(ctx context.Context, client *ent.Client, sn, orderN
|
||||
return bound, nil
|
||||
}
|
||||
|
||||
// stationHasEnabledLineDock 判断工位是否为「实体工位」:存在启用的 line 类型接驳台。
|
||||
// 虚拟/线下位(如末端下料检测位 11/12)无接驳台、不承载 AGV 物料物流,
|
||||
// 因此不采集装配物料绑定,报工/完工/追溯/终端面板一律放行(2026-11-08 B2 拍板)。
|
||||
func (s *Service) stationHasEnabledLineDock(ctx context.Context, client *ent.Client, stationNo int) bool {
|
||||
if stationNo <= 0 {
|
||||
return false
|
||||
}
|
||||
n, err := client.Dock.Query().Where(
|
||||
dock.StationNo(stationNo), dock.DockTypeEQ("line"), dock.StatusEQ("ENABLED")).Count(ctx)
|
||||
return err == nil && n > 0
|
||||
}
|
||||
|
||||
const bindSkipReason = "该工序未采集绑定(工位无接驳台)"
|
||||
|
||||
// BindNotCollected 追溯页:因候选工位无接驳台而未采集装配绑定的工序。
|
||||
type BindNotCollected struct {
|
||||
FlowId int `json:"flowId"`
|
||||
FlowName string `json:"flowName"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// flowBindGate 按工单工艺组合判定每道工序是否需采集装配绑定:
|
||||
// 多工位同工艺=并行候选工位,任一候选工位有启用 line 接驳台即需采集;
|
||||
// 该工序全部候选均无接驳台(虚拟/线下位)时不采集,并返回追溯用未采集清单。
|
||||
func (s *Service) flowBindGate(ctx context.Context, client *ent.Client, wo *ent.WorkOrder) (map[int]bool, []BindNotCollected) {
|
||||
items, _ := RouteStationsFromWO(ctx, client, wo)
|
||||
required := map[int]bool{}
|
||||
seen := map[int]bool{}
|
||||
skipped := []BindNotCollected{}
|
||||
for _, it := range items {
|
||||
if s.stationHasEnabledLineDock(ctx, client, it.StationNo) {
|
||||
required[it.FlowId] = true
|
||||
}
|
||||
}
|
||||
for _, it := range items {
|
||||
if seen[it.FlowId] || required[it.FlowId] {
|
||||
continue
|
||||
}
|
||||
seen[it.FlowId] = true
|
||||
skipped = append(skipped, BindNotCollected{
|
||||
FlowId: it.FlowId, FlowName: s.flowNameById(ctx, it.FlowId),
|
||||
StationNo: it.StationNo, Reason: bindSkipReason,
|
||||
})
|
||||
}
|
||||
return required, skipped
|
||||
}
|
||||
|
||||
// validateStationBinds 校验某工件在某工艺的装配物料是否绑齐(齐套强校验核心):
|
||||
// 返回缺料明细(空串=齐套)。判定:电气件(SN) 绑定的不同SN数 ≥ 单台用量;结构件(批次) 至少绑定1个批次号。
|
||||
// 该工艺未配置物料清单时视为不启用绑定校验,放行。
|
||||
func (s *Service) validateStationBinds(ctx context.Context, client *ent.Client, sn string, flowId int) (string, error) {
|
||||
// 该工艺未配置物料清单,或报工工位无启用产线接驳台(不采集绑定)时放行。
|
||||
func (s *Service) validateStationBinds(ctx context.Context, client *ent.Client, sn string, flowId int, requireBinds bool) (string, error) {
|
||||
if _, _, err := s.workpieceProduct(ctx, client, sn); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !requireBinds {
|
||||
return "", nil // 工位无启用产线接驳台(虚拟/线下位)→ 不采集绑定,放行
|
||||
}
|
||||
targets, err := s.stationBindTargets(ctx, client, flowId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -242,12 +294,14 @@ func (s *Service) validateStationBinds(ctx context.Context, client *ent.Client,
|
||||
}
|
||||
|
||||
// validateAllFlows 完工兜底:按工单工艺组合(唯一路线源头)逐工艺校验装配物料齐套。
|
||||
// 同一工艺绑多工位时只校验一次(按 FlowId 去重)。
|
||||
// 同一工艺绑多工位时只校验一次(按 FlowId 去重);该工序候选工位全无启用 line 接驳台
|
||||
// (虚拟/线下位,未采集绑定)时跳过,不再把「没绑」误判成缺料。
|
||||
func (s *Service) validateAllFlows(ctx context.Context, client *ent.Client, sn string, wo *ent.WorkOrder) (string, error) {
|
||||
if _, _, err := s.workpieceProduct(ctx, client, sn); err != nil {
|
||||
return "", err
|
||||
}
|
||||
items, _ := RouteStationsFromWO(ctx, client, wo)
|
||||
required, _ := s.flowBindGate(ctx, client, wo)
|
||||
missing := []string{}
|
||||
seen := map[int]bool{}
|
||||
for _, it := range items {
|
||||
@@ -255,7 +309,10 @@ func (s *Service) validateAllFlows(ctx context.Context, client *ent.Client, sn s
|
||||
continue
|
||||
}
|
||||
seen[it.FlowId] = true
|
||||
msg, err := s.validateStationBinds(ctx, client, sn, it.FlowId)
|
||||
if !required[it.FlowId] {
|
||||
continue // 该工序全部候选工位无接驳台 → 未采集绑定,不参与齐套
|
||||
}
|
||||
msg, err := s.validateStationBinds(ctx, client, sn, it.FlowId, true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -327,10 +384,11 @@ func (s *Service) ListWorkpieceBinds(ctx context.Context, sn string) ([]*ent.Wor
|
||||
|
||||
// BindTraceVO 追溯页:装机绑定明细 + 每工艺齐套状态 + 装机物料明细
|
||||
type BindTraceVO struct {
|
||||
Binds []*ent.WorkpieceBind `json:"binds"`
|
||||
Complete bool `json:"complete"`
|
||||
Missing string `json:"missing"`
|
||||
BomTree []BindNode `json:"bomTree"` // 装机物料明细(按工单工艺组合×工艺物料清单平铺一层,无多级树)
|
||||
Binds []*ent.WorkpieceBind `json:"binds"`
|
||||
Complete bool `json:"complete"`
|
||||
Missing string `json:"missing"`
|
||||
BomTree []BindNode `json:"bomTree"` // 装机物料明细(按工单工艺组合×工艺物料清单平铺一层,无多级树)
|
||||
NotCollected []BindNotCollected `json:"notCollected"` // 无接驳台工序:未采集绑定原因
|
||||
}
|
||||
|
||||
// BindNode 追溯用的装机物料明细节点(平铺一层;多级 BOM 已于 2026-09-23 退役,无下级展开)
|
||||
@@ -357,6 +415,8 @@ func (s *Service) BuildBindTrace(ctx context.Context, sn string) (*BindTraceVO,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 无接驳台工序未采集绑定:追溯页显式给出原因,避免与「已绑齐」的空列表混淆
|
||||
_, skipped := s.flowBindGate(ctx, s.ctx.EntClient, wo)
|
||||
// 物料组成:按工单工艺组合×工艺物料清单平铺一层(物料清单已删除,无多级树)
|
||||
var tree []BindNode
|
||||
for _, it := range s.WorkOrderUnitUsage(ctx, wo) {
|
||||
@@ -366,7 +426,8 @@ func (s *Service) BuildBindTrace(ctx context.Context, sn string) (*BindTraceVO,
|
||||
Qty: it.UnitQty,
|
||||
})
|
||||
}
|
||||
return &BindTraceVO{Binds: binds, Complete: missing == "", Missing: missing, BomTree: tree}, nil
|
||||
return &BindTraceVO{Binds: binds, Complete: missing == "", Missing: missing,
|
||||
BomTree: tree, NotCollected: skipped}, nil
|
||||
}
|
||||
|
||||
// BindRequiredItem 应绑清单条目(工位终端展示引导 + 前端齐套计算)
|
||||
@@ -393,6 +454,8 @@ type StationBindPanel struct {
|
||||
FlowId int `json:"flowId"`
|
||||
LastBinds []*ent.WorkpieceBind `json:"lastBinds"` // 最近10条绑定记录
|
||||
StationNames map[int]string `json:"-"`
|
||||
HasLineDock bool `json:"hasLineDock"` // 候选工位是否有启用 line 接驳台
|
||||
SkipReason string `json:"skipReason"` // 无需采集绑定的原因
|
||||
}
|
||||
|
||||
// StationBindPanelData 供工位终端在报工前拉取:本工件本工艺该装什么、已装什么
|
||||
@@ -417,7 +480,16 @@ func (s *Service) StationBindPanelData(ctx context.Context, sn string, flowId in
|
||||
}
|
||||
}
|
||||
}
|
||||
panel := &StationBindPanel{Enabled: len(targets) > 0, FlowId: flowId, StationNo: stationNo}
|
||||
// B2(2026-11-08):候选工位无启用 line 接驳台 → 该工序不采集装配绑定,
|
||||
// 面板不展示「需绑批次/需绑SN」,齐套恒为 true,前端不会拦截报工。
|
||||
hasDock := s.stationHasEnabledLineDock(ctx, s.ctx.EntClient, stationNo)
|
||||
panel := &StationBindPanel{
|
||||
Enabled: len(targets) > 0 && hasDock, FlowId: flowId, StationNo: stationNo,
|
||||
HasLineDock: hasDock, Required: []BindRequiredItem{},
|
||||
}
|
||||
if !hasDock {
|
||||
panel.SkipReason = bindSkipReason
|
||||
}
|
||||
// 全量绑定(齐套判定必须按全量统计,不能用 limit 截断,否则多料/多SN会误判缺料)
|
||||
allBinds, _ := s.ctx.EntClient.WorkpieceBind.Query().
|
||||
Where(workpiecebind.Sn(sn), workpiecebind.FlowId(flowId)).All(ctx)
|
||||
@@ -429,6 +501,9 @@ func (s *Service) StationBindPanelData(ctx context.Context, sn string, flowId in
|
||||
boundMap[b.MaterialCode][b.BindValue] = true
|
||||
}
|
||||
for _, t := range targets {
|
||||
if !hasDock {
|
||||
break // 无接驳台工位不展示「需绑批次 / 需绑SN」应绑清单
|
||||
}
|
||||
need := int(math.Ceil(t.UnitQty))
|
||||
if need < 1 {
|
||||
need = 1
|
||||
@@ -458,8 +533,8 @@ func (s *Service) StationBindPanelData(ctx context.Context, sn string, flowId in
|
||||
}
|
||||
}
|
||||
panel.Complete = allComplete
|
||||
if !allComplete {
|
||||
panel.Missing, _ = s.validateStationBinds(ctx, s.ctx.EntClient, sn, flowId)
|
||||
if !allComplete && hasDock {
|
||||
panel.Missing, _ = s.validateStationBinds(ctx, s.ctx.EntClient, sn, flowId, true)
|
||||
}
|
||||
// 最近绑定(仅展示用)
|
||||
sort.Slice(allBinds, func(i, j int) bool { return allBinds[i].ID > allBinds[j].ID })
|
||||
|
||||
Reference in New Issue
Block a user