feat(接口): 挤出/失重秤消耗量采集
This commit is contained in:
parent
184939adce
commit
9e8e02a010
@ -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.EapExtrudeRecordRequest;
|
||||
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.RemoteExtrudeRecordService;
|
||||
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_EXTRUDE_RECORD")
|
||||
public class EapExtrudeRecord implements HandlerService {
|
||||
|
||||
private final RemoteExtrudeRecordService remoteExtrudeRecordService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
String messageContent = invokeRequest.getMessageContent();
|
||||
// 将json对象jsonObject转成EapExtrudeRecordRequest对象
|
||||
EapExtrudeRecordRequest eapExtrudeRecordRequest = JSONObject.parseObject(messageContent, EapExtrudeRecordRequest.class);
|
||||
|
||||
String message = remoteExtrudeRecordService.receive(eapExtrudeRecordRequest).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("EXTRUDER_RESOURCE");
|
||||
if(StrUtil.isBlank(keyValue)) {
|
||||
keyValue = jsonObject.getString("RESOURCE");
|
||||
}
|
||||
invokeRequest.setKeyValue(keyValue);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,109 @@
|
||||
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 EapExtrudeRecordTest {
|
||||
|
||||
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/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 = 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("SENDER","EAP");
|
||||
jsonObject.put("MESSAGE_ID","EAP_EXTRUDE_RECORD");
|
||||
jsonObject.put("FAB_NO","009");
|
||||
jsonObject.put("WORK_CENTER","WC01");
|
||||
jsonObject.put("OPERATION","JMLS");
|
||||
jsonObject.put("RESOURCE","LS001");
|
||||
jsonObject.put("EXTRUDER_RESOURCE","TLK02");
|
||||
jsonObject.put("PROCESS_RESOURCE","TT02");
|
||||
jsonObject.put("MAIN_UOM","KG");
|
||||
jsonObject.put("MAIN_QTY","12");
|
||||
jsonObject.put("SUB_UOM","KG");
|
||||
jsonObject.put("SUB_QTY","3");
|
||||
jsonObject.put("TRANS_TYPE","1");
|
||||
jsonObject.put("TRANS_DATE","2024-11-29 12:00:00");
|
||||
jsonObject.put("START_DATE_TIME","2024-11-29 12:00:00");
|
||||
jsonObject.put("END_DATE_TIME","2024-11-30 12:00:00");
|
||||
JSONArray details = new JSONArray();
|
||||
JSONObject detail = new JSONObject();
|
||||
detail.put("SUB_RESOURCE","TT0201");
|
||||
detail.put("SET_VALUE","22.1");
|
||||
detail.put("ACTUAL_VALUE","33");
|
||||
detail.put("ACTUAL_QTY","66");
|
||||
details.add(detail);
|
||||
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