feat(接口): agv配送接口和自动拆包机接口修改
This commit is contained in:
parent
16ace28f92
commit
feab438a1f
@ -1,15 +1,22 @@
|
||||
package com.foreverwin.iep.integration.handler.def.agv;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.foreverwin.iep.common.model.http.HttpRequest;
|
||||
import com.foreverwin.iep.common.model.http.HttpResponse;
|
||||
import com.foreverwin.iep.common.utils.HttpUtils;
|
||||
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.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.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@ -18,27 +25,52 @@ import org.springframework.stereotype.Service;
|
||||
@AllArgsConstructor
|
||||
@Service("AGV_DELIVERY_CALL")
|
||||
public class AgvDeliveryCall implements HandlerService {
|
||||
|
||||
private final RemoteParamService remoteParamService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
HttpRequest httpRequest = new HttpRequest();
|
||||
httpRequest.setUrl("www.baidu.com");
|
||||
httpRequest.setRequest(invokeRequest.getMessageContent());
|
||||
|
||||
String url = remoteParamService.getByKey("AGV_DELIVERY_CALL_URL", SecurityConstants.FROM_IN).getData();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
invokeResponse.setTransSid(invokeRequest.getTransSid());
|
||||
invokeResponse.setTransTime(Local.now());
|
||||
if(StrUtil.isBlank(httpRequest.getUrl())){
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), "未获取到url配置,请先在字典中配置调用AGV配送的URL");
|
||||
invokeResponse.setResult("0");
|
||||
invokeResponse.setMessageContent(Msg.SUCCESS);
|
||||
|
||||
if(StrUtil.isBlank(url)){
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), "未获取到url配置,请先在字典中配置调用AGV配送的url参数AGV_DELIVERY_CALL_URL");
|
||||
}
|
||||
try {
|
||||
HttpResponse httpResponse = HttpUtils.doPost(httpRequest);
|
||||
invokeResponse.setResult("0");
|
||||
invokeResponse.setMessageContent(Msg.SUCCESS);
|
||||
if (httpResponse.getStatusCode() != 200) {
|
||||
invokeResponse.setResult("1");
|
||||
invokeResponse.setMessageContent(httpResponse.getResponse());
|
||||
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
HttpPost postRequest = new HttpPost(url);
|
||||
|
||||
postRequest.setHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
|
||||
String messageContent = invokeRequest.getMessageContent();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
StringEntity stringEntity = new StringEntity(objectMapper.writeValueAsString(objectMapper.readTree(messageContent)));
|
||||
stringEntity.setContentType("application/json");
|
||||
postRequest.setEntity(stringEntity);
|
||||
|
||||
try (CloseableHttpResponse response = httpClient.execute(postRequest)) {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != 200) {
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), responseBody);
|
||||
}
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
JsonNode responseJson = objectMapper.readTree(responseString);
|
||||
if (responseJson.get("CODE") != null && responseJson.get("CODE").asBoolean() == false) {
|
||||
invokeResponse.setResult("1");
|
||||
}
|
||||
if(responseJson.get("MSG") != null) {
|
||||
invokeResponse.setMessageContent(responseJson.get("MSG").asText());
|
||||
}
|
||||
return invokeResponse;
|
||||
} catch (Exception e) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), StrUtil.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
|
||||
}
|
||||
return invokeResponse;
|
||||
} catch (Exception e) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), StrUtil.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
|
||||
}
|
||||
|
||||
@ -1,46 +1,80 @@
|
||||
package com.foreverwin.iep.integration.handler.def.agv;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.foreverwin.iep.common.model.http.HttpRequest;
|
||||
import com.foreverwin.iep.common.model.http.HttpResponse;
|
||||
import com.foreverwin.iep.common.utils.HttpUtils;
|
||||
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.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.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 自动拆包机接口
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service("AGV_OUT_SO_ITEM_STOCK_BIN")
|
||||
public class AgvOutSoItemStockBin implements HandlerService {
|
||||
|
||||
|
||||
private final RemoteParamService remoteParamService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
HttpRequest httpRequest = new HttpRequest();
|
||||
httpRequest.setUrl("www.baidu.com");
|
||||
httpRequest.setRequest(invokeRequest.getMessageContent());
|
||||
String url = remoteParamService.getByKey("AGV_AUTO_UNPACK_CALL_URL", SecurityConstants.FROM_IN).getData();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
invokeResponse.setTransSid(invokeRequest.getTransSid());
|
||||
invokeResponse.setTransTime(Local.now());
|
||||
if(StrUtil.isBlank(httpRequest.getUrl())){
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), "未获取到url配置,请先在字典中配置调用AGV的URL");
|
||||
invokeResponse.setResult("0");
|
||||
invokeResponse.setMessageContent(Msg.SUCCESS);
|
||||
|
||||
if (StrUtil.isBlank(url)) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), "未获取到url配置,请先在字典中配置调用AGV自动拆包的url参数AGV_AUTO_UNPACK_CALL_URL");
|
||||
}
|
||||
try {
|
||||
HttpResponse httpResponse = HttpUtils.doPost(httpRequest);
|
||||
invokeResponse.setResult("0");
|
||||
invokeResponse.setMessageContent(Msg.SUCCESS);
|
||||
if (httpResponse.getStatusCode() != 200) {
|
||||
invokeResponse.setResult("1");
|
||||
invokeResponse.setMessageContent(httpResponse.getResponse());
|
||||
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
HttpPost postRequest = new HttpPost(url);
|
||||
|
||||
postRequest.setHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
|
||||
String messageContent = invokeRequest.getMessageContent();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
StringEntity stringEntity = new StringEntity(objectMapper.writeValueAsString(objectMapper.readTree(messageContent)));
|
||||
stringEntity.setContentType("application/json");
|
||||
postRequest.setEntity(stringEntity);
|
||||
|
||||
try (CloseableHttpResponse response = httpClient.execute(postRequest)) {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) {
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), responseBody);
|
||||
}
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
JsonNode responseJson = objectMapper.readTree(responseString);
|
||||
if (responseJson.get("CODE") != null && responseJson.get("CODE").asBoolean() == false) {
|
||||
invokeResponse.setResult("1");
|
||||
}
|
||||
if (responseJson.get("MSG") != null) {
|
||||
invokeResponse.setMessageContent(responseJson.get("MSG").asText());
|
||||
}
|
||||
return invokeResponse;
|
||||
} catch (Exception e) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), StrUtil.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
|
||||
}
|
||||
return invokeResponse;
|
||||
} catch (Exception e) {
|
||||
return getDefaultInvoke().fail(invokeRequest.getTransSid(), StrUtil.isBlank(e.getMessage()) ? e.toString() : e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String validation(InvokeRequest invokeRequest) {
|
||||
return null;
|
||||
|
||||
@ -9,6 +9,7 @@ import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
@ -24,35 +25,39 @@ class EapEdcRecordTest {
|
||||
|
||||
public static final String origin = "http://127.0.0.1:8091";
|
||||
|
||||
public static final String mesOrigin = "http://127.0.0.1:8080/";
|
||||
public static final String mesOrigin = "http://192.168.110.148:11001/";
|
||||
|
||||
private static final String TENANT_ID = "3041"; // 提取常量
|
||||
/**
|
||||
* 保护膜放卷与换轴采集测试
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testCallProtectiveFilmUnwindingCollection() throws Exception {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost postRequest = new HttpPost(mesOrigin + "/iep-int/invoke");
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
HttpPost postRequest = new HttpPost(mesOrigin + "/iep-int/invoke");
|
||||
|
||||
String token = getToken();
|
||||
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token);
|
||||
postRequest.setHeader("TENANT-ID", "2031");
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
String token = getToken();
|
||||
postRequest.setHeader("Authorization", "Bearer " + token);
|
||||
postRequest.setHeader("TENANT-ID", TENANT_ID);
|
||||
postRequest.setHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
|
||||
String assembleMsgBody = protectiveFilmUnwindingCollectionBody();
|
||||
String assembleMsgBody = protectiveFilmUnwindingCollectionBody();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
StringEntity stringEntity = new StringEntity(objectMapper.writeValueAsString(objectMapper.readTree(assembleMsgBody)));
|
||||
stringEntity.setContentType("application/json");
|
||||
postRequest.setEntity(stringEntity);
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(assembleMsgBody);
|
||||
StringEntity stringEntity = new StringEntity(jsonObject.toJSONString());
|
||||
stringEntity.setContentType("application/json");
|
||||
postRequest.setEntity(stringEntity);
|
||||
// 调用登陆接口获取token
|
||||
HttpResponse response = httpClient.execute(postRequest);
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
// 解析返回的 JSON 数据
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode responseJson = objectMapper.readTree(responseString);
|
||||
System.out.println(responseJson);
|
||||
try (CloseableHttpResponse response = httpClient.execute(postRequest)) {
|
||||
String responseString = EntityUtils.toString(response.getEntity());
|
||||
JsonNode responseJson = objectMapper.readTree(responseString);
|
||||
System.out.println("Response:" + responseJson);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error executing HTTP POST request:" + e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error creating HTTP client:" + e); // 异常处理
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +71,7 @@ class EapEdcRecordTest {
|
||||
|
||||
String token = getToken();
|
||||
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token);
|
||||
postRequest.setHeader("TENANT-ID", "2031");
|
||||
postRequest.setHeader("TENANT-ID", TENANT_ID);
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
|
||||
String assembleMsgBody = baseFilmWindingCollectionBody();
|
||||
@ -95,7 +100,7 @@ class EapEdcRecordTest {
|
||||
|
||||
String token = getToken();
|
||||
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token);
|
||||
postRequest.setHeader("TENANT-ID", "3041");
|
||||
postRequest.setHeader("TENANT-ID", TENANT_ID);
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
|
||||
String assembleMsgBody = energyDataProcessBody();
|
||||
@ -143,20 +148,20 @@ class EapEdcRecordTest {
|
||||
jsonObject.put("SENDER", "EAP");
|
||||
jsonObject.put("MESSAGE_ID", "down.switch.process");
|
||||
|
||||
jsonObject.put("FACTORY", "009");
|
||||
jsonObject.put("LINE_ID", "WC01");
|
||||
jsonObject.put("OPERATION", "JMLS");
|
||||
jsonObject.put("RESOURCE", "LS001");
|
||||
jsonObject.put("SUB_RESOURCE", "TLK02");
|
||||
jsonObject.put("FACTORY", "3041");
|
||||
jsonObject.put("LINE_ID", null);
|
||||
jsonObject.put("OPERATION", "S013");
|
||||
jsonObject.put("RESOURCE", "S013");
|
||||
jsonObject.put("SUB_RESOURCE", "B");
|
||||
jsonObject.put("MAIN_UOM", "M");
|
||||
jsonObject.put("MAIN_QTY", "999");
|
||||
jsonObject.put("PLANNED_QTY", "88");
|
||||
jsonObject.put("MAIN_QTY", 6312.069);
|
||||
jsonObject.put("PLANNED_QTY", 6400);
|
||||
jsonObject.put("SUB_UOM", "M");
|
||||
jsonObject.put("SUB_QTY", "22");
|
||||
jsonObject.put("TRANS_TYPE", "3");
|
||||
jsonObject.put("SUB_QTY", 0);
|
||||
jsonObject.put("TRANS_TYPE", 3);
|
||||
jsonObject.put("TRANS_DATE", "2024-11-29 12:00:00");
|
||||
jsonObject.put("COMPLETION_FLAG", "Y");
|
||||
jsonObject.put("ROLLER_SWITCH_FLAG", "Y");
|
||||
jsonObject.put("COMPLETION_FLAG", "N");
|
||||
// jsonObject.put("ROLLER_SWITCH_FLAG", "Y");
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
@ -194,7 +199,7 @@ class EapEdcRecordTest {
|
||||
pair.add(new BasicNameValuePair("password", "fCn7lpNYLSSJdA=="));
|
||||
|
||||
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Basic bW9tOm1vbQ==");
|
||||
postRequest.setHeader("TENANT-ID", "3041");
|
||||
postRequest.setHeader("TENANT-ID", TENANT_ID);
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
|
||||
postRequest.setEntity(new UrlEncodedFormEntity(pair, "UTF-8"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user