feat: 核心业务实体扩充(混产模板/产品BOM/试制记录)、WMS 库存检验增强与前端通用能力
- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页) - WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报 - AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典 - 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列 - 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等) - 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/productprocess"
|
||||
"bj_power_mes/ent/productprocessitem"
|
||||
"bj_power_mes/ent/productprocessmaterial"
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/internal/verr"
|
||||
)
|
||||
@@ -37,6 +38,9 @@ type ProductProcessReq struct {
|
||||
Status string `json:"status"`
|
||||
Remark string `json:"remark"`
|
||||
Flows []ProductProcessItemReq `json:"flows"`
|
||||
// 2026-11-13 拍板「总分制」:随产品工艺一起提交的分账行(总账物料分配到各工序)。
|
||||
// 总账存在时不分配完 / Σ分账≠总账 → 保存被硬拒。
|
||||
Allocations []BOMAllocation `json:"allocations"`
|
||||
}
|
||||
|
||||
// ProductProcessItemVO 明细行(含实时反查的绑定工位号)
|
||||
@@ -215,7 +219,7 @@ func ppExecutable(vo *ProductProcessVO) (bool, string) {
|
||||
// ④ 规则1(2026-10-20 拍板,2026-11-05 修订):有未完成工单(CREATED/IN_PROGRESS/PAUSED)引用 →
|
||||
// 定义与工艺明细(flows)一并禁改,保证工单路线前后一致;建议「复制工艺」后用新工艺建新单;
|
||||
// ⑤ 名称未传时按"${物料编码} ${物料名称} 工艺"兜底。
|
||||
func (s *Service) SaveProductProcess(ctx context.Context, req ProductProcessReq, operator string) error {
|
||||
func (s *Service) SaveProductProcess(ctx context.Context, req ProductProcessReq, operator string) (int, error) {
|
||||
// 收集式校验(报错一次收全 + 每条带怎么办,2026-10-20):全部问题列出、一次性返回
|
||||
ve := verr.New()
|
||||
if strings.TrimSpace(req.ProductCode) == "" {
|
||||
@@ -275,7 +279,26 @@ func (s *Service) SaveProductProcess(ctx context.Context, req ProductProcessReq,
|
||||
}
|
||||
}
|
||||
if err := ve.OrNil(); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
// 2026-11-13 拍板 P10:工艺配置与物料清单彻底分离、各自独立保存。
|
||||
// 产品工艺的保存不再写入分账(保存物料清单不会再保存一遍工艺);
|
||||
// 这里只校验「已有分账的工序仍在本次工艺路线内」,避免改路线后分账指向消失的工序。
|
||||
if req.Id > 0 && len(req.Flows) > 0 {
|
||||
flowSet := map[int]bool{}
|
||||
for _, f := range req.Flows {
|
||||
flowSet[f.FlowId] = true
|
||||
}
|
||||
allocRows, aErr := s.ctx.EntClient.ProductProcessMaterial.Query().
|
||||
Where(productprocessmaterial.ProductProcessId(req.Id)).All(ctx)
|
||||
if aErr != nil {
|
||||
return 0, aErr
|
||||
}
|
||||
for _, a := range allocRows {
|
||||
if !flowSet[a.FlowId] {
|
||||
return 0, fmt.Errorf("工序 %d 已从工艺路线移除,但物料清单里仍有该工序的物料分配;请先在物料清单里重新分配", a.FlowId)
|
||||
}
|
||||
}
|
||||
}
|
||||
var ppID int
|
||||
if req.Id > 0 {
|
||||
@@ -283,7 +306,7 @@ func (s *Service) SaveProductProcess(ctx context.Context, req ProductProcessReq,
|
||||
SetProductCode(req.ProductCode).SetProductName(req.ProductName).
|
||||
SetName(req.Name).SetStatus(status).SetRemark(req.Remark).
|
||||
Save(ctx); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
ppID = req.Id
|
||||
} else {
|
||||
@@ -292,7 +315,7 @@ func (s *Service) SaveProductProcess(ctx context.Context, req ProductProcessReq,
|
||||
SetName(req.Name).SetStatus(status).SetRemark(req.Remark).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
ppID = p.ID
|
||||
}
|
||||
@@ -303,12 +326,13 @@ func (s *Service) SaveProductProcess(ctx context.Context, req ProductProcessReq,
|
||||
if err := s.ctx.EntClient.ProductProcessItem.Create().
|
||||
SetProductProcessId(ppID).SetSeq(i + 1).SetFlowId(f.FlowId).
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
// 分账不再随产品工艺保存:由独立的「物料清单」页面/弹窗调 SaveProcessAllocations 写入
|
||||
s.ctx.EventLog.Write(ctx, "product.process.save", "", operator, "product_process", fmt.Sprint(ppID),
|
||||
"保存产品工艺", map[string]any{"id": ppID, "name": req.Name, "productCode": req.ProductCode, "flows": len(req.Flows)})
|
||||
return nil
|
||||
return ppID, nil
|
||||
}
|
||||
|
||||
// DeleteProductProcess 删除产品工艺(被工单引用过禁止删除,只能停用)
|
||||
@@ -324,6 +348,9 @@ func (s *Service) DeleteProductProcess(ctx context.Context, id int, operator str
|
||||
return errors.New("产品工艺不存在")
|
||||
}
|
||||
_, _ = s.ctx.EntClient.ProductProcessItem.Delete().Where(productprocessitem.ProductProcessId(id)).Exec(ctx)
|
||||
// 2026-11-13 拍板堵后门:删除产品工艺必须同步删除它的物料分账,不留孤儿行
|
||||
_, _ = s.ctx.EntClient.ProductProcessMaterial.Delete().
|
||||
Where(productprocessmaterial.ProductProcessId(id)).Exec(ctx)
|
||||
if err := s.ctx.EntClient.ProductProcess.DeleteOneID(id).Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -394,6 +421,17 @@ func (s *Service) CopyProductProcess(ctx context.Context, req CopyProductProcess
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
// 2026-11-13 拍板堵后门:复制产品工艺必须同步复制物料分账(按工序隔离)
|
||||
allocRows, _ := s.ctx.EntClient.ProductProcessMaterial.Query().
|
||||
Where(productprocessmaterial.ProductProcessId(src.ID)).All(ctx)
|
||||
for _, a := range allocRows {
|
||||
if err := s.ctx.EntClient.ProductProcessMaterial.Create().
|
||||
SetProductProcessId(np.ID).SetSeq(a.Seq).SetFlowId(a.FlowId).
|
||||
SetMaterialCode(a.MaterialCode).SetMaterialName(a.MaterialName).
|
||||
SetUnit(a.Unit).SetUnitQty(a.UnitQty).Exec(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "product.process.copy", "", operator, "product_process", fmt.Sprint(np.ID),
|
||||
"复制产品工艺", map[string]any{"fromId": src.ID, "fromName": src.Name, "toId": np.ID, "toName": newName})
|
||||
return np.ID, nil
|
||||
|
||||
Reference in New Issue
Block a user