From be8022c2ffa5135e3c44552ab988d6c5c3d58302 Mon Sep 17 00:00:00 2001 From: liaohechuan Date: Mon, 17 Feb 2025 14:30:14 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=88261=E5=92=8C101=E5=90=8C=E6=AD=A5JO?= =?UTF-8?q?B=EF=BC=89=EF=BC=9A101=E6=94=B9=E6=88=901=E7=AC=941=E7=AC=94?= =?UTF-8?q?=E5=8E=BB=E9=80=81=EF=BC=8C=E4=BE=BF=E4=BA=8E=E6=A0=B8=E6=9F=A5?= =?UTF-8?q?=E5=92=8C=E5=86=B2=E9=94=80=EF=BC=9B=E5=A2=9E=E5=8A=A0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=8A=82=E7=82=B9=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../def/job/SapMaterialConsumptionJob.java | 27 ++++++++++- .../def/job/SapShopOrderCompleteJob.java | 46 +++++++++++++++---- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapMaterialConsumptionJob.java b/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapMaterialConsumptionJob.java index ed1c949..c66d05a 100644 --- a/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapMaterialConsumptionJob.java +++ b/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapMaterialConsumptionJob.java @@ -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 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; // 如果抛出异常,说明字符串不是有效整数 + } + } } diff --git a/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapShopOrderCompleteJob.java b/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapShopOrderCompleteJob.java index 4a5bc0b..65f69f6 100644 --- a/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapShopOrderCompleteJob.java +++ b/int-core/src/main/java/com/foreverwin/iep/integration/handler/def/job/SapShopOrderCompleteJob.java @@ -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 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 oneZeroOneList = zLotMaterialCompleteTransactionList.stream().filter(zLotMaterialCompleteTransaction -> "101".equals(zLotMaterialCompleteTransaction.getProductType())).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(oneZeroOneList)){ - List> splitList = ListUtils.partition(oneZeroOneList,10); - for (int i = 0; i < splitList.size(); i++) { - InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(splitList.get(i), true, postingDate); +// List> splitList = ListUtils.partition(oneZeroOneList,10); + // 改成1笔1笔去送,便于核查和冲销 + for (int i = 0; i < oneZeroOneList.size(); i++) { + List 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 fiveThreeOneList = zLotMaterialCompleteTransactionList.stream().filter(zLotMaterialCompleteTransaction -> "531".equals(zLotMaterialCompleteTransaction.getProductType())).collect(Collectors.toList()); if(CollectionUtils.isNotEmpty(fiveThreeOneList)){ - List> splitList = ListUtils.partition(fiveThreeOneList,10); - for (int i = 0; i < splitList.size(); i++) { - InvokeResponse invokeResponse = lotMaterialDealSendSapService.callLotMaterialComplete(splitList.get(i), true, postingDate); +// List> splitList = ListUtils.partition(fiveThreeOneList,10); + // 改成1笔1笔去送,便于核查和冲销 + for (int i = 0; i < fiveThreeOneList.size(); i++) { + List 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; // 如果抛出异常,说明字符串不是有效整数 + } + } }