Commit eb9db9cfb46c76bb1be0535062669363099cf501

Authored by 杨鸣坤
1 parent 624b1fb8

fix: 修正MES同步接口请求格式及配置

- 将content从数组改为包含equipmentstatelist的对象
- 更新MES接口URL和方法名
- 修改服务端口为33221
- 改进JSON解析失败的异常日志输出
... ... @@ -104,7 +104,7 @@ public class MesSyncService {
104 104 response.getCode(), response.getMessage(), response.getExceptionMessage());
105 105 }
106 106 } catch (Exception e) {
107   - log.warn("MES响应JSON解析失败, 原始响应: {}", responseJson);
  107 + log.warn("MES响应JSON解析失败, 原始响应: {}, 异常: {}", responseJson, e.getMessage(), e);
108 108 }
109 109 } else if (responseJson != null && responseJson.equals("400")) {
110 110 log.error("========== MES接口返回400错误,请检查:1.请求格式是否正确 2.接口地址是否正确 3.header是否在body中 ==========");
... ... @@ -136,20 +136,20 @@ public class MesSyncService {
136 136 header.put("lang", "zh_CN");
137 137 header.put("platform", "web");
138 138
139   - // 2. 构建 content 数组
140   - ArrayNode contentArray = objectMapper.createArrayNode();
  139 + // 2. 构建 content 对象(MES要求 content 为JSON对象,内含 equipmentstatelist 数组)
  140 + ObjectNode contentObj = objectMapper.createObjectNode();
  141 + ArrayNode equipmentStateList = contentObj.putArray("equipmentstatelist");
141 142 for (DeviceState device : devices) {
142   - ObjectNode deviceNode = objectMapper.createObjectNode();
  143 + ObjectNode deviceNode = equipmentStateList.addObject();
143 144 deviceNode.put("equipmentno", device.getEquipmentNo());
144 145 deviceNode.put("equipmentstate", device.getState() != null ? device.getState().toString() : "0");
145 146 deviceNode.put("createdate", now.format(DATE_FORMAT));
146   - contentArray.add(deviceNode);
147 147 }
148 148
149 149 // 3. 组装完整的请求体
150 150 ObjectNode requestBody = objectMapper.createObjectNode();
151 151 requestBody.set("header", header);
152   - requestBody.set("content", contentArray);
  152 + requestBody.set("content", contentObj);
153 153
154 154 return objectMapper.writeValueAsString(requestBody);
155 155 }
... ...
... ... @@ -15,7 +15,7 @@ spring:
15 15 ddl-auto: none
16 16
17 17 server:
18   - port: 8080
  18 + port: 33221
19 19
20 20 logging:
21 21 level:
... ... @@ -39,6 +39,6 @@ scheduler:
39 39 mes:
40 40 sync:
41 41 enabled: true
42   - url: http://192.168.1.203/SMES_Test_Services/***
43   - method: ServicesCUS.Module_CUS.CUS_EquipmentStateSync
  42 + url: http://192.168.1.203/SMES_Test_Services/InvokeJSON
  43 + method: ServicesCUS.Module_CUS.CUS_EQPState_Collect
44 44 cron: "0 */1 * * * ?" # Every 1 minute
... ...