新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
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
|
|
}
|
|
}
|
|
}
|
|
}
|