feat: 实现工位终端滑动续签机制,强化安全与身份追溯
- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期 - 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度 - 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题 - 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险 - 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件 - 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
This commit is contained in:
@@ -32,19 +32,9 @@ func createFinishedInventory(ctx *svc.ServiceContext, req *finishedInboundReques
|
||||
if req.Sn == "" || req.ProductCode == "" {
|
||||
return nil, http.StatusBadRequest, errors.New("sn 与 productCode 必填")
|
||||
}
|
||||
quality := req.QualityStatus
|
||||
if quality == "" {
|
||||
// 未显式传质量状态时按产品状态派生(方案A契约:已通过→合格 / 部分通过→合格 / 返修→不合格),
|
||||
// 显式传入的值仍尊重不覆盖。
|
||||
switch req.ProductStatus {
|
||||
case "部分通过":
|
||||
quality = QStatusPass
|
||||
case "返修":
|
||||
quality = "不合格"
|
||||
default:
|
||||
quality = QStatusPass
|
||||
}
|
||||
}
|
||||
// 质量状态归一:合法枚举值原样尊重;空值或非枚举值(如 MES 误传「已通过/部分通过」)按产品状态派生兜底,
|
||||
// 避免脏值落库(库存质量状态仅认 合格/不合格/让步接收/未检/待退)。
|
||||
quality := normalizeQualityStatus(req.QualityStatus, req.ProductStatus)
|
||||
|
||||
// SN 全局防重(同品类成品 + 半成品 + 序列号件 SN 都不允许撞号)
|
||||
dup, err := ctx.EntClient.Inventory.Query().
|
||||
@@ -113,6 +103,9 @@ func createFinishedInventory(ctx *svc.ServiceContext, req *finishedInboundReques
|
||||
SetRemark(remark).
|
||||
Save(ctx0())
|
||||
if err != nil {
|
||||
if isUniqueViolation(err) {
|
||||
return nil, http.StatusConflict, errors.New("成品 SN 已存在库存: " + req.Sn)
|
||||
}
|
||||
return nil, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
@@ -126,6 +119,35 @@ func createFinishedInventory(ctx *svc.ServiceContext, req *finishedInboundReques
|
||||
return rec, 0, nil
|
||||
}
|
||||
|
||||
// normalizeQualityStatus 归一成品入库质量状态:合法枚举值原样尊重;空值或非库存枚举值
|
||||
// (如 MES 误传「已通过/部分通过」等业务态)按产品状态派生兜底,防止脏值落库。
|
||||
func normalizeQualityStatus(quality, productStatus string) string {
|
||||
switch quality {
|
||||
case QStatusPending, QStatusPass, QStatusFail, QStatusReturn, QStatusConcession:
|
||||
return quality
|
||||
}
|
||||
switch productStatus {
|
||||
case "部分通过", "已通过":
|
||||
return QStatusPass
|
||||
case "返修":
|
||||
return QStatusFail
|
||||
default:
|
||||
return QStatusPass
|
||||
}
|
||||
}
|
||||
|
||||
// isUniqueViolation 判定 DB 错误是否唯一约束冲突(部分唯一索引 ux_inventories_sn_code 等)。
|
||||
// 用错误文本匹配,避免强依赖 lib/pq(当前为 indirect 依赖)。
|
||||
func isUniqueViolation(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
msg := strings.ToLower(err.Error())
|
||||
return strings.Contains(msg, "ux_inventories_sn_code") ||
|
||||
strings.Contains(msg, "duplicate key") ||
|
||||
strings.Contains(msg, "violates unique constraint")
|
||||
}
|
||||
|
||||
// manualFinishedInboundHandler POST /api/finished/inbound 手工成品入库(登录态,权限 wms.finished:edit)。
|
||||
// 与 MES 完工回流共享创建逻辑(createFinishedInventory);差异仅在必填校验:
|
||||
// SN/产品编码/产品状态/记录员必填,记录日期默认今天;成功返回库存行。
|
||||
|
||||
Reference in New Issue
Block a user