fix(生产工单与投料关系下发):请求报文修改

This commit is contained in:
liaohechuan 2025-03-06 18:57:38 +08:00
parent 72304bb7e1
commit 7c955cb641

View File

@ -1,18 +1,22 @@
package com.foreverwin.iep.integration.handler.def.agv;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.foreverwin.iep.integration.constant.Msg;
import com.foreverwin.iep.integration.domain.InvokeRequest;
import com.foreverwin.iep.integration.domain.InvokeResponse;
import com.foreverwin.iep.integration.service.HandlerService;
import com.foreverwin.iep.integration.utils.JS;
import com.foreverwin.iep.integration.utils.Local;
import com.foreverwin.mom.admin.api.feign.RemoteParamService;
import com.foreverwin.mom.common.core.constant.SecurityConstants;
import lombok.AllArgsConstructor;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
@ -42,17 +46,50 @@ public class AgvOutSoItemStockBin implements HandlerService {
}
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost postRequest = new HttpPost(url);
postRequest.setHeader("Content-Type", "application/json; charset=UTF-8");
HttpPut putRequest = new HttpPut(url);
putRequest.setHeader("Content-Type", "application/json; charset=UTF-8");
String messageContent = invokeRequest.getMessageContent();
JSONObject messageContentJsonObject = JS.parseObject(messageContent);
JSONObject jsonObject = new JSONObject();
jsonObject.put("MESSAGE_ID", invokeRequest.getMessageId());
jsonObject.put("SITE", invokeRequest.getSite());
jsonObject.put("FAB_NO", messageContentJsonObject.getString("fabNo"));
jsonObject.put("WORK_CENTER", messageContentJsonObject.getString("workCenter"));
jsonObject.put("RESOURCE", messageContentJsonObject.getString("resource"));
jsonObject.put("REQ_ID", invokeRequest.getTransSid());
jsonObject.put("SEND_TIME", invokeRequest.getTransTime());
jsonObject.put("ORDER_NUMBER", messageContentJsonObject.getString("shopOrder"));
JSONArray jsonArray = messageContentJsonObject.getJSONArray("components");
JSONArray jsonArray1 = new JSONArray();
if (CollectionUtils.isNotEmpty(jsonArray)) {
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObjectComponent = jsonArray.getJSONObject(i);
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("MATERIAL_CODE", jsonObjectComponent.getString("item"));
jsonObject1.put("MATERIAL_NAME", jsonObjectComponent.getString("itemDesc"));
jsonObject1.put("MATERIAL_WEIGHT", jsonObjectComponent.getBigDecimal("splitStandardQty"));
String feedingPort = "0";
// 查找最后一个下划线的位置
int lastIndex = jsonObjectComponent.getString("dropBinNumber").lastIndexOf('_');
if (lastIndex != -1) { // 确保找到了下划线
// 获取下划线后面的部分
feedingPort = jsonObjectComponent.getString("dropBinNumber").substring(lastIndex + 1);
}
jsonObject1.put("FEEDING_PORT", feedingPort);
jsonObject1.put("STACKING_POSITION", "0");
jsonArray1.add(jsonObject1);
}
}
jsonObject.put("MATERIAL_INFO", jsonArray1);
invokeRequest.setMessageContent(jsonObject.toJSONString());
ObjectMapper objectMapper = new ObjectMapper();
StringEntity stringEntity = new StringEntity(objectMapper.writeValueAsString(objectMapper.readTree(messageContent)));
StringEntity stringEntity = new StringEntity(objectMapper.writeValueAsString(objectMapper.readTree(jsonObject.toString())));
stringEntity.setContentType("application/json");
postRequest.setEntity(stringEntity);
putRequest.setEntity(stringEntity);
try (CloseableHttpResponse response = httpClient.execute(postRequest)) {
try (CloseableHttpResponse response = httpClient.execute(putRequest)) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
String responseBody = EntityUtils.toString(response.getEntity());