feat: 看板管理屏专属面板与追溯查询三合一 + AGV状态WS实时推送 + 数据库错误友好文案分层
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user