Merge remote-tracking branch 'origin/main'

This commit is contained in:
彭枝刚 2024-12-19 13:18:28 +08:00
commit 58996c5f73
11 changed files with 360 additions and 4 deletions

View File

@ -12,4 +12,6 @@ public class IntegrationSrv {
public static final String ERP_MATERIEL_GET = "ERP_MATERIEL_GET";
public static final String AGV_OUT_SO_ITEM_STOCK_BIN = "AGV_OUT_SO_ITEM_STOCK_BIN";
public static final String AGV_DELIVERY_CALL = "AGV_DELIVERY_CALL";
}

View File

@ -3,10 +3,12 @@ package com.foreverwin.iep.integration.feign;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.iep.integration.domain.InvokeRequest;
import com.foreverwin.iep.integration.domain.InvokeResponse;
import com.foreverwin.mom.common.core.constant.SecurityConstants;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
@FeignClient(contextId = "remoteInvokeService", value = "iep-int")
public interface RemoteInvokeService {
@ -21,6 +23,9 @@ public interface RemoteInvokeService {
@PostMapping("/invoke-request")
InvokeResponse invokeRequest(@RequestBody InvokeRequest request);
@PostMapping("/invoke-inner")
InvokeResponse invokeInnerRequest(@RequestBody InvokeRequest request, @RequestHeader(SecurityConstants.FROM) String from);
@PostMapping("/{service}/invoke-request")
InvokeResponse invokeRequestByService(@PathVariable(value = "service", required = false) String service,
@RequestBody InvokeRequest request);

View File

@ -78,6 +78,20 @@ public class InvokeController {
InvokeResponse invokeResponse = invoke.execute(service, request);
return invokeResponse;
}
/**
* 无token呼叫
* @param service
* @param request
* @return
*/
@Inner(value = false)
@PostMapping(value = {"/invoke-inner", "/{service}/invoke-inner"})
public InvokeResponse invokeInnerRequest(@PathVariable(value = "service", required = false) String service,@RequestBody InvokeRequest request) {
InvokeResponse invokeResponse = invoke.execute(service, request);
return invokeResponse;
}
/*
OA 呼叫地址

View File

@ -0,0 +1,51 @@
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.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 lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* 调用AGV配送
*/
@AllArgsConstructor
@Service("AGV_DELIVERY_CALL")
public class AgvDeliveryCall implements HandlerService {
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
HttpRequest httpRequest = new HttpRequest();
httpRequest.setUrl("www.baidu.com");
httpRequest.setRequest(invokeRequest.getMessageContent());
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");
}
try {
HttpResponse httpResponse = HttpUtils.doPost(httpRequest);
invokeResponse.setResult("0");
invokeResponse.setMessageContent(Msg.SUCCESS);
if (httpResponse.getStatusCode() != 200) {
invokeResponse.setResult("1");
invokeResponse.setMessageContent(httpResponse.getResponse());
}
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;
}
}

View File

@ -19,6 +19,9 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 批次称重上传记录接口表
*/
@AllArgsConstructor
@Service("AGV_IN_LOT_MEASURING")
public class AgvInLotMeasuring implements HandlerService {

View File

@ -0,0 +1,62 @@
package com.foreverwin.iep.integration.handler.def.eap;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.iep.eap.domain.EapBaseFilmWindingCollectionRequest;
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.wip.feign.RemoteEdcRecordService;
import com.foreverwin.mom.common.core.util.I18nUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 保护膜放卷与换轴采集
*/
@AllArgsConstructor
@Service("EAP_BASE_FILM_WINDING_COLLECTION")
public class EapBaseFilmWindingCollection implements HandlerService {
private final RemoteEdcRecordService remoteEdcRecordService;
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
String messageContent = invokeRequest.getMessageContent();
// 将json对象jsonObject转成AgvAutoUnpackingCollectionRequest对象
EapBaseFilmWindingCollectionRequest request = JSONObject.parseObject(messageContent, EapBaseFilmWindingCollectionRequest.class);
String message = remoteEdcRecordService.baseFilmWindingCollection(request).getData();
InvokeResponse response = new InvokeResponse(invokeRequest);
response.setTransTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
if ("S".equals(message)) {
response.setResult("S");
response.setMessageContent(Msg.SUCCESS);
} else {
response.setResult("E");
response.setMessageContent(message);
}
return response;
}
@Override
public String validation(InvokeRequest invokeRequest) {
JSONObject jsonObject = JS.parseObject(invokeRequest.getMessageContent());
if (ObjectUtil.isNull(jsonObject)) {
return I18nUtil.getI18nText("int.invoke.error3", I18nUtil.getI18nText("int.invoke.msg9"));
}
String keyValue = jsonObject.getString("SUB_RESOURCE");
if (StrUtil.isBlank(keyValue)) {
keyValue = jsonObject.getString("RESOURCE");
}
invokeRequest.setKeyValue(keyValue);
return null;
}
}

View File

@ -0,0 +1,62 @@
package com.foreverwin.iep.integration.handler.def.eap;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.iep.eap.domain.EapProtectiveFilmUnwindingCollectionRequest;
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.wip.feign.RemoteEdcRecordService;
import com.foreverwin.mom.common.core.util.I18nUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* 保护膜放卷与换轴采集
*/
@AllArgsConstructor
@Service("EAP_PROTECTIVE_FILM_UNWINDING_COLLECTION")
public class EapProtectiveFilmUnwindingCollection implements HandlerService {
private final RemoteEdcRecordService remoteEdcRecordService;
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
String messageContent = invokeRequest.getMessageContent();
// 将json对象jsonObject转成AgvAutoUnpackingCollectionRequest对象
EapProtectiveFilmUnwindingCollectionRequest request = JSONObject.parseObject(messageContent, EapProtectiveFilmUnwindingCollectionRequest.class);
String message = remoteEdcRecordService.protectiveFilmUnwindingCollection(request).getData();
InvokeResponse response = new InvokeResponse(invokeRequest);
response.setTransTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
if ("S".equals(message)) {
response.setResult("S");
response.setMessageContent(Msg.SUCCESS);
} else {
response.setResult("E");
response.setMessageContent(message);
}
return response;
}
@Override
public String validation(InvokeRequest invokeRequest) {
JSONObject jsonObject = JS.parseObject(invokeRequest.getMessageContent());
if (ObjectUtil.isNull(jsonObject)) {
return I18nUtil.getI18nText("int.invoke.error3", I18nUtil.getI18nText("int.invoke.msg9"));
}
String keyValue = jsonObject.getString("SUB_RESOURCE");
if (StrUtil.isBlank(keyValue)) {
keyValue = jsonObject.getString("RESOURCE");
}
invokeRequest.setKeyValue(keyValue);
return null;
}
}

