| | |
| | | package me.zhengjie.modules.quartz.task; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.WeekFields; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import me.zhengjie.modules.task.domain.TaskDailyInterface; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.domain.ProjectProgress; |
| | | import me.zhengjie.modules.project.repository.ProjectProgressRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.task.domain.Task; |
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | import me.zhengjie.modules.project.service.ProjectProgressService; |
| | | |
| | | /** |
| | | * 钉钉定时任务(取考勤记录) |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | @Async |
| | | public class WeekReportMethod { |
| | | |
| | | private final ProjectRepository projectRepository; |
| | | |
| | | private final ProjectProgressRepository projectProgressRepository; |
| | | |
| | | private final TaskRepository taskRepository; |
| | | |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final ProjectProgressService projectProgressService; |
| | | |
| | | /** |
| | | * 生成周报 |
| | | * @throws Exception |
| | | */ |
| | | public void createWeekReport() throws Exception { |
| | | // String date = null; |
| | | // LocalDate localDate = null; |
| | | // if (date == null) { |
| | | // localDate = LocalDate.now().with(wfs.dayOfWeek(), 1L); |
| | | // } else { |
| | | // localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | // } |
| | | |
| | | // 当年第一周需满足四天。(例:2022年的第一周是从1月3号开始的,1号和2号并入到2021年度的最后一周里) |
| | | WeekFields wfs = WeekFields.of(DayOfWeek.MONDAY, 4); |
| | | LocalDate localDate = LocalDate.now().with(wfs.dayOfWeek(), 1L); |
| | | // 取得前一周的周五 |
| | | LocalDate localDate = LocalDate.now().with(wfs.dayOfWeek(), 5L).minusDays(7); |
| | | |
| | | int year = localDate.minusDays(7).get(wfs.weekBasedYear()); |
| | | int weeks = localDate.minusDays(7).get(wfs.weekOfWeekBasedYear()); |
| | | int year = localDate.get(wfs.weekBasedYear()); |
| | | int weeks = localDate.get(wfs.weekOfWeekBasedYear()); |
| | | |
| | | // 周初查询进行中的任务 TODO |
| | | // List<Project> projectList = projectRepository.findByProjectStatus(Constant.PROJECT_STATUS_UNDER_WAY); |
| | | List<Project> projectList = projectRepository.findAll(); |
| | | |
| | | projectList.forEach(project -> { |
| | | // 存在则更新,不存在则插入 |
| | | ProjectProgress projectProgress = projectProgressRepository.findByBelongYearAndBelongWeekAndProjectId(year, weeks, project.getId()).orElseGet(ProjectProgress::new); |
| | | if (projectProgress.getId() == null) { |
| | | projectProgress.setBelongYear(year); |
| | | projectProgress.setBelongWeek(weeks); |
| | | projectProgress.setBelongDate(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); |
| | | |
| | | projectProgress.setProject(project); |
| | | projectProgress.setApproveStatus(Constant.APPROVE_STATUS_UNRECOGNIZED); |
| | | } |
| | | |
| | | // 总工时 |
| | | Double timeTotalInit = 0.0; |
| | | // 总消化工时 |
| | | Double timeTotalCost = 0.0; |
| | | // 总工作量 |
| | | Double workTotalInit = 0.0; |
| | | // 总消耗工作量 |
| | | Double workTotalCost = 0.0; |
| | | // 真实时长 |
| | | Double realLastCost = 0.0; |
| | | List<Task> taskList = taskRepository.findByProjectIdUntilDate(project.getId(), projectProgress.getBelongDate()); |
| | | for (Task task : taskList) { |
| | | timeTotalInit = timeTotalInit + task.getPlanHours(); |
| | | workTotalInit = workTotalInit + (task.getPlanWorkload() == null ? 0.0 : task.getPlanWorkload()); |
| | | TaskDailyInterface taskDailyInterface = taskDaliyRepository.collectTaskDaliyUntilDate(task.getId(), projectProgress.getBelongDate()); |
| | | boolean flg = true; |
| | | if (flg) { // TODO 任务状态:未结束 task.getStatus() |
| | | timeTotalCost += BigDecimal.valueOf(task.getPlanHours()).multiply(BigDecimal.valueOf(taskDailyInterface.getTaskProgress())).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_CEILING).doubleValue(); |
| | | } else { |
| | | timeTotalCost += task.getPlanHours(); |
| | | } |
| | | workTotalCost += taskDailyInterface.getConsumedWorkload(); |
| | | realLastCost += taskDailyInterface.getConsumedHours(); |
| | | } |
| | | // 真实时长 |
| | | projectProgress.setRealLastCost(realLastCost); |
| | | // 总消化工时 |
| | | projectProgress.setTimeTotalCost(timeTotalCost); |
| | | // 总工时 |
| | | projectProgress.setTimeTotalInit(timeTotalInit); |
| | | // 总消耗工作量 |
| | | projectProgress.setWorkTotalCost(workTotalCost); |
| | | // 总工作量 |
| | | projectProgress.setWorkTotalInit(workTotalInit); |
| | | |
| | | // 存在则更新,不存在则插入 |
| | | projectProgressRepository.save(projectProgress); |
| | | }); |
| | | projectProgressService.autoGenerateProjectProcess(localDate, year, weeks); |
| | | } |
| | | } |