feat: 看板管理屏专属面板与追溯查询三合一 + AGV状态WS实时推送 + 数据库错误友好文案分层

This commit is contained in:
SunYF
2026-11-17 06:41:41 +08:00
parent 3b0fb2ea46
commit 5c9a7e32d2
59 changed files with 2302 additions and 789 deletions
@@ -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))