feat: 实现工位终端滑动续签机制,强化安全与身份追溯
- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期 - 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度 - 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题 - 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险 - 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件 - 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
This commit is contained in:
@@ -45,6 +45,10 @@ type deductStockRequest struct {
|
||||
// OverReason 超 BOM 领用原因(损耗/报废/返修/其他)。
|
||||
// 超领不硬卡:net_out > 需求时,填了原因即放行并留痕;未填仍 409 拦截。
|
||||
OverReason string `json:"overReason"`
|
||||
// IdempotencyKey 幂等键(安全审计 C2):调用方(如 MES 备料自动出库网络超时重试)
|
||||
// 传入稳定唯一键,同一键重复提交直接复用已生成的出库单,避免重复扣减库存。
|
||||
// 留空则按 OutboundNo 规则(手填校验唯一 / 留空自动生成)处理。
|
||||
IdempotencyKey string `json:"idempotencyKey"`
|
||||
}
|
||||
|
||||
// deductStockHandler 出库扣减
|
||||
@@ -107,12 +111,30 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
outboundNo := strings.TrimSpace(req.OutboundNo)
|
||||
// C2 幂等键(安全审计):调用方传入幂等键(如 MES 自动出库超时重试),
|
||||
// 同一键重复提交直接复用已生成的出库单,避免重复扣减库存。
|
||||
outboundNo := strings.TrimSpace(req.IdempotencyKey)
|
||||
if outboundNo != "" {
|
||||
if err := validateUniqueNo(ctx, "OB", outboundNo); err != nil {
|
||||
if exist, e := ctx.EntClient.OutboundOrder.Query().
|
||||
Where(outboundorder.OutboundNoEQ(outboundNo)).Only(ctx0()); e == nil && exist != nil {
|
||||
// 幂等复用:该出库请求此前已处理,直接返回既有单据与状态,不再扣减。
|
||||
ok(w, map[string]any{
|
||||
"outboundNo": outboundNo,
|
||||
"qty": exist.Quantity,
|
||||
"orderNo": req.OrderNo,
|
||||
"outboundType": exist.OutboundType,
|
||||
"status": exist.Status,
|
||||
"idempotent": true,
|
||||
"message": "幂等复用:该出库请求此前已处理",
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if obNo := strings.TrimSpace(req.OutboundNo); obNo != "" {
|
||||
if err := validateUniqueNo(ctx, "OB", obNo); err != nil {
|
||||
fail(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
outboundNo = obNo
|
||||
} else {
|
||||
no, err := nextDailyNo(ctx, "OB")
|
||||
if err != nil {
|
||||
@@ -167,6 +189,22 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
SetNillableRemark(strPtr(req.Remark)).
|
||||
Save(ctx0())
|
||||
if err != nil {
|
||||
// 并发幂等:另一条相同幂等键/单号的请求已抢先落库,复用其单号返回。
|
||||
if isDuplicateOutboundNo(err) {
|
||||
if exist, e2 := ctx.EntClient.OutboundOrder.Query().
|
||||
Where(outboundorder.OutboundNoEQ(outboundNo)).Only(ctx0()); e2 == nil && exist != nil {
|
||||
ok(w, map[string]any{
|
||||
"outboundNo": outboundNo,
|
||||
"qty": exist.Quantity,
|
||||
"orderNo": req.OrderNo,
|
||||
"outboundType": exist.OutboundType,
|
||||
"status": exist.Status,
|
||||
"idempotent": true,
|
||||
"message": "幂等复用:该出库请求此前已处理",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
fail(w, http.StatusInternalServerError, "创建出库单失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
@@ -299,8 +337,10 @@ func deductStockHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
status = "进行中"
|
||||
}
|
||||
// 台账 completed_at = 最后一笔领料完结出库时间(客户诉求 问题记录 L238-240:台账增加完成时间筛选)
|
||||
// 台账 out_qty 用原子自增(AddOutQty)替代「读改写绝对赋值」,消除并发丢失更新
|
||||
//(C1:原 newOutQty = ledgerNow.OutQty + actualQty 再 SetOutQty 在并发下会少计)。
|
||||
ledgerUpd := tx.OrderMaterialLedger.UpdateOneID(ledgerNow.ID).
|
||||
SetOutQty(newOutQty).
|
||||
AddOutQty(actualQty).
|
||||
SetStatus(status)
|
||||
if status == "领料完结" && ledgerNow.Status != "领料完结" {
|
||||
ledgerUpd.SetCompletedAt(time.Now().Unix())
|
||||
@@ -822,6 +862,18 @@ func min(a, b int) int {
|
||||
return b
|
||||
}
|
||||
|
||||
// isDuplicateOutboundNo 判定 DB 错误是否唯一约束冲突(出库单号 ux_outbound_orders_outbound_no)。
|
||||
// 用于幂等键并发落库时把 500 转为幂等复用,避免重复扣减。
|
||||
func isDuplicateOutboundNo(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
msg := strings.ToLower(err.Error())
|
||||
return strings.Contains(msg, "ux_outbound_orders_outbound_no") ||
|
||||
strings.Contains(msg, "duplicate key") ||
|
||||
strings.Contains(msg, "violates unique constraint")
|
||||
}
|
||||
|
||||
// locationText 库位展示串。入库/出库/库存统一口径:`Z02 A架/3层/12位`,无内容返回空串。
|
||||
// outboundLocationFallback 出库四级库位兜底(客户诉求 一.9「出库相同」)。
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user