From bb07bdd585e76a38ee4ade382156543fb146ffac Mon Sep 17 00:00:00 2001
From: baolhyhzhg <baolh@yhzhg.cn>
Date: Thu, 12 Dec 2024 08:43:40 +0000
Subject: [PATCH] 添加批量导入功能
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/WeekReportMethod.java | 88 ++-----------------------------------------
1 files changed, 5 insertions(+), 83 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/WeekReportMethod.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/WeekReportMethod.java
index 520768e..6d7c59d 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/WeekReportMethod.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/WeekReportMethod.java
@@ -1,117 +1,39 @@
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 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.domain.TaskDaliyCollectInterface;
-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);
int year = localDate.minusDays(7).get(wfs.weekBasedYear());
int weeks = localDate.minusDays(7).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());
- TaskDaliyCollectInterface taskDaliyCollection = taskDaliyRepository.collectTaskDaliyUntilDate(task.getId(), projectProgress.getBelongDate());
- boolean flg = true;
- if (flg) { // TODO 任务状态:未结束 task.getStatus()
- timeTotalCost += BigDecimal.valueOf(task.getPlanHours()).multiply(BigDecimal.valueOf(taskDaliyCollection.getTaskProgress())).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_CEILING).doubleValue();
- } else {
- timeTotalCost += task.getPlanHours();
- }
- workTotalCost += taskDaliyCollection.getConsumedWorkload();
- realLastCost += taskDaliyCollection.getConsumedHours();
- }
- // 真实时长
- projectProgress.setRealLastCost(realLastCost);
- // 总消化工时
- projectProgress.setTimeTotalCost(timeTotalCost);
- // 总工时
- projectProgress.setTimeTotalInit(timeTotalInit);
- // 总消耗工作量
- projectProgress.setWorkTotalCost(workTotalCost);
- // 总工作量
- projectProgress.setWorkTotalInit(workTotalInit);
-
- // 存在则更新,不存在则插入
- projectProgressRepository.save(projectProgress);
- });
+ projectProgressService.autoGenerateProjectProcess(localDate, year, weeks);
}
}
--
Gitblit v1.9.3