feat(接口): EDC电量采集
This commit is contained in:
parent
bfc7c96269
commit
db3b9563fe
@ -0,0 +1,57 @@
|
||||
package com.foreverwin.iep.integration.handler.def.eap;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.iep.eap.domain.EapEnergyDataProcessRequest;
|
||||
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.RemoteEdcRecordService;
|
||||
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("energy.data.process")
|
||||
public class EapEnergyDataProcess implements HandlerService {
|
||||
|
||||
private final RemoteEdcRecordService remoteEdcRecordService;
|
||||
|
||||
@Override
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
String messageContent = invokeRequest.getMessageContent();
|
||||
// 将json对象jsonObject转成EapExtrudeRecordRequest对象
|
||||
EapEnergyDataProcessRequest eapEnergyDataProcessRequest = JSONObject.parseObject(messageContent, EapEnergyDataProcessRequest.class);
|
||||
String message = remoteEdcRecordService.energyDataProcess(eapEnergyDataProcessRequest).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("RESOURCE");
|
||||
invokeRequest.setKeyValue(keyValue);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
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;
|
||||
@ -83,6 +84,35 @@ class EapEdcRecordTest {
|
||||
System.out.println(responseJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 电量采集
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void energyDataProcess() 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", "3041");
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
|
||||
String assembleMsgBody = energyDataProcessBody();
|
||||
|
||||
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 protectiveFilmUnwindingCollectionBody() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("REQ_ID", StrUtil.uuid());
|
||||
@ -130,16 +160,41 @@ class EapEdcRecordTest {
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
private String energyDataProcessBody() {
|
||||
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", "energy.data.process");
|
||||
jsonObject.put("FACTORY", "009");
|
||||
jsonObject.put("LINE_ID", "WC01");
|
||||
jsonObject.put("OPERATION", "JMLS");
|
||||
jsonObject.put("RESOURCE", "LS001");
|
||||
|
||||
JSONArray pdcBasis = new JSONArray();
|
||||
JSONObject par1 = new JSONObject();
|
||||
par1.put("PARAMETER", "WD");
|
||||
par1.put("PARAMETER_VALUE", "20");
|
||||
pdcBasis.add(par1);
|
||||
JSONObject par2 = new JSONObject();
|
||||
par2.put("PARAMETER", "SD");
|
||||
par2.put("PARAMETER_VALUE", "0.2");
|
||||
pdcBasis.add(par2);
|
||||
jsonObject.put("PDC_BASIS", pdcBasis);
|
||||
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=="));
|
||||
|
||||
pair.add(new BasicNameValuePair("username", "eap"));
|
||||
pair.add(new BasicNameValuePair("password", "fCn7lpNYLSSJdA=="));
|
||||
|
||||
postRequest.setHeader(HttpHeaders.AUTHORIZATION, "Basic bW9tOm1vbQ==");
|
||||
postRequest.setHeader("TENANT-ID", "2031");
|
||||
postRequest.setHeader("TENANT-ID", "3041");
|
||||
postRequest.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
|
||||
|
||||
postRequest.setEntity(new UrlEncodedFormEntity(pair, "UTF-8"));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user