feat: 看板管理屏专属面板与追溯查询三合一 + AGV状态WS实时推送 + 数据库错误友好文案分层
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
token "bj_power_mes/common/token"
|
||||
"bj_power_mes/common/httpx"
|
||||
token "bj_power_mes/common/token"
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/inspectionrecord"
|
||||
"bj_power_mes/ent/material"
|
||||
@@ -129,7 +129,6 @@ func StationOpIdInt(r *http.Request) (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
|
||||
// LogImpersonation 防冒名探测器(方案 B 补2):当请求体 operator 与登录态可信 operator 不一致时,
|
||||
// 写一条 security.impersonation 安全告警(含双方身份与工位号),用于上线后监测是否有人伪造操作人。
|
||||
// 仅在携带登录态(内部路由经 StationSessionAuth)时生效;管理后台 JWT 路径 bodyOp 为空不触发。
|
||||
@@ -320,6 +319,45 @@ func DoneWorkpieceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// WorkpieceLookupInternalHandler GET /api/internal/workpiece/lookup?sn=
|
||||
// 2026-11-16 拍板:建工单时已按数量预生成全部 SN(workpiece.status=NEW,带 order_no/work_order_id),
|
||||
// 工位终端上线建档只需扫 SN 即可秒认工单,不再让工人手选工单。查不到 SN 明确提示,不静默放行。
|
||||
// 纯查询接口,不加表、不加字段。
|
||||
func WorkpieceLookupInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
sn := strings.TrimSpace(r.URL.Query().Get("sn"))
|
||||
if sn == "" {
|
||||
httpx.Fail(w, 2003, "SN 必填")
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
wp, err := svcCtx.EntClient.Workpiece.Query().Where(workpiece.SnEQ(sn)).Only(ctx)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2003, "该 SN 未在建工单时生成,请确认 SN 是否正确,或先在 MES 建单")
|
||||
return
|
||||
}
|
||||
wo, err := svcCtx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNoEQ(wp.OrderNo)).Only(ctx)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2003, "该 SN 未找到对应工单")
|
||||
return
|
||||
}
|
||||
snMode := 0
|
||||
if wo.ProductCode != "" {
|
||||
if m, e := svcCtx.EntClient.Material.Query().Where(material.CodeEQ(wo.ProductCode)).Only(ctx); e == nil {
|
||||
snMode = m.SnMode
|
||||
}
|
||||
}
|
||||
httpx.Ok(w, map[string]any{
|
||||
"sn": sn, "orderNo": wo.WorkOrderNo, "workOrderId": wo.ID,
|
||||
"productCode": wo.ProductCode, "productName": wo.ProductName,
|
||||
"productSnMode": snMode, "workOrderStatus": wo.Status,
|
||||
"ownershipType": wo.OwnershipType, "ownershipNo": wo.ContractNo,
|
||||
"quantity": wo.Quantity, "flowCombination": wo.FlowCombination,
|
||||
"pieceStatus": wp.Status,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// FinishedLookupInternalHandler GET /api/internal/finished/lookup?sn=
|
||||
// 2026-11-13 拍板:WMS「成品入库」扫 SN 自动带出工单;图号/产品名称/产品状态/归属全部由 MES 透传,
|
||||
// WMS 只读展示、禁止库管手选。MES 侧没有「产品型号/SN 档案字段」这类臆造概念——SN 属于工件(workpiece.sn),
|
||||
@@ -410,8 +448,8 @@ func DashboardConfigInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
httpx.Ok(w, map[string]any{
|
||||
"title": vo.DashboardTitle,
|
||||
"voiceOn": vo.DashboardVoice,
|
||||
"kpiVisible": vo.DashboardKpiVisible, // JSON 数组字符串(前端 boardService 两种都兼容)
|
||||
"animationLevel": vo.DashboardAnimationLevel, // full/simple/off
|
||||
"kpiVisible": vo.DashboardKpiVisible, // JSON 数组字符串(前端 boardService 两种都兼容)
|
||||
"animationLevel": vo.DashboardAnimationLevel, // full/simple/off
|
||||
"titleScroll": vo.DashboardBoardTitleScroll, // 0/1
|
||||
})
|
||||
}
|
||||
@@ -430,3 +468,38 @@ func DashboardMaterialQueryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
// DashboardTempoHandler 管理屏节拍查询(客户诉求9):按天/3天/5天跨度汇总按人/按工艺/按工位节拍。
|
||||
func DashboardTempoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
days, _ := strconv.Atoi(r.URL.Query().Get("days"))
|
||||
data := logic.New(svcCtx).DashboardTempo(r.Context(), days)
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
// DashboardContractQueryHandler 管理屏合同号反查(客户诉求1):按合同号反查关联工单及成品流向。
|
||||
func DashboardContractQueryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
contractNo := r.URL.Query().Get("contractNo")
|
||||
data, err := logic.New(svcCtx).DashboardContractQuery(r.Context(), contractNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2011, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
// DashboardBatchTraceHandler 管理屏来料批次反查成品(客户诉求8):按批次反查关联成品 SN 列表。
|
||||
func DashboardBatchTraceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
batch := r.URL.Query().Get("batch")
|
||||
data, err := logic.New(svcCtx).DashboardBatchTrace(r.Context(), batch)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2012, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/workpiece/trace", Handler: internal(production.WorkpieceTraceInternalHandler(serverCtx)),
|
||||
})
|
||||
// 2026-11-16 拍板:工位终端上线建档扫 SN → MES 秒认工单并带出产品/归属只读信息(建单时已预生成 SN)。
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/workpiece/lookup", Handler: internal(production.WorkpieceLookupInternalHandler(serverCtx)),
|
||||
})
|
||||
// 2026-11-13 拍板:WMS 成品入库扫 SN → MES 透传工单/图号/名称/产品状态(只读);WMS 只在此链路调用,物料入库不依赖 MES。
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/finished/lookup", Handler: internal(production.FinishedLookupInternalHandler(serverCtx)),
|
||||
@@ -62,6 +66,16 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/material-query", Handler: internal(production.DashboardMaterialQueryHandler(serverCtx)),
|
||||
})
|
||||
// 客户 22 条:管理屏节拍(跨度)/合同号反查/来料批次反查
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/tempo", Handler: internal(production.DashboardTempoHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/contract-query", Handler: internal(production.DashboardContractQueryHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/batch-trace", Handler: internal(production.DashboardBatchTraceHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dashboard/stream", Handler: internal(serverCtx.SSE.Handler),
|
||||
}, rest.WithTimeout(3600_000_000_000))
|
||||
|
||||
@@ -47,7 +47,8 @@ func (s *Service) DashboardSnapshot(ctx context.Context) (*DashboardSnapshot, er
|
||||
snap.VirtualEquipment = s.buildEquipment(ctx, today, true) // 虚拟工位(OFFLINE,不连PLC)单独下发
|
||||
snap.Agv = s.buildAgv(ctx)
|
||||
snap.Performance = s.buildPerformance(ctx, today)
|
||||
snap.Alarms = s.buildAlarms(ctx, today)
|
||||
snap.Alarms = s.buildManageAlarms(ctx, today, s.buildAlarms(ctx, today)) // 客户诉求2:接入告警中心未处置项
|
||||
snap.Manage = s.buildManage(ctx, today) // 客户22条:管理屏专属聚合
|
||||
snap.Trends = s.buildTrends(ctx)
|
||||
snap.Events = s.buildEvents(ctx)
|
||||
s.CheckBackupOverdueAlert(ctx) // 备份超期→预警中心(惰性检查,天级节流,无定时器)
|
||||
|
||||
@@ -3,6 +3,7 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -37,8 +38,11 @@ type FrontStation struct {
|
||||
CurrentOperator string `json:"currentOperator"`
|
||||
CurrentProcess string `json:"currentProcess"` // 最近一道工序名
|
||||
DoneCount int `json:"doneCount"` // 今日完成数
|
||||
PlanCount int `json:"planCount"` // 当日计划数(客户诉求4:工位完成率=完成/计划)
|
||||
Paused bool `json:"paused"` // 当天已停单(前端仅图标提示)
|
||||
PauseReason string `json:"pauseReason,omitempty"`
|
||||
// 工位状态标签(客户诉求11):normal / shortage / leave / offline,前端据此渲染灰/正常/红呼吸灯
|
||||
StationTag string `json:"stationTag"`
|
||||
}
|
||||
|
||||
// FrontProduction 产能总览(前端 ProductionOverview)
|
||||
@@ -72,15 +76,15 @@ type FrontMovement struct {
|
||||
|
||||
// FrontWarehouse 仓储动态(前端 WarehouseOverview,数据源 WMS 8890)
|
||||
type FrontWarehouse struct {
|
||||
TotalStock int `json:"totalStock"`
|
||||
MaterialTypes int `json:"materialTypes"`
|
||||
InboundToday int `json:"inboundToday"`
|
||||
OutboundToday int `json:"outboundToday"`
|
||||
LocationUsed int `json:"locationUsed"`
|
||||
LocationTotal int `json:"locationTotal"`
|
||||
PendingInbound int `json:"pendingInbound"`
|
||||
PendingOutbound int `json:"pendingOutbound"`
|
||||
Movements []FrontMovement `json:"movements"`
|
||||
TotalStock int `json:"totalStock"`
|
||||
MaterialTypes int `json:"materialTypes"`
|
||||
InboundToday int `json:"inboundToday"`
|
||||
OutboundToday int `json:"outboundToday"`
|
||||
LocationUsed int `json:"locationUsed"`
|
||||
LocationTotal int `json:"locationTotal"`
|
||||
PendingInbound int `json:"pendingInbound"`
|
||||
PendingOutbound int `json:"pendingOutbound"`
|
||||
Movements []FrontMovement `json:"movements"`
|
||||
}
|
||||
|
||||
// FrontProgress 当前订单卡片(前端 ProductionProgress)
|
||||
@@ -110,18 +114,18 @@ type FrontTrends struct {
|
||||
|
||||
// FrontDashboard 前端全量快照(与 MES /board 前端数据契约对齐;isDemo 由前端标注,不回传)
|
||||
type FrontDashboard struct {
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Production FrontProduction `json:"production"`
|
||||
Warehouse FrontWarehouse `json:"warehouse"`
|
||||
Equipment []FrontStation `json:"equipment"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Production FrontProduction `json:"production"`
|
||||
Warehouse FrontWarehouse `json:"warehouse"`
|
||||
Equipment []FrontStation `json:"equipment"`
|
||||
// VirtualStations 虚拟工位(OFFLINE,不连PLC):地图"虚拟工位"滚动栏展示,不混入 equipment(12 工位映射口径不变)
|
||||
VirtualStations []FrontStation `json:"virtualStations"`
|
||||
Progress FrontProgress `json:"progress"`
|
||||
Progress FrontProgress `json:"progress"`
|
||||
// ProgressList 当前在产订单列表(多订单轮播):进行中的工单排前,最多 6 条;
|
||||
// 首条与 Progress 一致(老消费方可继续只用 progress)。
|
||||
ProgressList []FrontProgress `json:"progressList"`
|
||||
Traces []TraceItem `json:"traces"`
|
||||
Trends FrontTrends `json:"trends"`
|
||||
Traces []TraceItem `json:"traces"`
|
||||
Trends FrontTrends `json:"trends"`
|
||||
// Points 产线点位态(主线 15 位 / 接驳台 21 位 / 在途路径指令),驱动 2D 地图真实亮灭与流光
|
||||
Points FrontPoints `json:"points"`
|
||||
// Agv AGV 实时搬运任务(真实备料任务驱动;无坐标,前端按状态+目标接驳台做过渡动画)
|
||||
@@ -130,6 +134,9 @@ type FrontDashboard struct {
|
||||
Events []EventItem `json:"events"`
|
||||
// Alarms 仅用于前端语音播报(D2),不渲染到屏幕(报喜不报忧)。
|
||||
Alarms []AlarmItem `json:"alarms"`
|
||||
// Manage 管理屏专属聚合:停机TOP/不良TOP/返修报废/节拍/缺料/低库存。
|
||||
// 演示屏报喜不报忧——前端按 isManageScreen 决定是否渲染,本字段不下发负面数据到演示屏 UI。
|
||||
Manage ManageStats `json:"manage"`
|
||||
// RefreshSeconds 看板轮询兜底刷新间隔(秒,1~10),由 dashboard.refresh.seconds 配置驱动;
|
||||
// 仅影响 SSE 实时通道不可用时的 HTTP 轮询周期,SSE 可用时不依赖此值。
|
||||
RefreshSeconds int `json:"refreshSeconds"`
|
||||
@@ -157,6 +164,18 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
onlineDevices := 0
|
||||
summary := StationSummary{}
|
||||
equipment := make([]FrontStation, 0, len(r.Equipment))
|
||||
// 客户诉求4:工位当日计划数(daily_plan.stationPlanQty),按工位号映射
|
||||
todayPlan := s.stationPlanQtyMap(ctx, time.Now())
|
||||
stationTag := func(st StationState) string {
|
||||
// 客户诉求11:工位状态标签——offline灰 / paused缺料或离开→红呼吸灯 / running正常 / idle空闲
|
||||
if st.Status == "offline" {
|
||||
return "offline"
|
||||
}
|
||||
if st.Paused {
|
||||
return "shortage" // 停单(缺料/离开)→红呼吸灯
|
||||
}
|
||||
return "normal"
|
||||
}
|
||||
for _, st := range r.Equipment {
|
||||
tool := "online"
|
||||
switch st.Status {
|
||||
@@ -185,8 +204,10 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
CurrentOperator: st.CurrentOperator,
|
||||
CurrentProcess: st.CurrentProcess,
|
||||
DoneCount: st.DoneToday,
|
||||
PlanCount: todayPlan[strconv.Itoa(st.StationNo)],
|
||||
Paused: st.Paused,
|
||||
PauseReason: st.PauseReason,
|
||||
StationTag: stationTag(st),
|
||||
})
|
||||
}
|
||||
f.Equipment = equipment
|
||||
@@ -213,8 +234,10 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
CurrentOperator: st.CurrentOperator,
|
||||
CurrentProcess: st.CurrentProcess,
|
||||
DoneCount: st.DoneToday,
|
||||
PlanCount: todayPlan[strconv.Itoa(st.StationNo)],
|
||||
Paused: st.Paused,
|
||||
PauseReason: st.PauseReason,
|
||||
StationTag: stationTag(st),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -269,15 +292,15 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
})
|
||||
}
|
||||
f.Warehouse = FrontWarehouse{
|
||||
TotalStock: r.Warehouse.TotalQty,
|
||||
MaterialTypes: r.Warehouse.MaterialTypes,
|
||||
InboundToday: r.Warehouse.InToday,
|
||||
OutboundToday: r.Warehouse.OutToday,
|
||||
LocationUsed: r.Warehouse.LocationUsed,
|
||||
LocationTotal: r.Warehouse.LocationTotal,
|
||||
PendingInbound: r.Warehouse.PendingInbound,
|
||||
TotalStock: r.Warehouse.TotalQty,
|
||||
MaterialTypes: r.Warehouse.MaterialTypes,
|
||||
InboundToday: r.Warehouse.InToday,
|
||||
OutboundToday: r.Warehouse.OutToday,
|
||||
LocationUsed: r.Warehouse.LocationUsed,
|
||||
LocationTotal: r.Warehouse.LocationTotal,
|
||||
PendingInbound: r.Warehouse.PendingInbound,
|
||||
PendingOutbound: r.Warehouse.PendingOutbound,
|
||||
Movements: movements,
|
||||
Movements: movements,
|
||||
}
|
||||
|
||||
// -------- 当前订单卡片 --------
|
||||
@@ -351,12 +374,11 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
f.Agv = make([]FrontAgvRobot, 0, len(r.Agv.Robots))
|
||||
for _, rb := range r.Agv.Robots {
|
||||
f.Agv = append(f.Agv, FrontAgvRobot{
|
||||
Code: rb.Code,
|
||||
Status: rb.Status,
|
||||
From: dockCnLabel(dockCodeToCode(rb.FromDock)),
|
||||
To: dockCnLabel(dockCodeToCode(rb.ToDock)),
|
||||
Carrier: rb.Carrier,
|
||||
TaskNo: rb.TaskNo,
|
||||
Code: rb.Code, Status: rb.Status,
|
||||
StatusLabel: agvStatusLabel(rb.Status), // 客户诉求12:看板按状态映射颜色图标
|
||||
From: dockCnLabel(dockCodeToCode(rb.FromDock)),
|
||||
To: dockCnLabel(dockCodeToCode(rb.ToDock)),
|
||||
Carrier: rb.Carrier, TaskNo: rb.TaskNo,
|
||||
})
|
||||
}
|
||||
// 事件流:过滤 NG 结果项(大屏报喜不报忧;负面事件只进语音播报 alarms)
|
||||
@@ -367,14 +389,35 @@ func (s *Service) mapFrontDashboard(ctx context.Context, r *DashboardSnapshot) *
|
||||
}
|
||||
f.Events = append(f.Events, e)
|
||||
}
|
||||
// 报警仅透传给前端做语音播报(D2),屏幕不渲染(报喜不报忧)。
|
||||
// 报警仅透传给前端做语音播报(D2),屏幕不渲染(报喜不报忧);管理屏告警条由 isManageScreen 控制渲染。
|
||||
f.Alarms = r.Alarms
|
||||
if f.Alarms == nil {
|
||||
f.Alarms = []AlarmItem{}
|
||||
}
|
||||
// 管理屏专属聚合(客户 22 条):停机TOP/不良TOP/返修报废/节拍/缺料/低库存。
|
||||
// 演示屏报喜不报忧——前端按 isManageScreen 决定是否渲染这些字段。
|
||||
f.Manage = r.Manage
|
||||
return f
|
||||
}
|
||||
|
||||
// agvStatusLabel AGV 状态 → 中文显示名(客户诉求12:看板按空闲/运送/故障/充电映射颜色图标)
|
||||
func agvStatusLabel(status string) string {
|
||||
switch strings.ToLower(status) {
|
||||
case "idle", "waiting", "done":
|
||||
return "空闲"
|
||||
case "moving", "delivering":
|
||||
return "运送中"
|
||||
case "loading", "locked":
|
||||
return "装货中"
|
||||
case "charging":
|
||||
return "充电"
|
||||
case "fault", "error":
|
||||
return "故障"
|
||||
default:
|
||||
return "待命"
|
||||
}
|
||||
}
|
||||
|
||||
// shortDate "2006-01-02 15:04:05" → "2006-01-02"
|
||||
func shortDate(s string) string {
|
||||
if len(s) >= 10 {
|
||||
|
||||
@@ -0,0 +1,363 @@
|
||||
package logic
|
||||
|
||||
// 管理屏聚合(2026-11-16 客户 22 条诉求)。
|
||||
// 双屏机制:演示屏(未登录/参观指导)报喜不报忧;管理屏(其他登录账号)渲染本文件聚合的负面/管理数据。
|
||||
// 全部复用现有底座,不新建数据表、不重复造轮子:
|
||||
// - 停机原因:reasonDict + station_state.reason(现成字典与写入点)
|
||||
// - 不良:torque_record.NG + workpiece_process.NG(现成 NG 数据)
|
||||
// - 返修报废:trial_record(成品试验区,已建表)
|
||||
// - 节拍:workpiece_process.duration_sec(与 processflow.WorkloadRow 同源口径)
|
||||
// - 缺料:shortage_request + 现成支撑台数推算口径
|
||||
// - 告警:alert 表现成未处置项
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/alert"
|
||||
"bj_power_mes/ent/dailyplan"
|
||||
"bj_power_mes/ent/shortagerequest"
|
||||
"bj_power_mes/ent/stationstate"
|
||||
"bj_power_mes/ent/torquerecord"
|
||||
"bj_power_mes/ent/workpiece"
|
||||
"bj_power_mes/ent/workpieceprocess"
|
||||
)
|
||||
|
||||
// buildManage 管理屏聚合总入口。每块单独容错,某块失败只降级该块,不影响整屏。
|
||||
func (s *Service) buildManage(ctx context.Context, today time.Time) ManageStats {
|
||||
m := ManageStats{
|
||||
DownstopTop: []RankItem{},
|
||||
DefectTop: []RankItem{},
|
||||
Tempo: TempoStats{ByOperator: []TempoRow{}, ByProcess: []TempoRow{}, ByStation: []TempoRow{}, Days: 1},
|
||||
Shortages: []ShortageRow{},
|
||||
LowStockAlerts: []StockAlert{},
|
||||
}
|
||||
m.DownstopTop = s.buildDownstopTop(ctx, today)
|
||||
m.DefectTop, m.NgRate, m.NgTotal = s.buildDefectTop(ctx, today)
|
||||
m.Trials = s.buildTrialSummary(ctx)
|
||||
m.Tempo = s.buildTempo(ctx, today)
|
||||
m.Shortages = s.buildShortages(ctx)
|
||||
return m
|
||||
}
|
||||
|
||||
// buildDownstopTop 停机 TOP:按当天 station_state.reason(停机原因字典)聚合,附工位号。
|
||||
// 客户诉求 5:停机 TOP 排行(缺料/工具故障/其他设备),原因字典已就绪(reasonDict["stop"])。
|
||||
func (s *Service) buildDownstopTop(ctx context.Context, today time.Time) []RankItem {
|
||||
reasonCnt := map[string]int{}
|
||||
reasonStations := map[string][]int{}
|
||||
if pauses, err := s.ctx.EntClient.StationState.Query().
|
||||
Where(stationstate.Date(today.Format("2006-01-02")), stationstate.Paused(true)).All(ctx); err == nil {
|
||||
for _, p := range pauses {
|
||||
reason := strings.TrimSpace(p.Reason)
|
||||
if reason == "" {
|
||||
reason = "未填写原因"
|
||||
}
|
||||
reasonCnt[reason]++
|
||||
reasonStations[reason] = append(reasonStations[reason], p.StationNo)
|
||||
}
|
||||
}
|
||||
return rankFromReasonMap(reasonCnt, reasonStations, "停机")
|
||||
}
|
||||
|
||||
// buildDefectTop 不良率/不良总数/不良分类 TOP(客户诉求 6,生产中)。
|
||||
// 数据源:当天拧紧 NG(torque_record)+ 工序 NG(workpiece_process)。
|
||||
// 不良原因字典(reasonDict["defect"])在终端已按类选择,但 NG 明细未逐条存原因字段(当前底座),
|
||||
// 故分类 TOP 用「按工位 / 按人」两个维度呈现,与 NgByStation/NgByOperator 契约一致。
|
||||
func (s *Service) buildDefectTop(ctx context.Context, today time.Time) ([]RankItem, float64, int) {
|
||||
tomorrow := today.Add(24 * time.Hour)
|
||||
byStation := map[string]int{}
|
||||
byOperator := map[string]int{}
|
||||
total, ng := 0, 0
|
||||
if recs, err := s.ctx.EntClient.TorqueRecord.Query().
|
||||
Where(torquerecord.TimeGTE(today), torquerecord.TimeLT(tomorrow)).All(ctx); err == nil {
|
||||
for _, r := range recs {
|
||||
total++
|
||||
if strings.EqualFold(r.Result, "NG") {
|
||||
ng++
|
||||
byStation[r.StationNo]++
|
||||
byOperator[r.Operator]++
|
||||
}
|
||||
}
|
||||
}
|
||||
ngRate := safeRate(float64(ng), float64(total))
|
||||
// 合并工位与人员两个维度到同一 TOP(工位前缀区分,key 唯一)
|
||||
merged := map[string]int{}
|
||||
for k, v := range byStation {
|
||||
merged["工位·"+k] += v
|
||||
}
|
||||
for k, v := range byOperator {
|
||||
if k == "" {
|
||||
k = "未记录"
|
||||
}
|
||||
merged["人员·"+k] += v
|
||||
}
|
||||
top := rankFromReasonMap(merged, map[string][]int{}, "不良")
|
||||
return top, ngRate, ng
|
||||
}
|
||||
|
||||
// buildTrialSummary 返修/报废原因(客户诉求 7,生产后试验区):直接读 trial_record 表。
|
||||
func (s *Service) buildTrialSummary(ctx context.Context) TrialSummary {
|
||||
out := TrialSummary{Reasons: []RankItem{}}
|
||||
reasonCnt := map[string]int{}
|
||||
if rows, err := s.ctx.EntClient.TrialRecord.Query().All(ctx); err == nil {
|
||||
for _, r := range rows {
|
||||
switch r.Result {
|
||||
case TrialResultOK:
|
||||
out.OK++
|
||||
case TrialResultRepair:
|
||||
out.Repair++
|
||||
case TrialResultScrap:
|
||||
out.Scrap++
|
||||
}
|
||||
if r.Result == TrialResultRepair || r.Result == TrialResultScrap {
|
||||
reason := strings.TrimSpace(r.Reason)
|
||||
if reason == "" {
|
||||
reason = "未填写原因"
|
||||
}
|
||||
reasonCnt[reason]++
|
||||
}
|
||||
}
|
||||
}
|
||||
out.Reasons = rankFromReasonMap(reasonCnt, map[string][]int{}, "原因")
|
||||
return out
|
||||
}
|
||||
|
||||
// buildTempo 节拍对比/瓶颈识别(客户诉求 9,禁止降级)。
|
||||
// 复用 processflow.WorkloadRow 同源口径:时长取 workpiece_process.duration_sec。
|
||||
// 默认统计当天(Days=1);前端选 1/3/5 天跨度时通过独立查询接口获取(见 DashboardTempo)。
|
||||
func (s *Service) buildTempo(ctx context.Context, today time.Time) TempoStats {
|
||||
return s.buildTempoSince(ctx, today, 1)
|
||||
}
|
||||
|
||||
// buildTempoSince 按跨度(天)聚合节拍。给富快照用 days=1,给独立查询接口用 days=1/3/5。
|
||||
func (s *Service) buildTempoSince(ctx context.Context, from time.Time, days int) TempoStats {
|
||||
out := TempoStats{
|
||||
ByOperator: []TempoRow{}, ByProcess: []TempoRow{}, ByStation: []TempoRow{}, Days: days,
|
||||
}
|
||||
since := from.AddDate(0, 0, -(days - 1))
|
||||
type agg struct {
|
||||
count int
|
||||
sumSec int
|
||||
}
|
||||
byOp := map[string]*agg{}
|
||||
byProc := map[string]*agg{}
|
||||
bySt := map[string]*agg{}
|
||||
if rows, err := s.ctx.EntClient.WorkpieceProcess.Query().
|
||||
Where(workpieceprocess.EndedAtGTE(since)).All(ctx); err == nil {
|
||||
for _, r := range rows {
|
||||
dur := r.DurationSec
|
||||
if dur <= 0 {
|
||||
continue
|
||||
}
|
||||
op := strings.TrimSpace(r.Operator)
|
||||
if op == "" {
|
||||
op = "未记录"
|
||||
}
|
||||
proc := strings.TrimSpace(r.ProcessName)
|
||||
if proc == "" {
|
||||
proc = "未命名工序"
|
||||
}
|
||||
st := strings.TrimSpace(r.StationNo)
|
||||
if st == "" {
|
||||
st = "0"
|
||||
}
|
||||
add := func(m map[string]*agg, k string) {
|
||||
a := m[k]
|
||||
if a == nil {
|
||||
a = &agg{}
|
||||
m[k] = a
|
||||
}
|
||||
a.count++
|
||||
a.sumSec += dur
|
||||
}
|
||||
add(byOp, op)
|
||||
add(byProc, proc)
|
||||
add(bySt, "工位"+st)
|
||||
}
|
||||
}
|
||||
toRows := func(m map[string]*agg) []TempoRow {
|
||||
rows := make([]TempoRow, 0, len(m))
|
||||
minAvg := 0
|
||||
for k, a := range m {
|
||||
avg := 0
|
||||
if a.count > 0 {
|
||||
avg = a.sumSec / a.count
|
||||
}
|
||||
rows = append(rows, TempoRow{Key: k, Label: k, Count: a.count, AvgSec: avg})
|
||||
if avg > 0 && (minAvg == 0 || avg < minAvg) {
|
||||
minAvg = avg
|
||||
}
|
||||
}
|
||||
for i := range rows {
|
||||
// 相对效率 = 最快平均耗时 / 本行平均耗时 × 100(越快越接近 100)
|
||||
if rows[i].AvgSec > 0 && minAvg > 0 {
|
||||
rows[i].EffRate = float64(minAvg) / float64(rows[i].AvgSec) * 100
|
||||
}
|
||||
}
|
||||
sort.Slice(rows, func(i, j int) bool { return rows[i].AvgSec > rows[j].AvgSec }) // 耗时最长(瓶颈)排前
|
||||
return rows
|
||||
}
|
||||
out.ByOperator = toRows(byOp)
|
||||
out.ByProcess = toRows(byProc)
|
||||
out.ByStation = toRows(bySt)
|
||||
return out
|
||||
}
|
||||
|
||||
// buildShortages 即将缺料(客户诉求 10):读 shortage_request 当前 PENDING 单,按工位聚合。
|
||||
// 现有 shortage_predict(evaluateShortageAfterReport)推的是支撑台数,本处把待审批补料单按工位列出;
|
||||
// etaMinutes=-1 表示无节拍数据无法估算,前端显示「—」。
|
||||
func (s *Service) buildShortages(ctx context.Context) []ShortageRow {
|
||||
out := []ShortageRow{}
|
||||
reqs, err := s.ctx.EntClient.ShortageRequest.Query().
|
||||
Where(shortagerequest.Status("PENDING")).
|
||||
Order(ent.Desc(shortagerequest.FieldCreatedAt)).Limit(30).All(ctx)
|
||||
if err != nil || len(reqs) == 0 {
|
||||
return out
|
||||
}
|
||||
seen := map[int]bool{}
|
||||
for _, r := range reqs {
|
||||
if seen[r.StationNo] {
|
||||
continue
|
||||
}
|
||||
seen[r.StationNo] = true
|
||||
out = append(out, ShortageRow{
|
||||
StationNo: r.StationNo,
|
||||
Material: r.MaterialName,
|
||||
SupportQty: 0,
|
||||
Critical: true,
|
||||
EtaMinutes: -1,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// DashboardTempo 独立节拍查询接口(客户诉求 9:按天/3天/5天跨度汇总)。
|
||||
// 由前端选择跨度时调用,不进 60s 快照缓存。
|
||||
func (s *Service) DashboardTempo(ctx context.Context, days int) TempoStats {
|
||||
if days < 1 {
|
||||
days = 1
|
||||
}
|
||||
if days > 5 {
|
||||
days = 5
|
||||
}
|
||||
return s.buildTempoSince(ctx, dayStart(time.Now()), days)
|
||||
}
|
||||
|
||||
// DashboardContractQuery 合同号反查(客户诉求 1/8):按合同号反查关联工单及成品 SN。
|
||||
// 复用 workorder.ContractNo 过滤(ListWorkOrders 同源口径)+ workpiece 按工单反查 SN。
|
||||
func (s *Service) DashboardContractQuery(ctx context.Context, contractNo string) (*ContractFlow, error) {
|
||||
out := &ContractFlow{ContractNo: contractNo, Orders: []ContractOrder{}, Found: false}
|
||||
contractNo = strings.TrimSpace(contractNo)
|
||||
if contractNo == "" {
|
||||
return out, nil
|
||||
}
|
||||
wos, err := s.ListWorkOrders(ctx, "", "", "", "", contractNo, "", "", 50, 0, 0)
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
for _, wo := range wos {
|
||||
co := ContractOrder{
|
||||
OrderNo: wo.WorkOrderNo, ProductName: wo.ProductName,
|
||||
TotalQty: wo.Quantity, DoneQty: wo.FinishedNum, Status: wo.Status,
|
||||
FinishedSNs: []string{}, MaterialLots: []string{},
|
||||
}
|
||||
// 成品 SN:workpiece 按工单反查(SN 是成品唯一标识)
|
||||
if wps, e := s.ctx.EntClient.Workpiece.Query().Where(workpiece.OrderNoEQ(wo.WorkOrderNo)).All(ctx); e == nil {
|
||||
for _, wp := range wps {
|
||||
if sn := strings.TrimSpace(wp.Sn); sn != "" {
|
||||
co.FinishedSNs = append(co.FinishedSNs, sn)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(co.FinishedSNs) > 0 || co.DoneQty > 0 {
|
||||
out.Found = true
|
||||
}
|
||||
out.Orders = append(out.Orders, co)
|
||||
}
|
||||
if len(out.Orders) > 0 {
|
||||
out.Found = true
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DashboardBatchTrace 来料批次反查成品(客户诉求 8):按批次号反查用到该批次的成品 SN 列表。
|
||||
// 复用 association_trace(工件-物料关联)现成表;无关联数据时返回 found=false。
|
||||
func (s *Service) DashboardBatchTrace(ctx context.Context, batch string) (*BatchTrace, error) {
|
||||
out := &BatchTrace{Batch: batch, SNs: []string{}, Found: false}
|
||||
batch = strings.TrimSpace(batch)
|
||||
if batch == "" {
|
||||
return out, nil
|
||||
}
|
||||
// association_trace.batch_items 是 JSON 数组,无法 SQL 过滤,拉全部在内存里比对批次(现场关联量可控)
|
||||
seen := map[string]bool{}
|
||||
if rows, err := s.ctx.EntClient.AssociationTrace.Query().All(ctx); err == nil {
|
||||
for _, r := range rows {
|
||||
hit := false
|
||||
for _, b := range r.BatchItems {
|
||||
if strings.TrimSpace(b) == batch {
|
||||
hit = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if hit && r.FinishedSn != "" && !seen[r.FinishedSn] {
|
||||
seen[r.FinishedSn] = true
|
||||
out.SNs = append(out.SNs, r.FinishedSn)
|
||||
}
|
||||
}
|
||||
}
|
||||
out.Found = len(out.SNs) > 0
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// rankFromReasonMap 通用原因聚合 → RankItem 列表(按 count 降序,带工位号),供停机/不良/返修原因共用。
|
||||
func rankFromReasonMap(cnt map[string]int, stations map[string][]int, prefix string) []RankItem {
|
||||
out := make([]RankItem, 0, len(cnt))
|
||||
for k, v := range cnt {
|
||||
out = append(out, RankItem{Key: k, Label: prefix + "·" + k, Count: v, StationNos: stations[k]})
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Count > out[j].Count })
|
||||
return out
|
||||
}
|
||||
|
||||
// buildManageAlarms 告警中心未处置项接入管理屏告警条(客户诉求 2)。
|
||||
// 现两条告警源(拧紧NG/PLC在途)保留,追加 alert 表 UNREAD 项。
|
||||
func (s *Service) buildManageAlarms(ctx context.Context, today time.Time, base []AlarmItem) []AlarmItem {
|
||||
items := append([]AlarmItem{}, base...)
|
||||
if unread, err := s.ctx.EntClient.Alert.Query().
|
||||
Where(alert.Status("UNREAD")).
|
||||
Order(ent.Desc(alert.FieldCreatedAt)).Limit(10).All(ctx); err == nil {
|
||||
for _, a := range unread {
|
||||
msg := strings.TrimSpace(a.Content)
|
||||
if msg == "" {
|
||||
msg = a.Title
|
||||
}
|
||||
level := strings.ToLower(a.Level)
|
||||
if level != "critical" && level != "warning" {
|
||||
level = "warning"
|
||||
}
|
||||
items = append(items, AlarmItem{
|
||||
ID: "alert-" + itoa(a.ID), Level: level, Type: a.Type,
|
||||
Target: a.Target, Message: msg,
|
||||
Time: fmtDashboardTime(a.CreatedAt), Status: a.Status,
|
||||
})
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
// 工位计划数(客户诉求 4):读当天 daily_plan.stationPlanQty(map[string]int),按工位号映射。
|
||||
func (s *Service) stationPlanQtyMap(ctx context.Context, today time.Time) map[string]int {
|
||||
out := map[string]int{}
|
||||
if plans, err := s.ctx.EntClient.DailyPlan.Query().
|
||||
Where(dailyplan.PlanDate(today.Format("2006-01-02"))).All(ctx); err == nil {
|
||||
for _, p := range plans {
|
||||
for k, v := range p.StationPlanQty {
|
||||
out[k] += v
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -38,14 +38,14 @@ type WorkOrderProgress struct {
|
||||
|
||||
// ProductionStats 生产统计(屏1 KPI / 屏2 生产统计)
|
||||
type ProductionStats struct {
|
||||
OutputToday int `json:"outputToday"`
|
||||
TargetToday int `json:"targetToday"`
|
||||
AchieveRate float64 `json:"achieveRate"`
|
||||
InLine int `json:"inLine"`
|
||||
QualifiedRate float64 `json:"qualifiedRate"`
|
||||
QualityOk int `json:"qualityOk"`
|
||||
QualityNg int `json:"qualityNg"`
|
||||
TorqueTotal int `json:"torqueTotal"`
|
||||
OutputToday int `json:"outputToday"`
|
||||
TargetToday int `json:"targetToday"`
|
||||
AchieveRate float64 `json:"achieveRate"`
|
||||
InLine int `json:"inLine"`
|
||||
QualifiedRate float64 `json:"qualifiedRate"`
|
||||
QualityOk int `json:"qualityOk"`
|
||||
QualityNg int `json:"qualityNg"`
|
||||
TorqueTotal int `json:"torqueTotal"`
|
||||
// CycleTimeMin 实际生产节拍:相邻完工时间间隔均值(分钟)。口径可按现场调整。
|
||||
CycleTimeMin float64 `json:"cycleTime"`
|
||||
StationSummary StationSummary `json:"stationSummary"`
|
||||
@@ -107,8 +107,8 @@ type StationState struct {
|
||||
DoneToday int `json:"doneToday"`
|
||||
NgToday int `json:"ngToday"`
|
||||
LastActiveAt string `json:"lastActiveAt"`
|
||||
Paused bool `json:"paused"` // 当天已停单(station_state)
|
||||
PauseReason string `json:"pauseReason"` // 停单原因(自由文本,前端仅图标提示)
|
||||
Paused bool `json:"paused"` // 当天已停单(station_state)
|
||||
PauseReason string `json:"pauseReason"` // 停单原因(自由文本,前端仅图标提示)
|
||||
}
|
||||
|
||||
// TraceStep 工件追溯:单道工艺实绩
|
||||
@@ -147,23 +147,23 @@ type TraceStats struct {
|
||||
|
||||
// WarehouseStats 仓储动态(屏5,数据源为 WMS 8890)
|
||||
type WarehouseStats struct {
|
||||
Available bool `json:"available"`
|
||||
TotalQty int `json:"totalQty"`
|
||||
MaterialTypes int `json:"materialTypes"`
|
||||
BatchCount int `json:"batchCount"`
|
||||
SnInStock int `json:"snInStock"`
|
||||
SemiInStock int `json:"semiInStock"`
|
||||
PackageCount int `json:"packageCount"`
|
||||
InToday int `json:"inToday"`
|
||||
OutToday int `json:"outToday"`
|
||||
LockedQty int `json:"lockedQty"`
|
||||
ZoneDetail []ZoneStock `json:"zoneDetail"`
|
||||
LocationUsed int `json:"locationUsed"`
|
||||
LocationTotal int `json:"locationTotal"`
|
||||
PendingInbound int `json:"pendingInbound"`
|
||||
PendingOutbound int `json:"pendingOutbound"`
|
||||
Movements []WmsMovement `json:"movements"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Available bool `json:"available"`
|
||||
TotalQty int `json:"totalQty"`
|
||||
MaterialTypes int `json:"materialTypes"`
|
||||
BatchCount int `json:"batchCount"`
|
||||
SnInStock int `json:"snInStock"`
|
||||
SemiInStock int `json:"semiInStock"`
|
||||
PackageCount int `json:"packageCount"`
|
||||
InToday int `json:"inToday"`
|
||||
OutToday int `json:"outToday"`
|
||||
LockedQty int `json:"lockedQty"`
|
||||
ZoneDetail []ZoneStock `json:"zoneDetail"`
|
||||
LocationUsed int `json:"locationUsed"`
|
||||
LocationTotal int `json:"locationTotal"`
|
||||
PendingInbound int `json:"pendingInbound"`
|
||||
PendingOutbound int `json:"pendingOutbound"`
|
||||
Movements []WmsMovement `json:"movements"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// WmsMovement 出入库动态单条(含批次号,数据源 WMS 看板总览)
|
||||
@@ -221,7 +221,7 @@ type AlarmItem struct {
|
||||
|
||||
// FrontPoint 看板点位态(主线位置 / 接驳台)
|
||||
type FrontPoint struct {
|
||||
Code string `json:"code"` // C1..C15 / G1L..G10R / JBT21(稳定码,前端按码查占用)
|
||||
Code string `json:"code"` // C1..C15 / G1L..G10R / JBT21(稳定码,前端按码查占用)
|
||||
Label string `json:"label,omitempty"` // 中文显示名(工位N左/右、库房接驳台),地图标签数据驱动
|
||||
Has bool `json:"has"` // 有托盘=true
|
||||
}
|
||||
@@ -229,10 +229,10 @@ type FrontPoint struct {
|
||||
// FrontPoints 看板点位态集合(PLC 48 位 + 在途路径指令)。
|
||||
// Mock=true 表示 PLC 未接真实设备(模拟点位),前端角落须标「模拟数据」。
|
||||
type FrontPoints struct {
|
||||
Mock bool `json:"mock"`
|
||||
Main []FrontPoint `json:"main"` // 15 个主线位置 C1..C15
|
||||
Dock []FrontPoint `json:"dock"` // 21 个接驳台 G1L..G10R + JBT21
|
||||
Transit []InTransit `json:"transit"` // 当前在途路径指令(MW 非 0)
|
||||
Mock bool `json:"mock"`
|
||||
Main []FrontPoint `json:"main"` // 15 个主线位置 C1..C15
|
||||
Dock []FrontPoint `json:"dock"` // 21 个接驳台 G1L..G10R + JBT21
|
||||
Transit []InTransit `json:"transit"` // 当前在途路径指令(MW 非 0)
|
||||
}
|
||||
|
||||
// InTransit 一条在途路径指令(源→目标),源/目标为 G/C 编码(如 G9→C13)。
|
||||
@@ -243,12 +243,13 @@ type InTransit struct {
|
||||
|
||||
// FrontAgvRobot 看板 AGV(真实备料任务驱动,不做假坐标)。
|
||||
type FrontAgvRobot struct {
|
||||
Code string `json:"code"`
|
||||
Status string `json:"status"` // idle / loading / moving / done
|
||||
From string `json:"from"` // 起点接驳台(G1L 格式或 JBT21)
|
||||
To string `json:"to"` // 目标接驳台(空=待命)
|
||||
Carrier string `json:"carrier"` // 搬运物料名
|
||||
TaskNo string `json:"taskNo"`
|
||||
Code string `json:"code"`
|
||||
Status string `json:"status"` // idle / loading / moving / done / charging / fault
|
||||
StatusLabel string `json:"statusLabel"` // 中文状态:空闲/运送中/故障/充电(客户诉求12:看板按状态映射颜色图标)
|
||||
From string `json:"from"` // 起点接驳台(G1L 格式或 JBT21)
|
||||
To string `json:"to"` // 目标接驳台(空=待命)
|
||||
Carrier string `json:"carrier"` // 搬运物料名
|
||||
TaskNo string `json:"taskNo"`
|
||||
}
|
||||
|
||||
// TrendPoint 趋势点(产量/合格率/日合格率共用)
|
||||
@@ -265,25 +266,110 @@ type EventItem struct {
|
||||
Level string `json:"level"`
|
||||
}
|
||||
|
||||
// ===== 管理屏专属数据(2026-11-16 客户 22 条诉求,双屏机制:仅管理屏渲染,演示屏报喜不报忧)=====
|
||||
|
||||
// RankItem 已复用于停机TOP/不良TOP/节拍排行(key/label/count 语义通用)
|
||||
|
||||
// TrialSummary 生产后试验区统计(返工/返修/报废,客户诉求 7)
|
||||
type TrialSummary struct {
|
||||
OK int `json:"ok"` // 合格数
|
||||
Repair int `json:"repair"` // 返修数
|
||||
Scrap int `json:"scrap"` // 报废数
|
||||
Reasons []RankItem `json:"reasons"` // 返修/报废原因 TOP(按原因聚合)
|
||||
}
|
||||
|
||||
// TempoRow 节拍对比行(客户诉求 9):对比人/对比工艺/按天跨度,取 workpiece_process.duration_sec
|
||||
type TempoRow struct {
|
||||
Key string `json:"key"` // 人/工艺/工位的标识
|
||||
Label string `json:"label"` // 显示名
|
||||
Count int `json:"count"` // 完成数
|
||||
AvgSec int `json:"avgSec"` // 平均作业时长(秒)
|
||||
EffRate float64 `json:"effRate"` // 相对效率(%):以最快为 100
|
||||
}
|
||||
|
||||
// TempoStats 节拍/瓶颈数据(按人、按工艺、按工位三个维度,跨度由前端选 1/3/5 天)
|
||||
type TempoStats struct {
|
||||
ByOperator []TempoRow `json:"byOperator"`
|
||||
ByProcess []TempoRow `json:"byProcess"`
|
||||
ByStation []TempoRow `json:"byStation"`
|
||||
Days int `json:"days"` // 当前统计跨度(默认 1)
|
||||
}
|
||||
|
||||
// ShortageRow 即将缺料/断料行(客户诉求 10):复用 shortage_predict 的支撑台数推算
|
||||
type ShortageRow struct {
|
||||
StationNo int `json:"stationNo"`
|
||||
Material string `json:"material"`
|
||||
SupportQty int `json:"supportQty"` // 当前库存可支撑台数
|
||||
Critical bool `json:"critical"` // 已达阈值(即将断料)
|
||||
EtaMinutes int `json:"etaMinutes"` // 预计断料时间(分钟),-1=无法估算
|
||||
}
|
||||
|
||||
// ContractFlow 合同号反查流向结果(客户诉求 1/8):按合同号反查关联工单→成品/物料流向
|
||||
type ContractFlow struct {
|
||||
ContractNo string `json:"contractNo"`
|
||||
Orders []ContractOrder `json:"orders"`
|
||||
Found bool `json:"found"`
|
||||
}
|
||||
|
||||
// ContractOrder 单个合同下工单及其成品流向
|
||||
type ContractOrder struct {
|
||||
OrderNo string `json:"orderNo"`
|
||||
ProductName string `json:"productName"`
|
||||
TotalQty int `json:"totalQty"`
|
||||
DoneQty int `json:"doneQty"`
|
||||
Status string `json:"status"`
|
||||
FinishedSNs []string `json:"finishedSns"` // 关联成品 SN 列表
|
||||
MaterialLots []string `json:"materialLots"` // 关联来料批次
|
||||
}
|
||||
|
||||
// BatchTrace 来料批次反查成品(客户诉求 8):输入批次→用到该批次的成品 SN 列表
|
||||
type BatchTrace struct {
|
||||
Batch string `json:"batch"`
|
||||
SNs []string `json:"sns"`
|
||||
Found bool `json:"found"`
|
||||
}
|
||||
|
||||
// ManageStats 管理屏聚合(一次性下发,前端仅在 isManageScreen 时渲染)
|
||||
type ManageStats struct {
|
||||
DownstopTop []RankItem `json:"downstopTop"` // 停机 TOP(按停机原因+工位,客户诉求 5)
|
||||
DefectTop []RankItem `json:"defectTop"` // 不良分类 TOP(生产中,客户诉求 6)
|
||||
NgRate float64 `json:"ngRate"` // 不良率(%)
|
||||
NgTotal int `json:"ngTotal"` // 不良总数
|
||||
Trials TrialSummary `json:"trials"` // 返修/报废(生产后,客户诉求 7)
|
||||
Tempo TempoStats `json:"tempo"` // 节拍/瓶颈(客户诉求 9)
|
||||
Shortages []ShortageRow `json:"shortages"` // 即将断料(客户诉求 10)
|
||||
LowStockAlerts []StockAlert `json:"lowStockAlerts"` // 低安全库存(客户诉求 17,WMS 侧也有同构)
|
||||
}
|
||||
|
||||
// StockAlert 低安全库存告警项
|
||||
type StockAlert struct {
|
||||
Material string `json:"material"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Qty int `json:"qty"`
|
||||
SafetyStock int `json:"safetyStock"`
|
||||
}
|
||||
|
||||
// DashboardSnapshot 看板全量快照
|
||||
//
|
||||
// 一次返回全部 6 个屏所需数据,前端不再分接口拼装,避免多个接口字段各自对齐的维护成本。
|
||||
// 数据量可控:明细类(追溯 steps、扭矩散点、报警)均限条数。
|
||||
type DashboardSnapshot struct {
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Production ProductionStats `json:"production"`
|
||||
Quality QualityStats `json:"quality"`
|
||||
Trace TraceStats `json:"trace"`
|
||||
Warehouse WarehouseStats `json:"warehouse"`
|
||||
Equipment []StationState `json:"equipment"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Production ProductionStats `json:"production"`
|
||||
Quality QualityStats `json:"quality"`
|
||||
Trace TraceStats `json:"trace"`
|
||||
Warehouse WarehouseStats `json:"warehouse"`
|
||||
Equipment []StationState `json:"equipment"`
|
||||
// VirtualEquipment 虚拟工位(station_type=OFFLINE,不连 PLC、仅记录)。
|
||||
// 不混入 Equipment:12 工位地图映射与设备总数口径均按常规工位计算。
|
||||
VirtualEquipment []StationState `json:"virtualEquipment"`
|
||||
Agv AgvStats `json:"agv"`
|
||||
Performance []RankItem `json:"performance"`
|
||||
Alarms []AlarmItem `json:"alarms"`
|
||||
Trends []TrendPoint `json:"trends"`
|
||||
Events []EventItem `json:"events"`
|
||||
Agv AgvStats `json:"agv"`
|
||||
Performance []RankItem `json:"performance"`
|
||||
Alarms []AlarmItem `json:"alarms"`
|
||||
Trends []TrendPoint `json:"trends"`
|
||||
Events []EventItem `json:"events"`
|
||||
// Manage 管理屏专属聚合(客户 22 条诉求;演示屏不渲染)
|
||||
Manage ManageStats `json:"manage"`
|
||||
}
|
||||
|
||||
// 时间格式化统一口径:yyyy-MM-dd HH:mm:ss
|
||||
|
||||
@@ -59,7 +59,6 @@ type InspectionReq struct {
|
||||
// 序列号=是(sn_mode=1)填 SN、序列号=否(sn_mode=2)填批次号;
|
||||
// 定位口径由后端按物料档案 sn_mode 判定(SN=按序列号定位 / 批次=按批次定位)
|
||||
BatchSn string `json:"batchSn"`
|
||||
ReturnTrackingNo string `json:"returnTrackingNo"` // 退货运单号(退货/退换处置必填)
|
||||
// 完工检(FINAL)扩展:产成品入库随回流 WMS(选填,其他类别存了也无害)
|
||||
RelatedStandard string `json:"relatedStandard"` // 相关标准/试验方案号
|
||||
TestRecordNo string `json:"testRecordNo"` // 试验记录单号
|
||||
@@ -166,11 +165,10 @@ func (s *Service) CreateInspection(ctx context.Context, req InspectionReq, opera
|
||||
snMode = m.SnMode
|
||||
}
|
||||
wreq := wmsclient.DisposeInventoryReq{
|
||||
MaterialCode: req.MaterialCode,
|
||||
DisposalType: dt,
|
||||
ReturnTrackingNo: req.ReturnTrackingNo,
|
||||
Remark: req.DisposalRemark,
|
||||
Operator: req.Operator,
|
||||
MaterialCode: req.MaterialCode,
|
||||
DisposalType: dt,
|
||||
Remark: req.DisposalRemark,
|
||||
Operator: req.Operator,
|
||||
}
|
||||
if snMode == 1 {
|
||||
wreq.Sn = req.BatchSn
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"bj_power_mes/ent/workorder"
|
||||
"bj_power_mes/ent/workpieceprocess"
|
||||
"bj_power_mes/internal/verr"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// ---------- 工艺流程(块3) ----------
|
||||
@@ -445,6 +447,31 @@ if req.FlowId != nil {
|
||||
ve.Add("flowId", fmt.Sprintf("工位%d 存在正在进行的工单(生产路线包含此工位),禁止修改绑定工艺", st.StationNo),
|
||||
"请先将该工位的进行中工单完工或取消,再修改绑定工艺")
|
||||
}
|
||||
// 未退料闭环校验(2026-11-16 主控包项8):工位有尚未被 WMS 确认的退库单(PENDING)时,
|
||||
// 禁止改/解绑工艺绑定——强制先走完「清点退料 → WMS 确认收货」。WMS 不可达时 fail-open
|
||||
// (与 PLC 离线同口径:外部系统宕机不能永久卡死工位配置),仅记日志不硬拦。
|
||||
if s.ctx.Wms != nil {
|
||||
if returns, rErr := s.ctx.Wms.StationReturnList(ctx, st.StationNo); rErr != nil {
|
||||
logx.Errorf("工位%d 改绑定前查询未确认退库单失败(放行):%v", st.StationNo, rErr)
|
||||
} else {
|
||||
pending := 0
|
||||
for _, ro := range returns {
|
||||
stt := ""
|
||||
if ro != nil {
|
||||
if v, ok := ro["status"]; ok && v != nil {
|
||||
stt = fmt.Sprint(v)
|
||||
}
|
||||
}
|
||||
if stt == "PENDING" {
|
||||
pending++
|
||||
}
|
||||
}
|
||||
if pending > 0 {
|
||||
ve.Add("flowId", fmt.Sprintf("工位%d 有 %d 张未确认的退库单,禁止修改绑定工艺", st.StationNo, pending),
|
||||
"请先清点退料并在 WMS 退库单收货确认后,再修改绑定工艺")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if n, _ := s.ctx.EntClient.PlcSendLog.Query().
|
||||
Where(plcsendlog.Status("SENT"), plcsendlog.StationNo(st.StationNo)).Count(ctx); n > 0 {
|
||||
|
||||
@@ -20,12 +20,12 @@ import (
|
||||
// 2026-11-05 拍板修订:导入顺序改为「探测 WMS 可达 → 先推 WMS → WMS 成功后 MES 再落库」;
|
||||
// WMS 不可达或任一行推送失败则整批取消,MES 不写任何数据(物料档案两库对等双向同步:
|
||||
// 按 code 幂等互推;本流程先推 WMS 保证两侧一致,库存真源在 WMS)。
|
||||
// 2026-11-13 拍板:成品档案导入模板不允许出现「物料类型」列,全部按成品逻辑默认
|
||||
// (类型=其他3、序列号=是1)。旧模板含「类型」列也仍可导入(按表头名识别,多余列忽略)。
|
||||
// 2026-11-16 拍板(用户):模板删除「图号」「物料编码」两列——成品编码由系统自动生成
|
||||
// (PROD-YYYYMMDD-流水递增)、物料编码统一为空字符串;MES 成品导入仅限成品,
|
||||
// 原材料统一在 WMS 物料档案维护(原材料图号是两库同步业务键,须人工填写,不在本端导入)。
|
||||
var productTypeTemplateHeaders = []string{"名称", "规格", "单位", "类别", "序列号", "启用", "说明"}
|
||||
// 导入模板口径(2026-11-16 定):与「新增成品档案」界面字段一字不差、完全对齐——
|
||||
// 仅 5 列:名称 / 规格 / 单位 / 说明 / 启用。成品编码、物料编码、类型、类别、序列号
|
||||
// 均由系统按成品逻辑自动设定,模板与新建界面都不出现。旧版含多余列的模板仍可导入
|
||||
// (按表头名识别,多余列忽略),缺失的类别/序列号按成品默认(类型=其他3、序列号=是1)。
|
||||
// MES 成品导入仅限成品;原材料统一在 WMS 物料档案维护(不在本端导入)。
|
||||
var productTypeTemplateHeaders = []string{"名称", "规格", "单位", "说明", "启用"}
|
||||
|
||||
// ProductTypeImportResult 单行导入结果汇总。
|
||||
type ProductTypeImportResult struct {
|
||||
@@ -51,13 +51,13 @@ func (s *Service) BuildProductTypeTemplate() ([]byte, error) {
|
||||
if err := f.SetSheetRow(sheet, "A1", &productTypeTemplateHeaders); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 示例行:仅成品(2026-11-16 起原材料不在本端导入)
|
||||
example := []interface{}{"示例成品", "300x200x150", "台", "结构件", "是", "是", "示例行,导入前请删除"}
|
||||
// 示例行:仅成品(2026-11-16 起原材料不在本端导入;5 列与新建界面一致)
|
||||
example := []interface{}{"示例成品", "300x200x150", "台", "示例行,导入前请删除", "是"}
|
||||
if err := f.SetSheetRow(sheet, "A2", &example); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 列宽(7 列)
|
||||
widths := map[int]float64{1: 18, 2: 18, 3: 10, 4: 12, 5: 10, 6: 10, 7: 24}
|
||||
// 列宽(5 列)
|
||||
widths := map[int]float64{1: 18, 2: 18, 3: 10, 4: 24, 5: 10}
|
||||
for col, w := range widths {
|
||||
if cell, err := excelize.ColumnNumberToName(col); err == nil {
|
||||
_ = f.SetColWidth(sheet, cell, cell, w)
|
||||
@@ -70,17 +70,15 @@ func (s *Service) BuildProductTypeTemplate() ([]byte, error) {
|
||||
return nil, err
|
||||
}
|
||||
guides := []string{
|
||||
"【列顺序】名称 | 规格 | 单位 | 类别 | 序列号 | 启用 | 说明(成品档案模板,按表头名识别,请勿改动表头文字)",
|
||||
"【列顺序】名称 | 规格 | 单位 | 说明 | 启用(成品档案模板 5 列,与「新增成品档案」界面字段一字不差;按表头名识别,请勿改动表头文字)",
|
||||
"1. 仅保留第一个「Sheet1」数据页,「填写说明」页请勿删除或填入数据;第2行是示例,正式导入前请删除。",
|
||||
"2. 成品编码(图号)无需填写:系统自动生成(PROD-年月日-流水,递增且唯一)。",
|
||||
"2. 成品编码由系统自动生成(PROD-年月日-流水,递增且唯一),模板与新建界面均不提供此列,无需填写。",
|
||||
"3. 物料编码无需填写:统一为空。",
|
||||
"4. 名称 / 规格 / 单位:必填,不可为空。",
|
||||
"5. 类别:只能填「成品」;原材料请在 WMS 物料档案维护(不在本端导入)。",
|
||||
"6. 物料类型:本模板不提供此列,系统一律按成品逻辑默认(类型=其他、序列号=是)。",
|
||||
"7. 序列号:本模板不提供此列,成品强制为「是」。",
|
||||
"8. 启用:填「是」「否」或 true/false,默认「是」。",
|
||||
"9. 说明:可空,备注信息。",
|
||||
"10. 首行为表头,从第二行开始为数据;整批校验,任一行出错则一行不写(可在导入前点「预检」先看错误明细)。",
|
||||
"4. 名称 / 规格 / 单位:必填,不可为空(与新建界面一致)。",
|
||||
"5. 说明:可空,与新建界面的「说明」同义,备注信息。",
|
||||
"6. 启用:填「是」「否」或 true/false,默认「是」,与新建界面的「启用开关」一致。",
|
||||
"7. 类别 / 物料类型 / 序列号:模板与新建界面均不提供,系统一律按成品逻辑默认(类别=成品、类型=其他、序列号=是)。",
|
||||
"8. 首行为表头,从第二行开始为数据;整批校验,任一行出错则一行不写(可在导入前点「预检」先看错误明细)。",
|
||||
"【MES 业务差异】本端导入会先探测 WMS 可达并逐行先写 WMS,WMS 失败则整批取消。",
|
||||
}
|
||||
for i, g := range guides {
|
||||
|
||||
@@ -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 的步骤数据;缺失则拒绝报工。
|
||||
|
||||
@@ -216,9 +216,9 @@ func categoryTargetType(cat RouteCategory) SrcType {
|
||||
|
||||
// TargetOption 手动下发目标下拉项(带类型,前端按 code 展示)。
|
||||
type TargetOption struct {
|
||||
Type SrcType
|
||||
ID int
|
||||
Code string
|
||||
Type SrcType `json:"type"`
|
||||
ID int `json:"id"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
// MonitorTargets 返回某源允许的全部合法目标(跨该源涉及的多个类别合并),用于前端动态过滤下拉。
|
||||
|
||||
@@ -155,15 +155,14 @@ func (c *Client) postSemi(ctx context.Context, path string, body any) error {
|
||||
// DisposeInventoryReq MES → WMS 在库不合格处置请求(调 /api/internal/inventory/dispose)
|
||||
// 定位口径与 WMS 一致:sn 非空按 SN 料(material_code+序列号)精确定位;
|
||||
// 否则按批次料(material_code+batch_no)定位(同批次多行全部置状态)。
|
||||
// DisposalType 仅支持 RETURN/REWORK/SCRAP;RETURN 必填 ReturnTrackingNo。
|
||||
// DisposalType 仅支持 RETURN/REWORK/SCRAP(退货运单号已随 WMS 处置子表改造彻底废弃,不再下发)。
|
||||
type DisposeInventoryReq struct {
|
||||
MaterialCode string `json:"materialCode"`
|
||||
Sn string `json:"sn"`
|
||||
BatchNo string `json:"batchNo"`
|
||||
DisposalType string `json:"disposalType"`
|
||||
ReturnTrackingNo string `json:"returnTrackingNo"`
|
||||
Remark string `json:"remark"`
|
||||
Operator string `json:"operator"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
Sn string `json:"sn"`
|
||||
BatchNo string `json:"batchNo"`
|
||||
DisposalType string `json:"disposalType"`
|
||||
Remark string `json:"remark"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
|
||||
// DisposeInventory 调 WMS /api/internal/inventory/dispose 执行在库处置(退货/返修/报废)。
|
||||
|
||||
@@ -63,14 +63,23 @@ func (h *AgvHub) remove(c *agvClient) {
|
||||
_ = c.conn.Close()
|
||||
}
|
||||
|
||||
// snapshot 取一次手动链快照(仅 MANUAL 段,即人工派车页面消费的数据)。
|
||||
// snapshot 取一次 AGV 全域快照:
|
||||
// - chains:手动链(MANUAL 段,人工派车页 AgvManual.vue 消费);
|
||||
// - tasks:全量 AGV 任务(AGV管理页 Agv.vue 消费,替代原「刷新状态」手动按钮)。
|
||||
// 两个页面共用本 WS,任一方状态变化(含 RCS 回写任务状态)都会触发整帧推送,变化检测基于整个 payload。
|
||||
func (h *AgvHub) snapshot(ctx context.Context) []byte {
|
||||
list, err := logic.New(h.svcCtx).AgvChainList(ctx)
|
||||
svc := logic.New(h.svcCtx)
|
||||
list, err := svc.AgvChainList(ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("AGV 链快照失败:%v", err)
|
||||
list = []logic.AgvChainInfo{}
|
||||
}
|
||||
b, _ := json.Marshal(map[string]any{"chains": list})
|
||||
taskData, terr := svc.ListAgvTasks(ctx, "", "", 1, 200)
|
||||
if terr != nil {
|
||||
logx.Errorf("AGV 任务快照失败:%v", terr)
|
||||
taskData = map[string]any{"list": []any{}, "total": 0}
|
||||
}
|
||||
b, _ := json.Marshal(map[string]any{"chains": list, "tasks": taskData})
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user