Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
84b0cba063
@ -0,0 +1,82 @@
|
||||
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.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.wip.entity.ZTaskDetail;
|
||||
import com.foreverwin.iep.wip.feign.RemoteAgvTaskService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* AGV任务回传
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service("AGV_TASK_REPLY")
|
||||
public class AgvTaskReply implements HandlerService {
|
||||
|
||||
private final RemoteAgvTaskService remoteAgvTaskService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
JSONObject jsonObject = JS.parseObject(invokeRequest.getMessageContent());
|
||||
// remote api
|
||||
ZTaskDetail taskDetail = new ZTaskDetail();
|
||||
taskDetail.setSite(invokeRequest.getSite());
|
||||
taskDetail.setCreator(Msg.AGV);
|
||||
taskDetail.setTaskId(jsonObject.getString("TASK_ID"));
|
||||
taskDetail.setTaskStatus(jsonObject.getString("TASK_STATUS"));
|
||||
taskDetail.setCompletedDate(Local.toLocalDateTime(jsonObject.getString("COMPLETED_DATE"), "yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
String message = remoteAgvTaskService.taskReply(taskDetail).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 taskId = jsonObject.getString("TASK_ID");
|
||||
String taskStatus = jsonObject.getString("TASK_STATUS");
|
||||
String completedDate = jsonObject.getString("COMPLETED_DATE");
|
||||
if(StrUtil.isBlank(taskId)) {
|
||||
return "TASK_ID不能为空";
|
||||
}
|
||||
if(StrUtil.isBlank(taskStatus)) {
|
||||
return "TASK_STATUS不能为空";
|
||||
}
|
||||
if(StrUtil.isBlank(completedDate)) {
|
||||
return "COMPLETED_DATE不能为空";
|
||||
}
|
||||
try {
|
||||
Local.toLocalDateTime(jsonObject.getString("COMPLETED_DATE"), "yyyy-MM-dd HH:mm:ss");
|
||||
} catch (Exception e) {
|
||||
return "COMPLETED_DATE格式错误,请使用yyyy-MM-dd HH:mm:ss格式";
|
||||
}
|
||||
String keyValue = jsonObject.getString("TASK_ID");
|
||||
invokeRequest.setKeyValue(keyValue);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -43,12 +43,10 @@ public class SapExamineItem implements HandlerService {
|
||||
Gson gson = new Gson();
|
||||
SapExamineItemDTO sapExamineItemDTO = gson.fromJson(jsonObject.getJSONObject(Msg.MESSAGE_CONTENT).toJSONString(), SapExamineItemDTO.class);
|
||||
sapExamineItemDTO.setBatchId(invokeRequest.getTransSid());
|
||||
sapExamineItemDTO.setSite(invokeRequest.getSite());
|
||||
// 检验项目接口表
|
||||
ZQmsQcItemItf zQmsQcItemItf = new ZQmsQcItemItf();
|
||||
// 属性copy
|
||||
BeanUtils.copyProperties(sapExamineItemDTO, zQmsQcItemItf);
|
||||
zQmsQcItemItf.setHandle(StrUtil.uuid());
|
||||
zQmsQcItemItf.setCreator(Msg.SAP);
|
||||
zQmsQcItemItf.setDateCreate(nowLocalDateTime);
|
||||
zQmsQcItemItf.setResponseStatus(Msg.S);
|
||||
|
||||
@ -47,12 +47,10 @@ public class SapTextSub implements HandlerService {
|
||||
Gson gson = new Gson();
|
||||
SapQcItemTypeTextSubDTO sapQcItemTypeTextSubDTO = gson.fromJson(jsonObject.get(Msg.MESSAGE_CONTENT).toString(), SapQcItemTypeTextSubDTO.class);
|
||||
sapQcItemTypeTextSubDTO.setBatchId(invokeRequest.getTransSid());
|
||||
sapQcItemTypeTextSubDTO.setSite(invokeRequest.getSite());
|
||||
// 选项集同步接口表
|
||||
ZQmsQcItemTypeTextSubItf zQmsQcItemTypeTextSubItf = new ZQmsQcItemTypeTextSubItf();
|
||||
// 属性copy
|
||||
BeanUtils.copyProperties(sapQcItemTypeTextSubDTO, zQmsQcItemTypeTextSubItf);
|
||||
zQmsQcItemTypeTextSubItf.setHandle(StrUtil.uuid());
|
||||
zQmsQcItemTypeTextSubItf.setCreator(Msg.SAP);
|
||||
zQmsQcItemTypeTextSubItf.setDateCreate(nowLocalDateTime);
|
||||
zQmsQcItemTypeTextSubItf.setResponseStatus(Msg.S);
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
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 AgvTaskReplyTest {
|
||||
|
||||
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","3041");
|
||||
jsonObject.put("MESSAGE_ID","AGV_TASK_REPLY");
|
||||
jsonObject.put("TASK_ID", "AGV-20241220005");
|
||||
jsonObject.put("TASK_STATUS","1");
|
||||
jsonObject.put("COMPLETED_DATE","2024-11-29 12:00:00");
|
||||
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