feat(存储仓库库存大于0同步sap):新增job

This commit is contained in:
liaohechuan 2025-02-25 16:40:46 +08:00
parent 3284cf1570
commit 4bb39b94ec
4 changed files with 289 additions and 0 deletions

View File

@ -0,0 +1,120 @@
package com.foreverwin.iep.integration.handler.def.job;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
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.handler.def.sap.SapUtil;
import com.foreverwin.iep.integration.utils.JS;
import com.foreverwin.mom.common.data.tenant.TenantContextHolder;
import com.foreverwin.mom.wms.api.feign.RemoteWmsInventoryService;
import com.foreverwin.mom.wms.entity.ZWmsInventoryStockHisItf;
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.List;
import java.util.Map;
/**
* 发送库存数据到sap存表JOB
*/
@Component
@AllArgsConstructor
public class SapSendInventoryForWorkJob {
private final Invoke invoke;
private final RemoteWmsInventoryService remoteWmsInventoryService;
@XxlJob("sapSendInventoryForWorkJobHandler")
public ReturnT<String> sapSendInventoryForWorkJobHandler() {
// 传参对象
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", "SendInventory");
jsonBody.put("SEND_TIME", nowTime);
jsonBody.put("SENDER", Msg.IEP);
jsonBody.put("START", nowTime);
jsonBody.put("MESSAGE_ID", "SAP_SEND_INVENTORY");
jsonBody.put("RECEIVER", Msg.ERP);
jsonBody.put("RETRY", false);
JSONObject jsonObject = new JSONObject();
jsonObject.put("RFC_FUNCTION", "ZMM_MES_GET_STOCK_HIS");
JSONObject conTextJsonObject = new JSONObject();
conTextJsonObject.put("EXCHANGE_SYSTEM", "MES");
conTextJsonObject.put("EXCHANGE_ID", uuid);
conTextJsonObject.put("EXCHANGE_DOC", "");
jsonObject.put("REQUEST_CONTEXT", conTextJsonObject);
JSONObject bodyJsonObject = new JSONObject();
JSONArray inputJsonArray = new JSONArray();
List<ZWmsInventoryStockHisItf> zWmsInventoryStockHisItfList = remoteWmsInventoryService.readZWmsInventoryStockHisItfList(site).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);
// messageContent内容
JSONObject messageContentJson = SapUtil.appendHead(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

@ -0,0 +1,77 @@
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

@ -0,0 +1,54 @@
package com.foreverwin.iep.integration.handler.def.sap;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
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.iep.integration.utils.JS;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* 发送库存数据到sap
*/
@AllArgsConstructor
@Service("SAP_SEND_INVENTORY")
public class SapSendInventory implements HandlerService {
@Override
public InvokeResponse call(InvokeRequest invokeRequest) {
JSONObject messageContentjsonObject = JS.parseObject(invokeRequest.getMessageContent());
String jsonInputString = messageContentjsonObject.get(Msg.MESSAGE_CONTENT).toString(); // JSON 格式的请求数据
try {
// 统一调用 SAP 接口
InvokeResponse invokeResponse = SapUtil.sendSap(jsonInputString);
if(!Msg.E.equals(invokeResponse.getResult())){
// 请求处理成功
JSONObject jsonObject = JS.parseObject(invokeResponse.getMessageContent());
invokeResponse = new InvokeResponse();
invokeResponse.setTransSid(invokeRequest.getTransSid());
invokeResponse.setResult(Msg.S);
invokeResponse.setMessageContent(Msg.SUCCESS);
JSONObject responseContextJson = jsonObject.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"));
}
}
}
return invokeResponse;
} catch (Exception e) {
return getDefaultInvoke().fail(invokeRequest.getTransSid(), e.getMessage());
}
}
@Override
public String validation(InvokeRequest invokeRequest) {
return null;
}
}

View File

@ -0,0 +1,38 @@
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;
}
}