fix(存储仓库库存大于0同步sap):抛送变更

This commit is contained in:
liaohechuan 2025-03-05 18:57:47 +08:00
parent 35b1b6668f
commit 72304bb7e1
4 changed files with 70 additions and 163 deletions

View File

@ -33,11 +33,13 @@ public class SapSendInventoryForWorkJob {
JSONObject jsonBody = new JSONObject();
try {
String site = null;
int sendCount = 0;
String jobParam = XxlJobHelper.getJobParam();
if (StrUtil.isNotBlank(jobParam)) {
Map<String, String> paramMap = JS.parseMap(jobParam, "=", ";");
site = paramMap.get("site");
sendCount = Integer.parseInt(paramMap.get("sendCount"));
}
if (StrUtil.isBlank(site)) {
XxlJobHelper.log("******未维护站点[site]参数******");
@ -65,6 +67,7 @@ public class SapSendInventoryForWorkJob {
InvokeRequest request = JSONObject.parseObject(requestText, InvokeRequest.class);
request.setMessageContent(requestText);
request.setSrcRequestBody(requestText);
request.setRetryCount(sendCount);
invoke.execute(null, request);
} catch (Exception e) {
XxlJobHelper.handleFail("发送库存数据到sap失败:" + e);

View File

@ -1,77 +0,0 @@
package com.foreverwin.iep.integration.handler.def.job;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.foreverwin.iep.integration.component.Invoke;
import com.foreverwin.iep.integration.constant.Msg;
import com.foreverwin.iep.integration.domain.InvokeRequest;
import com.foreverwin.iep.integration.utils.JS;
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/**
* 发送库存数据到sap存表JOB
*/
@Component
@AllArgsConstructor
public class SapSendInventoryStabForWorkJob {
private final Invoke invoke;
@XxlJob("sapSendInventoryStabForWorkJobHandler")
public ReturnT<String> sapSendInventoryStabForWorkJobHandler() {
// 传参对象
JSONObject jsonBody = new JSONObject();
try {
String site = null;
String jobParam = XxlJobHelper.getJobParam();
if (StrUtil.isNotBlank(jobParam)) {
Map<String, String> paramMap = JS.parseMap(jobParam, "=", ";");
site = paramMap.get("site");
}
if (StrUtil.isBlank(site)) {
XxlJobHelper.log("******未维护站点[site]参数******");
return ReturnT.FAIL;
} else {
LocalDateTime nowLocalDateTime = LocalDateTime.now();
String nowTime = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String uuid = StrUtil.uuid();
jsonBody.put("SITE", site);
jsonBody.put("REQ_ID", uuid);
jsonBody.put("KEY_VALUE", "SendInventoryStab");
jsonBody.put("SEND_TIME", nowTime);
jsonBody.put("SENDER", Msg.IEP);
jsonBody.put("START", nowTime);
jsonBody.put("MESSAGE_ID", "SAP_SEND_INVENTORY_STAB");
jsonBody.put("RECEIVER", Msg.ERP);
jsonBody.put("RETRY", false);
// messageContent内容
JSONObject messageContentJson = new JSONObject();
jsonBody.put("MESSAGE_CONTENT", messageContentJson);
}
TenantContextHolder.setTenantId(site);
String requestText = jsonBody.toJSONString();
InvokeRequest request = JSONObject.parseObject(requestText, InvokeRequest.class);
request.setMessageContent(requestText);
request.setSrcRequestBody(requestText);
invoke.execute(null, request);
} catch (Exception e) {
XxlJobHelper.handleFail("发送库存数据到sap存表失败:" + e);
return ReturnT.FAIL;
}
XxlJobHelper.log("发送库存数据到sap存表成功:" + DateUtil.now());
return ReturnT.SUCCESS;
}
}

View File

@ -29,6 +29,7 @@ public class SapSendInventory implements HandlerService {
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
InvokeResponse invokeResponse = new InvokeResponse();
JSONObject jsonObject = new JSONObject();
jsonObject.put("RFC_FUNCTION", "ZMM_MES_GET_STOCK_HIS");
JSONObject conTextJsonObject = new JSONObject();
@ -36,59 +37,77 @@ public class SapSendInventory implements HandlerService {
conTextJsonObject.put("EXCHANGE_ID", invokeRequest.getTransSid());
conTextJsonObject.put("EXCHANGE_DOC", "");
jsonObject.put("REQUEST_CONTEXT", conTextJsonObject);
JSONObject bodyJsonObject = new JSONObject();
JSONArray inputJsonArray = new JSONArray();
List<ZWmsInventoryStockHisItf> zWmsInventoryStockHisItfList = remoteWmsInventoryService.readZWmsInventoryStockHisItfList(invokeRequest.getSite(), SecurityConstants.FROM_IN).getData();
if (CollectionUtils.isNotEmpty(zWmsInventoryStockHisItfList)) {
for (ZWmsInventoryStockHisItf zWmsInventoryStockHisItf : zWmsInventoryStockHisItfList) {
JSONObject inputJsonObject = new JSONObject();
inputJsonObject.put("ZUUID", "");
inputJsonObject.put("Z_TM", zWmsInventoryStockHisItf.getZTm());
inputJsonObject.put("ZDATE", zWmsInventoryStockHisItf.getZdate());
inputJsonObject.put("ZTIME", zWmsInventoryStockHisItf.getZtime());
inputJsonObject.put("MATNR", zWmsInventoryStockHisItf.getMatnr());
inputJsonObject.put("WERKS", zWmsInventoryStockHisItf.getWerks());
inputJsonObject.put("LGORT", zWmsInventoryStockHisItf.getLgort());
inputJsonObject.put("CHARG", zWmsInventoryStockHisItf.getCharg());
inputJsonObject.put("SOBKZ", zWmsInventoryStockHisItf.getSobkz());
inputJsonObject.put("VBELN", zWmsInventoryStockHisItf.getVbeln());
inputJsonObject.put("POSNR", zWmsInventoryStockHisItf.getPosnr());
inputJsonObject.put("KUNNR", zWmsInventoryStockHisItf.getKunnr());
inputJsonObject.put("LIFNR", zWmsInventoryStockHisItf.getLifnr());
inputJsonObject.put("Z_TP", zWmsInventoryStockHisItf.getZTp());
inputJsonObject.put("Z_KC", zWmsInventoryStockHisItf.getZKc());
inputJsonArray.add(inputJsonObject);
}
}
bodyJsonObject.put("IT_INPUT", inputJsonArray);
jsonObject.put("REQUEST_BODY", bodyJsonObject);
int sendCount = invokeRequest.getRetryCount();
if (sendCount > 0) {
// 获取库存需要发送总数
int invCount = remoteWmsInventoryService.readZWmsInventoryStockHisItfCount(invokeRequest.getSite(), SecurityConstants.FROM_IN).getData();
if (invCount > 0) {
// 计算每次发送数量
// 计算需要的次数,向上取整
int times = (int) Math.ceil((double) invCount / sendCount);
int start = 0;
int end = 0;
for (int i = 0; i < times; i++) {
start = 1 + end;
end = (i+1) * sendCount;
List<ZWmsInventoryStockHisItf> zWmsInventoryStockHisItfList = remoteWmsInventoryService.readZWmsInventoryStockHisItfList(invokeRequest.getSite(), start, end, SecurityConstants.FROM_IN).getData();
if (CollectionUtils.isNotEmpty(zWmsInventoryStockHisItfList)) {
JSONObject bodyJsonObject = new JSONObject();
JSONArray inputJsonArray = new JSONArray();
for (ZWmsInventoryStockHisItf zWmsInventoryStockHisItf : zWmsInventoryStockHisItfList) {
JSONObject inputJsonObject = new JSONObject();
inputJsonObject.put("ZUUID", "");
inputJsonObject.put("Z_TM", zWmsInventoryStockHisItf.getZTm());
inputJsonObject.put("ZDATE", zWmsInventoryStockHisItf.getZdate());
inputJsonObject.put("ZTIME", zWmsInventoryStockHisItf.getZtime());
inputJsonObject.put("MATNR", zWmsInventoryStockHisItf.getMatnr());
inputJsonObject.put("WERKS", zWmsInventoryStockHisItf.getWerks());
inputJsonObject.put("LGORT", zWmsInventoryStockHisItf.getLgort());
inputJsonObject.put("CHARG", zWmsInventoryStockHisItf.getCharg());
inputJsonObject.put("SOBKZ", zWmsInventoryStockHisItf.getSobkz());
inputJsonObject.put("VBELN", zWmsInventoryStockHisItf.getVbeln());
inputJsonObject.put("POSNR", zWmsInventoryStockHisItf.getPosnr());
inputJsonObject.put("KUNNR", zWmsInventoryStockHisItf.getKunnr());
inputJsonObject.put("LIFNR", zWmsInventoryStockHisItf.getLifnr());
inputJsonObject.put("Z_TP", zWmsInventoryStockHisItf.getZTp());
inputJsonObject.put("Z_KC", zWmsInventoryStockHisItf.getZKc());
inputJsonArray.add(inputJsonObject);
}
bodyJsonObject.put("IT_INPUT", inputJsonArray);
jsonObject.put("REQUEST_BODY", bodyJsonObject);
// messageContent内容
JSONObject messageContentJson = SapUtil.appendHead(jsonObject);
String jsonInputString = messageContentJson.toString(); // JSON 格式的请求数据
// messageContent内容
JSONObject messageContentJson = SapUtil.appendHead(jsonObject);
String jsonInputString = messageContentJson.toString(); // JSON 格式的请求数据
try {
// 统一调用 SAP 接口
InvokeResponse invokeResponse = SapUtil.sendSap(jsonInputString);
if(!Msg.E.equals(invokeResponse.getResult())){
// 请求处理成功
JSONObject reJsonObject = JS.parseObject(invokeResponse.getMessageContent());
invokeResponse = new InvokeResponse();
invokeResponse.setTransSid(invokeRequest.getTransSid());
invokeResponse.setResult(Msg.S);
invokeResponse.setMessageContent(Msg.SUCCESS);
JSONObject responseContextJson = reJsonObject.getJSONObject("RESPONSE_CONTEXT");
if (ObjectUtil.isNotEmpty(responseContextJson)) {
if (StrUtil.isNotBlank(responseContextJson.getString("RFC_CODE")) && !"200".equals(responseContextJson.getString("RFC_CODE"))) {
invokeResponse.setResult(Msg.E);
invokeResponse.setMessageContent(responseContextJson.getString("RFC_REASON"));
try {
// 统一调用 SAP 接口
invokeResponse = SapUtil.sendSap(jsonInputString);
if(!Msg.E.equals(invokeResponse.getResult())){
// 请求处理成功
JSONObject reJsonObject = JS.parseObject(invokeResponse.getMessageContent());
invokeResponse = new InvokeResponse();
invokeResponse.setTransSid(invokeRequest.getTransSid());
invokeResponse.setResult(Msg.S);
invokeResponse.setMessageContent(Msg.SUCCESS);
JSONObject responseContextJson = reJsonObject.getJSONObject("RESPONSE_CONTEXT");
if (ObjectUtil.isNotEmpty(responseContextJson)) {
if (StrUtil.isNotBlank(responseContextJson.getString("RFC_CODE")) && !"200".equals(responseContextJson.getString("RFC_CODE"))) {
invokeResponse.setResult(Msg.E);
invokeResponse.setMessageContent(responseContextJson.getString("RFC_REASON"));
}
}
}
if (Msg.E.equals(invokeResponse.getResult())) {
return invokeResponse;
}
} catch (Exception e) {
return getDefaultInvoke().fail(invokeRequest.getTransSid(), e.getMessage());
}
}
}
}
return invokeResponse;
} catch (Exception e) {
return getDefaultInvoke().fail(invokeRequest.getTransSid(), e.getMessage());
}
return invokeResponse;
}
@Override

View File

@ -1,38 +0,0 @@
package com.foreverwin.iep.integration.handler.def.sap;
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.mom.common.core.constant.SecurityConstants;
import com.foreverwin.mom.wms.api.feign.RemoteWmsInventoryService;
import com.foreverwin.mom.wms.entity.ZWmsInventoryStockHisItf;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* 发送库存数据到sap存表
*/
@AllArgsConstructor
@Service("SAP_SEND_INVENTORY_STAB")
public class SapSendInventoryStab implements HandlerService {
private final RemoteWmsInventoryService remoteWmsInventoryService;
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
ZWmsInventoryStockHisItf zWmsInventoryStockHisItf = new ZWmsInventoryStockHisItf();
zWmsInventoryStockHisItf.setWerks(invokeRequest.getSite());
remoteWmsInventoryService.saveZWmsInventoryStockHisItf(zWmsInventoryStockHisItf, SecurityConstants.FROM_IN);
InvokeResponse invokeResponse = new InvokeResponse();
invokeResponse.setTransSid(invokeRequest.getTransSid());
invokeResponse.setResult(Msg.S);
invokeResponse.setMessageContent(Msg.SUCCESS);
return invokeResponse;
}
@Override
public String validation(InvokeRequest invokeRequest) {
return null;
}
}