Merge branch 'dev' into prd
# Conflicts: # int-core/src/main/java/com/foreverwin/iep/integration/controller/CopyShopOrderStatisticTransController.java # int-core/src/main/java/com/foreverwin/iep/integration/controller/InvokeController.java # int-core/src/main/java/com/foreverwin/iep/integration/handler/def/oa/OAUtil.java # int-core/src/main/java/com/foreverwin/iep/integration/handler/def/sap/EsbFileDealService.java # int-core/src/main/java/com/foreverwin/iep/integration/handler/def/sap/MesPostDnService.java # int-core/src/main/java/com/foreverwin/iep/integration/handler/def/sap/SapExamineItem.java # int-core/src/main/java/com/foreverwin/iep/integration/handler/def/sap/SapTextSub.java # int-core/src/main/java/com/foreverwin/iep/integration/handler/def/sap/SapUtil.java
This commit is contained in:
commit
7ea07b7d7d
@ -68,7 +68,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
@SysLog("生产管理报工平台-工单报工")
|
||||
@PostMapping("/callErp")
|
||||
public R callErp() {
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("0");
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("0", "1");
|
||||
List<InventoryRecord> inventoryRecordList = byType.getData();
|
||||
// if (inventoryRecordList.size() == 0){
|
||||
// return R.failed("没有需要同步的库存数据");
|
||||
@ -81,6 +81,13 @@ public class CopyShopOrderStatisticTransController {
|
||||
newList.add(inventoryRecord);
|
||||
}
|
||||
|
||||
// R<List<InventoryRecord>> listR = inventoryRecordMapper.selectBySyncStatus();
|
||||
// List<InventoryRecord> inventoryRecords = listR.getData();
|
||||
// for (InventoryRecord inventoryRecord : inventoryRecords) {
|
||||
//
|
||||
// processInventoryRecord(inventoryRecord, site);
|
||||
// }
|
||||
|
||||
|
||||
//========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
|
||||
|
||||
@ -110,7 +117,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
invokeRequest.setRetry(false);
|
||||
TenantContextHolder.setTenantId(site);
|
||||
invokeResponse = inventoryRecordService.call(invokeRequest);
|
||||
invokeResponse = updateLotComplete(invokeResponse.getObjectResponse(), newList, invokeResponse);
|
||||
invokeResponse = updateCallErp(invokeResponse.getObjectResponse(), newList, invokeResponse);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -123,12 +130,12 @@ public class CopyShopOrderStatisticTransController {
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
return R.failed(invokeResponse.getMessageContent());
|
||||
} else {
|
||||
R<List<InventoryRecord>> listR = inventoryRecordMapper.selectBySyncStatus();
|
||||
List<InventoryRecord> inventoryRecords = listR.getData();
|
||||
for (InventoryRecord inventoryRecord : inventoryRecords) {
|
||||
|
||||
processInventoryRecord(inventoryRecord, site);
|
||||
}
|
||||
// R<List<InventoryRecord>> listR = inventoryRecordMapper.selectBySyncStatus();
|
||||
// List<InventoryRecord> inventoryRecords = listR.getData();
|
||||
// for (InventoryRecord inventoryRecord : inventoryRecords) {
|
||||
//
|
||||
// processInventoryRecord(inventoryRecord, site);
|
||||
// }
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
@ -274,7 +281,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
@SysLog("生产管理报工平台-物料消耗报工")
|
||||
@PostMapping("/callErpMaterial")
|
||||
public R callErpMaterial() {
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("1");
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("1","0");
|
||||
List<InventoryRecord> inventoryRecords = byType.getData();
|
||||
// if (inventoryRecords.size() == 0){
|
||||
// return R.failed("没有需要同步的库存数据");
|
||||
@ -379,6 +386,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
targetObj.setIsSap("1");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
@ -420,7 +428,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
@SysLog("生产管理报工平台-批次完工入库报工")
|
||||
@PostMapping("/callErpLot")
|
||||
public R callErpLot() {
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("0");
|
||||
R<List<InventoryRecord>> byType = inventoryRecordMapper.getByType("0","0");
|
||||
List<InventoryRecord> inventoryRecords = byType.getData();
|
||||
// if (inventoryRecords.size() == 0){
|
||||
// return R.failed("没有需要同步的库存数据");
|
||||
@ -517,6 +525,36 @@ public class CopyShopOrderStatisticTransController {
|
||||
}
|
||||
}
|
||||
|
||||
public InvokeResponse updateCallErp(JSONObject jsonObject, List<InventoryRecord> srcList, InvokeResponse invokeResponse) {
|
||||
JSONObject bodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
|
||||
JSONObject outJson = bodyJson.getJSONObject("ES_OUTPUT");
|
||||
String rmzhl = outJson.getString("RMZHL");
|
||||
String rueck = outJson.getString("RUECK");
|
||||
String result = outJson.getString("MSGTY");
|
||||
String message = outJson.getString("MSGTX");
|
||||
String msgNo = outJson.getString("MSGNO");
|
||||
String mblnr = outJson.getString("MBLNR");
|
||||
String msgid = outJson.getString("MSGID");// 物料凭证编号
|
||||
for (InventoryRecord targetObj : srcList) {
|
||||
targetObj.setSyncTicketLine(rmzhl);
|
||||
targetObj.setSyncTicketNo(rueck);
|
||||
targetObj.setSyncStatus(result);
|
||||
targetObj.setSyncMessageText(message);
|
||||
targetObj.setSyncMessageNo(msgNo);
|
||||
targetObj.setSyncVoucherNo(mblnr);
|
||||
targetObj.setSyncSubmitter(SecurityUtils.getUserName());
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
targetObj.setSyncMessageRemark(msgid);
|
||||
targetObj.setIsSap("2");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
invokeResponse.setResult(result);
|
||||
invokeResponse.setMessageContent(message);
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
public InvokeResponse updateLotComplete(JSONObject jsonObject, List<InventoryRecord> srcList, InvokeResponse invokeResponse) {
|
||||
JSONObject bodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
|
||||
JSONObject outJson = bodyJson.getJSONObject("ES_OUTPUT");
|
||||
@ -538,6 +576,7 @@ public class CopyShopOrderStatisticTransController {
|
||||
targetObj.setCreator(SecurityUtils.getUserName());
|
||||
targetObj.setDateCreate(LocalDateTime.now());
|
||||
targetObj.setSyncMessageRemark(msgid);
|
||||
targetObj.setIsSap("1");
|
||||
R r = inventoryRecordMapper.apiUpdateById(targetObj);
|
||||
r.getMsg();
|
||||
}
|
||||
|
||||
@ -28,8 +28,11 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.UUID;
|
||||
|
||||
import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(value = "invoke", tags = "整合服務接口")
|
||||
@ -39,9 +42,16 @@ public class InvokeController {
|
||||
|
||||
private final IntInDataService intInDataService;
|
||||
|
||||
/**
|
||||
* 头部信息
|
||||
*/
|
||||
private final HttpServletRequest servletRequest;
|
||||
|
||||
@PostMapping(value = {"/heartBeateInvoke"})
|
||||
public R heartBeateInvoke(@RequestBody JSONObject jsonBody) {
|
||||
String token = jsonBody.getString("access_token");
|
||||
// String ipAddress = SapUtil.getIpAddr(servletRequest);
|
||||
// String message = "OK,您的IP地址是"+ipAddress;
|
||||
return R.ok("OK");
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,7 @@ public class OAUtil {
|
||||
|
||||
private static final String apikey = "hWS3L96a0h4NKCAjN9hG1OmOeEIsxCTz";
|
||||
|
||||
private static final String env = "PRD";
|
||||
private static final String env = "DEV";
|
||||
|
||||
public static String appendHead(String jsonStr) {
|
||||
JSONObject allJson = new JSONObject();
|
||||
|
||||
@ -5,12 +5,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.iep.common.faas.common.util.StringUtils;
|
||||
import com.foreverwin.iep.integration.domain.InvokeRequest;
|
||||
import com.foreverwin.iep.integration.domain.InvokeResponse;
|
||||
import com.foreverwin.iep.integration.entity.IntInData;
|
||||
import com.foreverwin.iep.integration.entity.IntInDataLog;
|
||||
import com.foreverwin.iep.integration.service.IntInDataLogService;
|
||||
import com.foreverwin.iep.integration.service.IntInDataService;
|
||||
import com.foreverwin.iep.integration.utils.Local;
|
||||
import com.foreverwin.mom.common.security.util.SecurityUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
@ -19,7 +15,6 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 传送ESB的文件上传和下载查看服务
|
||||
@ -29,7 +24,6 @@ import java.util.UUID;
|
||||
public class EsbFileDealService {
|
||||
|
||||
private final IntInDataService intInDataService;
|
||||
private final IntInDataLogService intInDataLogService;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public InvokeResponse call(InvokeRequest invokeRequest, MultipartFile multipartFile) {
|
||||
@ -60,13 +54,13 @@ public class EsbFileDealService {
|
||||
}
|
||||
invokeResponse.setTransTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
invokeResponse.setTransSid(reqId);
|
||||
saveLogData(invokeRequest, invokeResponse);
|
||||
intInDataService.saveLogData(invokeRequest, invokeResponse);
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public InvokeResponse call(InvokeRequest invokeRequest,String objectFilePath ) {
|
||||
public InvokeResponse call(InvokeRequest invokeRequest, String objectFilePath) {
|
||||
String reqId = invokeRequest.getTransSid();
|
||||
InvokeResponse invokeResponse = new InvokeResponse(invokeRequest);
|
||||
String errorMsg = "成功";
|
||||
@ -92,37 +86,9 @@ public class EsbFileDealService {
|
||||
}
|
||||
invokeResponse.setTransTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
invokeResponse.setTransSid(reqId);
|
||||
saveLogData(invokeRequest, invokeResponse);
|
||||
intInDataService.saveLogData(invokeRequest, invokeResponse);
|
||||
}
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
private void saveLogData(InvokeRequest invokeRequest, InvokeResponse invokeResponse) {
|
||||
if (StringUtils.isNotEmpty(invokeRequest.getTransSid())) {
|
||||
// 存储日志
|
||||
IntInData intInData = new IntInData();
|
||||
intInData.setSid(invokeRequest.getTransSid());
|
||||
intInData.setRequest(invokeRequest.getMessageContent());
|
||||
intInData.setFunctionName(invokeRequest.getMessageId());
|
||||
intInData.setKeyValue(invokeRequest.getKeyValue());
|
||||
intInData.setFromSystem(invokeRequest.getFromSystem());
|
||||
intInData.setToSystem(invokeRequest.getToSystem());
|
||||
intInData.setRetryCount(0);
|
||||
intInData.setSite(invokeRequest.getSite());
|
||||
intInData.setCreator(SecurityUtils.getUserName());
|
||||
intInData.setDateCreate(LocalDateTime.now());
|
||||
intInDataService.save(intInData);
|
||||
IntInDataLog log = new IntInDataLog();
|
||||
log.setSid(UUID.randomUUID().toString());
|
||||
log.setIntInDataSid(intInData.getSid());
|
||||
log.setCreator(SecurityUtils.getUserName());
|
||||
log.setDateCreate(LocalDateTime.now());
|
||||
log.setSeq(0);
|
||||
log.setMessage(StringUtils.isEmpty(invokeResponse.getMessageContent()) ? "N/A" : invokeResponse.getMessageContent());
|
||||
log.setResponse(invokeResponse.getObjectResponse().toJSONString());
|
||||
log.setState(invokeResponse.getResult());
|
||||
intInDataLogService.save(log);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class MesPostDnService implements HandlerService {
|
||||
// 请求处理成功
|
||||
JSONObject jsonObject = invokeResponse.getObjectResponse();
|
||||
JSONObject bodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
|
||||
JSONObject outJson = bodyJson.getJSONObject("ES_OUTPUT");
|
||||
JSONObject outJson = bodyJson.getJSONObject("ES_RETURN");
|
||||
String result = outJson.getString("MSGTY");
|
||||
status = !"S".equals(result) ? "E" : result;
|
||||
String message = outJson.getString("MSGTX");
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -25,10 +25,12 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -36,6 +38,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class SapUtil {
|
||||
|
||||
@ -46,7 +49,7 @@ public class SapUtil {
|
||||
private static final String sapPassword = "Admin@1234567890";
|
||||
|
||||
private static final String apikey = "hWS3L96a0h4NKCAjN9hG1OmOeEIsxCTz";
|
||||
private static final String env = "PRD";
|
||||
private static final String env = "DEV";
|
||||
|
||||
private static final String EsbUploadFileServerUrl = "https://agw.esb.nit.pub/oss/upload";
|
||||
private static final String EsbGetFileServerUrl = "https://agw.esb.nit.pub/oss/file";
|
||||
@ -279,4 +282,39 @@ public class SapUtil {
|
||||
// 生成时间戳部分
|
||||
return dateFormat.format(new Date());
|
||||
}
|
||||
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ipAddress = null;
|
||||
try {
|
||||
ipAddress = request.getHeader("x-forwarded-for");
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getRemoteAddr();
|
||||
if (ipAddress.equals("127.0.0.1")) {
|
||||
// 根据网卡取本机配置的IP
|
||||
InetAddress inet = null;
|
||||
try {
|
||||
inet = InetAddress.getLocalHost();
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ipAddress = inet.getHostAddress();
|
||||
}
|
||||
}
|
||||
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
|
||||
if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()
|
||||
if (ipAddress.indexOf(",") > 0) {
|
||||
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ipAddress = "";
|
||||
}
|
||||
return ipAddress;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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