feat(mes/wms/终端): 签字循环业务重构 + 叫料池实物账两列 + 工位流水按包真分页 + 下线单据提示条(2026-11-30 现场整改)
【MES · 签字循环重构(业务重构,非修 bug)】 - 旧模型作废(签字随报工落库、检验员分支永不生效的死代码);新口径: 工人干完点「呼叫签字」→ 检验员巡检端签 OK/NG → OK 后工人再点一次「报工」;NG 整改后重新呼叫(新一轮) - 内容指纹(SHA256):呼叫时算一次落库,报工时重算比对,变了即「签字后改数据作废本轮」要求重呼; 只覆盖步骤录入(值/文本/勾选/拧紧结果),装机绑定不进指纹(独立台账)、改备注不触发 - 轮次统一:一次呼叫=一轮,操作工/检验员共用 round;NG/撤回/重呼=新一轮,旧轮作废历史保留 - 三档状态(作业中/签字中/待整改/可报工)从签字记录推导,不建表不存终端 - 报工闸门:本轮需签步骤齐全(操作工+检验员OK)+ 指纹未变才放行 - 撤回呼叫整轮作废;超时巡检每分钟扫描(阈值 30 分钟可在基础设置调),超时落预警中心+异常角标不进铃铛,60 分钟窗口去重 - 工位终端新增签字交互接口与呼叫/撤回/状态查询;巡检端保留 NG 回看 【MES · 叫料池实物账(十五节 Q1/Q16 + 17.6 裁决)】 - call_pool 新增 receivedQty(已收累计,拒收按退库单冲减)/ returnedQty(已退累计,按退库单号防重)两列实物账,与 sentQty 额度账并存 - 台面在手(可用)= 已收 − 已装 − 已退;在途 = 已发 − 已收 【工位终端 · 物料/叫料页重构(十五节 Q1~Q17 拍板落地)】 - 「本工位物料明细」改名「物料明细」,四数列改为:可用/需求/已发/已收/已装,量为 0 也显示不分左右托盘 - 去除「刷新池子」「刷新」按钮(有长连接);「我的叫料单」扩为类银行流水(叫料/退料/等等) - 叫料/退料数量列直排,提交时弹窗确认数量并选接驳台;管理端叫料与退料 AGV 派车流程统一收归库管 - 工位流水按包真分页(2026-11-29 拍板):后端按包号分组 Count+Limit/Offset,每页 20 包,前端不再内存聚合 【下线 · 单据流转提示条】 - MES/WMS 前端整体删除 NextStepBar / nextStep / nextStepRules(35 条规则表整套下线),页面不再出现常驻「下一步」提示条 【文档】 - 问题临时.md 新增十四节(主控独立审计:终端账号删除/心跳/闸门函数 8 处对码全过)+ 十五节(工位物料叫料 8 条原话逐字留档与 Q1~Q17 拍板底稿) - 新增《工位终端页面.md》;案例.md 同步更新验收口径
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
"bj_power_mes/ent/station"
|
||||
|
||||
"bj_power_mes/ent/workorder"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// ============ B5 叫料池 + 叫料单(2026-10-13 定稿) ============
|
||||
@@ -773,6 +772,10 @@ func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []C
|
||||
"操作人["+operator+"] "+borrowDetail(bl.alloc, stationNo, bl.materialCode), nil)
|
||||
}
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(stationNo, "call.created", packageNo)
|
||||
if len(borrowLogs) > 0 {
|
||||
s.notifyStationMaterial(stationNo, "call.borrow", packageNo)
|
||||
}
|
||||
return created, nil
|
||||
}
|
||||
|
||||
@@ -849,6 +852,7 @@ func (s *Service) CancelCall(ctx context.Context, requestNo string, stationNo in
|
||||
s.ctx.EventLog.Write(ctx, "call.cancel", "", operator, "material_request", requestNo,
|
||||
cancelDesc, map[string]any{"stationNo": locked.StationNo, "materialCode": locked.MaterialCode})
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(locked.StationNo, "call.cancelled", requestNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -873,6 +877,7 @@ func (s *Service) MarkCallsDelivered(ctx context.Context, requestNos []string, o
|
||||
continue
|
||||
}
|
||||
changed++
|
||||
s.notifyStationMaterial(mr.StationNo, "call.delivered", no)
|
||||
}
|
||||
if changed > 0 {
|
||||
s.ctx.EventLog.Write(ctx, "call.delivered", operator, "", "material_request", strings.Join(requestNos, ","),
|
||||
@@ -907,6 +912,7 @@ func (s *Service) SignCall(ctx context.Context, requestNo string, stationNo int,
|
||||
// 由人工在 MES「AGV配送」页兜底)。
|
||||
s.releaseArrivedTransportOnSign(ctx, mr.StationNo, requestNo, operator)
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(mr.StationNo, "call.signed", requestNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1002,6 +1008,7 @@ func (s *Service) RejectCall(ctx context.Context, requestNo, reason, operator st
|
||||
rejectDesc, map[string]any{"stationNo": locked.StationNo, "materialCode": locked.MaterialCode,
|
||||
"reason": strings.TrimSpace(reason), "crossDay": locked.CrossDay})
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(locked.StationNo, "call.rejected", requestNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1022,26 +1029,14 @@ func (s *Service) RequestReturn(ctx context.Context, requestNo string, stationNo
|
||||
return errors.New("仅待签收(货到工位、签收前)的叫料单可拒收退库")
|
||||
}
|
||||
if s.ctx.Wms != nil {
|
||||
// 2026-11-28:拒收退库也走当场校验+当场派车(先校验,避免建了单却派不了车)
|
||||
if err := s.checkDockHasPalletHard(ctx, mr.TargetDock); err != nil {
|
||||
return err
|
||||
}
|
||||
if free, why := s.Jbt21Free(ctx); !free {
|
||||
return fmt.Errorf("库房接驳台暂无空位:%s", why)
|
||||
}
|
||||
// 2026-11-28 拍板 Q10:派车权收归库管。拒收只建退库单,不在此派车。
|
||||
// 2026-11-29:一次操作=一个退料包;拒收退为单件包,补写 RP 包号供流水按包聚合。
|
||||
returnNo, werr := s.ctx.Wms.CreateReturnOrder(ctx, "", "", mr.MaterialCode, mr.MaterialName, "",
|
||||
"叫料单退库", operator, mr.StationNo, int(mr.ReqQty), mr.Unit, requestNo, mr.TargetDock, "", "agv", nil)
|
||||
"叫料单退库", operator, mr.StationNo, int(mr.ReqQty), mr.Unit, requestNo, nextReturnPackageNo(), mr.TargetDock, "", "agv", nil)
|
||||
if werr != nil {
|
||||
return fmt.Errorf("通知 WMS 建退库单失败(%v)。本地单未退回、货还在工位,请到「同步失败台账」重试或重新发起退库", werr)
|
||||
}
|
||||
if derr := s.dispatchReturnOrderNow(ctx, returnNo, mr.TargetDock, operator); derr != nil {
|
||||
s.CreateAlert(ctx, "agv_dispatch_fail", "警告", returnNo,
|
||||
"退库单 "+returnNo+" 派车失败:"+derr.Error()+"(单据已建,请点重试派车)")
|
||||
} else {
|
||||
if merr := s.ctx.Wms.MarkReturnDispatched(ctx, returnNo); merr != nil {
|
||||
logx.Errorf("退库单 %s 派车标记回写失败: %v", returnNo, merr)
|
||||
}
|
||||
}
|
||||
_ = returnNo // 退库单已建、待库管在 WMS 派车
|
||||
} else {
|
||||
// 配置缺失(2026-11-08):不拒绝本地退库,但必须落预警中心,避免形成
|
||||
// 无对应 WMS 单据的孤儿 RETURNING 状态而不被业务人员察觉。
|
||||
@@ -1054,6 +1049,7 @@ func (s *Service) RequestReturn(ctx context.Context, requestNo string, stationNo
|
||||
s.ctx.EventLog.Write(ctx, "call.return_request", "", operator, "material_request", requestNo,
|
||||
"叫料单申请退库", map[string]any{"stationNo": mr.StationNo, "materialCode": mr.MaterialCode, "qty": mr.ReqQty})
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(mr.StationNo, "call.return_requested", requestNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1134,6 +1130,7 @@ func (s *Service) CompleteCall(ctx context.Context, requestNo string, sentQty fl
|
||||
completeDesc, map[string]any{"stationNo": locked.StationNo, "materialCode": locked.MaterialCode,
|
||||
"reqQty": locked.ReqQty, "sentQty": actual, "outboundNo": outboundNo})
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(locked.StationNo, "call.prepared", requestNo)
|
||||
// AGV 三段链(2026-11-03 定论修订):完成备料=托盘已备好在库房接驳台 → 仅写台账(hasPallet=true)。
|
||||
// 废除「备料完成自动派车」:库管在 WMS 叫料队列点「送货」(DispatchCallAgv)人工触发才下发空车段。
|
||||
if locked.NeedAgv && locked.TargetDock != "" {
|
||||
@@ -1142,6 +1139,140 @@ func (s *Service) CompleteCall(ctx context.Context, requestNo string, sentQty fl
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccumulateStationReturned 巡检/工位退料收货确认 → 已退累计(2026-11-28 对账铁律,17.6 裁决选项B)。
|
||||
// 这类退料不建 material_request、refNo 空、不回调 ConfirmReturn,故单独开回调直接累加实物账。
|
||||
// 幂等:按 WMS 退库单号查 event_log(call.station_return_accum),重复确认只累加一次。
|
||||
func (s *Service) AccumulateStationReturned(ctx context.Context, stationNo int, materialCode string, qty int, returnNo string) error {
|
||||
if stationNo <= 0 || materialCode == "" || qty <= 0 || returnNo == "" {
|
||||
return errors.New("工位/物料/数量/退库单号必填")
|
||||
}
|
||||
tx, terr := s.ctx.EntClient.Tx(ctx)
|
||||
if terr != nil {
|
||||
return terr
|
||||
}
|
||||
committed := false
|
||||
defer func() {
|
||||
if !committed {
|
||||
_ = tx.Rollback()
|
||||
}
|
||||
}()
|
||||
// 先锁池行,再查幂等日志:同一退库单的并发重放串行化,后到者能看到先到者的日志。
|
||||
poolRow, pErr := tx.CallPool.Query().Where(
|
||||
callpool.StationNo(stationNo), callpool.MaterialCode(materialCode),
|
||||
).ForUpdate().First(ctx)
|
||||
if pErr != nil || poolRow == nil {
|
||||
return nil // 无池行(虚拟工位/工艺已变更):不影响收货,仅不记账
|
||||
}
|
||||
exist, err := tx.EventLog.Query().Where(
|
||||
eventlog.EventTypeEQ("call.station_return_accum"), eventlog.EntityIdEQ(returnNo),
|
||||
).Exist(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if exist {
|
||||
return nil // 幂等:已累加过
|
||||
}
|
||||
if _, uErr := tx.CallPool.UpdateOneID(poolRow.ID).AddReturnedQty(qty).Save(ctx); uErr != nil {
|
||||
return uErr
|
||||
}
|
||||
if _, eErr := tx.EventLog.Create().
|
||||
SetEventType("call.station_return_accum").
|
||||
SetOperator("WMS").
|
||||
SetEntityType("return_order").
|
||||
SetEntityId(returnNo).
|
||||
SetDescription(fmt.Sprintf("巡检退料收货已退累计:工位%d %s +%d(退库单 %s)", stationNo, materialCode, qty, returnNo)).
|
||||
SetPayload(map[string]any{"stationNo": stationNo, "materialCode": materialCode, "qty": qty, "returnNo": returnNo}).
|
||||
Save(ctx); eErr != nil {
|
||||
return eErr
|
||||
}
|
||||
if cerr := tx.Commit(); cerr != nil {
|
||||
return cerr
|
||||
}
|
||||
committed = true
|
||||
s.notifyStationMaterial(stationNo, "return.received", returnNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
// StationReturnAdjustInput WMS 已收货的巡检/工位退料单修正数量后的 MES 同步入参。
|
||||
type StationReturnAdjustInput struct {
|
||||
ReturnNo string `json:"returnNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
Qty int `json:"qty"`
|
||||
BeforeQty int `json:"beforeQty"`
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
|
||||
// AdjustStationReturned 巡检/工位退料修正数量 → 按差额冲正 call_pool.returnedQty。
|
||||
// 这类退料没有 material_request,不能走 AdjustReturnAfterConfirm;按 returnNo+目标数量幂等。
|
||||
func (s *Service) AdjustStationReturned(ctx context.Context, in StationReturnAdjustInput) error {
|
||||
if in.ReturnNo == "" || in.StationNo <= 0 || in.MaterialCode == "" {
|
||||
return errors.New("退库单号/工位/物料必填")
|
||||
}
|
||||
if in.Qty <= 0 {
|
||||
return errors.New("修正数量必须大于 0")
|
||||
}
|
||||
if strings.TrimSpace(in.Reason) == "" {
|
||||
return errors.New("修正原因必填")
|
||||
}
|
||||
delta := in.Qty - in.BeforeQty
|
||||
if delta == 0 {
|
||||
return nil
|
||||
}
|
||||
idemKey := in.ReturnNo + "#" + strconv.Itoa(in.Qty)
|
||||
tx, terr := s.ctx.EntClient.Tx(ctx)
|
||||
if terr != nil {
|
||||
return terr
|
||||
}
|
||||
committed := false
|
||||
defer func() {
|
||||
if !committed {
|
||||
_ = tx.Rollback()
|
||||
}
|
||||
}()
|
||||
exists, e := tx.EventLog.Query().Where(
|
||||
eventlog.EventTypeEQ("call.station_return_adjust"), eventlog.EntityIdEQ(idemKey),
|
||||
).Exist(ctx)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if exists {
|
||||
return nil
|
||||
}
|
||||
poolRow, perr := tx.CallPool.Query().
|
||||
Where(callpool.StationNo(in.StationNo), callpool.MaterialCode(in.MaterialCode)).
|
||||
ForUpdate().First(ctx)
|
||||
if perr != nil || poolRow == nil {
|
||||
return nil // 无池行(虚拟工位/工艺已变更):不影响 WMS 修正,仅不记账
|
||||
}
|
||||
next := poolRow.ReturnedQty + delta
|
||||
if next < 0 {
|
||||
next = 0
|
||||
}
|
||||
if _, ue := tx.CallPool.UpdateOneID(poolRow.ID).SetReturnedQty(next).Save(ctx); ue != nil {
|
||||
return ue
|
||||
}
|
||||
if _, ee := tx.EventLog.Create().
|
||||
SetEventType("call.station_return_adjust").
|
||||
SetOperator(in.Operator).
|
||||
SetEntityType("return_order").
|
||||
SetEntityId(idemKey).
|
||||
SetDescription(fmt.Sprintf("巡检退料修正数量:%d→%d(差额%+d)原因:%s", in.BeforeQty, in.Qty, delta, strings.TrimSpace(in.Reason))).
|
||||
SetPayload(map[string]any{
|
||||
"returnNo": in.ReturnNo, "stationNo": in.StationNo, "materialCode": in.MaterialCode,
|
||||
"targetQty": in.Qty, "beforeQty": in.BeforeQty, "delta": delta, "reason": in.Reason,
|
||||
}).Save(ctx); ee != nil {
|
||||
return ee
|
||||
}
|
||||
if cerr := tx.Commit(); cerr != nil {
|
||||
return cerr
|
||||
}
|
||||
committed = true
|
||||
s.notifyStationMaterial(in.StationNo, "return.adjusted", in.ReturnNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfirmReturn 仓库确认收回(退库闭环终点):RETURNING → RETURNED,
|
||||
// 按库管实收量回补(R18 2026-11-03 拍板:实收<应退为收货差异,按实收回补额度;
|
||||
// 差异落「待核」,不自动进损耗台账——以库管真实核算为准,核实为损耗后由主管走损耗登记挂工单)。
|
||||
@@ -1186,6 +1317,11 @@ func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string,
|
||||
alloc = map[string]int{strconv.Itoa(locked.StationNo): int(ret)}
|
||||
}
|
||||
back := distributeAmount(int(ret), alloc)
|
||||
// 2026-11-28 对账铁律(17.6 裁决):
|
||||
// 额度账(sentQty)按 alloc 冲减,借出方额度一并回补;
|
||||
// 实物账(receivedQty/returnedQty)只记物理到货/退货的借入方工位,不能按 alloc 分摊,
|
||||
// 否则借料场景会把借出方(实收=0)的已收/已退记到不存在的实物上。
|
||||
isReject := locked.Source == "CALL"
|
||||
for src, amt := range back {
|
||||
srcNo, e := strconv.Atoi(src)
|
||||
if e != nil {
|
||||
@@ -1200,6 +1336,26 @@ func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string,
|
||||
}
|
||||
}
|
||||
}
|
||||
physical, perr := tx.CallPool.Query().
|
||||
Where(callpool.StationNo(locked.StationNo), callpool.MaterialCode(locked.MaterialCode)).
|
||||
ForUpdate().First(ctx)
|
||||
retInt := int(math.Round(ret))
|
||||
if perr == nil && physical != nil {
|
||||
if isReject {
|
||||
// 拒收冲减已收,floor 0 兜底:已收不会小于 0(防迟到回调/部分场景重复冲)
|
||||
sub := retInt
|
||||
if physical.ReceivedQty < sub {
|
||||
sub = physical.ReceivedQty
|
||||
}
|
||||
if sub > 0 {
|
||||
if _, uerr := tx.CallPool.UpdateOneID(physical.ID).AddReceivedQty(-sub).Save(ctx); uerr != nil {
|
||||
return uerr
|
||||
}
|
||||
}
|
||||
} else if _, uerr := tx.CallPool.UpdateOneID(physical.ID).AddReturnedQty(retInt).Save(ctx); uerr != nil {
|
||||
return uerr
|
||||
}
|
||||
}
|
||||
if _, uerr := tx.MaterialRequest.UpdateOneID(locked.ID).
|
||||
SetStatus("RETURNED").SetReturnedQty(ret).
|
||||
SetReceiveQty(ret).SetReceiveDiff(receiveDiff).SetReceiveNote(receiveNote).Save(ctx); uerr != nil {
|
||||
@@ -1223,6 +1379,7 @@ func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string,
|
||||
// 事件驱动收口:退料收货后检查 CLOSING 班次可否置 CLOSED(下班闭环,2026-11-03)
|
||||
s.maybeCloseShifts(ctx)
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(locked.StationNo, "return.received", requestNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1329,6 +1486,30 @@ func (s *Service) AdjustReturnAfterConfirm(ctx context.Context, in ReturnAdjustI
|
||||
return ue
|
||||
}
|
||||
}
|
||||
// 实物账同 ConfirmReturn 口径:拒收调 receivedQty,转产/下班调 returnedQty,
|
||||
// 且只落在物理工位 locked.StationNo,不按借料 alloc 分摊。
|
||||
physical, pe := tx.CallPool.Query().
|
||||
Where(callpool.StationNo(locked.StationNo), callpool.MaterialCode(locked.MaterialCode)).
|
||||
ForUpdate().First(ctx)
|
||||
if pe == nil && physical != nil {
|
||||
if locked.Source == "CALL" {
|
||||
next := physical.ReceivedQty - delta
|
||||
if next < 0 {
|
||||
next = 0
|
||||
}
|
||||
if _, ue := tx.CallPool.UpdateOneID(physical.ID).SetReceivedQty(next).Save(ctx); ue != nil {
|
||||
return ue
|
||||
}
|
||||
} else {
|
||||
next := physical.ReturnedQty + delta
|
||||
if next < 0 {
|
||||
next = 0
|
||||
}
|
||||
if _, ue := tx.CallPool.UpdateOneID(physical.ID).SetReturnedQty(next).Save(ctx); ue != nil {
|
||||
return ue
|
||||
}
|
||||
}
|
||||
}
|
||||
materialName := strings.TrimSpace(in.MaterialName)
|
||||
if materialName == "" {
|
||||
materialName = locked.MaterialName
|
||||
@@ -1382,6 +1563,7 @@ func (s *Service) AdjustReturnAfterConfirm(ctx context.Context, in ReturnAdjustI
|
||||
}
|
||||
committed = true
|
||||
s.notifyDashboard()
|
||||
s.notifyStationMaterial(locked.StationNo, "return.adjusted", in.ReturnNo)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user