瀏覽代碼

确认原始记录时异步更新质检记录统计表

lingpeng.li 5 天之前
父節點
當前提交
d04c4a157e

+ 10 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsendChangeShift/controller/BilletHotsendChangeShiftController.java

@@ -27,6 +27,7 @@ import org.jeecg.modules.billet.billetHotsendChangeShift.util.ScheduleUtils;
 import org.jeecg.modules.billet.billetHotsendChangeShift.util.ShiftInfo;
 import org.jeecg.modules.billet.billetLiftingBill.entity.BilletLiftingBill;
 import org.jeecg.modules.billet.billetLiftingBill.service.IBilletLiftingBillService;
+import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordService;
 import org.jeecg.modules.billet.rollClubOne.entity.RollClubOneDetails;
 import org.jeecg.modules.billet.rollClubOne.service.IRollClubOneDetailsService;
 import org.jeecg.modules.billet.rollClubThree.entity.RollClubThreeDetails;
@@ -130,6 +131,9 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 	@Autowired
 	private RestTemplate restTemplate;
 
+	@Autowired
+	private IBilletOriginalProductRecordService billetOriginalProductRecordService;
+
 	/**
 	 * 分页列表查询
 	 *
@@ -329,6 +333,12 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
 		String changeShiftId = null;
 		billetHotsendChangeShiftService.executeShiftTask(billetHotsendChangeShiftInfo.getCcmNo(),changeShiftId);
 
+		// 延迟统计(同步 SampleCardDeliveryRecord 后)
+		billetOriginalProductRecordService.delayAndInitStatistics(
+				billetHotsendChangeShiftInfo.getCcmNo(),
+				billetHotsendChangeShiftInfo.getId()
+		);
+
 		return Result.OK("操作成功!");
 	}
 	

+ 24 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/config/AsyncConfig.java

@@ -0,0 +1,24 @@
+package org.jeecg.modules.billet.billetOriginalProductRecord.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+
+@Configuration
+@EnableAsync
+public class AsyncConfig {
+
+    @Bean(name = "asyncExecutor")
+    public Executor asyncExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(4);
+        executor.setMaxPoolSize(8);
+        executor.setQueueCapacity(100);
+        executor.setThreadNamePrefix("Async-");
+        executor.initialize();
+        return executor;
+    }
+}

+ 9 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/service/IBilletOriginalProductRecordService.java

@@ -18,4 +18,13 @@ public interface IBilletOriginalProductRecordService extends IService<BilletOrig
     Map<String, Object> getQualityInspectionMenu(QualityInspectionQueryDTO queryDTO);
 
     void getQualityInspectionScreen();
+
+    void initMonthlyStatisticsIfMissing(String ccmNo, String changeShiftId);
+
+    /**
+     * 延迟初始化指定铸机号和换班ID的质检统计数据
+     * @param ccmNo 铸机号
+     * @param changeShiftId 换班记录ID,可为空
+     */
+    void delayAndInitStatistics(String ccmNo, String changeShiftId);
 }

+ 37 - 8
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/service/impl/BilletOriginalProductRecordServiceImpl.java

@@ -25,6 +25,7 @@ import org.jeecg.modules.billet.sampleCardDeliveryRecord.entity.SampleCardDelive
 import org.jeecg.modules.billet.sampleCardDeliveryRecord.mapper.SampleCardDeliveryRecordMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -340,12 +341,13 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
         String ccmNo6 = "6";
 
         // 初始化补全月统计(缺失部分)
-        initMonthlyStatisticsIfMissing(ccmNo5);
-        initMonthlyStatisticsIfMissing(ccmNo6);
+        initMonthlyStatisticsIfMissing(ccmNo5,null);
+        initMonthlyStatisticsIfMissing(ccmNo6,null);
 
     }
 
-    private void initMonthlyStatisticsIfMissing(String ccmNo) {
+    @Override
+    public void initMonthlyStatisticsIfMissing(String ccmNo,String changeShiftId) {
         Date monthStart = DateUtils.getMonthStart(new Date());
         Date searchStart = new Date(monthStart.getTime() - 10 * 60 * 1000); // 向前推10分钟
         Date now = new Date();
@@ -389,10 +391,9 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
                                 .eq(QualityInspectionStatistics::getChangeShiftId, shift.getId())
                 );
 
-                // 如果交班时间存在,且从交班时间到当前时间超过30分钟,才跳过;否则仍然重新统计、更新
-                if (existing != null && shift.getChangeShiftTime() != null) {
-                    long minutesSinceChange = (System.currentTimeMillis() - shift.getChangeShiftTime().getTime()) / (60 * 1000);
-                    if (minutesSinceChange >= 30) {
+                // 如果是补全任务(changeShiftId为空),且该班次已交班,则跳过
+                if (StringUtils.isBlank(changeShiftId) && shift.getChangeShiftTime() != null) {
+                    if (existing != null) {
                         int dayEndCount = dayStartCount + existing.getClassTotalCount();
                         BigDecimal dayEndWeight = dayStartWeight.add(existing.getClassTotalWeight());
                         dayStartCount = dayEndCount;
@@ -406,6 +407,23 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
                     }
                 }
 
+                // 如果是指定处理某条changeShiftId,但当前循环的shift不是目标,且已交班,也跳过
+                if (StringUtils.isNotBlank(changeShiftId)
+                        && !shift.getId().equals(changeShiftId)
+                        && shift.getChangeShiftTime() != null
+                        && existing != null) {
+                    int dayEndCount = dayStartCount + existing.getClassTotalCount();
+                    BigDecimal dayEndWeight = dayStartWeight.add(existing.getClassTotalWeight());
+                    dayStartCount = dayEndCount;
+                    dayStartWeight = dayEndWeight;
+
+                    int monthEndCount = monthStartCount + existing.getClassTotalCount();
+                    BigDecimal monthEndWeight = monthStartWeight.add(existing.getClassTotalWeight());
+                    monthStartCount = monthEndCount;
+                    monthStartWeight = monthEndWeight;
+                    continue;
+                }
+
                 // 新建或更新记录
                 QualityInspectionStatisticsVO vo = this.getStatisticsByShift(shift, shiftList,shiftByDate);
                 QualityInspectionStatistics record = existing != null ? existing : new QualityInspectionStatistics();
@@ -460,6 +478,18 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
     }
 
 
+    @Override
+    @Async("asyncExecutor") // 使用定义好的异步线程池
+    public void delayAndInitStatistics(String ccmNo, String changeShiftId) {
+        try {
+            Thread.sleep(3_000); // 延迟 3 秒
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt(); // 恢复中断状态
+        }
+
+        initMonthlyStatisticsIfMissing(ccmNo, changeShiftId);
+    }
+
     public QualityInspectionStatisticsVO getStatisticsByShift(BilletHotsendChangeShift shiftRecord, List<BilletHotsendChangeShift> allShiftsOfTheDay,Map<LocalDate, List<BilletHotsendChangeShift>> shiftByDate) {
         Date classStartTime = shiftRecord.getCreateTime();
         Date classEndTime = Optional.ofNullable(shiftRecord.getChangeShiftTime()).orElse(new Date());
@@ -817,5 +847,4 @@ public class BilletOriginalProductRecordServiceImpl extends ServiceImpl<BilletOr
         return ldt.toLocalDate();
     }
 
-
 }