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)) if err != nil { // MES 不可达:静默跳过,提示不拦,不影响终端作业 logx.Errorf("PLC↔MES 对账检查 MES 不可达,静默跳过: %v", err) 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) } }