增加从ESB获取附件功能
This commit is contained in:
parent
84b0cba063
commit
747d6f0c9c
@ -4,6 +4,7 @@ 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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -14,4 +15,7 @@ public interface RemoteEsbFileDealService {
|
||||
|
||||
@PostMapping(value = "/esbFileDeal/api/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
R<Map<String, String>> uploadFileDoExecute(@RequestPart(value = "file") MultipartFile file);
|
||||
|
||||
@PostMapping("/esbFileDeal/api/downLoadFile")
|
||||
R<Map<String, String>> downLoadFileDoExecute(@RequestBody String objectPath);
|
||||
}
|
||||
|
||||
@ -14,10 +14,7 @@ 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.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@ -52,7 +49,7 @@ public class EsbFileDealController {
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
try {
|
||||
// 发送给ERP执行 ZMM_MES_POST_DN 接口
|
||||
// 发送给ERP执行 ESB_FILE_DEAL 接口
|
||||
LocalDateTime nowLocalDateTime = LocalDateTime.now();
|
||||
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
invokeRequest.setTransSid(SapUtil.generateReqId());
|
||||
@ -86,16 +83,46 @@ public class EsbFileDealController {
|
||||
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();
|
||||
@ApiOperation(value = "销售出货-附件打印获取附件", notes = "销售出货-附件打印获取附件")
|
||||
@SysLog("销售出货-附件打印获取附件")
|
||||
@PostMapping("/api/downLoadFile")
|
||||
public R downLoadFileDoExecute(@RequestBody String objectPath) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
try {
|
||||
// 发送给ERP执行 ESB_FILE_DEAL 接口
|
||||
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();
|
||||
// 组装抛送的报文
|
||||
contentObject.put("OBJECT_PATH", objectPath);
|
||||
invokeRequest.setMessageContent(contentObject.toJSONString());
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(objectPath);
|
||||
invokeRequest.setRetry(false);
|
||||
// 呼叫SAP
|
||||
invokeResponse = esbFileDealService.call(invokeRequest,objectPath);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -65,6 +65,38 @@ public class EsbFileDealService {
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public InvokeResponse call(InvokeRequest invokeRequest,String objectFilePath ) {
|
||||
String reqId = invokeRequest.getTransSid();
|
||||
InvokeResponse invokeResponse = new InvokeResponse(invokeRequest);
|
||||
String errorMsg = "成功";
|
||||
String status = "S";
|
||||
try {
|
||||
// 处理响应
|
||||
invokeResponse = SapUtil.getFileFormEsb(objectFilePath);
|
||||
invokeResponse.setTransSid(invokeRequest.getTransSid());
|
||||
invokeResponse.setTransTime(Local.now());
|
||||
if (!"E".equals(invokeResponse.getResult())) {
|
||||
invokeResponse.setResult("S");
|
||||
// 请求处理成功
|
||||
JSONObject jsonObject = invokeResponse.getObjectResponse();
|
||||
invokeResponse.setMessageContent(jsonObject.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())) {
|
||||
// 存储日志
|
||||
|
||||
@ -6,6 +6,7 @@ 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 com.foreverwin.mom.wms.util.StringUtil;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
@ -70,12 +71,25 @@ public class SapUtil {
|
||||
return allJson;
|
||||
}
|
||||
|
||||
/*
|
||||
发送照片上传到ESB
|
||||
*/
|
||||
public static InvokeResponse sendFileToEsb(String fileDirValue, MultipartFile multipartFile) {
|
||||
String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(multipartFile.getOriginalFilename());
|
||||
return callEsb("FILE_DIR",fileDirValue,fileName, multipartFile);
|
||||
}
|
||||
|
||||
/*
|
||||
从ESB获取文件、获取销售订单的客户发货附件等
|
||||
*/
|
||||
public static InvokeResponse getFileFormEsb(String objectFilePath){
|
||||
return callEsb("OBJECT_PATH",objectFilePath,null, null);
|
||||
}
|
||||
|
||||
public static InvokeResponse callEsb(String jsonKey,String jsonValue,String fileName, 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();
|
||||
@ -86,10 +100,12 @@ public class SapUtil {
|
||||
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();
|
||||
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create().setCharset(StandardCharsets.UTF_8).setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
|
||||
.addTextBody(jsonKey, jsonValue);
|
||||
if(StringUtil.notEmpty(fileName)){
|
||||
multipartEntityBuilder.addBinaryBody("file", multipartFile.getInputStream(), ContentType.APPLICATION_OCTET_STREAM, fileName);
|
||||
}
|
||||
HttpEntity reqEntity = multipartEntityBuilder.build();
|
||||
httpPost.setEntity(reqEntity);
|
||||
httpPost.setHeader("Content-Type", reqEntity.getContentType().getValue()); // 设置内容类型
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user