Files
bj_power/bj_power_workstation/internal/handler/plc_mismatch.go
T
SunYF f65a52d9e1 feat: 多系统新增扫码中间件与 AGV 对接,优化拧紧与退库流程
新增扫码中间件支持网络型扫码枪键盘注入,AGV 对接从 WMS 迁至 MES 统一管理;新增拧紧不合格人工处置与 PLC 对账机制,优化退库单关联与工位终端功能,同时清理旧 AGV 任务表,完善数据库与配置项。
2026-10-14 17:24:59 +08:00

40 lines
1.4 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))
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)
}
}