feat: AGV状态实时推送与受控异常处置 + rcs-dps状态接口独立配置与日志落盘修复
This commit is contained in:
@@ -14,9 +14,13 @@ import (
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"bj_power_workstation/internal/netutil"
|
||||
"bj_power_workstation/internal/tightening"
|
||||
)
|
||||
|
||||
// commTag 本机 IP 前缀(进程启动解析一次),断网排查时可一眼看出日志来自哪台终端机。
|
||||
var commTag = netutil.Tag()
|
||||
|
||||
// ErrAuth 认证失效(401 / 登录态过期):可恢复错误。
|
||||
// 调用方据此提示重新登录(2026-11-05 拍板:断网/认证失败直接报错,无离线重试)。
|
||||
var ErrAuth = errors.New("station auth expired or invalid")
|
||||
@@ -128,16 +132,16 @@ func (c *Client) GetStream(path string, query url.Values) (io.ReadCloser, error)
|
||||
req.Header.Set("Accept", "text/event-stream")
|
||||
resp, err := c.streamClient.Do(req)
|
||||
if err != nil {
|
||||
logx.Errorf("[终端→MES] <-- SSE connect error %s err=%v", u, err)
|
||||
logx.Errorf("[终端→MES]"+commTag+" <-- SSE connect error %s err=%v", u, err)
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
logx.Errorf("[终端→MES] <-- SSE HTTP %d %s body=%s", resp.StatusCode, u, truncate(string(body), 200))
|
||||
logx.Errorf("[终端→MES]"+commTag+" <-- SSE HTTP %d %s body=%s", resp.StatusCode, u, truncate(string(body), 200))
|
||||
return nil, fmt.Errorf("MES %s 返回 %d:%s", path, resp.StatusCode, truncate(string(body), 200))
|
||||
}
|
||||
logx.Infof("[终端→MES] <-- SSE connected %s", u)
|
||||
logx.Infof("[终端→MES]"+commTag+" <-- SSE connected %s", u)
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
||||
@@ -164,12 +168,12 @@ func (c *Client) do(method, u string, body io.Reader, bearer string) ([]byte, ht
|
||||
reqBodyForLog, _ = io.ReadAll(body)
|
||||
req.Body = io.NopCloser(bytes.NewReader(reqBodyForLog))
|
||||
}
|
||||
logx.Infof("[终端→MES] --> %s %s body=%s", method, u, truncate(string(reqBodyForLog), 1000))
|
||||
logx.Infof("[终端→MES]"+commTag+" --> %s %s body=%s", method, u, truncate(string(reqBodyForLog), 1000))
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
// 2026-11-16 联调:终端→MES 全量交互落日志(传输错误单独记录,grep "[终端→MES]")
|
||||
logx.WithContext(req.Context()).Errorf("[终端→MES] <-- transport error %s %s err=%v", method, u, err)
|
||||
logx.WithContext(req.Context()).Errorf("[终端→MES]"+commTag+" <-- transport error %s %s err=%v", method, u, err)
|
||||
return nil, nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
@@ -179,7 +183,7 @@ func (c *Client) do(method, u string, body io.Reader, bearer string) ([]byte, ht
|
||||
return nil, resp.Header, err
|
||||
}
|
||||
// 请求/响应全量日志(请求体在下面 marshal 后记录;这里记录响应)
|
||||
logx.WithContext(req.Context()).Infof("[终端→MES] <-- HTTP %d %s body=%s", resp.StatusCode, u, truncate(string(respBody), 1000))
|
||||
logx.WithContext(req.Context()).Infof("[终端→MES]"+commTag+" <-- HTTP %d %s body=%s", resp.StatusCode, u, truncate(string(respBody), 1000))
|
||||
if resp.StatusCode == http.StatusUnauthorized {
|
||||
// 401 = 工位登录态过期/无效:调用方据此提示重新登录。
|
||||
return respBody, resp.Header, fmt.Errorf("MES %s %s: %w", method, u, ErrAuth)
|
||||
|
||||
Reference in New Issue
Block a user