| | |
| | | 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 me.zhengjie.modules.task.domain.TaskDailyInterface; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | 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.TaskDaliyCollectInterface; |
| | | import me.zhengjie.modules.task.domain.TaskDaliy; |
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | |
| | |
| | | private final TaskRepository taskRepository; |
| | | |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | |
| | | private final ProjectCostService projectCostService; |
| | | |
| | | /** |
| | | * 生成周报 |
| | |
| | | // 真实时长 |
| | | 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()); |
| | | TaskDaliyCollectInterface taskDaliyCollection = taskDaliyRepository.collectTaskDaliyUntilDate(task.getId(), projectProgress.getBelongDate()); |
| | | TaskDailyInterface taskDailyInterface = 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(); |
| | | timeTotalCost += BigDecimal.valueOf(task.getPlanHours()).multiply(BigDecimal.valueOf(taskDailyInterface.getTaskProgress())).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_CEILING).doubleValue(); |
| | | } else { |
| | | timeTotalCost += task.getPlanHours(); |
| | | } |
| | | workTotalCost += taskDaliyCollection.getConsumedWorkload(); |
| | | realLastCost += taskDaliyCollection.getConsumedHours(); |
| | | workTotalCost += taskDailyInterface.getConsumedWorkload(); |
| | | realLastCost += taskDailyInterface.getConsumedHours(); |
| | | } |
| | | // 真实时长 |
| | | projectProgress.setRealLastCost(realLastCost); |
| | |
| | | projectProgress.setWorkTotalCost(workTotalCost); |
| | | // 总工作量 |
| | | projectProgress.setWorkTotalInit(workTotalInit); |
| | | // 计划总成本 |
| | | projectProgress.setMoneyTotalInit(project.getPerformancePrice().multiply(BigDecimal.valueOf(timeTotalInit))); |
| | | // 总消耗成本 |
| | | projectProgress.setMoneyTotalCost(totalCost); |
| | | |
| | | // 存在则更新,不存在则插入 |
| | | projectProgressRepository.save(projectProgress); |