feat&refactor: 2026-09-22 半成品业务模型重构与功能完善
- 重构半成品流转逻辑:进度权威源改为 workpiece.currentStationNo,新增 completedText 快照字段,废除 doneProcessCodes - 清理物料品类中半成品类型,存量数据幂等清理,调整物料管理方式文案为批次/序列号 - 新增日排产状态专用更新接口,修复工单工艺校验逻辑 - 新增物料档案代理接口、深路径文件下载接口 - 优化前端界面文案与工位选择逻辑,补充追溯页半成品流转展示 - 调整WMS端物料品类校验与入库接口契约 - 新增/更新数据库表结构与实体类代码
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/associationtrace"
|
||||
"bj_power_mes/ent/processstep"
|
||||
"bj_power_mes/ent/semiflow"
|
||||
"bj_power_mes/ent/station"
|
||||
"bj_power_mes/ent/stepcriterion"
|
||||
"bj_power_mes/ent/stepdata"
|
||||
@@ -66,25 +67,86 @@ type OnlineReq struct {
|
||||
WorkOrderId int `json:"workOrderId"`
|
||||
}
|
||||
|
||||
// OnlineWorkpiece 工件进线登记
|
||||
// 执行路线 = 工单工艺组合(唯一路线源头),工件只需按组合逐工位报工推进
|
||||
func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator string) error {
|
||||
// OnlineWorkpiece 工件进线登记(返回提示文案,供响应透出)。
|
||||
// 执行路线 = 工单工艺组合(唯一路线源头),工件只需按组合逐工位报工推进。
|
||||
// 重上线识别:workpiece 已存在且未完工 → 先调 SemiFlow(OUTBOUND)(WMS 半成品出库,
|
||||
// 失败报错不继续、文案含 WMS 原文),再按工单工艺组合计算下一站并提示"继续执行:工位N·工艺名";
|
||||
// 新件路径不变。
|
||||
func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator string) (string, error) {
|
||||
if req.Sn == "" {
|
||||
return errors.New("sn 不能为空")
|
||||
return "", errors.New("sn 不能为空")
|
||||
}
|
||||
exist, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(req.Sn)).First(ctx)
|
||||
if err != nil && !ent.IsNotFound(err) {
|
||||
return "", err
|
||||
}
|
||||
if exist != nil {
|
||||
if exist.Status == "DONE" || exist.Status == "SCRAPPED" {
|
||||
return "", errors.New("工件已完工/报废,不可重复上线登记")
|
||||
}
|
||||
return s.reonlineWorkpiece(ctx, exist, operator)
|
||||
}
|
||||
if req.WorkOrderId == 0 {
|
||||
if wo, err := s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNo(req.OrderNo)).First(ctx); err == nil {
|
||||
req.WorkOrderId = wo.ID
|
||||
}
|
||||
}
|
||||
err := s.ctx.EntClient.Workpiece.Create().
|
||||
if err := s.ctx.EntClient.Workpiece.Create().
|
||||
SetSn(req.Sn).SetOrderNo(req.OrderNo).SetWorkOrderId(req.WorkOrderId).
|
||||
SetStatus("ONLINE").SetOnlineAt(time.Now()).Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
SetStatus("ONLINE").SetOnlineAt(time.Now()).Exec(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.online", req.OrderNo, operator, "workpiece", req.Sn, "工件进线登记", nil)
|
||||
s.notifyDashboard()
|
||||
return "进线登记成功", nil
|
||||
}
|
||||
|
||||
// reonlineWorkpiece 重上线(暂存退库后再次进线):
|
||||
// ① 先校验:工单组合非空且存在下一站(stationNo > currentStationNo),无副作用不通过即拒绝;
|
||||
// ② 再调 SemiFlow(OUTBOUND) 让 WMS 半成品出库,失败则报错不继续(文案含 WMS 原文)——
|
||||
//
|
||||
// 顺序保证:校验全部通过后才产生出库这一副作用,避免"已出库却登记失败"的悬挂状态;
|
||||
//
|
||||
// ③ 下一站工位当天停单时提示"工位N已停止接单"(复用 GetStationPaused 既有停单判定,不阻断登记)。
|
||||
func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, operator string) (string, error) {
|
||||
items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, s.workpieceWorkOrder(ctx, wp))
|
||||
if len(items) == 0 {
|
||||
return "", errors.New("工单未配置工艺组合")
|
||||
}
|
||||
next, nextFlow := 0, 0
|
||||
for _, it := range items {
|
||||
if it.StationNo > wp.CurrentStationNo && (next == 0 || it.StationNo < next) {
|
||||
next, nextFlow = it.StationNo, it.FlowId
|
||||
}
|
||||
}
|
||||
if next == 0 {
|
||||
return "", fmt.Errorf("工件已报工至工位%d,工艺组合中无下一站", wp.CurrentStationNo)
|
||||
}
|
||||
if err := s.SemiFlow(ctx, SemiReq{Sn: wp.Sn, OrderNo: wp.OrderNo, Action: "OUTBOUND"}, operator); err != nil {
|
||||
return "", fmt.Errorf("重上线失败:%s", err.Error())
|
||||
}
|
||||
msg := fmt.Sprintf("重上线成功,继续执行:工位%d·%s", next, s.flowNameById(ctx, nextFlow))
|
||||
if s.GetStationPaused(ctx, next) {
|
||||
msg += "(注意:工位" + itoa(next) + "已停止接单)"
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.reonline", wp.OrderNo, operator, "workpiece", wp.Sn,
|
||||
"工件重上线(暂存退库后出库继续)", map[string]any{"nextStationNo": next, "nextFlowId": nextFlow})
|
||||
s.notifyDashboard()
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
// workpieceWorkOrder 取工件所属工单:优先 workOrderId,缺失按 orderNo 兜底解析
|
||||
func (s *Service) workpieceWorkOrder(ctx context.Context, wp *ent.Workpiece) *ent.WorkOrder {
|
||||
if wp.WorkOrderId > 0 {
|
||||
if wo, err := s.ctx.EntClient.WorkOrder.Get(ctx, wp.WorkOrderId); err == nil {
|
||||
return wo
|
||||
}
|
||||
}
|
||||
if wp.OrderNo != "" {
|
||||
if wo, err := s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNo(wp.OrderNo)).First(ctx); err == nil {
|
||||
return wo
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -457,6 +519,9 @@ func (s *Service) Trace(ctx context.Context, sn string) (map[string]any, error)
|
||||
torque, _ := s.ctx.EntClient.TorqueRecord.Query().
|
||||
Where(torquerecord.Sn(sn)).Order(ent.Desc(torquerecord.FieldTime)).Limit(200).All(ctx)
|
||||
bindVO, _ := s.BuildBindTrace(ctx, sn)
|
||||
// 半成品流转记录(IN=暂存退库 / OUT=重上线),追溯页展示完成至工位快照
|
||||
semiFlows, _ := s.ctx.EntClient.SemiFlow.Query().
|
||||
Where(semiflow.Sn(sn)).Order(ent.Desc(semiflow.FieldID)).All(ctx)
|
||||
|
||||
return map[string]any{
|
||||
"workpiece": wp,
|
||||
@@ -465,6 +530,7 @@ func (s *Service) Trace(ctx context.Context, sn string) (map[string]any, error)
|
||||
"associationTrace": assoc,
|
||||
"torqueRecords": torque,
|
||||
"bindTrace": bindVO,
|
||||
"semiFlows": semiFlows,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user