feat: AGV状态实时推送与受控异常处置 + rcs-dps状态接口独立配置与日志落盘修复

This commit is contained in:
SunYF
2026-11-16 19:42:22 +08:00
parent d92ca803d5
commit a998a0d0f7
18 changed files with 861 additions and 119 deletions
@@ -11,9 +11,13 @@ import (
"io"
"net/http"
"bj_power_mes/internal/netutil"
"github.com/zeromicro/go-zero/core/logx"
)
// commTag 本机 IP 前缀(进程启动解析一次),断网排查时可一眼看出日志来自哪台机器。
var commTag = netutil.Tag()
// loggingTransport 日志装饰 transport。
type loggingTransport struct{ base http.RoundTripper }
@@ -34,11 +38,11 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error)
_ = req.Body.Close()
req.Body = io.NopCloser(bytes.NewReader(reqBody))
}
logx.WithContext(req.Context()).Infof("[MES→WMS] --> %s %s body=%s", req.Method, u, truncateLogBytes(reqBody))
logx.WithContext(req.Context()).Infof("[MES→WMS]"+commTag+"--> %s %s body=%s", req.Method, u, truncateLogBytes(reqBody))
resp, err := t.base.RoundTrip(req)
if err != nil {
logx.WithContext(req.Context()).Errorf("[MES→WMS] <-- transport error %s err=%v", u, err)
logx.WithContext(req.Context()).Errorf("[MES→WMS]"+commTag+"<-- transport error %s err=%v", u, err)
if FailHook != nil {
FailHook(req.Context(), req.Method, u, err)
}
@@ -47,10 +51,10 @@ func (t *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error)
raw, rerr := io.ReadAll(resp.Body)
_ = resp.Body.Close()
if rerr != nil {
logx.WithContext(req.Context()).Errorf("[MES→WMS] <-- read body error %s status=%d err=%v", u, resp.StatusCode, rerr)
logx.WithContext(req.Context()).Errorf("[MES→WMS]"+commTag+"<-- read body error %s status=%d err=%v", u, resp.StatusCode, rerr)
}
resp.Body = io.NopCloser(bytes.NewReader(raw))
logx.WithContext(req.Context()).Infof("[MES→WMS] <-- HTTP %d %s body=%s", resp.StatusCode, u, truncateLogBytes(raw))
logx.WithContext(req.Context()).Infof("[MES→WMS]"+commTag+"<-- HTTP %d %s body=%s", resp.StatusCode, u, truncateLogBytes(raw))
return resp, nil
}