View File

@ -73,7 +73,7 @@ public class FqInCuttingInventory implements HandlerService {
cuttingInventory.setDateUpdate(nowLocalDateTime);
cuttingInventory.setDateCreate(nowLocalDateTime);
remoteCuttingInventoryService.remoteSaveOrUpdate(cuttingInventory, SecurityConstants.FROM_IN);
remoteCuttingInventoryService.remoteSaveOrUpdate(cuttingInventory);
InvokeResponse response = new InvokeResponse(invokeRequest);
response.setTransTime(nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

View File

@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets;
public class OAUtil {
private static final String oaUrl = "/api/naliv/wf/createOrupdateWf";
private static final String oaUrl = "/api/nalinv/wf/createOrupdateWf";
private static final String WbpUrl = "https://agw.esb.nit.pub/oa/pip";

View File

@ -0,0 +1,157 @@
package com.foreverwin.iep.integration.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
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.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.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
class EapEdcRecordTest {
public static final String origin = "http://127.0.0.1:8091";
public static final String mesOrigin = "http://localhost:8080";
/**
* 保护膜放卷与换轴采集测试
* @throws Exception
*/
@Test
public void testCallProtectiveFilmUnwindingCollection() throws Exception {
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 assembleMsgBody = protectiveFilmUnwindingCollectionBody();
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);
}
/**
* 基膜收卷与换轴采集测试
* @throws Exception
*/
@Test
public void testCallBaseFilmWindingCollection() throws Exception {
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 assembleMsgBody = baseFilmWindingCollectionBody();
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);
}
private String protectiveFilmUnwindingCollectionBody() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("REQ_ID", StrUtil.uuid());
jsonObject.put("SEND_TIME", "2024-11-29 12:00:00");
jsonObject.put("SITE", "3041");
jsonObject.put("SENDER", "EAP");
jsonObject.put("MESSAGE_ID", "EAP_PROTECTIVE_FILM_UNWINDING_COLLECTION");
jsonObject.put("FACTORY", "009");
jsonObject.put("LINE_ID", "WC01");
jsonObject.put("OPERATION", "JMLS");
jsonObject.put("RESOURCE", "LS001");
jsonObject.put("SUB_RESOURCE", "TLK02");
jsonObject.put("PROCESSED_QTY", "25");
jsonObject.put("REMAINED_QTY", "999");
jsonObject.put("TRANS_TYPE", "2");
jsonObject.put("TRANS_DATE_TIME", "2024-11-29 12:00:00");
jsonObject.put("COMPLETION_FLAG", "Y");
jsonObject.put("ROLLER_SWITCH_FLAG", "Y");
return jsonObject.toJSONString();
}
private String baseFilmWindingCollectionBody() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("REQ_ID", StrUtil.uuid());
jsonObject.put("SEND_TIME", "2024-11-29 12:00:00");
jsonObject.put("SITE", "3041");
jsonObject.put("SENDER", "EAP");
jsonObject.put("MESSAGE_ID", "EAP_BASE_FILM_WINDING_COLLECTION");
jsonObject.put("FACTORY", "009");
jsonObject.put("LINE_ID", "WC01");
jsonObject.put("OPERATION", "JMLS");
jsonObject.put("RESOURCE", "LS001");
jsonObject.put("SUB_RESOURCE", "TLK02");
jsonObject.put("MAIN_UOM", "M");
jsonObject.put("MAIN_QTY", "999");
jsonObject.put("PLANNED_QTY", "88");
jsonObject.put("SUB_UOM", "M");
jsonObject.put("SUB_QTY", "22");
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");
return jsonObject.toJSONString();
}
public String getToken() throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost postRequest = new HttpPost(mesOrigin + "/auth/oauth/token?randomStr=blockPuzzle&grant_type=password");
// 构建请求参数
List<NameValuePair> pair = new ArrayList<>();
pair.add(new BasicNameValuePair("username", "agv"));
pair.add(new BasicNameValuePair("password", "dAPopZNYLST8ew=="));
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Basic bW9tOm1vbQ==");
postRequest.setHeader("TENANT-ID", "2031");
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
postRequest.setEntity(new UrlEncodedFormEntity(pair, "UTF-8"));
// 调用登陆接口获取token
HttpResponse response = httpClient.execute(postRequest);
String responseString = EntityUtils.toString(response.getEntity());
// 解析返回的 JSON 数据
ObjectMapper objectMapper = new ObjectMapper();
JsonNode responseJson = objectMapper.readTree(responseString);
String accessToken = responseJson.get("access_token").asText();
System.out.println(responseJson);
return accessToken;
}
}

View File

@ -57,8 +57,8 @@ class EapExtrudeRecordTest {
jsonObject.put("SITE","3041");
jsonObject.put("SENDER","EAP");
jsonObject.put("MESSAGE_ID","EAP_EXTRUDE_RECORD");
jsonObject.put("FAB_NO","009");
jsonObject.put("WORK_CENTER","WC01");
jsonObject.put("FACTORY","009");
jsonObject.put("LINE_ID","WC01");
jsonObject.put("OPERATION","JMLS");
jsonObject.put("RESOURCE","LS001");
jsonObject.put("EXTRUDER_RESOURCE","TLK02");