feat: 新增产品工艺管理与工序审核功能
- 新增产品工艺(product_process)及明细(product_process_item)数据模型 - 新增工序审核开关(need_audit)与审核角色(audit_role)字段 - 新增待审核签字页面与路由 - 优化 WMS/MES 接口交互,增加业务错误处理与友好提示 - 补充库存过滤逻辑,避免返回已出库 SN 数据 - 调整默认查询时间范围为近一个月,优化用户体验
This commit is contained in:
@@ -34,6 +34,9 @@ type WorkOrderReq struct {
|
||||
DueDate string `json:"dueDate"`
|
||||
// 工艺组合(唯一路线源头):[{flowId,stationNo}],工位号即顺序号,按工位号升序执行、可跳过未选工位
|
||||
FlowCombination []map[string]int `json:"flowCombination"`
|
||||
// 来源产品工艺(2026-10-09):建单选产品时带出默认产品工艺并自动填组合;
|
||||
// 组合是快照可手改,本字段恒保留=来源定义(0=无来源,历史工单),供追溯与偏差提示。
|
||||
ProductProcessId int `json:"productProcessId"`
|
||||
}
|
||||
|
||||
// CreateWorkOrder 创建工单(状态恒 CREATED,后续用状态流转按钮推进)
|
||||
@@ -102,6 +105,13 @@ func (s *Service) CreateWorkOrder(ctx context.Context, req WorkOrderReq, operato
|
||||
}
|
||||
b.SetFlowCombination(flowItemsToMaps(items))
|
||||
}
|
||||
// 来源产品工艺:传了必须存在( ACTIVE/停用均可落——前端只列启用的,此处宽松校验存在性)
|
||||
if req.ProductProcessId > 0 {
|
||||
if _, err := s.ctx.EntClient.ProductProcess.Get(ctx, req.ProductProcessId); err != nil {
|
||||
return errors.New("所选产品工艺不存在")
|
||||
}
|
||||
b.SetProductProcessId(req.ProductProcessId)
|
||||
}
|
||||
// 创建人(Item M):取当前登录用户
|
||||
b.SetCreatedBy(operator)
|
||||
if _, err := b.Save(ctx); err != nil {
|
||||
@@ -227,6 +237,13 @@ func (s *Service) UpdateWorkOrder(ctx context.Context, req WorkOrderReq, operato
|
||||
}
|
||||
u.SetFlowCombination(flowItemsToMaps(items))
|
||||
}
|
||||
// 来源产品工艺:传了必须存在(恒保留=来源定义,不随组合手改清空)
|
||||
if req.ProductProcessId > 0 {
|
||||
if _, err := s.ctx.EntClient.ProductProcess.Get(ctx, req.ProductProcessId); err != nil {
|
||||
return errors.New("所选产品工艺不存在")
|
||||
}
|
||||
u.SetProductProcessId(req.ProductProcessId)
|
||||
}
|
||||
if req.Quantity > 0 {
|
||||
u.SetQuantity(req.Quantity)
|
||||
}
|
||||
@@ -263,8 +280,10 @@ func (s *Service) UpdateWorkOrder(ctx context.Context, req WorkOrderReq, operato
|
||||
}
|
||||
|
||||
// ListWorkOrders 查询工单(支持工单号/状态/产品编码/产品名称/归属类型/归属编号 过滤;
|
||||
// 工程编号查询已随编号体系改造移除,字段保留仅防历史迁移)
|
||||
func (s *Service) ListWorkOrders(ctx context.Context, orderNo, status, productCode, productName, contractNo, ownershipType, dueFrom, dueTo string) ([]*ent.WorkOrder, error) {
|
||||
// 工程编号查询已随编号体系改造移除,字段保留仅防历史迁移)。
|
||||
// keyword:跨字段模糊(工单号/产品编码/产品名称/合同号 任一命中),供下拉远程搜索用;
|
||||
// limit:>0 时启用截断(封顶 200),仅下拉搜索场景传参,列表页不传=全量,行为向后兼容。
|
||||
func (s *Service) ListWorkOrders(ctx context.Context, orderNo, status, productCode, productName, contractNo, ownershipType, dueFrom, dueTo, keyword string, limit int) ([]*ent.WorkOrder, error) {
|
||||
q := s.ctx.EntClient.WorkOrder.Query()
|
||||
if orderNo != "" {
|
||||
q = q.Where(workorder.WorkOrderNoContains(orderNo))
|
||||
@@ -295,6 +314,23 @@ func (s *Service) ListWorkOrders(ctx context.Context, orderNo, status, productCo
|
||||
q = q.Where(workorder.DueDateLTE(t))
|
||||
}
|
||||
}
|
||||
// keyword 跨字段模糊(下拉远程搜索):工单号/产品编码/产品名称/合同号 任一命中
|
||||
if keyword != "" {
|
||||
kw := workorder.Or(
|
||||
workorder.WorkOrderNoContains(keyword),
|
||||
workorder.ProductCodeContains(keyword),
|
||||
workorder.ProductNameContains(keyword),
|
||||
workorder.ContractNoContains(keyword),
|
||||
)
|
||||
q = q.Where(kw)
|
||||
}
|
||||
// limit 截断(封顶 200):仅下拉搜索场景启用,防数据炸弹
|
||||
if limit > 0 {
|
||||
if limit > 200 {
|
||||
limit = 200
|
||||
}
|
||||
q = q.Limit(limit)
|
||||
}
|
||||
return q.Order(ent.Desc(workorder.FieldCreatedAt), ent.Desc(workorder.FieldID)).All(ctx)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user