feat: 新增产品工艺管理与工序审核功能
- 新增产品工艺(product_process)及明细(product_process_item)数据模型 - 新增工序审核开关(need_audit)与审核角色(audit_role)字段 - 新增待审核签字页面与路由 - 优化 WMS/MES 接口交互,增加业务错误处理与友好提示 - 补充库存过滤逻辑,避免返回已出库 SN 数据 - 调整默认查询时间范围为近一个月,优化用户体验
This commit is contained in:
@@ -231,11 +231,19 @@ type importErr struct {
|
||||
}
|
||||
|
||||
// excelInboundHandler Excel 批量导入入库
|
||||
// mode=batch(批次件):列头(首行忽略) 图号 | 批次号(可空自动生成) | 数量 | 生产日期 | 供应商 | 区域 | 备注
|
||||
// mode=sn(序列号件): 列头(首行忽略) 图号 | SN | 区域 | 生产日期 | 供应商
|
||||
// mode=batch(批次件) 列头(首行忽略):
|
||||
//
|
||||
// 图号 | 批次号(可空自动生成) | 数量 | 生产日期 | 供应商 | 区域 | 架 | 层 | 位 | 备注 | 检测单号 | 产品工号 | 归属类型 | 归属编号
|
||||
//
|
||||
// mode=sn(序列号件) 列头(首行忽略):
|
||||
//
|
||||
// 图号 | SN | 区域 | 生产日期 | 供应商 | 架 | 层 | 位 | 备注 | 检测单号 | 产品工号 | 归属类型 | 归属编号
|
||||
//
|
||||
// 新增列(架/层/位/备注/检测单号/产品工号/归属) 均为【可选、追加在末尾】,老模板文件缺这些列仍可导入(对应字段留空)。
|
||||
// 归属类型填 workorder/project/other(其他值按 other 处理);workorder/project 必须同时填归属编号,other 可不填。
|
||||
//
|
||||
// 强约束:全成功或全失败(一次性全导入 or 全失败,禁止部分成功)。
|
||||
// 流程:阶段1 逐行解析+校验(物料存在/数量>0/SN不重复/区域必填) → 任一错则整体拒绝并列出错误行(一行不写);
|
||||
// 流程:阶段1 逐行解析+校验(物料存在/数量>0/SN不重复/区域必填/归属编号规则) → 任一错则整体拒绝并列出错误行(一行不写);
|
||||
// 阶段2 全部通过 → 开启单事务,整体提交,任一步失败整体回滚。
|
||||
func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -272,15 +280,22 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
type planRow struct {
|
||||
row int
|
||||
code string
|
||||
batchNo string
|
||||
sn string
|
||||
qty int
|
||||
prodDate string
|
||||
supplier string
|
||||
zone string
|
||||
remark string
|
||||
row int
|
||||
code string
|
||||
batchNo string
|
||||
sn string
|
||||
qty int
|
||||
prodDate string
|
||||
supplier string
|
||||
zone string
|
||||
remark string
|
||||
shelfNo string
|
||||
layerNo string
|
||||
positionNo string
|
||||
inspectionNo string
|
||||
productWorkNo string
|
||||
ownershipType string
|
||||
ownershipNo string
|
||||
}
|
||||
plans := make([]planRow, 0, len(rows)-1)
|
||||
errs := make([]importErr, 0)
|
||||
@@ -300,18 +315,34 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
pr := planRow{row: i + 1}
|
||||
pr.code = cell(0)
|
||||
if mode == "sn" {
|
||||
// 图号|SN|区域|生产日期|供应商|架|层|位|备注|检测单号|产品工号|归属类型|归属编号
|
||||
pr.sn = cell(1)
|
||||
pr.zone = cell(2) // 序列号件模板: 图号|SN|区域|生产日期|供应商
|
||||
pr.zone = cell(2)
|
||||
pr.prodDate = cell(3)
|
||||
pr.supplier = cell(4)
|
||||
pr.remark = cell(4)
|
||||
pr.shelfNo = cell(5)
|
||||
pr.layerNo = cell(6)
|
||||
pr.positionNo = cell(7)
|
||||
pr.remark = cell(8)
|
||||
pr.inspectionNo = cell(9)
|
||||
pr.productWorkNo = cell(10)
|
||||
pr.ownershipType = cell(11)
|
||||
pr.ownershipNo = cell(12)
|
||||
} else {
|
||||
// 图号|批次号|数量|生产日期|供应商|区域|架|层|位|备注|检测单号|产品工号|归属类型|归属编号
|
||||
pr.batchNo = cell(1)
|
||||
pr.qty = atoi(cell(2), 0)
|
||||
pr.prodDate = cell(3)
|
||||
pr.supplier = cell(4)
|
||||
pr.zone = cell(5) // 批次件模板: 图号|批次号|数量|生产日期|供应商|区域|备注
|
||||
pr.remark = cell(6)
|
||||
pr.zone = cell(5)
|
||||
pr.shelfNo = cell(6)
|
||||
pr.layerNo = cell(7)
|
||||
pr.positionNo = cell(8)
|
||||
pr.remark = cell(9)
|
||||
pr.inspectionNo = cell(10)
|
||||
pr.productWorkNo = cell(11)
|
||||
pr.ownershipType = cell(12)
|
||||
pr.ownershipNo = cell(13)
|
||||
}
|
||||
|
||||
if pr.code == "" {
|
||||
@@ -357,6 +388,14 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "区域为空(必填)"})
|
||||
continue
|
||||
}
|
||||
// 归属校验(与手动录入口径一致:workorder/project 必填编号;other/空 不需要)
|
||||
pr.ownershipType = ownershipTypeOrNone(pr.ownershipType)
|
||||
if pr.ownershipType == "workorder" || pr.ownershipType == "project" {
|
||||
if pr.ownershipNo == "" {
|
||||
errs = append(errs, importErr{pr.row, pr.code, "归属类型为" + pr.ownershipType + "时归属编号必填"})
|
||||
continue
|
||||
}
|
||||
}
|
||||
plans = append(plans, pr)
|
||||
}
|
||||
|
||||
@@ -396,6 +435,12 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
SetNillableProductionDate(strPtr(pr.prodDate)).
|
||||
SetNillableSupplier(strPtr(pr.supplier)).
|
||||
SetNillableZoneCode(strPtr(pr.zone)).
|
||||
SetNillableShelfNo(strPtr(pr.shelfNo)).
|
||||
SetNillableLayerNo(strPtr(pr.layerNo)).
|
||||
SetNillablePositionNo(strPtr(pr.positionNo)).
|
||||
SetNillableProductWorkNo(strPtr(pr.productWorkNo)).
|
||||
SetNillableOwnershipType(strPtr(pr.ownershipType)).
|
||||
SetNillableOwnershipNo(strPtr(pr.ownershipNo)).
|
||||
SetStatus("在库").
|
||||
SetInboundNo(inboundNo).
|
||||
Save(ctx0()); e != nil {
|
||||
@@ -420,6 +465,10 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
if _, e = tx.Inventory.UpdateOneID(existing.ID).
|
||||
AddQuantity(pr.qty).
|
||||
SetNillableSupplier(strPtr(pr.supplier)).
|
||||
SetNillableProductWorkNo(strPtr(pr.productWorkNo)).
|
||||
SetNillableShelfNo(strPtr(pr.shelfNo)).
|
||||
SetNillableLayerNo(strPtr(pr.layerNo)).
|
||||
SetNillablePositionNo(strPtr(pr.positionNo)).
|
||||
Save(ctx0()); e != nil {
|
||||
fail(w, http.StatusInternalServerError, "追加批次失败: "+e.Error())
|
||||
return
|
||||
@@ -436,6 +485,12 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
SetNillableSupplier(strPtr(pr.supplier)).
|
||||
SetQualityStatus("未检").
|
||||
SetNillableZoneCode(strPtr(pr.zone)).
|
||||
SetNillableShelfNo(strPtr(pr.shelfNo)).
|
||||
SetNillableLayerNo(strPtr(pr.layerNo)).
|
||||
SetNillablePositionNo(strPtr(pr.positionNo)).
|
||||
SetNillableProductWorkNo(strPtr(pr.productWorkNo)).
|
||||
SetNillableOwnershipType(strPtr(pr.ownershipType)).
|
||||
SetNillableOwnershipNo(strPtr(pr.ownershipNo)).
|
||||
SetStatus("在库").
|
||||
SetInboundNo(inboundNo).
|
||||
Save(ctx0()); e != nil {
|
||||
@@ -458,8 +513,16 @@ func excelInboundHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
SetManageMode(m.ManageMode).
|
||||
SetSnMode(m.SnMode).
|
||||
SetNillableZoneCode(strPtr(pr.zone)).
|
||||
SetNillableShelfNo(strPtr(pr.shelfNo)).
|
||||
SetNillableLayerNo(strPtr(pr.layerNo)).
|
||||
SetNillablePositionNo(strPtr(pr.positionNo)).
|
||||
SetQuantity(ternary(mode == "sn", 1, pr.qty)).
|
||||
SetNillableRemark(strPtr(pr.remark)).
|
||||
SetInspectionNo(pr.inspectionNo).
|
||||
SetOwnershipType(ownershipTypeOrNone(pr.ownershipType)).
|
||||
SetNillableOwnershipNo(strPtr(pr.ownershipNo)).
|
||||
SetNillableProductWorkNo(strPtr(pr.productWorkNo)).
|
||||
SetNillableQualityStatus(strPtr("未检")).
|
||||
SetOperator("excel-import").
|
||||
Save(ctx0()); e != nil {
|
||||
fail(w, http.StatusInternalServerError, "创建入库单失败: "+e.Error())
|
||||
|
||||
@@ -456,6 +456,46 @@ func materialTypesHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// materialManageModesHandler 内部接口:批量查询物料「类型」(manage_mode: 1结构件/2电气件/3其他)。
|
||||
// 与 materialTypesHandler(品类 item_type)相互独立:品类=成品/组件类,类型=结构件/电气件/其他。
|
||||
// body: {"codes":["A","B"]} → data: {"manageModes": {"A":1}}(不存在的编码不返回)。
|
||||
func materialManageModesHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Codes []string `json:"codes"`
|
||||
}
|
||||
if err := parseJSON(r, &req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "参数错误")
|
||||
return
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
codes := []string{}
|
||||
for _, c := range req.Codes {
|
||||
c = strings.TrimSpace(c)
|
||||
if c == "" || seen[c] {
|
||||
continue
|
||||
}
|
||||
seen[c] = true
|
||||
codes = append(codes, c)
|
||||
}
|
||||
mm := map[string]int{}
|
||||
if len(codes) > 0 {
|
||||
list, err := ctx.EntClient.Material.Query().
|
||||
Where(material.CodeIn(codes...)).
|
||||
Select(material.FieldCode, material.FieldManageMode).
|
||||
All(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, "查询物料类型失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
for _, m := range list {
|
||||
mm[m.Code] = m.ManageMode
|
||||
}
|
||||
}
|
||||
ok(w, map[string]any{"manageModes": mm})
|
||||
}
|
||||
}
|
||||
|
||||
// materialExistsHandler 内部接口:批量校验物料编码是否存在于物料档案。
|
||||
// body: {"codes":["A","B"]} → data: {"missing":["B"]}(不存在于档案的编码列表)。
|
||||
// 供 MES 备料单生成前防呆使用(wrapInternal + X-API-TOKEN 保护)。
|
||||
|
||||
@@ -262,6 +262,7 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodPost, Path: "/api/internal/materials/upsert", Handler: wrapInternal(ctx)(upsertMaterialInternalHandler(ctx))},
|
||||
{Method: http.MethodPost, Path: "/api/internal/material/exists", Handler: wrapInternal(ctx)(materialExistsHandler(ctx))},
|
||||
{Method: http.MethodPost, Path: "/api/internal/material/types", Handler: wrapInternal(ctx)(materialTypesHandler(ctx))},
|
||||
{Method: http.MethodPost, Path: "/api/internal/material/manage-modes", Handler: wrapInternal(ctx)(materialManageModesHandler(ctx))},
|
||||
// 物料分页查询(需求一 M7:MES 冷启动全量拉取用;MES 推送走上方 /upsert)
|
||||
{Method: http.MethodGet, Path: "/api/internal/materials", Handler: wrapInternal(ctx)(queryMaterialsHandler(ctx))},
|
||||
{Method: http.MethodGet, Path: "/api/internal/material/list-all", Handler: wrapInternal(ctx)(listMaterialsHandler(ctx))},
|
||||
|
||||
@@ -1406,6 +1406,10 @@ func listStockBatchesInternalHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
inventory.MaterialCodeEQ(materialCode),
|
||||
inventory.QuantityGT(0),
|
||||
inventory.QualityStatusIn(QStatusPass, QStatusConcession),
|
||||
// 仅「在库」可出库:SN 行出库走状态机(status 置「出库」)而 quantity 仍为 1,
|
||||
// 缺此过滤会把已出库 SN 误返回,MES 自动备料逐颗尝试时第一颗即失败(AITEST 闭环实测缺陷)。
|
||||
// 盘点冻结(锁定)行也不返回:与 stock/deduct 的冻结守卫口径一致,避免 MES 撞拦截。
|
||||
inventory.StatusEQ("在库"),
|
||||
)
|
||||
if zc := strings.TrimSpace(r.URL.Query().Get("zoneCode")); zc != "" {
|
||||
q = q.Where(inventory.ZoneCodeEQ(zc))
|
||||
|
||||
Reference in New Issue
Block a user