feat: 实现工位终端滑动续签机制,强化安全与身份追溯
- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期 - 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度 - 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题 - 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险 - 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件 - 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
This commit is contained in:
@@ -255,6 +255,9 @@ func (s *Service) AutoOutboundRequests(ctx context.Context, planDate, orderNo, o
|
||||
if mr.Source == "REFILL" {
|
||||
obType = "refill"
|
||||
}
|
||||
// C2 幂等键轮次:同一备料单每次 StockDeduct 调用用稳定唯一键,
|
||||
// 网络超时重试时 WMS 按键复用已生成的出库单,杜绝重复扣减。
|
||||
round := 0
|
||||
opts := wmsclient.StockDeductOpts{
|
||||
Qty: need, Operator: operator, TargetDock: dock,
|
||||
OutboundType: obType, NeedAgv: mr.NeedAgv, OverReason: mr.OverReason,
|
||||
@@ -264,10 +267,12 @@ func (s *Service) AutoOutboundRequests(ctx context.Context, planDate, orderNo, o
|
||||
if remain <= 0 {
|
||||
break
|
||||
}
|
||||
round++
|
||||
opts.SnList = []string{sn}
|
||||
opts.BatchNo = ""
|
||||
opts.Qty = 1
|
||||
no, _, e := s.ctx.Wms.StockDeduct(ctx, mr.OrderNo, mr.MaterialCode, opts)
|
||||
opts.IdempotencyKey = fmt.Sprintf("IDEM-%s-%s-%s-%d", mr.OrderNo, mr.MaterialCode, sn, round)
|
||||
no, _, _, e := s.ctx.Wms.StockDeduct(ctx, mr.OrderNo, mr.MaterialCode, opts)
|
||||
if e != nil {
|
||||
break
|
||||
}
|
||||
@@ -286,11 +291,13 @@ func (s *Service) AutoOutboundRequests(ctx context.Context, planDate, orderNo, o
|
||||
if take <= 0 {
|
||||
continue
|
||||
}
|
||||
round++
|
||||
opts.SnList = nil
|
||||
opts.BatchNo = b.BatchNo
|
||||
opts.Qty = take
|
||||
opts.ZoneCode = b.ZoneCode
|
||||
no, _, e := s.ctx.Wms.StockDeduct(ctx, mr.OrderNo, mr.MaterialCode, opts)
|
||||
opts.IdempotencyKey = fmt.Sprintf("IDEM-%s-%s-%s-%d", mr.OrderNo, mr.MaterialCode, b.BatchNo, round)
|
||||
no, _, _, e := s.ctx.Wms.StockDeduct(ctx, mr.OrderNo, mr.MaterialCode, opts)
|
||||
if e != nil {
|
||||
break
|
||||
}
|
||||
@@ -300,15 +307,47 @@ func (s *Service) AutoOutboundRequests(ctx context.Context, planDate, orderNo, o
|
||||
}
|
||||
sent := need - remain
|
||||
if sent > 0 {
|
||||
upd := s.ctx.EntClient.MaterialRequest.UpdateOneID(mr.ID).AddSentQty(float64(sent))
|
||||
if remain == 0 {
|
||||
// 出库量已达标:备料完成,等 AGV 配送(WMS 下发后回写 DELIVERING)
|
||||
upd = upd.SetStatus("LOCKED")
|
||||
done++
|
||||
// C3 行锁 + 钳制:在事务内锁定该行后重读 sentQty 并重算,避免并发/重试重复累计;
|
||||
// 以 reqQty 为上限钳制,杜绝超出 BOM 需求量的虚高计数(网络重试幂等复用场景下尤其关键)。
|
||||
applied := false
|
||||
if tx, txErr := s.ctx.EntClient.Tx(ctx); txErr == nil {
|
||||
locked, lErr := tx.MaterialRequest.Query().
|
||||
Where(materialrequest.ID(mr.ID)).ForUpdate().Only(ctx)
|
||||
if lErr == nil {
|
||||
newSent := locked.SentQty + float64(sent)
|
||||
if newSent > locked.ReqQty {
|
||||
newSent = locked.ReqQty // 钳制到需求量上限
|
||||
}
|
||||
upd := tx.MaterialRequest.UpdateOneID(locked.ID).SetSentQty(newSent)
|
||||
if remain == 0 {
|
||||
// 出库量已达标:备料完成,等 AGV 配送(WMS 下发后回写 DELIVERING)
|
||||
upd = upd.SetStatus("LOCKED")
|
||||
}
|
||||
if _, e := upd.Save(ctx); e == nil {
|
||||
_ = tx.Commit()
|
||||
applied = true
|
||||
if remain == 0 {
|
||||
done++
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "material.outbound.auto", mr.OrderNo, operator, "material_request", mr.RequestNo,
|
||||
"备料自动出库", map[string]any{"materialCode": mr.MaterialCode, "qty": sent, "outboundNos": strings.Join(outboundNos, ",")})
|
||||
}
|
||||
}
|
||||
if !applied {
|
||||
_ = tx.Rollback()
|
||||
}
|
||||
}
|
||||
if _, e := upd.Save(ctx); e == nil {
|
||||
s.ctx.EventLog.Write(ctx, "material.outbound.auto", mr.OrderNo, operator, "material_request", mr.RequestNo,
|
||||
"备料自动出库", map[string]any{"materialCode": mr.MaterialCode, "qty": sent, "outboundNos": strings.Join(outboundNos, ",")})
|
||||
if !applied {
|
||||
// 行锁事务不可用时的兜底:直接原子累加(并发下仍有极小概率重复累计,由 WMS 幂等键兜底扣减)
|
||||
upd := s.ctx.EntClient.MaterialRequest.UpdateOneID(mr.ID).AddSentQty(float64(sent))
|
||||
if remain == 0 {
|
||||
upd = upd.SetStatus("LOCKED")
|
||||
done++
|
||||
}
|
||||
if _, e := upd.Save(ctx); e == nil {
|
||||
s.ctx.EventLog.Write(ctx, "material.outbound.auto", mr.OrderNo, operator, "material_request", mr.RequestNo,
|
||||
"备料自动出库", map[string]any{"materialCode": mr.MaterialCode, "qty": sent, "outboundNos": strings.Join(outboundNos, ",")})
|
||||
}
|
||||
}
|
||||
}
|
||||
if remain > 0 {
|
||||
|
||||
Reference in New Issue
Block a user