From 5df93a0bf12bfc95d9f3c4a67067fd2852603d02 Mon Sep 17 00:00:00 2001
From: yaozc <unbelievers@yeah.net>
Date: Tue, 17 Jan 2023 02:04:16 +0000
Subject: [PATCH] 项目修改

---
 eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/WeekReportMethod.java |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 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..ff0ddd0 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,12 +1,17 @@
 package me.zhengjie.modules.quartz.task;
 
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.temporal.WeekFields;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
 
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -18,7 +23,9 @@
 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.project.service.ProjectCostService;
 import me.zhengjie.modules.task.domain.Task;
+import me.zhengjie.modules.task.domain.TaskDaliy;
 import me.zhengjie.modules.task.domain.TaskDaliyCollectInterface;
 import me.zhengjie.modules.task.repository.TaskDaliyRepository;
 import me.zhengjie.modules.task.repository.TaskRepository;
@@ -39,6 +46,8 @@
     private final TaskRepository taskRepository;
 
     private final TaskDaliyRepository taskDaliyRepository;
+
+    private final ProjectCostService projectCostService;
 
     /**
      * 生成周报
@@ -86,6 +95,32 @@
 			// 真实时长
 			Double realLastCost = 0.0;
 			List<Task> taskList = taskRepository.findByProjectIdUntilDate(project.getId(), projectProgress.getBelongDate());
+
+//			List<TaskDaliyCostGroupByUserInterface> taskDaliyCostGroupByUserList = taskDaliyRepository.collectCostByProjectIdGroupUser(project.getId());
+//			for (TaskDaliyCostGroupByUserInterface taskDaliyCostGroupByUser : taskDaliyCostGroupByUserList) {
+//
+//			}
+
+			List<TaskDaliy> taskDaliyList = taskDaliyRepository.findByProjectId(project.getId());
+			Map<Long, List<TaskDaliy>> collectMap = taskDaliyList.stream().collect(Collectors.groupingBy(TaskDaliy::getUserId));
+
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+			BigDecimal totalCost = BigDecimal.valueOf(0.0);
+			for (Entry<Long, List<TaskDaliy>> entry : collectMap.entrySet()) {
+				List<TaskDaliy> taskDaliyListSub = entry.getValue();
+				Map<String, Double> costHourMap = new HashMap<String, Double>();
+				taskDaliyListSub.forEach(taskDaliy -> {
+					costHourMap.put(sdf.format(taskDaliy.getFillDate()), taskDaliy.getConsumedHours());
+				});
+				String startDate = sdf.format(taskDaliyListSub.get(0).getFillDate());
+				String endDate = sdf.format(taskDaliyListSub.get(taskDaliyListSub.size() - 1).getFillDate());
+				try {
+					totalCost = totalCost.add(projectCostService.calcUserCostByDate(entry.getKey(), startDate + " 00:00:00", endDate + " 00:00:00", costHourMap));
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+
 			for (Task task : taskList) {
     			timeTotalInit = timeTotalInit + task.getPlanHours();
     			workTotalInit = workTotalInit + (task.getPlanWorkload() == null ? 0.0 : task.getPlanWorkload());
@@ -109,6 +144,10 @@
 			projectProgress.setWorkTotalCost(workTotalCost);
 			// 总工作量
 			projectProgress.setWorkTotalInit(workTotalInit);
+			// 计划总成本
+			projectProgress.setMoneyTotalInit(project.getPerformancePrice().multiply(BigDecimal.valueOf(timeTotalInit)));
+			// 总消耗成本
+			projectProgress.setMoneyTotalCost(totalCost);
 
 			// 存在则更新,不存在则插入
 			projectProgressRepository.save(projectProgress);

--
Gitblit v1.9.3