Fancy
2024-12-10 513f1f3c738b2d5e087d841ffe162e63ae778a70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.dy.pmsOther.task;
 
import com.dy.common.schedulerTask.TaskJob;
import com.dy.common.springUtil.SpringContextUtil;
import com.dy.pmsGlobal.daoOth.OthStatisticWorkloadMapper;
import com.dy.pmsGlobal.pojoSta.StaDeviceProductionLog;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
 
@Slf4j
public class WorkloadTask extends TaskJob {
 
    @Override
    @Transactional
    public void execute(JobExecutionContext ctx) throws JobExecutionException {
        //today 0点5分 统计before today
        log.info("启动统计人员工作量任务");
        OthStatisticWorkloadMapper workloadMapper = SpringContextUtil.getBean(OthStatisticWorkloadMapper.class);
        //应该统计的日期
        DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE;
        LocalDate maxLocalDate = LocalDate.parse(workloadMapper.selectMaxDate(), formatter);
        LocalDate today = LocalDate.now();
        long daysBetween = ChronoUnit.DAYS.between(maxLocalDate, today);
        if (daysBetween > 30) {
            daysBetween = 30;
            maxLocalDate = today.minusDays(daysBetween);
        }
 
        LocalDate statisticDate = maxLocalDate;
        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);
            log.info("startDt: {} , endDt: {} ", startDt, endDt);
            statisticDate = maxLocalDate.plusDays(i);
        }
        log.info("统计人员工作量任务结束");
    }
}