feat: 看板管理屏专属面板与追溯查询三合一 + AGV状态WS实时推送 + 数据库错误友好文案分层
This commit is contained in:
@@ -26,6 +26,8 @@ import (
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/ent/workpiece"
|
||||
"bj_power_mes/ent/workpieceprocess"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
func itoa(n int) string { return strconv.Itoa(n) }
|
||||
@@ -637,16 +639,76 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera
|
||||
// 本工位剩余物料可支撑台数/时长,低于阈值落预警(工位终端实时弹播;推算失败静默不阻断);单台用量按工单来源产品工艺的工序分账取(无分账回退旧口径)。
|
||||
s.evaluateShortageAfterReport(ctx, req.StationNo, flowId, durationSec, wo)
|
||||
s.notifyDashboard()
|
||||
// 报工后自动流转连锁(triggerFlowChain,2026-11-11 拍板):异步推进工件物理位置
|
||||
// (送下一道工序候选工位 / 下游被占按缓存策略进缓存或滞留 / 层层拉入上游腾位)。
|
||||
// 异步执行:不阻塞、不影响报工结果;流转失败只影响物理位置推进,报工实绩已提交。
|
||||
go func() {
|
||||
defer func() { _ = recover() }()
|
||||
s.TriggerFlowChainForSn(context.Background(), req.Sn, operator)
|
||||
}()
|
||||
// 报工后处理分两支,互斥执行(避免自动完工与物理流转并发改同一工件):
|
||||
// A) 虚拟工位末道工序自动完工(2026-11-16 主控包项6):当前报工是本工单最后一道工序,且
|
||||
// 报工工位是虚拟工位(stationType=OFFLINE)时,报工即收口为 DONE,工人无需再到「下线完工」
|
||||
// 手动操作。虚拟工位无物理点位/下料位,不再触发物理流转(否则 flowChain 会往 G11/G12 送件,
|
||||
// 与立即 DONE 语义冲突)。判定以 DB 为准:route 全部工序已有 DONE 报工 + 工位 OFFLINE。
|
||||
// B) 其余情况走原自动流转连锁(triggerFlowChain,2026-11-11 拍板):异步推进工件物理位置
|
||||
// (送下一道工序候选工位 / 下游被占按缓存策略进缓存或滞留 / 层层拉入上游腾位)。
|
||||
// 两支均异步执行:不阻塞报工响应;失败只记日志,不回滚已提交的报工实绩。
|
||||
autoDone := false
|
||||
if _, allDone := s.firstUndoneFlowSeq(context.Background(), s.ctx.EntClient, req.Sn, route); allDone {
|
||||
if st, e := s.ctx.EntClient.Station.Query().Where(station.StationNo(req.StationNo)).First(ctx); e == nil && st.StationType == "OFFLINE" {
|
||||
autoDone = true
|
||||
binds := make([]string, 0)
|
||||
for _, b := range req.Binds {
|
||||
if v := strings.TrimSpace(b.BindValue); v != "" {
|
||||
binds = append(binds, v)
|
||||
}
|
||||
}
|
||||
go func() {
|
||||
defer func() { _ = recover() }()
|
||||
s.autoDoneVirtualFinal(context.Background(), req.Sn, wp.OrderNo, req.StationNo, binds, operator)
|
||||
}()
|
||||
}
|
||||
}
|
||||
if !autoDone {
|
||||
go func() {
|
||||
defer func() { _ = recover() }()
|
||||
s.TriggerFlowChainForSn(context.Background(), req.Sn, operator)
|
||||
}()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// autoDoneVirtualFinal 虚拟工位末道工序报工后的自动完工收口。
|
||||
// 走与 DoneWorkpiece DONE 分支相同的落库动作,区别:不预检/占用下料点位(虚拟工位无物理位),
|
||||
// 关联追溯清单取本次报工的装机绑定(无绑定则留空,成品SN追溯仍落库)。幂等:已 DONE 直接返回。
|
||||
func (s *Service) autoDoneVirtualFinal(ctx context.Context, sn, orderNo string, stationNo int, batchItems []string, operator string) {
|
||||
wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(sn)).Only(ctx)
|
||||
if err != nil || wp.Status == "DONE" || wp.Status == "SCRAPPED" {
|
||||
return // 已完工/报废,幂等返回
|
||||
}
|
||||
now := time.Now()
|
||||
if _, err := s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID).
|
||||
SetStatus("DONE").SetDoneAt(now).SetAtStationNo(0).Save(ctx); err != nil {
|
||||
logx.Errorf("虚拟工位自动完工失败(更新工件状态):sn=%s err=%v", sn, err)
|
||||
return
|
||||
}
|
||||
s.writeLifecycle(ctx, sn, wp.OrderNo, "PROCESSING", "DONE", stationNo, 0, operator, "workstation", "虚拟工位末道工序自动完工")
|
||||
// 关联追溯:成品SN(主件)唯一一条,清单取报工绑定(可空)
|
||||
existID, _ := s.ctx.EntClient.AssociationTrace.Query().Where(associationtrace.FinishedSn(sn)).FirstID(ctx)
|
||||
if existID == 0 {
|
||||
routeStr := ""
|
||||
if wo, e := s.ctx.EntClient.WorkOrder.Get(ctx, wp.WorkOrderId); e == nil && wo != nil {
|
||||
if items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo); len(items) > 0 {
|
||||
routeStr = RouteStationsStrOfWO(items)
|
||||
}
|
||||
}
|
||||
if _, cerr := s.ctx.EntClient.AssociationTrace.Create().
|
||||
SetFinishedSn(sn).SetOrderNo(wp.OrderNo).SetProcessCode(routeStr).
|
||||
SetBatchItems(batchItems).SetSerialItems([]string{}).SetOperator(operator).Save(ctx); cerr != nil {
|
||||
logx.Errorf("虚拟工位自动完工失败(关联追溯):sn=%s err=%v", sn, cerr)
|
||||
}
|
||||
}
|
||||
s.bumpWorkOrderProgress(ctx, wp.OrderNo, sn)
|
||||
s.bumpDailyPlanCompleted(ctx, wp.OrderNo, now)
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.auto_done", wp.OrderNo, operator, "workpiece", sn,
|
||||
"虚拟工位末道工序报工自动完工", map[string]any{"stationNo": stationNo, "orderNo": wp.OrderNo})
|
||||
s.notifyDashboard()
|
||||
}
|
||||
|
||||
// validateNeedCheck 检测确认(needCheck)服务端强校验。
|
||||
// 规则:本工位在本工艺组合中的出现序号 k 对应的步骤(seq=k),凡标记 needCheck=true,
|
||||
// 报工请求里必须存在对应 stepId 且 checked=true 的步骤数据;缺失则拒绝报工。
|
||||
|
||||
Reference in New Issue
Block a user