|
@@ -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();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|