Files
bj_power/bj_power_workstation/internal/handler/plc_mismatch.go
T
SunYF 7b7d27d150 feat: 会话令牌与守卫、看板组件及工位终端功能完善
- 用户表扩展:MES/WMS user 实体新增字段,新增 active_token 迁移 SQL(2026-11-11)
- 会话机制:MES 新增 session_guard,重构 token/auth/jwt/perm 与路由;WMS/工作站同步令牌续签与鉴权
- 看板(board):调整 MES 看板产线/生产/侧栏/仓库组件及样式;WMS 看板展示页同步调整
- 工位终端后端:完善报警流、绑定、PLC 对账、拧紧、proxy、上报、站点告警/操作等 handler,补充 mes client/store
- 工位终端前端:登录/主界面/各操作面板调整,新增滚动分页与多语言 yaml 文案,刷新构建产物
- MES 业务:新增流程链 logic,调整待审核/产能支撑/产品工艺/设置页、PLC 监控与帮助文档,刷新构建产物
- 更新问题记录文档
2026-11-11 14:36:16 +08:00

42 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import (
"encoding/json"
"io"
"net/http"
"bj_power_workstation/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
// plcMismatchCheckHandler POST /api/plc/mismatch/check
// 代理 MES /api/internal/plc/mismatch/check(事件驱动,禁止定时轮询)。
// 终端在「开始作业(T2)/扫SN(T3)」时按需调用单工位检查;MES 不可达或业务拒绝均静默跳过,不阻断作业。
func plcMismatchCheckHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
payload, err := io.ReadAll(r.Body)
if err != nil {
fail(w, http.StatusBadRequest, "请求体读取失败")
return
}
respBody, _, err := ctx.Mes.Post("/api/internal/plc/mismatch/check", json.RawMessage(payload), bearerOf(r))
if err != nil {
// 查询类静默降级(2026-11-08):仍不拦作业,但必须落本地操作日志留痕
logx.Errorf("PLC↔MES 对账检查 MES 不可达,静默跳过: %v", err)
ctx.Store.AddEventLog("", "system", "plc_mismatch_unreachable",
"PLC↔MES 对账检查 MES 不可达,已降级放行: "+err.Error())
ok(w, map[string]any{"hasMismatch": false})
return
}
if msg := mesRespCode(respBody); msg != "" {
// 业务拒绝(如工位号无效):静默跳过,不阻断作业
logx.Errorf("PLC↔MES 对账检查 MES 业务拒绝,静默跳过: %s", msg)
ok(w, map[string]any{"hasMismatch": false})
return
}
// 透传 MES 响应体(data={hasMismatch,stationNo,plcBit,detail,options,graceWindow})
passJSON(w, respBody)
}
}