公司间收货入库INTERCOMPANY_RETURN:
1、取消交货单状态回传接口 2、过账用公司间过账接口
This commit is contained in:
parent
184939adce
commit
c994bc6cd8
@ -0,0 +1,23 @@
|
||||
package com.foreverwin.iep.integration.feign;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.foreverwin.mom.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @program: mom-wms-biz
|
||||
* @description: 公司间交货过账入库
|
||||
* @author: Snow
|
||||
* @create: 2024-11-26 09:24:08
|
||||
*/
|
||||
@FeignClient(contextId = "remoteMesPostDnService", value = "iep-int")
|
||||
public interface RemoteMesPostDnService {
|
||||
|
||||
@PostMapping("/mesPostDn/api/doExecute")
|
||||
R<Map<String, String>> doExecute(@RequestBody JSONObject contentObject);
|
||||
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
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.MesPostDnService;
|
||||
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.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 公司间交货过账入库
|
||||
*
|
||||
* @author Snow
|
||||
* @date 2024-12-17 09:59:18
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/mesPostDn")
|
||||
@Api(value = "mesPostDn", tags = "公司间交货过账入库")
|
||||
public class MesPostDnController {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("ZMM_MES_POST_DN")
|
||||
private final MesPostDnService mesPostDnService;
|
||||
|
||||
private final String MESSAGE_ID = "ZMM_MES_POST_DN";
|
||||
|
||||
@ApiOperation(value = "公司间交货过账入库", notes = "公司间交货过账入库")
|
||||
@SysLog("公司间交货过账入库")
|
||||
@PostMapping("/api/doExecute")
|
||||
public R doExecute(@RequestBody JSONObject contentObject) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
InvokeResponse invokeResponse = new InvokeResponse();
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
try {
|
||||
// 发送给ERP执行FSMM008-2接口
|
||||
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("ERP");
|
||||
invokeRequest.setSite(site);
|
||||
invokeRequest.setMessageId(MESSAGE_ID);
|
||||
|
||||
// 组装抛送的报完呢
|
||||
String srcJsonBody = assembleFSMM0082(contentObject);
|
||||
String jsonObjectStr = SapUtil.appendHead(srcJsonBody);
|
||||
invokeRequest.setMessageContent(jsonObjectStr);
|
||||
invokeRequest.setStart(nowTime);
|
||||
invokeRequest.setKeyValue(contentObject.getJSONObject("IS_HEAD").toJSONString());
|
||||
invokeRequest.setRetry(false);
|
||||
// 呼叫SAP
|
||||
invokeResponse = mesPostDnService.call(invokeRequest);
|
||||
} 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 assembleFSMM0082(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();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
package com.foreverwin.iep.integration.handler.def.sap;
|
||||
|
||||
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.HandlerService;
|
||||
import com.foreverwin.iep.integration.service.IntInDataLogService;
|
||||
import com.foreverwin.iep.integration.service.IntInDataService;
|
||||
import com.foreverwin.iep.integration.utils.JS;
|
||||
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 java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 公司间交货过账入库
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Service("ZMM_MES_POST_DN")
|
||||
public class MesPostDnService implements HandlerService {
|
||||
|
||||
private final IntInDataService intInDataService;
|
||||
private final IntInDataLogService intInDataLogService;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public InvokeResponse call(InvokeRequest invokeRequest) {
|
||||
String reqId = invokeRequest.getTransSid();
|
||||
InvokeResponse invokeResponse = new InvokeResponse(invokeRequest);
|
||||
String errorMsg = "成功";
|
||||
String status = "S";
|
||||
try {
|
||||
// 处理响应
|
||||
invokeResponse = SapUtil.sendSap(invokeRequest.getMessageContent());
|
||||
invokeResponse.setTransSid(invokeRequest.getTransSid());
|
||||
invokeResponse.setTransTime(Local.now());
|
||||
if (!"E".equals(invokeResponse.getResult())) {
|
||||
invokeResponse.setResult("S");
|
||||
// 请求处理成功
|
||||
JSONObject jsonObject = invokeResponse.getObjectResponse();
|
||||
JSONObject bodyJson = jsonObject.getJSONObject("RESPONSE_BODY");
|
||||
JSONObject outJson = bodyJson.getJSONObject("ES_OUTPUT");
|
||||
String result = outJson.getString("MSGTY");
|
||||
status = !"S".equals(result) ? "E" : result;
|
||||
String message = outJson.getString("MSGTX");
|
||||
invokeResponse.setMessageContent(StringUtils.isEmpty(message) ? "成功" : message);
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String validation(InvokeRequest invokeRequest) {
|
||||
JSONObject jsonObject = JS.parseObject(invokeRequest.getMessageContent());
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user