fix(261和101同步JOB):101改成1笔1笔去送,便于核查和冲销;增加时间节点参数

This commit is contained in:
liaohechuan 2025-02-17 14:30:14 +08:00
parent 0ed836937e
commit be8022c2ff
2 changed files with 64 additions and 9 deletions

View File

@ -15,10 +15,10 @@ 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.apache.commons.collections4.ListUtils;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
@ -42,6 +42,8 @@ public class SapMaterialConsumptionJob {
String startDate = null;
String endDate = null;
String postingDate = null;
// 同步时间节点
String syncTimeNode = null;
String jobParam = XxlJobHelper.getJobParam();
if (StrUtil.isNotBlank(jobParam)) {
Map<String, String> paramMap = JS.parseMap(jobParam, "=", ";");
@ -49,6 +51,7 @@ public class SapMaterialConsumptionJob {
startDate = paramMap.get("startDate");
endDate = paramMap.get("endDate");
postingDate = paramMap.get("postingDate");
syncTimeNode = paramMap.get("syncTimeNode");
}
if (StrUtil.isBlank(site)) {
XxlJobHelper.log("ERROR:未维护站点[site]参数");
@ -60,6 +63,19 @@ public class SapMaterialConsumptionJob {
startDate = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
endDate = DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
}
if (StrUtil.isNotBlank(syncTimeNode)) {
if (!isInteger(syncTimeNode)) {
XxlJobHelper.log("物料消耗JOB任务参数同步时间节点(syncTimeNode)【"+syncTimeNode+"】只能维护整数!");
return ReturnT.FAIL;
}
LocalDateTime localDateTime = LocalDateTime.now();
// 减去 x 个小时
LocalDateTime newTime = localDateTime.minusHours(Integer.parseInt(syncTimeNode));
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 将 LocalDateTime 转换为指定格式的字符串
endDate = newTime.format(formatter);
}
XxlJobHelper.log("*************************站点:" + site + ",开始261物料消耗同步至ERP************************");
XxlJobHelper.log("*************************时间:" + startDate + "至" + endDate + "************************");
XxlJobHelper.log("*************************过账日期:" + postingDate + "************************");
@ -97,4 +113,13 @@ public class SapMaterialConsumptionJob {
return ReturnT.FAIL;
}
}
public static boolean isInteger(String str) {
try {
Integer.parseInt(str); // 尝试将字符串转换为整数
return true; // 如果成功,返回true
} catch (NumberFormatException e) {
return false; // 如果抛出异常,说明字符串不是有效整数
}
}
}

View File

@ -9,18 +9,18 @@ import com.foreverwin.iep.integration.domain.InvokeResponse;
import com.foreverwin.iep.integration.service.LotMaterialDealSendSapService;
import com.foreverwin.iep.integration.utils.JS;
import com.foreverwin.iep.prd.entity.ZLotMaterialCompleteTransaction;
import com.foreverwin.iep.prd.entity.ZLotMaterialConsumptionTransaction;
import com.foreverwin.iep.prd.mapper.ZLotMaterialCompleteTransactionMapper;
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.apache.commons.collections4.ListUtils;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -43,6 +43,8 @@ public class SapShopOrderCompleteJob {
String startDate = null;
String endDate = null;
String postingDate = null;
// 同步时间节点
String syncTimeNode = null;
String jobParam = XxlJobHelper.getJobParam();
if (StrUtil.isNotBlank(jobParam)) {
Map<String, String> paramMap = JS.parseMap(jobParam, "=", ";");
@ -50,6 +52,7 @@ public class SapShopOrderCompleteJob {
startDate = paramMap.get("startDate");
endDate = paramMap.get("endDate");
postingDate = paramMap.get("postingDate");
syncTimeNode = paramMap.get("syncTimeNode");
}
if (StrUtil.isBlank(site)) {
XxlJobHelper.log("ERROR:未维护站点[site]参数");
@ -61,6 +64,19 @@ public class SapShopOrderCompleteJob {
startDate = DateUtil.format(DateUtil.beginOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
endDate = DateUtil.format(DateUtil.endOfDay(DateUtil.yesterday()), "yyyy-MM-dd HH:mm:ss");
}
if (StrUtil.isNotBlank(syncTimeNode)) {
if (!isInteger(syncTimeNode)) {
XxlJobHelper.log("物料消耗JOB任务参数同步时间节点(syncTimeNode)【"+syncTimeNode+"】只能维护整数!");
return ReturnT.FAIL;
}
LocalDateTime localDateTime = LocalDateTime.now();
// 减去 x 个小时
LocalDateTime newTime = localDateTime.minusHours(Integer.parseInt(syncTimeNode));
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 将 LocalDateTime 转换为指定格式的字符串
endDate = newTime.format(formatter);
}
XxlJobHelper.log("*************************站点:" + site + ",开始101或531完工入库同步至ERP************************");
XxlJobHelper.log("*************************时间:" + startDate + "至" + endDate + "************************");
XxlJobHelper.log("*************************过账日期:" + postingDate + "************************");
@ -83,9 +99,12 @@ public class SapShopOrderCompleteJob {
// 先处理101的
List<ZLotMaterialCompleteTransaction> oneZeroOneList = zLotMaterialCompleteTransactionList.stream().filter(zLotMaterialCompleteTransaction -> "101".equals(zLotMaterialCompleteTransaction.getProductType())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(oneZeroOneList)){
List<List<ZLotMaterialCompleteTransaction>> splitList = ListUtils.partition(oneZeroOneList,10);
for (int i = 0; i < splitList.size(); i++) {
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(splitList.get(i), true, postingDate);
// List<List<ZLotMaterialCompleteTransaction>> splitList = ListUtils.partition(oneZeroOneList,10);
// 改成1笔1笔去送,便于核查和冲销
for (int i = 0; i < oneZeroOneList.size(); i++) {
List<ZLotMaterialCompleteTransaction> newList = new ArrayList<>();
newList.add(oneZeroOneList.get(i));
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(newList, true, postingDate);
if (!"S".equals(invokeResponse.getResult())) {
XxlJobHelper.log("WARN:同步101完工入库数据失败!!!" + invokeResponse.getMessageContent());
}
@ -95,9 +114,12 @@ public class SapShopOrderCompleteJob {
// 再处理531的
List<ZLotMaterialCompleteTransaction> fiveThreeOneList = zLotMaterialCompleteTransactionList.stream().filter(zLotMaterialCompleteTransaction -> "531".equals(zLotMaterialCompleteTransaction.getProductType())).collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(fiveThreeOneList)){
List<List<ZLotMaterialCompleteTransaction>> splitList = ListUtils.partition(fiveThreeOneList,10);
for (int i = 0; i < splitList.size(); i++) {
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(splitList.get(i), true, postingDate);
// List<List<ZLotMaterialCompleteTransaction>> splitList = ListUtils.partition(fiveThreeOneList,10);
// 改成1笔1笔去送,便于核查和冲销
for (int i = 0; i < fiveThreeOneList.size(); i++) {
List<ZLotMaterialCompleteTransaction> newList = new ArrayList<>();
newList.add(fiveThreeOneList.get(i));
InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(newList, true, postingDate);
if (!"S".equals(invokeResponse.getResult())) {
XxlJobHelper.log("WARN:同步531完工入库数据失败!!!" + invokeResponse.getMessageContent());
}
@ -112,4 +134,12 @@ public class SapShopOrderCompleteJob {
}
}
public static boolean isInteger(String str) {
try {
Integer.parseInt(str); // 尝试将字符串转换为整数
return true; // 如果成功,返回true
} catch (NumberFormatException e) {
return false; // 如果抛出异常,说明字符串不是有效整数
}
}
}