feat(AGV): 接口
1. 缓存架与基膜卷绑定关系记录接口 2. edc自动呼叫agv新增判断阈值快码是否启用判断
This commit is contained in:
parent
558778b94b
commit
ac93c4df0d
@ -0,0 +1,84 @@
|
||||
package com.foreverwin.iep.integration.handler.def.agv;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.prd.entity.ZAgvCacheLotRelationship;
|
||||
import com.foreverwin.iep.prd.feign.RemoteAgvCacheLotRelationshipService;
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 缓存架与基膜卷绑定关系上传记录接口
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service("AGV_CACHE_LOT_RELATIONSHIP")
|
||||
public class AgvCacheLotRelationship implements HandlerService {
|
||||
|
||||
private final RemoteAgvCacheLotRelationshipService remoteAgvCacheLotRelationshipService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
JSONObject jsonObject = JS.parseObject(invokeRequest.getMessageContent());
|
||||
JSONArray details = jsonObject.getJSONArray("DETAILS");
|
||||
List<ZAgvCacheLotRelationship> agvCacheLotRelationshipList = new ArrayList<>();
|
||||
// remote api
|
||||
for(int i = 0; i < details.size(); i++) {
|
||||
JSONObject detail = details.getJSONObject(i);
|
||||
ZAgvCacheLotRelationship agvCacheLotRelationship = new ZAgvCacheLotRelationship();
|
||||
agvCacheLotRelationship.setSite(invokeRequest.getSite());
|
||||
agvCacheLotRelationship.setCreator(Msg.AGV);
|
||||
agvCacheLotRelationship.setFabNo(jsonObject.getString("FAB_NO"));
|
||||
agvCacheLotRelationship.setWorkCenter(jsonObject.getString("WORK_CENTER"));
|
||||
agvCacheLotRelationship.setResrce(jsonObject.getString("RESOURCE"));
|
||||
agvCacheLotRelationship.setMainUom(jsonObject.getString("MAIN_UOM"));
|
||||
agvCacheLotRelationship.setMainQty(jsonObject.getBigDecimal("MAIN_QTY"));
|
||||
agvCacheLotRelationship.setSubUom(jsonObject.getString("SUB_UOM"));
|
||||
agvCacheLotRelationship.setSubQty(jsonObject.getBigDecimal("SUB_QTY"));
|
||||
|
||||
agvCacheLotRelationship.setCacheNo(detail.getString("CACHE_NO"));
|
||||
agvCacheLotRelationship.setCacheLayer(detail.getString("CACHE_LAYER"));
|
||||
agvCacheLotRelationship.setMaterialItem(detail.getString("MATERIAL_ITEM"));
|
||||
agvCacheLotRelationship.setMaterialBatch(detail.getString("MATERIAL_BATCH"));
|
||||
agvCacheLotRelationshipList.add(agvCacheLotRelationship);
|
||||
}
|
||||
String message = remoteAgvCacheLotRelationshipService.batchSaveOrUpdate(agvCacheLotRelationshipList).getData();
|
||||
InvokeResponse response = new InvokeResponse(invokeRequest);
|
||||
response.setTransTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
if ("true".equals(message) || "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"));
|
||||
}
|
||||
JSONArray details = jsonObject.getJSONArray("DETAILS");
|
||||
if(details == null || details.isEmpty()) {
|
||||
return "DETAILS不能为空";
|
||||
}
|
||||
String keyValue = jsonObject.getString("REQ_ID");
|
||||
invokeRequest.setKeyValue(keyValue);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
package com.foreverwin.iep.integration.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
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 AgvCacheLotRelationshipTest {
|
||||
|
||||
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_CACHE_LOT_RELATIONSHIP");
|
||||
JSONArray details = new JSONArray();
|
||||
JSONObject detail1 = new JSONObject();
|
||||
detail1.put("CACHE_NO","1001");
|
||||
detail1.put("CACHE_LAYER","1");
|
||||
detail1.put("MATERIAL_BATCH","10000001234");
|
||||
detail1.put("MATERIAL_ITEM","NV1001A123");
|
||||
details.add(detail1);
|
||||
JSONObject detail2 = new JSONObject();
|
||||
detail2.put("CACHE_NO","1001");
|
||||
detail2.put("CACHE_LAYER","2");
|
||||
detail2.put("MATERIAL_BATCH","10000001235");
|
||||
detail2.put("MATERIAL_ITEM","NV1001A123");
|
||||
details.add(detail2);
|
||||
JSONObject detail3 = new JSONObject();
|
||||
detail3.put("CACHE_NO","1001");
|
||||
detail3.put("CACHE_LAYER","3");
|
||||
detail3.put("MATERIAL_BATCH","");
|
||||
detail3.put("MATERIAL_ITEM","");
|
||||
details.add(detail3);
|
||||
JSONObject detail4 = new JSONObject();
|
||||
detail4.put("CACHE_NO","1002");
|
||||
detail4.put("CACHE_LAYER","1");
|
||||
detail4.put("MATERIAL_BATCH","10000001237");
|
||||
detail4.put("MATERIAL_ITEM","NV1001A123");
|
||||
details.add(detail4);
|
||||
JSONObject detail5 = new JSONObject();
|
||||
detail5.put("CACHE_NO","1002");
|
||||
detail5.put("CACHE_LAYER","2");
|
||||
detail5.put("MATERIAL_BATCH","10000001237");
|
||||
detail5.put("MATERIAL_ITEM","NV1001A123");
|
||||
details.add(detail5);
|
||||
jsonObject.put("DETAILS", details);
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user