放开交货单SAP接口
This commit is contained in:
parent
2bb2494669
commit
e1ad9f4494
@ -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_GOODMVT_REVERSE")
|
||||
public class GoodMvtReverseService 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -133,11 +133,8 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
|
||||
invokeRequest.setKeyValue(srcPo);
|
||||
invokeRequest.setRetry(false);
|
||||
|
||||
// 暂时注释不调用SAP
|
||||
remotePoService.saveDocumentData(newDocumentList).getData();
|
||||
|
||||
// 呼叫SAP
|
||||
/*invokeResponse = materialConsumptionService.call(invokeRequest);
|
||||
invokeResponse = materialConsumptionService.call(invokeRequest);
|
||||
|
||||
if ("S".equals(invokeResponse.getResult())) {
|
||||
// 调用远程服务进行单据的保存和记录库存
|
||||
@ -145,7 +142,7 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
|
||||
documentDetail.setMaterialDocument(invokeResponse.getMessageContent());
|
||||
}
|
||||
remotePoService.saveDocumentData(newDocumentList).getData();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
invokeResponse.setResult("E");
|
||||
@ -158,16 +155,6 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
|
||||
return invokeResponse;
|
||||
}
|
||||
|
||||
// 冲销
|
||||
@Override
|
||||
@Transactional
|
||||
public void cancelDocumentNo(DocumentDetailed documentDetailed) {
|
||||
String documentNo = documentDetailed.getDocumentNo();
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
remotePoService.cancelDocumentNo(documentDetailed);
|
||||
// @TODO 呼叫SAP
|
||||
}
|
||||
|
||||
private Item findItemCurrentRevision(String itemNo, String site) {
|
||||
QueryWrapper<Item> queryWrapper = new QueryWrapper<Item>();
|
||||
queryWrapper.lambda().eq(Item::getItem, itemNo).eq(Item::getSite, site).eq(Item::getCurrentRevision, "Y");
|
||||
@ -311,4 +298,35 @@ public class RegisterDocumentServiceImpl implements RegisterDocumentService {
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
// 冲销
|
||||
@Override
|
||||
@Transactional
|
||||
public void cancelDocumentNo(DocumentDetailed documentDetailed) {
|
||||
String documentNo = documentDetailed.getDocumentNo();
|
||||
String site = TenantContextHolder.getTenantId();
|
||||
remotePoService.cancelDocumentNo(documentDetailed);
|
||||
// @TODO 呼叫SAP
|
||||
}
|
||||
|
||||
private String assembleCancelBody(String mblnr) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("RFC_FUNCTION", "ZMM_MES_GOODMVT_REVERSE");
|
||||
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 bodyRe = new JSONObject();
|
||||
JSONObject inputJson = new JSONObject();
|
||||
inputJson.put("MBLNR",mblnr); // 物料凭证编号
|
||||
inputJson.put("BUDAT",LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); // 凭证中的过账日期
|
||||
inputJson.put("ZPARTNER",SecurityUtils.getUserName()); // 员工BP编号
|
||||
bodyRe.put("IS_INPUT", inputJson);
|
||||
jsonObject.put("REQUEST_BODY", bodyRe);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user