43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
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)
|
||
|
|
}
|
||
|
|
}
|