feat(agv): 接口
1. 批次称重上传记录接口
This commit is contained in:
parent
792fa24dc5
commit
2d286ee378
@ -19,6 +19,8 @@ public class Msg {
|
||||
public static final String EAP = "EAP";
|
||||
|
||||
public static final String SAP = "SAP";
|
||||
|
||||
public static final String AGV = "AGV";
|
||||
|
||||
public static final String DEFAULT_TO_SYSTEM = IEP;
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ import com.foreverwin.mom.common.core.util.I18nUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@ -88,4 +90,37 @@ public class Invoke {
|
||||
}
|
||||
return invokeService.invoke(request);
|
||||
}
|
||||
|
||||
public InvokeResponse executeAGV(String service, InvokeRequest request) {
|
||||
request.setStart(Local.now());
|
||||
|
||||
InvokeService def = invokeServiceMap.get(Msg.DEFAULT);
|
||||
if (StrUtil.isBlank(service)) {
|
||||
service = Msg.DEFAULT;
|
||||
}
|
||||
|
||||
InvokeService invokeService = invokeServiceMap.get(service);
|
||||
if (ObjectUtil.isNull(invokeService)) {
|
||||
// Service異常
|
||||
return def.log(request, new InvokeResponse().initInvokeFail(service, request));
|
||||
}
|
||||
|
||||
request.setFromSystem(Msg.AGV);
|
||||
|
||||
String transSid = request.getTransSid();
|
||||
if (StrUtil.isNotBlank(transSid)) {
|
||||
IntInDataLogService intInDataLogService = SpringUtil.getBean(IntInDataLogService.class);
|
||||
IntInDataLog intInDataLog = intInDataLogService.getOne(Wrappers.<IntInDataLog>lambdaQuery().eq(IntInDataLog::getIntInDataSid, transSid).eq(IntInDataLog::getState, "S").orderByDesc(IntInDataLog::getDateCreate), false);
|
||||
if (intInDataLog != null) {
|
||||
return invokeService.fail(transSid, I18nUtil.getI18nText("int.invoke.error6", I18nUtil.getI18nText("int.invoke.msg1")));
|
||||
}
|
||||
}
|
||||
|
||||
String errorMsg = invokeService.validation(request);
|
||||
if (StrUtil.isNotBlank(errorMsg)) {
|
||||
// 查核異常
|
||||
return def.log(request, invokeService.fail(transSid, errorMsg));
|
||||
}
|
||||
return invokeService.invoke(request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,8 +21,14 @@ import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@ -87,6 +93,34 @@ public class InvokeController {
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* agv呼叫接口
|
||||
* @param service
|
||||
* @param jsonBody
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = {"/agvInvoke", "/{service}/agvInvoke"})
|
||||
public JSONObject agvInvoke(@PathVariable(value = "service", required = false) String service, @RequestBody JSONObject jsonBody) {
|
||||
String requestText = jsonBody.toJSONString();
|
||||
InvokeRequest request = JSONObject.parseObject(requestText, InvokeRequest.class);
|
||||
request.setMessageContent(requestText);
|
||||
request.setSrcRequestBody(requestText);
|
||||
InvokeResponse invokeResponse = invoke.executeAGV(service, request);
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("REQ_ID", invokeResponse.getTransSid());
|
||||
response.put("RESULT", invokeResponse.getResult());
|
||||
response.put("MESSAGE", invokeResponse.getMessageContent());
|
||||
|
||||
JSONObject objectResponse = invokeResponse.getObjectResponse();
|
||||
if (ObjectUtil.isNotNull(objectResponse)) {
|
||||
for (String key : objectResponse.keySet()) {
|
||||
response.put(key, objectResponse.getString(key));
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Inner(value = false)
|
||||
@PostMapping(value = {"/callERPInvoke", "/{service}/callERPInvoke"})
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
package com.foreverwin.iep.integration.handler.def.agv;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.iep.common.constant.BaseConstants;
|
||||
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.iep.prd.entity.ZLotMeasuringRecordItf;
|
||||
import com.foreverwin.iep.prd.feign.RemoteLotMeasuringRecordItfService;
|
||||
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("AGV_IN_LOT_MEASURING")
|
||||
public class AgvInLotMeasuring implements HandlerService {
|
||||
|
||||
private final RemoteLotMeasuringRecordItfService remoteLotMeasuringRecordItfService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
JSONObject jsonObject = JS.parseObject(invokeRequest.getMessageContent());
|
||||
// updateFlag默认为Y;当为Y时,需要更新批次所在的LOT_STATE表记录
|
||||
String updateFlag = jsonObject.getString("UPDATE_FLAG");
|
||||
if(StrUtil.isBlank(updateFlag)) {
|
||||
updateFlag = BaseConstants.Y;
|
||||
}
|
||||
String transType = jsonObject.getString("TRANS_TYPE");
|
||||
if(StrUtil.isBlank(transType)) {
|
||||
transType = "1";
|
||||
}
|
||||
// remote api
|
||||
ZLotMeasuringRecordItf lotMeasuringRecordItf = new ZLotMeasuringRecordItf();
|
||||
lotMeasuringRecordItf.setSite(invokeRequest.getSite());
|
||||
lotMeasuringRecordItf.setCreator(Msg.AGV);
|
||||
lotMeasuringRecordItf.setTransactionId(invokeRequest.getTransSid());
|
||||
lotMeasuringRecordItf.setLotNo(jsonObject.getString("LOT_NO"));
|
||||
lotMeasuringRecordItf.setFabNo(jsonObject.getString("FAB_NO"));
|
||||
lotMeasuringRecordItf.setWorkCenter(jsonObject.getString("WORK_CENTER"));
|
||||
lotMeasuringRecordItf.setResrce(jsonObject.getString("RESOURCE"));
|
||||
lotMeasuringRecordItf.setMaterialItem(jsonObject.getString("MATERIAL_ITEM"));
|
||||
lotMeasuringRecordItf.setMaterialBatch(jsonObject.getString("MATERIAL_BATCH"));
|
||||
lotMeasuringRecordItf.setMainUom(jsonObject.getString("MAIN_UOM"));
|
||||
lotMeasuringRecordItf.setMainQty(jsonObject.getBigDecimal("MAIN_QTY"));
|
||||
lotMeasuringRecordItf.setSubUom(jsonObject.getString("SUB_UOM"));
|
||||
lotMeasuringRecordItf.setSubQty(jsonObject.getBigDecimal("SUB_QTY"));
|
||||
lotMeasuringRecordItf.setTransactionType(transType);
|
||||
lotMeasuringRecordItf.setTransactionDate(Local.toLocalDateTime(invokeRequest.getTransTime(), "yyyy-MM-dd HH:mm:ss"));
|
||||
lotMeasuringRecordItf.setUpdateFlag(updateFlag);
|
||||
|
||||
String message = remoteLotMeasuringRecordItfService.receive(lotMeasuringRecordItf).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("lotNo");
|
||||
if(StrUtil.isBlank(keyValue)) {
|
||||
keyValue = jsonObject.getString("materialBatch");
|
||||
}
|
||||
invokeRequest.setKeyValue(keyValue);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,207 @@
|
||||
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 com.foreverwin.iep.integration.handler.def.sap.SapUtil;
|
||||
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 LotMeasuringRecordItfServiceImplTest {
|
||||
|
||||
public static final String origin = "http://127.0.0.1:8091";
|
||||
public static final String mesOrigin = "http://localhost:8080";
|
||||
|
||||
@Test
|
||||
public void testCallAgv() throws Exception {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost postRequest = new HttpPost(mesOrigin + "/iep-int/agvInvoke");
|
||||
|
||||
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 = assembleMsgBody();
|
||||
|
||||
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 assembleMsgBody() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("REQ_ID", StrUtil.uuid());
|
||||
jsonObject.put("SEND_TIME","2024-11-29 12:00:00");
|
||||
jsonObject.put("SITE","2031");
|
||||
jsonObject.put("MESSAGE_ID","AGV_IN_LOT_MEASURING");
|
||||
jsonObject.put("LOT_NO", "10000001234");
|
||||
jsonObject.put("FAB_NO","009");
|
||||
jsonObject.put("WORK_CENTER","WC01");
|
||||
jsonObject.put("RESOURCE","RES01");
|
||||
jsonObject.put("MATERIAL_ITEM","MI01");
|
||||
jsonObject.put("MATERIAL_BATCH","MB01");
|
||||
jsonObject.put("MAIN_UOM","KG");
|
||||
jsonObject.put("MAIN_QTY","12");
|
||||
jsonObject.put("SUB_UOM","M");
|
||||
jsonObject.put("SUB_QTY","100");
|
||||
jsonObject.put("TRANS_TYPE","1");
|
||||
jsonObject.put("UPDATE_FLAG","Y");
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPost() 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");
|
||||
msgBody = msgBody.replaceAll ("\n", "");
|
||||
JSONObject jsonObject = JSONObject.parseObject(msgBody);
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static String msgBody = "{\n" +
|
||||
" \"SITE\": \"2031\",\n" +
|
||||
" \"REQ_ID\": \"2024110814133743434\",\n" +
|
||||
" \"keyValue\": \"SNOW\",\n" +
|
||||
" \"SEND_TIME\": \"2024-11-08 14:13:37\",\n" +
|
||||
" \"SENDER\": \"ERP\",\n" +
|
||||
" \"start\": \"2024-11-06 17:05:37\",\n" +
|
||||
" \"MESSAGE_ID\": \"ERP_IN_SALES_ORDER\",\n" +
|
||||
" \"RECEIVER\": \"IEP\",\n" +
|
||||
" \"retry\": false,\n" +
|
||||
" \"messageContent\": [\n" +
|
||||
" {\n" +
|
||||
" \"SO_NUMBER\": \"JI\",\n" +
|
||||
" \"SO_CREATOR\": \"80\",\n" +
|
||||
" \"SO_CREATE_TIME\": \"2024-11-01 12:30:57\",\n" +
|
||||
" \"SO_REASON\": \"测试\",\n" +
|
||||
" \"SO_TYPE\": \"A\",\n" +
|
||||
" \"SO_CATEGORY\": \"A\",\n" +
|
||||
" \"SO_CURRENCY\": \"20\",\n" +
|
||||
" \"SO_SALES_ORG\": \"中\",\n" +
|
||||
" \"SO_SALES_DISTRIBUTOR\": \"8089888-80\",\n" +
|
||||
" \"SO_SALES_OFFICE\": \"8089888-80\",\n" +
|
||||
" \"SO_SALES_GROUP\": \"8089888-80\",\n" +
|
||||
" \"SO_SALES_PARTNER\": \"8089888-80\",\n" +
|
||||
" \"SO_SALES_PARTNER_CODE\": \"8089888-80\",\n" +
|
||||
" \"SO_MANAGER\": \"8089888-80\",\n" +
|
||||
" \"SO_ASSISTANT\": \"SO销售助理\",\n" +
|
||||
" \"SO_CUSTOMER\": \"APP\",\n" +
|
||||
" \"SO_CUSTOMER_CODE\": \"43\",\n" +
|
||||
" \"SO_CREDIT_STATUS\": \"OK\",\n" +
|
||||
" \"SO_PAYMENT_STATUS\": \"Y\",\n" +
|
||||
" \"LINE_INFO\": [\n" +
|
||||
" {\n" +
|
||||
" \"SO_LINE_ID\": \"1\",\n" +
|
||||
" \"CATEGORY\": \"B\",\n" +
|
||||
" \"REASON\": \"SO拒绝原因\",\n" +
|
||||
" \"ITEM\": \"BJ0\",\n" +
|
||||
" \"QTY\": \"999\",\n" +
|
||||
" \"OVER_QTY\": \"100\",\n" +
|
||||
" \"DELIVERY_DATE\": \"2024-11-07\",\n" +
|
||||
" \"UOM\": \"PCS\",\n" +
|
||||
" \"SALES_UOM\": \"EM\",\n" +
|
||||
" \"DELIVERY_PLANT\": \"2023\",\n" +
|
||||
" \"PRICE_STATUS\": \"Y\",\n" +
|
||||
" \"DELIVERY_STATUS\": \"N\",\n" +
|
||||
" \"CONFIG_ID\": \"001\",\n" +
|
||||
" \"CONFIG_INFO\": [\n" +
|
||||
" {\n" +
|
||||
" \"CONFIG_ITEM\": \"BM\",\n" +
|
||||
" \"CONFIG_ITEM_DESC\": \"SO配置项描述\",\n" +
|
||||
" \"CONFIG_ITEM_VALUE\": \"23\",\n" +
|
||||
" \"CONFIG_ITEM_VALUE_DESC\": \"SO配置值描述\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"CONFIG_ITEM\": \"CM\",\n" +
|
||||
" \"CONFIG_ITEM_DESC\": \"第二笔\",\n" +
|
||||
" \"CONFIG_ITEM_VALUE\": \"43\",\n" +
|
||||
" \"CONFIG_ITEM_VALUE_DESC\": \"测试\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"SO_LINE_ID\": \"2\",\n" +
|
||||
" \"CATEGORY\": \"C\",\n" +
|
||||
" \"REASON\": \"销售订单第二行\",\n" +
|
||||
" \"ITEM\": \"BJ0\",\n" +
|
||||
" \"QTY\": \"999\",\n" +
|
||||
" \"OVER_QTY\": \"100\",\n" +
|
||||
" \"DELIVERY_DATE\": \"2024-11-07\",\n" +
|
||||
" \"UOM\": \"PCS\",\n" +
|
||||
" \"SALES_UOM\": \"EM\",\n" +
|
||||
" \"DELIVERY_PLANT\": \"2023\",\n" +
|
||||
" \"PRICE_STATUS\": \"Y\",\n" +
|
||||
" \"DELIVERY_STATUS\": \"N\",\n" +
|
||||
" \"CONFIG_ID\": \"002\",\n" +
|
||||
" \"CONFIG_INFO\": [\n" +
|
||||
"\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user