feat(接口): 自动拆包计数采集
This commit is contained in:
parent
45d05cd163
commit
222d40f05b
@ -0,0 +1,62 @@
|
||||
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.agv.domain.AgvAutoUnpackingCountCollectionRequest;
|
||||
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.wms.feign.RemoteEqpFeedingService;
|
||||
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_AUTO_UNPACKING_COUNT_COLLECTION")
|
||||
public class AgvAutoUnpackingCountCollection implements HandlerService {
|
||||
|
||||
private final RemoteEqpFeedingService remoteEqpFeedingService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
String messageContent = invokeRequest.getMessageContent();
|
||||
// 将json对象jsonObject转成AgvAutoUnpackingCollectionRequest对象
|
||||
AgvAutoUnpackingCountCollectionRequest agvAutoUnpackingCollectionRequest = JSONObject.parseObject(messageContent, AgvAutoUnpackingCountCollectionRequest.class);
|
||||
|
||||
String message = remoteEqpFeedingService.countCollection(agvAutoUnpackingCollectionRequest).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;
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package com.foreverwin.iep.integration.service.impl;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.foreverwin.iep.common.base.FrontPage;
|
||||
import com.foreverwin.iep.common.utils.JsonUtils;
|
||||
import com.foreverwin.iep.integration.domain.InvokeRequest;
|
||||
import com.foreverwin.iep.integration.dto.IntInDataDTO;
|
||||
import com.foreverwin.iep.integration.entity.IntInData;
|
||||
@ -56,7 +56,8 @@ public class IntInDataServiceImpl extends ServiceImpl<IntInDataMapper, IntInData
|
||||
public void retry(String sid) {
|
||||
IntInData intInData = getById(sid);
|
||||
|
||||
InvokeRequest invokeRequest = JsonUtils.readValue(intInData.getRequest(), InvokeRequest.class);
|
||||
// InvokeRequest invokeRequest = JsonUtils.readValue(intInData.getRequest(), InvokeRequest.class);
|
||||
InvokeRequest invokeRequest = JSON.parseObject(intInData.getRequest(), InvokeRequest.class);
|
||||
invokeRequest.setTransTime(Local.now());
|
||||
invokeRequest.setRetry(false);
|
||||
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
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 AgvAutoUnpackingCountTest {
|
||||
|
||||
public static final String origin = "http://127.0.0.1:8091";
|
||||
public static final String mesOrigin = "http://localhost:8080";
|
||||
|
||||
@Test
|
||||
public void testCall() 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","3041");
|
||||
jsonObject.put("MESSAGE_ID","AGV_AUTO_UNPACKING_COUNT_COLLECTION");
|
||||
jsonObject.put("FAB_NO","009");
|
||||
jsonObject.put("WORK_CENTER","WC01");
|
||||
jsonObject.put("OPERATION","OP01");
|
||||
jsonObject.put("SHOP_ORDER","SO01");
|
||||
jsonObject.put("RESOURCE","FQ001");
|
||||
jsonObject.put("SUB_RESOURCE","TLK02");
|
||||
jsonObject.put("PROCESS_RESOURCE","TT02");
|
||||
jsonObject.put("MATERIAL_BATCH","MB01");
|
||||
jsonObject.put("PROCESSED_COUNT","1");
|
||||
jsonObject.put("PROCESSED_QTY","25");
|
||||
jsonObject.put("TRANS_TYPE","1");
|
||||
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