feat: 完成客户第12条需求+多系统改造
1. 新增预警表添加工单号字段,支持按工单号检索预警 2. 添加工单过滤在制品/绩效报表/预警中心查询 3. 补全WMS台账字段口径与权限配置 4. 修复备料单与数量不符处理流程 5. 新增配送进度/库位联动/自动出库功能 6. 修复AGV配送状态更新逻辑 7. 优化退料与库存管理细节
This commit is contained in:
@@ -302,47 +302,18 @@ func (s *Service) BuildBindTrace(ctx context.Context, sn string) (*BindTraceVO,
|
||||
// 避免成品作零部件被引用时只显示上层成品而漏下层料、追溯断链。
|
||||
var tree []BindNode
|
||||
if _, wo, perr := s.workpieceProduct(ctx, s.ctx.EntClient, sn); perr == nil && wo != nil {
|
||||
tree = s.expandBindBom(ctx, s.ctx.EntClient, wo.ProductCode, "", 1, 0, map[string]bool{})
|
||||
tree = s.expandBindBom(ctx, wo.ProductCode, "", 1, 0, map[string]bool{})
|
||||
}
|
||||
return &BindTraceVO{Binds: binds, Complete: missing == "", Missing: missing, BomTree: tree}, nil
|
||||
}
|
||||
|
||||
// expandBindBom 递归展开某产品的物料组成树(成品/装配件若存在下级 BOM 则继续展开,叶子终止)。
|
||||
// 不依赖 WMS:用 BomItem 是否存在 productCode 记录判断是否有下级 BOM,避免 WMS 不可达时不展开。
|
||||
// 防环:同一条展开路径出现重复编码视为配置错误,跳过该分支。
|
||||
func (s *Service) expandBindBom(ctx context.Context, client *ent.Client, productCode, bomName string, qty float64, depth int, path map[string]bool) []BindNode {
|
||||
const maxDepth = 10
|
||||
if depth > maxDepth || productCode == "" {
|
||||
return nil
|
||||
}
|
||||
if path[productCode] {
|
||||
s.ctx.EventLog.Write(ctx, "bom.expand.cycle", "", "", "product_bom", productCode,
|
||||
"产品物料清单存在循环引用,已跳过", map[string]any{"depth": depth})
|
||||
return nil
|
||||
}
|
||||
items, err := client.BomItem.Query().
|
||||
Where(bomitem.ProductCode(productCode), bomitem.BomName(bomNameOrDefault(bomName))).All(ctx)
|
||||
if err != nil || len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
path[productCode] = true
|
||||
defer delete(path, productCode)
|
||||
out := make([]BindNode, 0, len(items))
|
||||
for _, it := range items {
|
||||
if it.MaterialCode == "" {
|
||||
continue
|
||||
}
|
||||
node := BindNode{
|
||||
MaterialCode: it.MaterialCode, MaterialName: it.MaterialName, Spec: it.Spec,
|
||||
Unit: it.Unit, ManageMode: it.ManageMode, Qty: it.UnitQty * qty, Level: depth,
|
||||
}
|
||||
// 该物料自身是否还有下级 BOM(成品/装配件):递归展开其子件
|
||||
if has, _ := client.BomItem.Query().Where(bomitem.ProductCode(it.MaterialCode)).Exist(ctx); has {
|
||||
node.Children = s.expandBindBom(ctx, client, it.MaterialCode, bomName, it.UnitQty*qty, depth+1, path)
|
||||
}
|
||||
out = append(out, node)
|
||||
}
|
||||
return out
|
||||
// expandBindBom 递归展开某产品的物料组成树(供追溯页/成品档案展示完整物料构成)。
|
||||
//
|
||||
// R1(2026-09-19):递归骨架统一到 bom_expand.go 的 expandBomTree,与备料算料共用同一份实现;
|
||||
// 下钻判定由 localBomExistsResolver 注入(本地存在下级清单才继续展开)——不依赖 WMS,
|
||||
// 保证 WMS 不可达时追溯仍能展示完整物料组成、不断链。
|
||||
func (s *Service) expandBindBom(ctx context.Context, productCode, bomName string, qty float64, depth int, path map[string]bool) []BindNode {
|
||||
return bomTreeToBindNodes(s.expandBomTree(ctx, productCode, bomNameOrDefault(bomName), qty, depth, path, s.localBomExistsResolver))
|
||||
}
|
||||
|
||||
// BindRequiredItem 应绑清单条目(工位终端/手动报工展示引导 + 前端齐套计算)
|
||||
|
||||
Reference in New Issue
Block a user