Merge branch 'main' of http://10.10.11.66:3000/mes/nalinv-int
This commit is contained in:
commit
78684c2d9f
@ -0,0 +1,17 @@
|
||||
package com.foreverwin.iep.integration.feign;
|
||||
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FeignClient(contextId = "remoteEsbFileDealService", value = "iep-int")
|
||||
public interface RemoteEsbFileDealService {
|
||||
|
||||
@PostMapping(value = "/esbFileDeal/api/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
R<Map<String, String>> uploadFileDoExecute(@RequestPart(value = "file") MultipartFile file);
|
||||
}
|
||||
@ -161,5 +161,17 @@
|
||||
<version>4.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.5.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version> <!-- 请根据需要选择合适的版本 -->
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,101 @@
|
||||
package com.foreverwin.iep.integration.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.iep.integration.domain.InvokeRequest;
|
||||
import com.foreverwin.iep.integration.domain.InvokeResponse;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.EsbFileDealService;
|
||||
import com.foreverwin.iep.integration.handler.def.sap.SapUtil;
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
|
||||
import com.foreverwin.mom.common.log.annotation.SysLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 传送ESB的文件上传和下载查看服务
|
||||
*
|
||||
* @author Snow
|
||||
* @date 2024-12-19 10:59:18
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/esbFileDeal")
|
||||
@Api(value = "esbFileDeal", tags = "传送ESB的文件上传和下载查看服务")
|
||||
public class EsbFileDealController {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("ESB_FILE_DEAL")
|
||||
private final EsbFileDealService esbFileDealService;
|
||||
|
||||
private final String MESSAGE_ID = "ESB_FILE_DEAL";
|
||||
|
||||
@ApiOperation(value = "传送ESB的文件上传和下载查看服务", notes = "传送ESB的文件上传和下载查看服务")
|
||||
@SysLog("传送ESB的文件上传和下载查看服务")
|
||||
@PostMapping(value = "/api/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public R uploadFileDoExecute(@RequestPart(value = "file") MultipartFile file) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
try {
|
||||
// 发送给ERP执行 ZMM_MES_POST_DN 接口
|
||||
LocalDateTime nowLocalDateTime = LocalDateTime.now();
|
||||
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
invokeRequest.setTransTime(nowTime); // 设定过账日期
|
||||
invokeRequest.setFromSystem("IEP");
|
||||
invokeRequest.setToSystem("ESB");
|
||||
invokeRequest.setSite(site);
|
||||
invokeRequest.setMessageId(MESSAGE_ID);
|
||||
|
||||
JSONObject contentObject = new JSONObject();
|
||||
// 组装抛送的报文
|
||||
String fileDir = "MES/" + site + "/" + SapUtil.generateYearMonth();
|
||||
contentObject.put("FILE_DIR", fileDir);
|
||||
invokeRequest.setMessageContent(fileDir);
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(file.getOriginalFilename());
|
||||
invokeRequest.setRetry(false);
|
||||
// 呼叫SAP
|
||||
invokeResponse = esbFileDealService.call(invokeRequest, file);
|
||||
params.put("RESULT", invokeResponse.getResult());
|
||||
params.put("MSG", invokeResponse.getMessageContent());
|
||||
} catch (Exception e) {
|
||||
params.put("RESULT", "E");
|
||||
params.put("MSG", e.getMessage());
|
||||
}
|
||||
// 如果处理失败,抛出异常,让业务逻辑回滚,但日志还是记录
|
||||
if ("E".equals(invokeResponse.getResult())) {
|
||||
params.put("RESULT", "E");
|
||||
params.put("MSG", invokeResponse.getMessageContent());
|
||||
}
|
||||
return R.ok(params);
|
||||
}
|
||||
|
||||
private String assembleMesPostDn(JSONObject requestBody) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("RFC_FUNCTION", MESSAGE_ID);
|
||||
JSONObject headRe = new JSONObject();
|
||||
headRe.put("EXCHANGE_SYSTEM", "MES");
|
||||
headRe.put("EXCHANGE_ID", SapUtil.generateReqId());
|
||||
headRe.put("EXCHANGE_DOC", "iMES_Call_SAP");
|
||||
jsonObject.put("REQUEST_CONTEXT", headRe);
|
||||
jsonObject.put("REQUEST_BODY", requestBody);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -35,6 +35,7 @@ public class SapMaterielReceiveForWorkJob {
|
||||
String site = null;
|
||||
String startDate = null;
|
||||
String endDate = null;
|
||||
String item = null;
|
||||
|
||||
String jobParam = XxlJobHelper.getJobParam();
|
||||
if (StrUtil.isNotBlank(jobParam)) {
|
||||
@ -42,6 +43,7 @@ public class SapMaterielReceiveForWorkJob {
|
||||
site = paramMap.get("site");
|
||||
startDate = paramMap.get("startDate");
|
||||
endDate = paramMap.get("endDate");
|
||||
item = paramMap.get("item");
|
||||
}
|
||||
if (StrUtil.isBlank(site)) {
|
||||
XxlJobHelper.log("******未维护站点[site]参数******");
|
||||
@ -68,7 +70,11 @@ public class SapMaterielReceiveForWorkJob {
|
||||
jsonObject.put("REQUEST_CONTEXT", conTextJsonObject);
|
||||
JSONObject bodyJsonObject = new JSONObject();
|
||||
JSONObject inputJsonObject = new JSONObject();
|
||||
inputJsonObject.put("MATNR", "");
|
||||
if (StrUtil.isBlank(item)) {
|
||||
inputJsonObject.put("MATNR", "");
|
||||
} else {
|
||||
inputJsonObject.put("MATNR", item);
|
||||
}
|
||||
inputJsonObject.put("MTART", "");
|
||||
inputJsonObject.put("MATKL", "");
|
||||
inputJsonObject.put("WERKS", site);
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
package com.foreverwin.iep.integration.handler.def.sap;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
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;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 传送ESB的文件上传和下载查看服务
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service("ESB_FILE_DEAL")
|
||||
public class EsbFileDealService {
|
||||
|
||||
private final IntInDataService intInDataService;
|
||||
private final IntInDataLogService intInDataLogService;
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public InvokeResponse call(InvokeRequest invokeRequest, MultipartFile multipartFile) {
|
||||
String reqId = invokeRequest.getTransSid();
|
||||
InvokeResponse invokeResponse = new InvokeResponse(invokeRequest);
|
||||
String errorMsg = "成功";
|
||||
String status = "S";
|
||||
try {
|
||||
// 处理响应
|
||||
invokeResponse = SapUtil.sendFileToEsb(invokeRequest.getMessageContent(), multipartFile);
|
||||
invokeResponse.setTransSid(invokeRequest.getTransSid());
|
||||
invokeResponse.setTransTime(Local.now());
|
||||
if (!"E".equals(invokeResponse.getResult())) {
|
||||
invokeResponse.setResult("S");
|
||||
// 请求处理成功
|
||||
JSONObject jsonObject = invokeResponse.getObjectResponse();
|
||||
JSONArray bodyJson = jsonObject.getJSONArray("files");
|
||||
JSONObject outJson = bodyJson.getJSONObject(0);
|
||||
invokeResponse.setMessageContent(outJson.toJSONString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
status = "E";
|
||||
errorMsg = e.getMessage();
|
||||
} finally {
|
||||
invokeResponse.setResult(status);
|
||||
if (StringUtils.isEmpty(invokeResponse.getMessageContent())) {
|
||||
invokeResponse.setMessageContent(errorMsg);
|
||||
}
|
||||
invokeResponse.setTransTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
invokeResponse.setTransSid(reqId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,13 +1,34 @@
|
||||
package com.foreverwin.iep.integration.handler.def.sap;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.iep.integration.domain.InvokeResponse;
|
||||
import com.foreverwin.iep.integration.utils.SSLUtil;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.mime.HttpMultipartMode;
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -17,10 +38,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class SapUtil {
|
||||
|
||||
// private static final String sapUrl = "http://vhhzwds4ci.sap.nalinv.com:8000/sap/bc/center/tbus?sap-client=110";
|
||||
private static final String sapUrl = "/sap/bc/center/tbus?sap-client=110";
|
||||
// private static final String sapUser = "RFC";
|
||||
// private static final String sapPassword = "Admin@1234567890";
|
||||
|
||||
private static final String WbpUrl = "http://47.103.63.63/sap/pip";
|
||||
private static final String sapUser = "RFC";
|
||||
@ -29,6 +47,8 @@ public class SapUtil {
|
||||
private static final String apikey = "hWS3L96a0h4NKCAjN9hG1OmOeEIsxCTz";
|
||||
private static final String env = "DEV";
|
||||
|
||||
private static final String EsbFileServerUrl = "https://agw.esb.nit.pub/oss/upload";
|
||||
|
||||
|
||||
public static String appendHead(String jsonStr) {
|
||||
JSONObject allJson = new JSONObject();
|
||||
@ -47,6 +67,103 @@ public class SapUtil {
|
||||
return allJson;
|
||||
}
|
||||
|
||||
public static InvokeResponse sendFileToEsb(String fileDirValue, MultipartFile multipartFile) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
invokeResponse.setResult("S");
|
||||
try {
|
||||
String fileDir = "FILE_DIR";
|
||||
String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(multipartFile.getOriginalFilename());
|
||||
// 禁用 SSL 验证
|
||||
SSLUtil.disableCertificateValidation();
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
httpClient = (CloseableHttpClient) wrapClient(httpClient);
|
||||
|
||||
HttpPost httpPost = new HttpPost();
|
||||
httpPost.setURI(new URI(EsbFileServerUrl));
|
||||
httpPost.setHeader("x-esb-apikey", apikey);
|
||||
httpPost.setHeader("x-esb-env", env);
|
||||
|
||||
HttpEntity reqEntity = MultipartEntityBuilder.create().setCharset(StandardCharsets.UTF_8).setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
|
||||
.addTextBody(fileDir, fileDirValue)
|
||||
.addBinaryBody("file", multipartFile.getInputStream(), ContentType.APPLICATION_OCTET_STREAM, fileName)
|
||||
.build();
|
||||
httpPost.setEntity(reqEntity);
|
||||
httpPost.setHeader("Content-Type", reqEntity.getContentType().getValue()); // 设置内容类型
|
||||
|
||||
HttpResponse response = httpClient.execute(httpPost);
|
||||
|
||||
StatusLine statusLine = response.getStatusLine();
|
||||
// 获取最终响应码
|
||||
int finalResponseCode = statusLine.getStatusCode();
|
||||
|
||||
if (finalResponseCode == HttpURLConnection.HTTP_OK) {
|
||||
// 从响应对象中提取正文
|
||||
String responseBody = EntityUtils.toString(response.getEntity());
|
||||
JSONObject bodyJson = JSONObject.parseObject(responseBody);
|
||||
Integer status = bodyJson.getInteger("status");
|
||||
if (200 == status) {
|
||||
invokeResponse.setResult("S");
|
||||
invokeResponse.setMessageContent("成功");
|
||||
invokeResponse.setObjectResponse(bodyJson.getJSONObject("data"));
|
||||
} else {
|
||||
invokeResponse.setResult("E");
|
||||
}
|
||||
invokeResponse.setMessageContent(responseBody);
|
||||
return invokeResponse;
|
||||
} else {
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(String.valueOf(finalResponseCode));
|
||||
return invokeResponse;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
invokeResponse.setResult("E");
|
||||
invokeResponse.setMessageContent(e.getMessage());
|
||||
return invokeResponse;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 避免HttpClient的”SSLPeerUnverifiedException: peer not authenticated”异常
|
||||
* 不用导入SSL证书
|
||||
*
|
||||
* @param base
|
||||
* @return
|
||||
*/
|
||||
public static HttpClient wrapClient(HttpClient base) {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
X509TrustManager tm = new X509TrustManager() {
|
||||
|
||||
@Override
|
||||
public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
|
||||
throws java.security.cert.CertificateException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
|
||||
throws java.security.cert.CertificateException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
};
|
||||
ctx.init(null, new TrustManager[]{tm}, null);
|
||||
SSLConnectionSocketFactory ssf = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
|
||||
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(ssf).build();
|
||||
return httpclient;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return HttpClients.createDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static InvokeResponse sendSap(String requestBody) {
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
invokeResponse.setResult("S");
|
||||
@ -136,4 +253,10 @@ public class SapUtil {
|
||||
// 组合成业务流水号
|
||||
return timestamp + String.format("%03d", randomNumber);
|
||||
}
|
||||
|
||||
public static String generateYearMonth() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMM");
|
||||
// 生成时间戳部分
|
||||
return dateFormat.format(new Date());
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
join INT_IN_DATA_LOG B on A.SID = B.INT_IN_DATA_SID and A.RETRY_COUNT=B.SEQ
|
||||
where a.SITE = #{dto.site}
|
||||
<if test="dto.sid != null and dto.sid != ''">
|
||||
and A.sid = #{dto.sid}
|
||||
and A.sid like concat('%',#{dto.sid},'%')
|
||||
</if>
|
||||
<if test="dto.fromSystem != null and dto.fromSystem != ''">
|
||||
and A.FROM_SYSTEM = #{dto.fromSystem}
|
||||
@ -46,7 +46,7 @@
|
||||
and A.FUNCTION_NAME = #{dto.functionName}
|
||||
</if>
|
||||
<if test="dto.keyValue != null and dto.keyValue != ''">
|
||||
and A.KEY_VALUE = #{dto.keyValue}
|
||||
and A.KEY_VALUE like concat('%',#{dto.keyValue},'%')
|
||||
</if>
|
||||
<if test="dto.start != null ">
|
||||
and A.DATE_CREATE >= #{dto.start}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user