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