From 051414acd3a8c3e761d1010b14014d6b9bddd7fb Mon Sep 17 00:00:00 2001
From: Fancy <Fancy.fx@outlook.com>
Date: 星期二, 15 十月 2024 15:52:06 +0800
Subject: [PATCH] statistic workload change
---
pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/WorkloadTask.java | 38 +++++++++++++++++++++++---------------
1 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/WorkloadTask.java b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/WorkloadTask.java
index 4229b6f..e39742c 100644
--- a/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/WorkloadTask.java
+++ b/pms-parent/pms-web-other/src/main/java/com/dy/pmsOther/task/WorkloadTask.java
@@ -24,24 +24,32 @@
@Override
@Transactional
public void execute(JobExecutionContext ctx) throws JobExecutionException {
+ //today 0鐐�5鍒� 缁熻before today
log.info("鍚姩缁熻浜哄憳宸ヤ綔閲忎换鍔�");
- OthStatisticWorkloadMapper workloadMapper = SpringContextUtil.getBean(OthStatisticWorkloadMapper.class);
+ OthStatisticWorkloadMapper workloadMapper = SpringContextUtil.getBean(OthStatisticWorkloadMapper.class);
//鎵惧埌鏈�澶т竴鏉℃棩鏈熻褰�
Date maxDate = workloadMapper.selectMaxDate();
- //寰�鍚庡惊鐜ぉ鏁版眹鎬�
- if(maxDate != null){
- //寰幆缁熻
- LocalDate firstDay = maxDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
- LocalDate today = LocalDate.now();
- LocalDate nextDate = firstDay.plusDays(1);
- long daysBetween = ChronoUnit.DAYS.between(firstDay,today);
- for(int i=1 ; i<= daysBetween ; i++){
- Date startDt = Date.from(LocalDateTime.of(nextDate, LocalTime.of(0,0,0)).atZone(ZoneId.systemDefault()).toInstant()); ;
- Date endDt = Date.from(LocalDateTime.of(nextDate, LocalTime.of(23,59,59)).atZone(ZoneId.systemDefault()).toInstant());
- workloadMapper.insertBatch(startDt,endDt);
- nextDate = firstDay.plusDays(i);
- }
+ //寰�鍚庡惊鐜ぉ鏁版眹鎬� //寰幆缁熻
+ LocalDate maxLocalDate = null;
+ if (maxDate == null) {
+ maxLocalDate = LocalDate.now().minusDays(2);
+ } else {
+ maxLocalDate = maxDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
- log.info("鐢熶骇鏃ュ織绉诲姩浠诲姟缁撴潫");
+
+ LocalDate today = LocalDate.now();
+ LocalDate statisticDate = maxLocalDate.plusDays(1);
+ long daysBetween = ChronoUnit.DAYS.between(maxLocalDate, today);
+ if (daysBetween > 30) {
+ daysBetween = 30;
+ statisticDate = today.minusDays(daysBetween);
+ }
+ for (int i = 1; i <= daysBetween; i++) {
+ Date startDt = Date.from(LocalDateTime.of(statisticDate, LocalTime.of(0, 0, 0)).atZone(ZoneId.systemDefault()).toInstant());
+ Date endDt = Date.from(LocalDateTime.of(statisticDate, LocalTime.of(23, 59, 59)).atZone(ZoneId.systemDefault()).toInstant());
+ workloadMapper.insertBatch(startDt, endDt);
+ statisticDate = maxLocalDate.plusDays(i);
+ }
+ log.info("缁熻浜哄憳宸ヤ綔閲忎换鍔$粨鏉�");
}
}
--
Gitblit v1.8.0