feat: 完成多模块迭代更新
- 新增过程巡检按步骤上报、数量不符上报、工位退料功能 - 增加工单工程编号三级归属字段 - 新增物料安全库存与缺货预警 - 新增附件管理、退库单管理模块 - 优化生产看板展示逻辑与前端页面文案 - 清理冗余的工艺路线相关代码与备份文件
This commit is contained in:
@@ -4,10 +4,13 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/associationtrace"
|
||||
"bj_power_mes/ent/processstep"
|
||||
"bj_power_mes/ent/station"
|
||||
"bj_power_mes/ent/stepcriterion"
|
||||
"bj_power_mes/ent/stepdata"
|
||||
"bj_power_mes/ent/torquerecord"
|
||||
@@ -57,6 +60,8 @@ type StepDataReq struct {
|
||||
Name string `json:"name"`
|
||||
Value float64 `json:"value"`
|
||||
Text string `json:"text"`
|
||||
// Checked:该步骤是否已完成「检测确认」。needCheck=true 的步骤必须为 true,服务端强校验,防止绕过前端。
|
||||
Checked bool `json:"checked"`
|
||||
}
|
||||
|
||||
type OnlineReq struct {
|
||||
@@ -127,6 +132,11 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera
|
||||
} else if miss != "" {
|
||||
return errors.New(miss)
|
||||
}
|
||||
// 阶段2:检测确认(needCheck)强校验——服务端为准,前端勾选只是辅助提示。
|
||||
// 本工位绑定工艺流程中标记“需要检测确认”的步骤,报工数据里必须逐条带 checked=true,否则拒绝报工。
|
||||
if err := s.validateNeedCheck(ctx, req); err != nil {
|
||||
return err
|
||||
}
|
||||
now := time.Now()
|
||||
proc, err := s.ctx.EntClient.WorkpieceProcess.Create().
|
||||
SetSn(req.Sn).SetProcessCode(req.ProcessCode).
|
||||
@@ -162,6 +172,45 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateNeedCheck 检测确认(needCheck)服务端强校验。
|
||||
// 规则:本工位绑定的工艺流程中,凡标记 needCheck=true 的工艺步骤,
|
||||
// 报工请求里必须存在对应 stepId 且 checked=true 的步骤数据;缺失则拒绝报工。
|
||||
// 工位未绑定流程、或流程内没有 needCheck 步骤时不拦截(与现场配置保持一致)。
|
||||
func (s *Service) validateNeedCheck(ctx context.Context, req ReportProcessReq) error {
|
||||
if req.StationNo <= 0 {
|
||||
return nil
|
||||
}
|
||||
st, err := s.ctx.EntClient.Station.Query().Where(station.StationNo(req.StationNo)).First(ctx)
|
||||
if err != nil || st.FlowId <= 0 {
|
||||
return nil
|
||||
}
|
||||
steps, err := s.ctx.EntClient.ProcessStep.Query().
|
||||
Where(processstep.FlowId(st.FlowId), processstep.NeedCheck(true)).All(ctx)
|
||||
if err != nil || len(steps) == 0 {
|
||||
return nil
|
||||
}
|
||||
checked := map[int]bool{}
|
||||
for _, sd := range req.Steps {
|
||||
if sd.Checked {
|
||||
checked[sd.StepId] = true
|
||||
}
|
||||
}
|
||||
missing := make([]string, 0, len(steps))
|
||||
for _, ps := range steps {
|
||||
if !checked[ps.ID] {
|
||||
name := ps.Name
|
||||
if name == "" {
|
||||
name = "步骤" + itoa(ps.ID)
|
||||
}
|
||||
missing = append(missing, name)
|
||||
}
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
return errors.New("以下步骤需先完成检测确认后方可报工:" + strings.Join(missing, "、"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeStepData 写一条步骤考核数据,按标准自动判定是否合格
|
||||
func (s *Service) writeStepData(ctx context.Context, sn string, processId int, st StepDataReq, operator string) (bool, error) {
|
||||
ok := true
|
||||
|
||||
Reference in New Issue
Block a user