| | |
| | | package me.zhengjie.modules.project.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.WeekFields; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.Map.Entry; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | |
| | | 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.project.service.ProjectProgressService; |
| | | import me.zhengjie.modules.project.service.dto.ProjectProgressDto; |
| | | import me.zhengjie.modules.project.service.dto.ProjectProgressQueryCriteria; |
| | | import me.zhengjie.modules.project.service.mapstruct.ProjectProgressMapper; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.task.domain.Task; |
| | | import me.zhengjie.modules.task.domain.TaskDailyInterface; |
| | | import me.zhengjie.modules.task.domain.TaskDaliy; |
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | |
| | | private final ProjectProgressMapper projectProgressMapper; |
| | | private final ProjectRepository projectRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | |
| | | private final TaskRepository taskRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final ProjectCostService projectCostService; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(ProjectProgressQueryCriteria criteria, Pageable pageable){ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void generateProjectProcess(Integer year, Integer weeks, Long[] ids) { |
| | | |
| | | List<Project> projectList = null; |
| | | if (ids == null || ids.length == 0) { |
| | | projectList = projectRepository.findByProjectStatus(Constant.PROJECT_STATUS_UNDER_WAY); |
| | | } else { |
| | | projectList = projectRepository.findByProjectStatusAndIdIn(Constant.PROJECT_STATUS_UNDER_WAY, ids); |
| | | } |
| | | |
| | | WeekFields wfs = WeekFields.of(DayOfWeek.MONDAY, 4); |
| | | |
| | | // 根据项目ID查询项目信息 |
| | | LocalDate localDate = LocalDate.now() |
| | | .with(wfs.weekBasedYear(), year) |
| | | .with(wfs.weekOfWeekBasedYear(), weeks) |
| | | .with(wfs.dayOfWeek(), 1L) |
| | | .minusDays(7); |
| | | |
| | | 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(Timestamp.valueOf(localDate.atStartOfDay())); |
| | | |
| | | 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()); |
| | | |
| | | 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()); |
| | | TaskDailyInterface taskDailyInterface = taskDaliyRepository.collectTaskDaliyUntilDate(task.getId(), projectProgress.getBelongDate()); |
| | | if (Constant.TASK_STATUS_COMPLETED.equals(task.getTaskStatus())) { |
| | | 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); |
| | | // 计划总成本 |
| | | projectProgress.setMoneyTotalInit(project.getPerformancePrice().multiply(BigDecimal.valueOf(timeTotalInit))); |
| | | // 总消耗成本 |
| | | projectProgress.setMoneyTotalCost(totalCost); |
| | | |
| | | // 存在则更新,不存在则插入 |
| | | projectProgressRepository.save(projectProgress); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public List<ProjectProgressDto> queryAll(ProjectProgressQueryCriteria criteria){ |
| | | return projectProgressMapper.toDto(projectProgressRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | } |
| | |
| | | .with(wfs.weekBasedYear(), resources.getBelongYear()) |
| | | .with(wfs.weekOfWeekBasedYear(), resources.getBelongWeek()) |
| | | .with(wfs.dayOfWeek(), 1L); |
| | | resources.setBelongDate(Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); |
| | | resources.setBelongDate(Timestamp.valueOf(localDate.atStartOfDay())); |
| | | } |
| | | return projectProgressMapper.toDto(projectProgressRepository.save(resources)); |
| | | } |