feat: 新增收集式校验错误弹窗及工位报警语音播报

新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
This commit is contained in:
SunYF
2026-10-20 16:36:26 +08:00
parent f743cf21fb
commit b0c048d9aa
126 changed files with 4603 additions and 1639 deletions
@@ -0,0 +1,47 @@
package handler
import (
"fmt"
"net/http"
"time"
"bj_power_workstation/internal/svc"
)
// alertsStreamHandler GET /api/alerts/stream(本机 SSE,免鉴权)
// 终端前端 EventSource 订阅本端点(同源、EventSource 无法携带 JWT,故走免鉴权组;
// 数据已经 alertstream.Manager 按本机固定工位号过滤,仅本机 LAN 可达,敏感度低)。
// 收到 MES station.alert 即转发;15 秒心跳注释行防空闲断链;前端断开由 r.Context().Done() 感知。
func alertsStreamHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fl, ok := w.(http.Flusher)
if !ok {
http.Error(w, "streaming unsupported", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/event-stream")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Connection", "keep-alive")
ch := ctx.AlertStream.Subscribe()
defer ctx.AlertStream.Unsubscribe(ch)
fl.Flush()
ticker := time.NewTicker(15 * time.Second)
defer ticker.Stop()
for {
select {
case data := <-ch:
if _, err := fmt.Fprintf(w, "event: station.alert\ndata: %s\n\n", data); err != nil {
return
}
fl.Flush()
case <-ticker.C:
if _, err := fmt.Fprint(w, ": ping\n\n"); err != nil {
return
}
fl.Flush()
case <-r.Context().Done():
return
}
}
}
}
@@ -18,6 +18,8 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
{Method: http.MethodGet, Path: "/api/config", Handler: configHandler(ctx)},
// 工艺文件免鉴权直链(query 传名,支持日期子目录;供 iframe/window.open)
{Method: http.MethodGet, Path: "/pdfview", Handler: pdfViewHandler(ctx)},
// 本机工位报警 SSE(免鉴权:EventSource 无法携带 JWT;数据已按本机工位过滤,LAN 内低敏感)
{Method: http.MethodGet, Path: "/api/alerts/stream", Handler: alertsStreamHandler(ctx)},
// 前端静态托管
{Method: http.MethodGet, Path: "/", Handler: indexHandler(ctx.WebFS)},
{Method: http.MethodGet, Path: "/assets/:file", Handler: assetHandler(ctx.WebFS)},
@@ -82,6 +84,9 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
{Method: http.MethodPost, Path: "/api/workpiece/online", Handler: onlineHandler(ctx)},
{Method: http.MethodPost, Path: "/api/workpiece/done", Handler: doneHandler(ctx)},
// 本工位相关报警(谁受影响谁播报,2026-10-20):终端前端轮询 + 语音播报
{Method: http.MethodGet, Path: "/api/alerts/station", Handler: stationAlertsHandler(ctx)},
// PLC↔MES 对账(#8 T2/T3 终端事件驱动检查,不轮询):代理 MES 内部接口,MES 不可达静默跳过
{Method: http.MethodPost, Path: "/api/plc/mismatch/check", Handler: plcMismatchCheckHandler(ctx)},
},
@@ -0,0 +1,42 @@
package handler
import (
"net/http"
"net/url"
"strconv"
"strings"
"bj_power_workstation/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
// stationAlertsHandler GET /api/alerts/station?stationNo=&minutes=
// 代理 MES GET /api/internal/station/alerts(谁受影响谁播报,2026-10-20)。
// 终端前端 30 秒轮询本工位相关报警;MES 不可达/业务拒绝静默返回空列表,不影响作业。
func stationAlertsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
stationNo := atoi(strings.TrimSpace(r.URL.Query().Get("stationNo")), 0)
minutes := atoi(strings.TrimSpace(r.URL.Query().Get("minutes")), 10)
if stationNo <= 0 {
ok(w, []any{})
return
}
body, _, err := ctx.Mes.Get("/api/internal/station/alerts", url.Values{
"stationNo": {strconv.Itoa(stationNo)},
"minutes": {strconv.Itoa(minutes)},
})
if err != nil {
// MES 不可达:静默返回空,终端语音播报不因后端抖动而报错刷屏
logx.Errorf("工位报警查询 MES 不可达,静默跳过: %v", err)
ok(w, []any{})
return
}
if msg := mesRespCode(body); msg != "" {
logx.Errorf("工位报警查询 MES 业务拒绝,静默跳过: %s", msg)
ok(w, []any{})
return
}
passJSON(w, body)
}
}