feat: 新增产品工艺管理与工序审核功能
- 新增产品工艺(product_process)及明细(product_process_item)数据模型 - 新增工序审核开关(need_audit)与审核角色(audit_role)字段 - 新增待审核签字页面与路由 - 优化 WMS/MES 接口交互,增加业务错误处理与友好提示 - 补充库存过滤逻辑,避免返回已出库 SN 数据 - 调整默认查询时间范围为近一个月,优化用户体验
This commit is contained in:
@@ -322,16 +322,20 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera
|
||||
return errors.New(miss)
|
||||
}
|
||||
// 阶段2:检测确认(needCheck)强校验——服务端为准,前端勾选只是辅助提示。
|
||||
// 本工位绑定工艺流程中标记“需要检测确认”的步骤,报工数据里必须逐条带 checked=true,否则拒绝报工。
|
||||
if err := s.validateNeedCheck(ctx, client, req); err != nil {
|
||||
// 本工位在本工艺组合中的出现序号 k 对应步骤 seq=k,标记“需要检测确认”的步骤须带 checked=true。
|
||||
// k 由组合派生(第 k 次出现 ↔ 步骤 seq=k),与签字校验同源,避免跨工位误拦。
|
||||
k := stationSeqInFlow(items, flowId, req.StationNo)
|
||||
if err := s.validateNeedCheck(ctx, client, req, flowId, k); err != nil {
|
||||
return err
|
||||
}
|
||||
// 阶段2.5:签字机制(需求B)强校验 + 落操作工签字(needOperatorSign 步骤)。
|
||||
// needInspectorSign 步骤要求检验员已在巡检终端「待签任务」页签签字,否则拒流转。
|
||||
if err := s.validateNeedSign(ctx, client, req, flowId); err != nil {
|
||||
// 校验同时返回 k(同 stationSeqInFlow),供落签字时同范围使用。
|
||||
k, err = s.validateNeedSign(ctx, client, req, flowId, k)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.writeOperatorSigns(ctx, client, req, flowId, wp.OrderNo, operator); err != nil {
|
||||
if err := s.writeOperatorSigns(ctx, client, req, flowId, k, wp.OrderNo, operator); err != nil {
|
||||
return err
|
||||
}
|
||||
now := time.Now()
|
||||
@@ -398,19 +402,16 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera
|
||||
}
|
||||
|
||||
// validateNeedCheck 检测确认(needCheck)服务端强校验。
|
||||
// 规则:本工位绑定的工艺流程中,凡标记 needCheck=true 的工艺步骤,
|
||||
// 规则:本工位在本工艺组合中的出现序号 k 对应的步骤(seq=k),凡标记 needCheck=true,
|
||||
// 报工请求里必须存在对应 stepId 且 checked=true 的步骤数据;缺失则拒绝报工。
|
||||
// 工位未绑定流程、或流程内没有 needCheck 步骤时不拦截(与现场配置保持一致)。
|
||||
func (s *Service) validateNeedCheck(ctx context.Context, client *ent.Client, req ReportProcessReq) error {
|
||||
if req.StationNo <= 0 {
|
||||
return nil
|
||||
}
|
||||
st, err := client.Station.Query().Where(station.StationNo(req.StationNo)).First(ctx)
|
||||
if err != nil || st.FlowId <= 0 {
|
||||
// 与 validateNeedSign 同源:跨工位的检测确认步骤不应在本工位报工时被要求(2026-10-08 审核修正)。
|
||||
// 工位不在组合中、或本步骤非 needCheck 时不拦截(与现场配置保持一致)。
|
||||
func (s *Service) validateNeedCheck(ctx context.Context, client *ent.Client, req ReportProcessReq, flowId, k int) error {
|
||||
if req.StationNo <= 0 || flowId <= 0 || k <= 0 {
|
||||
return nil
|
||||
}
|
||||
steps, err := client.ProcessStep.Query().
|
||||
Where(processstep.FlowId(st.FlowId), processstep.NeedCheck(true)).All(ctx)
|
||||
Where(processstep.FlowId(flowId), processstep.NeedCheck(true), processstep.Seq(k)).All(ctx)
|
||||
if err != nil || len(steps) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -436,19 +437,39 @@ func (s *Service) validateNeedCheck(ctx context.Context, client *ent.Client, req
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateNeedSign 签字机制(需求B)服务端强校验,镜像 validateNeedCheck:
|
||||
// 本工位绑定工艺流程中,凡标记 needOperatorSign=true 的工艺步骤,报工请求必须携带对应签字
|
||||
// (Signs 中存在 stepId 匹配且 signer 非空);凡标记 needInspectorSign=true 的步骤,必须已存在
|
||||
// 检验员签字记录(step_sign_record, signRole=INSPECTOR, 未撤销, signedBy 非空)方可流转。
|
||||
// 工位未绑定流程、或流程内无签字步骤时不拦截(与现场配置保持一致)。
|
||||
func (s *Service) validateNeedSign(ctx context.Context, client *ent.Client, req ReportProcessReq, flowId int) error {
|
||||
if req.StationNo <= 0 || flowId <= 0 {
|
||||
return nil
|
||||
// stationSeqInFlow 返回工位在指定工艺组合中的出现序号 k(按工位号升序的第 k 次出现,从 1 起)。
|
||||
// 语义:组合条目 ↔ 工艺步骤 seq 一一对应(第 k 次出现 ↔ 步骤 seq=k)。不在组合中返回 0。
|
||||
func stationSeqInFlow(items []FlowItem, flowId, stationNo int) int {
|
||||
k, cur := 0, 0
|
||||
for _, it := range items {
|
||||
if it.FlowId != flowId {
|
||||
continue
|
||||
}
|
||||
cur++
|
||||
if it.StationNo == stationNo {
|
||||
k = cur
|
||||
break
|
||||
}
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
||||
// validateNeedSign 签字机制(需求B)服务端强校验,返回本工位在本工艺组合中的出现序号 k:
|
||||
// 组合条目(按工位号升序)与工艺步骤 seq 一一对应——本工艺在组合中第 k 次出现 ↔ 步骤 seq=k。
|
||||
// - needOperatorSign:仅校验「本次报工步骤」(seq=k),报工请求必须携带对应操作工签字;
|
||||
// 随报工事务落 step_sign_record(signRole=OPERATOR)(writeOperatorSigns,同样限 seq=k)。
|
||||
// - needInspectorSign:仅校验「历史步骤」(seq<k),检验员 OK 签字必须已存在方可流转到本工位——
|
||||
// 本步骤的检验员签字发生在本工位报工之后(巡检终端待签任务),若在报工时校验本步骤
|
||||
// 会与「检验员签字前置=操作工已签字」形成死锁(2026-10-08 闭环联调实测确认并修复)。
|
||||
// k=0 表示工位不在组合中(不拦截);工位在组合中但流程内无签字步骤时原样返回 k 供调用方复用。
|
||||
func (s *Service) validateNeedSign(ctx context.Context, client *ent.Client, req ReportProcessReq, flowId, k int) (int, error) {
|
||||
if req.StationNo <= 0 || flowId <= 0 || k <= 0 {
|
||||
return k, nil
|
||||
}
|
||||
steps, err := client.ProcessStep.Query().
|
||||
Where(processstep.FlowId(flowId), processstep.Or(processstep.NeedOperatorSign(true), processstep.NeedInspectorSign(true))).All(ctx)
|
||||
if err != nil || len(steps) == 0 {
|
||||
return err
|
||||
return k, err
|
||||
}
|
||||
stationNo := itoa(req.StationNo)
|
||||
signMap := map[int]StepSignInput{}
|
||||
@@ -458,44 +479,47 @@ func (s *Service) validateNeedSign(ctx context.Context, client *ent.Client, req
|
||||
}
|
||||
}
|
||||
for _, ps := range steps {
|
||||
if ps.NeedOperatorSign {
|
||||
if ps.NeedOperatorSign && ps.Seq == k {
|
||||
// 当前报工步骤:必须有操作工签字(随报工落库)
|
||||
sg, ok := signMap[ps.ID]
|
||||
if !ok || strings.TrimSpace(sg.Signer) == "" {
|
||||
name := ps.Name
|
||||
if name == "" {
|
||||
name = "步骤" + itoa(ps.ID)
|
||||
}
|
||||
return errors.New("以下步骤需操作工签字确认后才能报工:" + name)
|
||||
return k, errors.New("以下步骤需操作工签字确认后才能报工:" + name)
|
||||
}
|
||||
}
|
||||
if ps.NeedInspectorSign {
|
||||
// 检验员必须「签字确认」(result=OK、未撤销、有签字人) 才能流转;NG 结论视为未通过、不放行。
|
||||
if ps.NeedInspectorSign && ps.Seq < k {
|
||||
// 历史步骤(已报工、待流转):检验员必须「签字确认」(result=OK、未撤销、有签字人);
|
||||
// NG 结论视为未通过、不放行。
|
||||
has, e := client.StepSignRecord.Query().
|
||||
Where(stepsignrecord.Sn(req.Sn), stepsignrecord.StationNo(stationNo),
|
||||
stepsignrecord.StepId(ps.ID), stepsignrecord.SignRole("INSPECTOR"),
|
||||
stepsignrecord.Revoked(false), stepsignrecord.SignedByNEQ(""),
|
||||
stepsignrecord.Result("OK")).Exist(ctx)
|
||||
if e != nil {
|
||||
return e
|
||||
return k, e
|
||||
}
|
||||
if !has {
|
||||
name := ps.Name
|
||||
if name == "" {
|
||||
name = "步骤" + itoa(ps.ID)
|
||||
}
|
||||
return errors.New("以下步骤需检验员签字确认(合格)后才能流转:" + name)
|
||||
return k, errors.New("以下步骤需检验员签字确认(合格)后才能流转:" + name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return k, nil
|
||||
}
|
||||
|
||||
// writeOperatorSigns 在报工事务内落操作工签字(needOperatorSign 步骤,签字确认弹框采集);
|
||||
// 按唯一索引(sn, stationNo, stepId, signRole=OPERATOR, round) 去重,避免重报产生重复签字。
|
||||
// 仅落「本次报工步骤」(seq=k,与 validateNeedSign 校验范围一致),按唯一索引
|
||||
// (sn, stationNo, stepId, signRole=OPERATOR, round) 去重,避免重报产生重复签字。
|
||||
// orderNo 取自工件所属工单(wp.OrderNo),签字记录随单追溯。
|
||||
func (s *Service) writeOperatorSigns(ctx context.Context, client *ent.Client, req ReportProcessReq, flowId int, orderNo, operator string) error {
|
||||
func (s *Service) writeOperatorSigns(ctx context.Context, client *ent.Client, req ReportProcessReq, flowId, k int, orderNo, operator string) error {
|
||||
steps, err := client.ProcessStep.Query().
|
||||
Where(processstep.FlowId(flowId), processstep.NeedOperatorSign(true)).All(ctx)
|
||||
Where(processstep.FlowId(flowId), processstep.NeedOperatorSign(true), processstep.Seq(k)).All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -790,7 +814,8 @@ func (s *Service) inspectionRecordAttachments(ctx context.Context, rec *ent.Insp
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Service) ListWorkpieces(ctx context.Context, sn, orderNo string) ([]*ent.Workpiece, error) {
|
||||
// ListWorkpieces 查询工件(sn 模糊包含、orderNo 精确;limit>0 时截断封顶 200,默认 500)
|
||||
func (s *Service) ListWorkpieces(ctx context.Context, sn, orderNo string, limit int) ([]*ent.Workpiece, error) {
|
||||
q := s.ctx.EntClient.Workpiece.Query()
|
||||
if sn != "" {
|
||||
q = q.Where(workpiece.SnContains(sn))
|
||||
@@ -798,7 +823,15 @@ func (s *Service) ListWorkpieces(ctx context.Context, sn, orderNo string) ([]*en
|
||||
if orderNo != "" {
|
||||
q = q.Where(workpiece.OrderNo(orderNo))
|
||||
}
|
||||
return q.Order(ent.Desc(workpiece.FieldID)).Limit(500).All(ctx)
|
||||
if limit > 0 {
|
||||
if limit > 200 {
|
||||
limit = 200
|
||||
}
|
||||
q = q.Limit(limit)
|
||||
} else {
|
||||
q = q.Limit(500)
|
||||
}
|
||||
return q.Order(ent.Desc(workpiece.FieldID)).All(ctx)
|
||||
}
|
||||
|
||||
// InProcessItem 在制品(已进线未完工)视图项。跨天工件继续停留,日排产不重复排。
|
||||
|
||||
Reference in New Issue
Block a user