From a5aa9503efd20103df066219c512b47b7f65e363 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期六, 02 八月 2025 11:57:49 +0800
Subject: [PATCH] art: 生产订单同步定时任务调试,问题修改

---
 src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java |   52 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncJob.java b/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
similarity index 73%
copy from src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncJob.java
copy to src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
index f6db679..93dd7ee 100644
--- a/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncJob.java
+++ b/src/main/java/org/jeecg/modules/mes/job/ProductionOrderSyncUpdateJob.java
@@ -1,10 +1,16 @@
 package org.jeecg.modules.mes.job;
 
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.modules.mdc.util.DateUtils;
+import org.jeecg.modules.mdc.util.ThrowableUtil;
 import org.jeecg.modules.mes.entity.MesProductionOrder;
 import org.jeecg.modules.mes.service.IMesProductionOrderService;
 import org.jeecg.modules.pms.service.IPmsMaterialProcessService;
 import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsService;
+import org.jeecg.modules.quartz.entity.QuartzJob;
+import org.jeecg.modules.quartz.entity.SysQuartzLog;
+import org.jeecg.modules.quartz.service.IQuartzJobService;
+import org.jeecg.modules.quartz.service.ISysQuartzLogService;
 import org.jeecg.modules.sap.dto.OrderBomDTO;
 import org.jeecg.modules.sap.dto.OrderProcessDTO;
 import org.jeecg.modules.sap.dto.ProductionOrderDTO;
@@ -18,12 +24,13 @@
 import org.springframework.stereotype.Component;
 
 import java.time.LocalDateTime;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 @Component
 @Slf4j
-public class ProductionOrderSyncJob implements Job {
+public class ProductionOrderSyncUpdateJob implements Job {
     //宸ュ巶缂栫爜(鏂扮伀鐐� 2301)
     private static final String FACTORY_CODE = "2301";
     /**
@@ -75,13 +82,33 @@
     private IPmsProcessBillMaterialsService processBillMaterialsService;
     @Autowired
     private IPmsMaterialProcessService materialProcessService;
+    @Autowired
+    private ISysQuartzLogService sysQuartzLogService;
+    @Autowired
+    private IQuartzJobService quartzJobService;
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        //浠诲姟鏃ュ織
+        SysQuartzLog quartzLog = new SysQuartzLog();
+        quartzLog.setCreateTime(new Date());
+        List<QuartzJob> byJobClassName = quartzJobService.findByJobClassName(this.getClass().getName());
+        if (byJobClassName != null && !byJobClassName.isEmpty()) {
+            quartzLog.setJobId(byJobClassName.get(0).getId());
+        }
+        long startTime = System.currentTimeMillis();
         //鑾峰彇涓婃鍚屾鏃堕棿
+        String lastSyncDateLow = productionOrderService.getLastSyncUpdateDate();
+        String lastSyncDateHigh = null;
+        if (lastSyncDateLow != null) {
+            lastSyncDateHigh = DateUtils.format(new Date(), "yyyyMMdd");
+            if (lastSyncDateLow.equals(lastSyncDateHigh)) {
+                lastSyncDateHigh = null;
+            }
+        }
         try {
             //璋冪敤SAP鎺ュ彛鑾峰彇鐢熶骇璁㈠崟
-            Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(FACTORY_CODE, ORDER_TYPE_CODE, PRODUCTION_MANAGER, ORDER_STATUS, null, null);
+            Map<String, Object> productionOrderMap = productionOrderSync.syncProductionOrder(FACTORY_CODE, ORDER_TYPE_CODE, PRODUCTION_MANAGER, ORDER_STATUS, null, null, lastSyncDateLow, lastSyncDateHigh);
             if (productionOrderMap == null || !SUCCESS_CODE.equals(productionOrderMap.get("ztype"))) {
                 log.error("鏈悓姝ュ埌璁㈠崟淇℃伅锛佹棩鏈燂細{}", LocalDateTime.now());
                 return;
@@ -89,7 +116,7 @@
             //璋冪敤鎴愬姛锛岃幏鍙栬繑鍥炴暟鎹�
             Object result = productionOrderMap.get("result");
             boolean b = result instanceof List;
-            if(!b) {
+            if (!b) {
                 log.error("杩斿洖绫诲瀷閿欒锛� class:{}", result == null ? null : result.getClass());
                 return;
             }
@@ -105,13 +132,13 @@
             //璋冪敤鎴愬姛锛岃幏鍙栬繑鍥炴暟鎹�
             result = orderBomMap.get("result");
             b = result instanceof List;
-            if(!b) {
+            if (!b) {
                 log.error("杩斿洖绫诲瀷閿欒锛� class:{}", result == null ? null : result.getClass());
                 return;
             }
             List<OrderBomDTO> orderBomDTOList = (List<OrderBomDTO>) result;
             b = processBillMaterialsService.saveOrUpdateOrderBom(orderMap, orderBomDTOList);
-            if(!b) {
+            if (!b) {
                 log.error("淇濆瓨璁㈠崟BOM澶辫触锛屾棩鏈燂細{}", LocalDateTime.now());
                 return;
             }
@@ -122,20 +149,25 @@
                 return;
             }
             //璋冪敤鎴愬姛锛岃幏鍙栬繑鍥炴暟鎹�
-            result = orderBomMap.get("result");
+            result = orderProcessMap.get("result");
             b = result instanceof List;
-            if(!b) {
+            if (!b) {
                 log.error("杩斿洖绫诲瀷閿欒锛� class:{}", result == null ? null : result.getClass());
                 return;
             }
             List<OrderProcessDTO> orderProcessDTOList = (List<OrderProcessDTO>) result;
             b = materialProcessService.saveOrUpdateOrderProcess(orderMap, orderProcessDTOList);
-            if(!b) {
+            if (!b) {
                 log.error("淇濆瓨璁㈠崟宸ュ簭澶辫触锛屾棩鏈燂細{}", LocalDateTime.now());
             }
+            quartzLog.setIsSuccess(0);
         } catch (Exception e) {
-            throw new RuntimeException(e);
+            log.error("瀹氭椂浠诲姟澶辫触锛寋}", e.getMessage(), e);
+            quartzLog.setIsSuccess(-1);
+            quartzLog.setExceptionDetail(ThrowableUtil.getStackTrace(e));
         }
-
+        long endTime = System.currentTimeMillis();
+        quartzLog.setExecutionTime(Integer.parseInt(String.valueOf(endTime - startTime)));
+        sysQuartzLogService.save(quartzLog);
     }
 }

--
Gitblit v1.9.3