- 新增滑动续签功能:人工触屏触发本地心跳 + 30秒节流刷新JWT,避免作业中令牌过期 - 拆分质量检验权限:过程检/完工检使用不同权限码,细化权限粒度 - 新增操作人用户ID字段:报工、拧紧记录落库时携带可信用户ID,解决身份追溯问题 - 移除编译期默认密钥,启动期校验所有必要密钥非空,防止密钥泄露风险 - 修复WMS附件越权遍历问题:使用UUID文件名替代顺序ID访问附件 - 实现登录态过期数据隔离:仅返回当前操作人的待同步数据,避免身份混淆
923 lines
36 KiB
Go
923 lines
36 KiB
Go
package logic
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"fmt"
|
||
"math"
|
||
"net/url"
|
||
"strconv"
|
||
"strings"
|
||
"time"
|
||
|
||
"bj_power_mes/ent"
|
||
"bj_power_mes/ent/associationtrace"
|
||
"bj_power_mes/ent/attachment"
|
||
"bj_power_mes/ent/inspectionrecord"
|
||
"bj_power_mes/ent/material"
|
||
"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"
|
||
"bj_power_mes/ent/stepsignrecord"
|
||
"bj_power_mes/ent/torquerecord"
|
||
"bj_power_mes/ent/workorder"
|
||
"bj_power_mes/ent/workpiece"
|
||
"bj_power_mes/ent/workpieceprocess"
|
||
"bj_power_mes/internal/wmsclient"
|
||
)
|
||
|
||
func itoa(n int) string { return strconv.Itoa(n) }
|
||
|
||
// evalLogic 依据考核逻辑判定
|
||
func evalLogic(c *ent.StepCriterion, v float64) bool {
|
||
switch c.Logic {
|
||
case "GE":
|
||
return v >= c.Target
|
||
case "LE":
|
||
return v <= c.Target
|
||
case "GT":
|
||
return v > c.Target
|
||
case "LT":
|
||
return v < c.Target
|
||
case "RANGE":
|
||
l, r := true, true
|
||
if c.Min != nil {
|
||
l = v >= *c.Min
|
||
}
|
||
if c.Max != nil {
|
||
r = v <= *c.Max
|
||
}
|
||
return l && r
|
||
case "EQUAL":
|
||
return v == c.Target
|
||
default:
|
||
return true
|
||
}
|
||
}
|
||
|
||
type StepDataReq struct {
|
||
StepId int `json:"stepId"`
|
||
Name string `json:"name"`
|
||
Value float64 `json:"value"`
|
||
Text string `json:"text"`
|
||
// Checked:该步骤是否已完成「检测确认」。needCheck=true 的步骤必须为 true,服务端强校验,防止绕过前端。
|
||
Checked bool `json:"checked"`
|
||
}
|
||
|
||
// StepSignInput 报工携带的步骤签字:操作工在工位终端/虚拟工位「签字确认」弹框中录入,
|
||
// 与 needOperatorSign 步骤一一对应;服务端强校验(validateNeedSign)后落 step_sign_record(signRole=OPERATOR)。
|
||
// 检验员签字(needInspectorSign)不走报工,由巡检终端「待签任务」页签单独签字(需求B)。
|
||
type StepSignInput struct {
|
||
StepId int `json:"stepId"`
|
||
SignRole string `json:"signRole"` // OPERATOR
|
||
Signer string `json:"signer"` // 签字人(操作工登录账号/姓名)
|
||
Remark string `json:"remark"`
|
||
}
|
||
|
||
type OnlineReq struct {
|
||
Sn string `json:"sn"`
|
||
OrderNo string `json:"orderNo"`
|
||
WorkOrderId int `json:"workOrderId"`
|
||
}
|
||
|
||
// OnlineWorkpiece 工件进线登记(返回提示文案,供响应透出)。
|
||
// 执行路线 = 工单工艺组合(唯一路线源头),工件只需按组合逐工位报工推进。
|
||
// SN 口径按产品型号/物料档案 sn_mode 分流(2026-09-30 解耦定稿):
|
||
// - sn_mode=1 序列号件:必须接收客户端扫入的来料 SN,校验其存在于 WMS SN 库存(已入库登记),
|
||
// 有效则工件 SN = 扫入SN(不再自动发号);
|
||
// - sn_mode=2 批次件:保持现状——终端自动发号后提交,MES 原样收号;
|
||
// - sn_mode=0 未选择:拒绝建档,报错提示先去产品型号/物料档案选择序列号件。
|
||
//
|
||
// 重上线识别:workpiece 已存在且未完工 → 先调 SemiFlow(OUTBOUND)(WMS 半成品出库,
|
||
// 失败报错不继续、文案含 WMS 原文),再按工单工艺组合计算下一站并提示"继续执行:工位N·工艺名"。
|
||
func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator string) (string, error) {
|
||
// 重上线识别先于分流:重上线不涉及发号/SN 校验
|
||
if req.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)
|
||
}
|
||
}
|
||
// 解析工单(sn_mode 挂在产品型号/物料档案上,必须先定位工单→产品)
|
||
if req.WorkOrderId == 0 && req.OrderNo != "" {
|
||
if wo, err := s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNo(req.OrderNo)).First(ctx); err == nil {
|
||
req.WorkOrderId = wo.ID
|
||
}
|
||
}
|
||
var wo *ent.WorkOrder
|
||
if req.WorkOrderId > 0 {
|
||
wo, _ = s.ctx.EntClient.WorkOrder.Get(ctx, req.WorkOrderId)
|
||
}
|
||
if wo == nil && req.OrderNo != "" {
|
||
wo, _ = s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNo(req.OrderNo)).First(ctx)
|
||
}
|
||
if wo == nil {
|
||
return "", errors.New("工单不存在,无法确定序列号件类型")
|
||
}
|
||
// SN 分流:读产品编码对应的物料档案 sn_mode(档案缺失视同未选择)
|
||
snMode := 0
|
||
if m, err := s.ctx.EntClient.Material.Query().Where(material.CodeEQ(wo.ProductCode)).First(ctx); err == nil {
|
||
snMode = m.SnMode
|
||
}
|
||
req.Sn = strings.TrimSpace(req.Sn)
|
||
switch snMode {
|
||
case 1: // 序列号件:工件 SN = 扫入的来料 SN,须已在 WMS 入库登记
|
||
if req.Sn == "" {
|
||
return "", errors.New("序列号件:请扫描来料SN(已在WMS入库登记)")
|
||
}
|
||
_, sns, err := s.ctx.Wms.StockBatches(ctx, wo.ProductCode)
|
||
if err != nil {
|
||
return "", fmt.Errorf("WMS SN 库存查询失败:%s", err.Error())
|
||
}
|
||
found := false
|
||
for _, sn := range sns {
|
||
if sn == req.Sn {
|
||
found = true
|
||
break
|
||
}
|
||
}
|
||
if !found {
|
||
return "", fmt.Errorf("来料SN %s 不在 WMS 库存(请确认已在 WMS 入库登记)", req.Sn)
|
||
}
|
||
case 2: // 批次件:保持现状,终端自动发号后提交
|
||
if req.Sn == "" {
|
||
return "", errors.New("sn 不能为空")
|
||
}
|
||
default: // 0=未选择(档案缺失/未配置)
|
||
return "", errors.New("请先在产品型号/物料档案选择序列号件")
|
||
}
|
||
if err := s.ctx.EntClient.Workpiece.Create().
|
||
SetSn(req.Sn).SetOrderNo(req.OrderNo).SetWorkOrderId(req.WorkOrderId).
|
||
SetStatus("ONLINE").SetOnlineAt(time.Now()).Exec(ctx); err != nil {
|
||
return "", err
|
||
}
|
||
s.ctx.EventLog.Write(ctx, "workpiece.online", req.OrderNo, operator, "workpiece", req.Sn,
|
||
"工件进线登记", map[string]any{"snMode": snMode,
|
||
"snSource": map[int]string{1: "SCANNED", 2: "AUTO"}[snMode]})
|
||
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
|
||
}
|
||
|
||
type ReportProcessReq struct {
|
||
Sn string `json:"sn"`
|
||
FlowId int `json:"flowId"` // 报工工艺(缺省回退工位当前绑定的工艺)
|
||
StationNo int `json:"stationNo"`
|
||
Operator string `json:"operator"` // 操作工(工位终端登录人注入;内部接口无 JWT 时作为操作人来源,杜绝「system」伪造留痕)
|
||
Steps []StepDataReq `json:"steps"`
|
||
// 签字确认(需求B):needOperatorSign 步骤须带操作工签字(签字确认弹框采集),服务端强校验并落库
|
||
Signs []StepSignInput `json:"signs"`
|
||
Binds []BindItemReq `json:"binds"` // 装机绑定(本工序装配物料:批次件批次号/序列号件SN),随报工原子提交
|
||
// 作业时长采集(方案 M / P0-3):工位终端在「上料到本工位」时采 startedAt、点「报工」时采 endedAt,
|
||
// 两端时间戳同源于终端时钟(ISO8601),离线重传也不失真;缺失则回退服务端当前时刻(时长=0)。
|
||
StartedAt string `json:"startedAt"`
|
||
EndedAt string `json:"endedAt"`
|
||
}
|
||
|
||
// parseClientTime 解析工位终端上报的 ISO8601 时间戳(兼容带/不带毫秒、Z/时区偏移)。
|
||
func parseClientTime(s string) (time.Time, error) {
|
||
s = strings.TrimSpace(s)
|
||
if s == "" {
|
||
return time.Time{}, errors.New("empty time")
|
||
}
|
||
layouts := []string{time.RFC3339Nano, time.RFC3339, "2006-01-02T15:04:05", "2006-01-02 15:04:05"}
|
||
for _, l := range layouts {
|
||
if t, err := time.Parse(l, s); err == nil {
|
||
return t, nil
|
||
}
|
||
}
|
||
return time.Time{}, errors.New("unrecognized time format: " + s)
|
||
}
|
||
|
||
// ReportProcess 工位报工:先应用装机绑定并做强校验(齐套才放行),再写报工实绩 + 步骤考核。
|
||
// 绑料是"落到工艺"的强约束:工艺物料清单(flow_material)中要求装配的物料必须绑齐,
|
||
// 电气件按单台用量逐颗SN、结构件至少一个批次号;缺料直接拒绝报工并返回缺料清单。
|
||
// 顺序校验(工单工艺组合为唯一路线源头):报工工位必须在组合中、工艺匹配,且不可倒序(可跳过未选工位)。
|
||
func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, operator string, operatorId int) error {
|
||
if req.Sn == "" || req.StationNo <= 0 {
|
||
return errors.New("sn 与 stationNo 必填")
|
||
}
|
||
wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(req.Sn)).First(ctx)
|
||
if err != nil {
|
||
return errors.New("工件未进线登记")
|
||
}
|
||
// 严格校验(业务口径已确认):仅“在制”工件可报工;DONE/REPAIR/SCRAPPED 一律拒绝。
|
||
if wp.Status != "ONLINE" && wp.Status != "PROCESSING" {
|
||
return errors.New("工件当前状态为「" + wp.Status + "」,非在制,不允许报工")
|
||
}
|
||
// 工艺解析:优先取报工传入 flowId;缺省回退工位当前绑定的工艺
|
||
flowId := req.FlowId
|
||
if flowId <= 0 {
|
||
if st, e := s.ctx.EntClient.Station.Query().Where(station.StationNo(req.StationNo)).First(ctx); e == nil {
|
||
flowId = st.FlowId
|
||
}
|
||
}
|
||
if flowId <= 0 {
|
||
return errors.New("无法确定报工工艺:请传 flowId 或确认工位已绑定工艺")
|
||
}
|
||
// 组合校验:报工条目必须在工单工艺组合中且工艺匹配;不可倒序(工位号即顺序号)
|
||
wo, err := s.ctx.EntClient.WorkOrder.Get(ctx, wp.WorkOrderId)
|
||
if err != nil || wo == nil {
|
||
return errors.New("工件所属工单不存在")
|
||
}
|
||
items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo)
|
||
matched := false
|
||
for _, it := range items {
|
||
if it.StationNo == req.StationNo {
|
||
matched = true
|
||
if it.FlowId != flowId {
|
||
return fmt.Errorf("工位%d当前工艺与工单工艺组合不匹配", req.StationNo)
|
||
}
|
||
break
|
||
}
|
||
}
|
||
if !matched {
|
||
return fmt.Errorf("工位%d不在该工单的工艺组合中,不可报工", req.StationNo)
|
||
}
|
||
if req.StationNo <= wp.CurrentStationNo {
|
||
return errors.New("不可倒序报工:工件已报工到工位" + itoa(wp.CurrentStationNo) +
|
||
",不能在工位" + itoa(req.StationNo) + "重复/回退报工")
|
||
}
|
||
// 报工是"装机绑定→校验齐套→写实绩→写步骤考核→回写结果/工件状态"的多步写,必须整体事务化(方案 U3):
|
||
// 任一步失败全部回滚,杜绝"实绩已建但工件状态没推进/结果没落"的半成品脏数据;
|
||
// 校验(齐套/needCheck)也走同一 tx client,才能读到本事务内刚写入的绑定。
|
||
tx, err := s.ctx.EntClient.Tx(ctx)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
committed := false
|
||
defer func() {
|
||
if !committed {
|
||
_ = tx.Rollback()
|
||
}
|
||
}()
|
||
client := tx.Client()
|
||
// 阶段1:装机绑定(随报工提交)→ 落库后强校验齐套
|
||
stationNo := ""
|
||
if req.StationNo > 0 {
|
||
stationNo = itoa(req.StationNo)
|
||
}
|
||
if _, err := s.applyBinds(ctx, client, req.Sn, wp.OrderNo, flowId, stationNo, operator, req.Binds); err != nil {
|
||
return err
|
||
}
|
||
if miss, err := s.validateStationBinds(ctx, client, req.Sn, flowId); err != nil {
|
||
return err
|
||
} else if miss != "" {
|
||
return errors.New(miss)
|
||
}
|
||
// 阶段2:检测确认(needCheck)强校验——服务端为准,前端勾选只是辅助提示。
|
||
// 本工位绑定工艺流程中标记“需要检测确认”的步骤,报工数据里必须逐条带 checked=true,否则拒绝报工。
|
||
if err := s.validateNeedCheck(ctx, client, req); err != nil {
|
||
return err
|
||
}
|
||
// 阶段2.5:签字机制(需求B)强校验 + 落操作工签字(needOperatorSign 步骤)。
|
||
// needInspectorSign 步骤要求检验员已在巡检终端「待签任务」页签签字,否则拒流转。
|
||
if err := s.validateNeedSign(ctx, client, req, flowId); err != nil {
|
||
return err
|
||
}
|
||
if err := s.writeOperatorSigns(ctx, client, req, flowId, wp.OrderNo, operator); err != nil {
|
||
return err
|
||
}
|
||
now := time.Now()
|
||
// 作业时长(方案 M / P0-3):startedAt=进工位(上料)时刻、endedAt=报工时刻,均由工位终端采集;
|
||
// 缺失或非法则回退到服务端当前时刻(durationSec=0),时钟回拨导致负数则时长归零。
|
||
startedAt, endedAt := now, now
|
||
if t, e := parseClientTime(req.StartedAt); e == nil {
|
||
startedAt = t
|
||
}
|
||
if t, e := parseClientTime(req.EndedAt); e == nil {
|
||
endedAt = t
|
||
}
|
||
durationSec := int(endedAt.Sub(startedAt).Seconds())
|
||
if durationSec < 0 {
|
||
durationSec = 0
|
||
endedAt = startedAt
|
||
}
|
||
proc, err := client.WorkpieceProcess.Create().
|
||
SetSn(req.Sn).SetFlowId(flowId).
|
||
SetStationNo(itoa(req.StationNo)).SetOrderNo(wp.OrderNo).
|
||
SetProcessName(s.flowNameById(ctx, flowId)).
|
||
SetStatus("DONE").SetOperator(operator).SetOperatorId(operatorId).SetResult("OK").
|
||
SetStartedAt(startedAt).SetEndedAt(endedAt).SetDurationSec(durationSec).Save(ctx)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
allOK := true
|
||
for _, st := range req.Steps {
|
||
ok, e := s.writeStepData(ctx, client, req.Sn, proc.ID, st, operator)
|
||
if e != nil {
|
||
return e
|
||
}
|
||
if !ok {
|
||
allOK = false
|
||
}
|
||
}
|
||
if bad, e := client.StepData.Query().
|
||
Where(stepdata.ProcessId(proc.ID), stepdata.IsOK(false)).Exist(ctx); e != nil {
|
||
return e
|
||
} else if bad {
|
||
allOK = false
|
||
}
|
||
result := "OK"
|
||
if !allOK {
|
||
result = "NG"
|
||
}
|
||
if _, err := client.WorkpieceProcess.UpdateOneID(proc.ID).SetResult(result).Save(ctx); err != nil {
|
||
return err
|
||
}
|
||
if _, err := client.Workpiece.UpdateOneID(wp.ID).
|
||
SetCurrentStationNo(req.StationNo).SetStatus("PROCESSING").Save(ctx); err != nil {
|
||
return err
|
||
}
|
||
if err := tx.Commit(); err != nil {
|
||
return err
|
||
}
|
||
committed = true
|
||
|
||
s.ctx.EventLog.Write(ctx, "workpiece.process.report", wp.OrderNo, operator, "workpiece", req.Sn,
|
||
"工位报工", map[string]any{"flowId": flowId, "stationNo": req.StationNo, "result": result})
|
||
s.notifyDashboard()
|
||
return nil
|
||
}
|
||
|
||
// validateNeedCheck 检测确认(needCheck)服务端强校验。
|
||
// 规则:本工位绑定的工艺流程中,凡标记 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 {
|
||
return nil
|
||
}
|
||
steps, err := client.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
|
||
}
|
||
|
||
// 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
|
||
}
|
||
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
|
||
}
|
||
stationNo := itoa(req.StationNo)
|
||
signMap := map[int]StepSignInput{}
|
||
for _, sg := range req.Signs {
|
||
if sg.SignRole == "OPERATOR" {
|
||
signMap[sg.StepId] = sg
|
||
}
|
||
}
|
||
for _, ps := range steps {
|
||
if ps.NeedOperatorSign {
|
||
sg, ok := signMap[ps.ID]
|
||
if !ok || strings.TrimSpace(sg.Signer) == "" {
|
||
name := ps.Name
|
||
if name == "" {
|
||
name = "步骤" + itoa(ps.ID)
|
||
}
|
||
return errors.New("以下步骤需操作工签字确认后才能报工:" + name)
|
||
}
|
||
}
|
||
if ps.NeedInspectorSign {
|
||
// 检验员必须「签字确认」(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
|
||
}
|
||
if !has {
|
||
name := ps.Name
|
||
if name == "" {
|
||
name = "步骤" + itoa(ps.ID)
|
||
}
|
||
return errors.New("以下步骤需检验员签字确认(合格)后才能流转:" + name)
|
||
}
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// writeOperatorSigns 在报工事务内落操作工签字(needOperatorSign 步骤,签字确认弹框采集);
|
||
// 按唯一索引(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 {
|
||
steps, err := client.ProcessStep.Query().
|
||
Where(processstep.FlowId(flowId), processstep.NeedOperatorSign(true)).All(ctx)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
if len(steps) == 0 {
|
||
return nil
|
||
}
|
||
stationNo := itoa(req.StationNo)
|
||
signMap := map[int]StepSignInput{}
|
||
for _, sg := range req.Signs {
|
||
if sg.SignRole == "OPERATOR" {
|
||
signMap[sg.StepId] = sg
|
||
}
|
||
}
|
||
for _, ps := range steps {
|
||
sg, ok := signMap[ps.ID]
|
||
if !ok || strings.TrimSpace(sg.Signer) == "" {
|
||
continue // 已在 validateNeedSign 拦截,这里兜底跳过
|
||
}
|
||
exist, _ := client.StepSignRecord.Query().
|
||
Where(stepsignrecord.Sn(req.Sn), stepsignrecord.StationNo(stationNo),
|
||
stepsignrecord.StepId(ps.ID), stepsignrecord.SignRole("OPERATOR"),
|
||
stepsignrecord.Round(1)).First(ctx)
|
||
if exist != nil {
|
||
continue
|
||
}
|
||
_, err = client.StepSignRecord.Create().
|
||
SetSn(req.Sn).SetOrderNo(orderNo).SetFlowId(flowId).
|
||
SetStationNo(stationNo).SetStepId(ps.ID).SetStepName(ps.Name).
|
||
SetSignRole("OPERATOR").SetResult("OK").
|
||
SetSignedBy(strings.TrimSpace(sg.Signer)).SetRound(1).
|
||
SetSource("station").SetRemark(sg.Remark).Save(ctx)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
}
|
||
return nil
|
||
}
|
||
|
||
// writeStepData 写一条步骤考核数据,按标准自动判定是否合格
|
||
func (s *Service) writeStepData(ctx context.Context, client *ent.Client, sn string, processId int, st StepDataReq, operator string) (bool, error) {
|
||
ok := true
|
||
crits, err := client.StepCriterion.Query().Where(stepcriterion.StepId(st.StepId)).All(ctx)
|
||
if err != nil {
|
||
return false, err
|
||
}
|
||
for _, c := range crits {
|
||
if !evalLogic(c, st.Value) {
|
||
ok = false
|
||
}
|
||
}
|
||
var cname, clogic string
|
||
cid := 0
|
||
if len(crits) > 0 {
|
||
cname = crits[0].Name
|
||
clogic = crits[0].Logic
|
||
cid = crits[0].ID
|
||
}
|
||
_, err = client.StepData.Create().
|
||
SetSn(sn).SetProcessId(processId).SetStepId(st.StepId).
|
||
SetStepName(st.Name).SetCriterionId(cid).SetCriterionName(cname).
|
||
SetCriterionLogic(clogic).SetValue(st.Value).SetValueText(st.Text).
|
||
SetIsOK(ok).SetOperator(operator).Save(ctx)
|
||
return ok, err
|
||
}
|
||
|
||
// DoneReq 完工 + 成品关联追溯
|
||
type DoneReq struct {
|
||
Sn string `json:"sn"`
|
||
BatchItems []string `json:"batchItems"` // 批次件批次号
|
||
SerialItems []string `json:"serialItems"` // 序列号件SN
|
||
}
|
||
|
||
// DoneWorkpiece 完工:先兜底校验全部工序装配物料齐套(工艺流程强校验),再登记成品并生成关联追溯
|
||
func (s *Service) DoneWorkpiece(ctx context.Context, req DoneReq, operator string) error {
|
||
wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(req.Sn)).First(ctx)
|
||
if err != nil {
|
||
return errors.New("工件不存在")
|
||
}
|
||
// 兜底强校验:工单工艺组合中每个工艺的装配物料都须绑齐(工艺未配置物料清单时自动放行)
|
||
wo, err := s.ctx.EntClient.WorkOrder.Get(ctx, wp.WorkOrderId)
|
||
if err != nil || wo == nil {
|
||
return errors.New("工件所属工单不存在")
|
||
}
|
||
if miss, err := s.validateAllFlows(ctx, s.ctx.EntClient, req.Sn, wo); err != nil {
|
||
return err
|
||
} else if miss != "" {
|
||
return errors.New("完工前必须绑齐全部装配物料:" + miss)
|
||
}
|
||
now := time.Now()
|
||
_, _ = s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID).
|
||
SetStatus("DONE").SetDoneAt(now).Save(ctx)
|
||
|
||
existID, _ := s.ctx.EntClient.AssociationTrace.Query().
|
||
Where(associationtrace.FinishedSn(req.Sn)).FirstID(ctx)
|
||
if existID > 0 {
|
||
_, _ = s.ctx.EntClient.AssociationTrace.UpdateOneID(existID).
|
||
SetBatchItems(req.BatchItems).SetSerialItems(req.SerialItems).SetOperator(operator).Save(ctx)
|
||
} else {
|
||
routeStr := ""
|
||
if items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo); len(items) > 0 {
|
||
routeStr = RouteStationsStrOfWO(items)
|
||
}
|
||
_, err = s.ctx.EntClient.AssociationTrace.Create().
|
||
SetFinishedSn(req.Sn).SetOrderNo(wp.OrderNo).SetProcessCode(routeStr).
|
||
SetBatchItems(req.BatchItems).SetSerialItems(req.SerialItems).
|
||
SetOperator(operator).Save(ctx)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
}
|
||
s.bumpWorkOrderProgress(ctx, wp.OrderNo, req.Sn)
|
||
s.bumpDailyPlanCompleted(ctx, wp.OrderNo, now)
|
||
s.ctx.EventLog.Write(ctx, "workpiece.done", wp.OrderNo, operator, "workpiece", req.Sn, "完工+关联追溯", map[string]any{"batchItems": req.BatchItems, "serialItems": req.SerialItems})
|
||
// 完工确认 = 生产完成(方案A定稿):此处不再回流 WMS 入库,成品改由「完工检」结论触发——
|
||
// 完工检合格(已通过/部分通过)才回流入库,见 inspection.go finishedInspectionInbound。
|
||
// 反冲扣账:物料在当道工序被消耗,完工即按整份 BOM 反冲扣 WMS 库存。
|
||
// 失败仅记 eventlog 不阻塞完工。
|
||
s.backflushWorkpiece(ctx, wp, operator)
|
||
s.notifyDashboard()
|
||
return nil
|
||
}
|
||
|
||
// backflushWorkpiece 反冲扣账:按工单工艺组合的单台用料(工艺物料清单汇总,含损耗)算「单件消耗」,
|
||
// 调 WMS 内部反冲接口 FIFO 扣库存 + 生成 backflush 出库单。
|
||
// 用料唯一来源=工单组合×flow_material(BOM 已删除);WMS 不可达/校验失败仅记日志。
|
||
func (s *Service) backflushWorkpiece(ctx context.Context, wp *ent.Workpiece, operator string) {
|
||
wo, err := s.ctx.EntClient.WorkOrder.Get(ctx, wp.WorkOrderId)
|
||
if err != nil || wo == nil {
|
||
s.ctx.EventLog.Write(ctx, "wms.backflush.failed", wp.OrderNo, operator, "workpiece", wp.Sn,
|
||
"反冲失败:工单不存在", map[string]any{"workOrderId": wp.WorkOrderId})
|
||
return
|
||
}
|
||
usage := s.WorkOrderUnitUsage(ctx, wo)
|
||
if len(usage) == 0 {
|
||
s.ctx.EventLog.Write(ctx, "wms.backflush.skip", wp.OrderNo, operator, "workpiece", wp.Sn,
|
||
"工单工艺组合无物料清单,跳过反冲", map[string]any{"orderNo": wp.OrderNo})
|
||
return
|
||
}
|
||
items := make([]wmsclient.BackflushItem, 0, len(usage))
|
||
for _, it := range usage {
|
||
// 单件消耗 = 单台含损耗用量,四舍五入;≤0 跳过
|
||
qty := int(math.Round(it.EffQty))
|
||
if qty <= 0 {
|
||
continue
|
||
}
|
||
items = append(items, wmsclient.BackflushItem{MaterialCode: it.MaterialCode, Qty: qty})
|
||
}
|
||
if len(items) == 0 {
|
||
return
|
||
}
|
||
if wmsErr := s.ctx.Wms.Backflush(ctx, wp.OrderNo, 0, 0, operator, items); wmsErr != nil {
|
||
s.ctx.EventLog.Write(ctx, "wms.backflush.failed", wp.OrderNo, operator, "workpiece", wp.Sn,
|
||
"反冲扣账WMS失败(库存未扣,请人工核查)", map[string]any{"error": wmsErr.Error(), "orderNo": wp.OrderNo})
|
||
return
|
||
}
|
||
s.ctx.EventLog.Write(ctx, "wms.backflush", wp.OrderNo, operator, "workpiece", wp.Sn,
|
||
"反冲扣账已下发WMS", map[string]any{"orderNo": wp.OrderNo, "items": len(items)})
|
||
}
|
||
|
||
// Trace 追溯查询(SN 维度):工序时间线/操作人/步骤数据/物料批次SN/拧紧数据
|
||
func (s *Service) Trace(ctx context.Context, sn string) (map[string]any, error) {
|
||
wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(sn)).First(ctx)
|
||
if err != nil {
|
||
return nil, errors.New("该SN无追溯数据")
|
||
}
|
||
procList, _ := s.ctx.EntClient.WorkpieceProcess.Query().
|
||
Where(workpieceprocess.Sn(sn)).Order(ent.Asc(workpieceprocess.FieldFlowId), ent.Asc(workpieceprocess.FieldID)).All(ctx)
|
||
steps, _ := s.ctx.EntClient.StepData.Query().
|
||
Where(stepdata.Sn(sn)).Order(ent.Desc(stepdata.FieldID)).All(ctx)
|
||
assoc, _ := s.ctx.EntClient.AssociationTrace.Query().
|
||
Where(associationtrace.FinishedSn(sn)).First(ctx)
|
||
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)
|
||
// 检验记录(过程检/完工检,只读展示;PAD 巡检动作不纳入)
|
||
inspections := s.traceInspections(ctx, sn)
|
||
// 签字记录(需求B):操作工/检验员对工艺步骤的签字确认,只读展示
|
||
signs, _ := s.ctx.EntClient.StepSignRecord.Query().
|
||
Where(stepsignrecord.Sn(sn), stepsignrecord.Revoked(false)).
|
||
Order(ent.Desc(stepsignrecord.FieldID)).All(ctx)
|
||
|
||
return map[string]any{
|
||
"workpiece": wp,
|
||
"processTimeline": procList,
|
||
"stepData": steps,
|
||
"associationTrace": assoc,
|
||
"torqueRecords": torque,
|
||
"bindTrace": bindVO,
|
||
"semiFlows": semiFlows,
|
||
"inspections": inspections,
|
||
"signs": signs,
|
||
}, nil
|
||
}
|
||
|
||
// TraceAttachmentVO 追溯页检验附件条目(预览走公开直链,下载走带鉴权 id 路由,前端点击打开)
|
||
type TraceAttachmentVO struct {
|
||
ID int `json:"id"`
|
||
FileName string `json:"fileName"`
|
||
URL string `json:"url"` // /api/v1/attachment/file/:id?dl=1(带 JWT 下载)
|
||
PreviewURL string `json:"previewUrl"` // 免鉴权公开直链 /api/v1/files?name=
|
||
}
|
||
|
||
// TraceInspectionVO 追溯页检验记录条目(过程检/完工检,只读展示)
|
||
type TraceInspectionVO struct {
|
||
ID int `json:"id"`
|
||
Category string `json:"category"` // QC_PROCESS=过程检 / FINAL=完工检
|
||
Result string `json:"result"` // OK/NG/PARTIAL
|
||
DisposalType string `json:"disposalType"` // 退货/返修/退换/报废(空=无处置)
|
||
DisposalRemark string `json:"disposalRemark"` // 处置说明
|
||
RelatedStandard string `json:"relatedStandard"`
|
||
TestRecordNo string `json:"testRecordNo"`
|
||
Operator string `json:"operator"`
|
||
CreatedAt time.Time `json:"createdAt"`
|
||
Attachments []TraceAttachmentVO `json:"attachments"`
|
||
}
|
||
|
||
// traceInspections 追溯页检验记录:该 SN 的过程检(QC_PROCESS)/完工检(FINAL)记录,时间倒序。
|
||
// MES 质检过程检落 QC_PROCESS(与 PAD 过程巡检 PROCESS 隔离,P1-8),
|
||
// CHECKIN/POINT/PROCESS/DONE/ALARM 为巡检动作不纳入;无记录返回空不报错。
|
||
func (s *Service) traceInspections(ctx context.Context, sn string) []TraceInspectionVO {
|
||
recs, err := s.ctx.EntClient.InspectionRecord.Query().
|
||
Where(inspectionrecord.SnEQ(sn), inspectionrecord.CategoryIn("QC_PROCESS", "FINAL")).
|
||
Order(ent.Desc(inspectionrecord.FieldCreatedAt), ent.Desc(inspectionrecord.FieldID)).
|
||
Limit(200).All(ctx)
|
||
if err != nil || len(recs) == 0 {
|
||
return nil
|
||
}
|
||
out := make([]TraceInspectionVO, 0, len(recs))
|
||
for _, rec := range recs {
|
||
out = append(out, TraceInspectionVO{
|
||
ID: rec.ID,
|
||
Category: rec.Category,
|
||
Result: rec.Result,
|
||
DisposalType: rec.DisposalType,
|
||
DisposalRemark: rec.DisposalRemark,
|
||
RelatedStandard: rec.RelatedStandard,
|
||
TestRecordNo: rec.TestRecordNo,
|
||
Operator: rec.Operator,
|
||
CreatedAt: rec.CreatedAt,
|
||
Attachments: s.inspectionRecordAttachments(ctx, rec),
|
||
})
|
||
}
|
||
return out
|
||
}
|
||
|
||
// inspectionRecordAttachments 某检验记录的附件列表,合并两条现有关联口径并按 ID 去重:
|
||
// ① 记录上的 attachmentIds(逗号分隔,关联 attachment 表);
|
||
// ② 附件表按 bizType=quality & bizId=报检单号(质检页上传/查看的既有模式)。
|
||
func (s *Service) inspectionRecordAttachments(ctx context.Context, rec *ent.InspectionRecord) []TraceAttachmentVO {
|
||
seen := map[int]bool{}
|
||
var atts []*ent.Attachment
|
||
if rec.AttachmentIds != "" {
|
||
for _, p := range strings.Split(rec.AttachmentIds, ",") {
|
||
id, e := strconv.Atoi(strings.TrimSpace(p))
|
||
if e != nil || id <= 0 || seen[id] {
|
||
continue
|
||
}
|
||
seen[id] = true
|
||
if a, ge := s.ctx.EntClient.Attachment.Get(ctx, id); ge == nil && !a.Deleted {
|
||
atts = append(atts, a)
|
||
}
|
||
}
|
||
}
|
||
if rec.ReportNo != "" {
|
||
byBiz, qe := s.ctx.EntClient.Attachment.Query().
|
||
Where(attachment.BizTypeEQ("quality"), attachment.BizIdEQ(rec.ReportNo), attachment.DeletedEQ(false)).
|
||
Order(ent.Asc(attachment.FieldID)).All(ctx)
|
||
if qe == nil {
|
||
for _, a := range byBiz {
|
||
if !seen[a.ID] {
|
||
seen[a.ID] = true
|
||
atts = append(atts, a)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
out := make([]TraceAttachmentVO, 0, len(atts))
|
||
for _, a := range atts {
|
||
vo := TraceAttachmentVO{
|
||
ID: a.ID,
|
||
FileName: a.FileName,
|
||
URL: "/api/v1/attachment/file/" + strconv.Itoa(a.ID) + "?dl=1",
|
||
}
|
||
if a.FilePath != "" {
|
||
vo.PreviewURL = "/api/v1/files?name=" + url.QueryEscape(a.FilePath)
|
||
}
|
||
out = append(out, vo)
|
||
}
|
||
return out
|
||
}
|
||
|
||
func (s *Service) ListWorkpieces(ctx context.Context, sn, orderNo string) ([]*ent.Workpiece, error) {
|
||
q := s.ctx.EntClient.Workpiece.Query()
|
||
if sn != "" {
|
||
q = q.Where(workpiece.SnContains(sn))
|
||
}
|
||
if orderNo != "" {
|
||
q = q.Where(workpiece.OrderNo(orderNo))
|
||
}
|
||
return q.Order(ent.Desc(workpiece.FieldID)).Limit(500).All(ctx)
|
||
}
|
||
|
||
// InProcessItem 在制品(已进线未完工)视图项。跨天工件继续停留,日排产不重复排。
|
||
type InProcessItem struct {
|
||
Sn string `json:"sn"`
|
||
OrderNo string `json:"orderNo"`
|
||
ProductCode string `json:"productCode"`
|
||
ProductName string `json:"productName"`
|
||
CurrentStation int `json:"currentStation"` // 0=上线位, 13=下线位, 其余为物理工位
|
||
CurrentStationName string `json:"currentStationName"` // 工位显示名(上线位/下线位/装配X)
|
||
Status string `json:"status"`
|
||
OnlineAt string `json:"onlineAt"`
|
||
DwellSec int64 `json:"dwellSec"` // 停留时长(秒),自进线起算
|
||
DoneSteps int `json:"doneSteps"`
|
||
TotalSteps int `json:"totalSteps"`
|
||
}
|
||
|
||
// WorkpiecesInProcess 列出停在各工位、尚未完工的在制品(ONLINE/PROCESSING/REPAIR)。
|
||
// stationNo<=0 返回全部;stationNo>0 仅返回当前停在该工位(0=上线位, 13=下线位)的工件。
|
||
// orderNo 非空时按工单号模糊过滤(客户第12条「记录查看加一项看工单号查询」)。
|
||
// 已进线未完工的工件跨天继续,日排产仅排「未开工数量」,不会重复排产。
|
||
func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderNo string) ([]InProcessItem, error) {
|
||
q := s.ctx.EntClient.Workpiece.Query().
|
||
Where(workpiece.Or(
|
||
workpiece.Status("ONLINE"),
|
||
workpiece.Status("PROCESSING"),
|
||
workpiece.Status("REPAIR"),
|
||
))
|
||
if orderNo != "" {
|
||
q = q.Where(workpiece.OrderNoContainsFold(orderNo))
|
||
}
|
||
list, err := q.Order(ent.Desc(workpiece.FieldOnlineAt)).All(ctx)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
out := make([]InProcessItem, 0, len(list))
|
||
woCache := map[int]*ent.WorkOrder{}
|
||
getWO := func(wp *ent.Workpiece) *ent.WorkOrder {
|
||
if wp.WorkOrderId <= 0 {
|
||
return nil
|
||
}
|
||
if wo, ok := woCache[wp.WorkOrderId]; ok {
|
||
return wo
|
||
}
|
||
wo, err := s.ctx.EntClient.WorkOrder.Get(ctx, wp.WorkOrderId)
|
||
if err != nil {
|
||
wo = nil
|
||
}
|
||
woCache[wp.WorkOrderId] = wo
|
||
return wo
|
||
}
|
||
for _, wp := range list {
|
||
// 路线 = 工单工艺组合(唯一路线源头);未配置组合则无路线(maxStation=0)
|
||
items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, getWO(wp))
|
||
seq := RouteStationsOfWO(items)
|
||
maxStation := 0
|
||
for _, c := range seq {
|
||
if c > maxStation {
|
||
maxStation = c
|
||
}
|
||
}
|
||
// 推算当前物理工位:ONLINE 在 上线位(0);PROCESSING 且已到末端 → 下线位(13)
|
||
cur := 0
|
||
if wp.Status == "PROCESSING" || wp.Status == "REPAIR" {
|
||
cp := wp.CurrentStationNo
|
||
if cp <= 0 {
|
||
cp = maxStation
|
||
}
|
||
if cp >= maxStation && wp.Status == "PROCESSING" {
|
||
cur = 13
|
||
} else {
|
||
cur = cp
|
||
}
|
||
}
|
||
if stationNo > 0 && cur != stationNo {
|
||
continue
|
||
}
|
||
dwell := int64(0)
|
||
var onlineAt string
|
||
if wp.OnlineAt != nil {
|
||
dwell = int64(time.Since(*wp.OnlineAt).Seconds())
|
||
onlineAt = wp.OnlineAt.Format("2006-01-02 15:04:05")
|
||
}
|
||
done := 0
|
||
if procs, e := s.ctx.EntClient.WorkpieceProcess.Query().
|
||
Where(workpieceprocess.Sn(wp.Sn), workpieceprocess.Status("DONE")).Count(ctx); e == nil {
|
||
done = procs
|
||
}
|
||
code, name := "", ""
|
||
if wp.WorkOrderId > 0 {
|
||
if wo, e := s.ctx.EntClient.WorkOrder.Get(ctx, wp.WorkOrderId); e == nil {
|
||
code, name = wo.ProductCode, wo.ProductName
|
||
}
|
||
}
|
||
if code == "" && wp.OrderNo != "" {
|
||
if wo, e := s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNo(wp.OrderNo)).First(ctx); e == nil {
|
||
code, name = wo.ProductCode, wo.ProductName
|
||
}
|
||
}
|
||
stName := stationDisplayName("", cur)
|
||
if cur == 0 {
|
||
stName = "上线位(虚拟)"
|
||
} else if cur == 13 {
|
||
stName = "下线位(虚拟)"
|
||
}
|
||
out = append(out, InProcessItem{
|
||
Sn: wp.Sn,
|
||
OrderNo: wp.OrderNo,
|
||
ProductCode: code,
|
||
ProductName: name,
|
||
CurrentStation: cur,
|
||
CurrentStationName: stName,
|
||
Status: wp.Status,
|
||
OnlineAt: onlineAt,
|
||
DwellSec: dwell,
|
||
DoneSteps: done,
|
||
TotalSteps: len(seq),
|
||
})
|
||
}
|
||
return out, nil
|
||
}
|