| | |
| | | package me.zhengjie.modules.project.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.Map.Entry; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.contract.repository.ContractProjectRepository; |
| | | import me.zhengjie.modules.cost.repository.CostRepository; |
| | | import me.zhengjie.modules.project.domain.*; |
| | | import me.zhengjie.modules.project.repository.*; |
| | | import me.zhengjie.modules.project.service.ProjectCostService; |
| | | import me.zhengjie.modules.system.domain.DictDetail; |
| | | import me.zhengjie.modules.system.domain.SysGoalSetting; |
| | | import me.zhengjie.modules.system.repository.SysGoalSettingRepository; |
| | | import me.zhengjie.modules.system.service.SysGoalSettingService; |
| | | import me.zhengjie.modules.system.service.dto.SysGoalSettingDto; |
| | | import me.zhengjie.modules.system.service.dto.SysGoalSettingQueryCriteria; |
| | | import me.zhengjie.modules.task.domain.TaskDailyInterface; |
| | | import me.zhengjie.modules.task.domain.TaskDaliy; |
| | | import me.zhengjie.modules.task.domain.TaskInterface; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.domain.ProjectCostSummary; |
| | | import me.zhengjie.modules.project.domain.ProjectTask; |
| | | import me.zhengjie.modules.project.domain.ProjectTaskSummary; |
| | | import me.zhengjie.modules.project.domain.ProjectType; |
| | | import me.zhengjie.modules.project.repository.ProjectCostRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectTaskRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectTypeRepository; |
| | | import me.zhengjie.modules.project.service.ProjectService; |
| | | import me.zhengjie.modules.project.service.dto.ProjectDto; |
| | | import me.zhengjie.modules.project.service.dto.ProjectQueryCriteria; |
| | |
| | | private final RoleService roleService; |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final ProjectCostRepository projectCostRepository; |
| | | private final ProjectCostOtherRepository projectCostOtherRepository; |
| | | private final TaskRepository taskRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final ProjectCostService projectCostService; |
| | | private final ProjectProgressRepository projectProgressRepository; |
| | | private final ProjectPerformanceRepository projectPerformanceRepository; |
| | | private final ProjectPerformanceDetailRepository projectPerformanceDetailRepository; |
| | | private final CostRepository costRepository; |
| | | private final ContractProjectRepository contractProjectRepository; |
| | | private final SysGoalSettingService sysGoalSettingService; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(ProjectQueryCriteria criteria, Pageable pageable) { |
| | |
| | | // 查询用户角色 |
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId); |
| | | if (roleSet.stream().anyMatch(role -> DataScopeEnum.find(role.getDataScope()) == DataScopeEnum.THIS_LEVEL)) { |
| | | criteria.setLiableUserId(userId); |
| | | // 根据用户ID查询负责的项目ID |
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(userId); |
| | | // 根据用户ID查询参与的项目ID |
| | | List<Long> taskUserProjectIdList = projectCostRepository.findProjectIdByUserId(userId); |
| | | // 检索条件 |
| | | List<Long> totalProjectIdList = Stream.of(taskUserProjectIdList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList()); |
| | | if (totalProjectIdList.size() == 0) { |
| | | return PageUtil.toPage(Collections.emptyList(), 0); |
| | | } |
| | | criteria.setLiableUserId("-" + userId + "-"); |
| | | } |
| | | } |
| | | |
| | |
| | | projectDto.setProjectTypeName(projectType.getName()); |
| | | // 判断是否有负责人 |
| | | if(projectDto.getLiableUserId() != null) { |
| | | // 根据负责人ID查询用户信息 |
| | | User user = userRepository.findById(projectDto.getLiableUserId()).orElseGet(User::new); |
| | | ValidationUtil.isNull(project.getId(),"User","id",projectDto.getLiableUserId()); |
| | | // 负责人名称 |
| | | projectDto.setLiableUserName(user.getNickName()); |
| | | String liableUserName = null; |
| | | // 负责人ID列表 |
| | | List<Long> liableUserIdList = new ArrayList<>(); |
| | | // 负责人ID |
| | | String handleLiableUserId = projectDto.getLiableUserId().replace("-", ""); |
| | | // 负责人ID列表 |
| | | String[] handleLiableUserIdList = handleLiableUserId.split(","); |
| | | // 循环负责人ID列表 |
| | | for (String liableUserId : handleLiableUserIdList) { |
| | | // 负责人ID列表 |
| | | liableUserIdList.add(Long.valueOf(liableUserId)); |
| | | // 根据负责人ID查询用户信息 |
| | | User user = userRepository.findById(Long.valueOf(liableUserId)).orElseGet(User::new); |
| | | ValidationUtil.isNull(project.getId(),"User","id",projectDto.getLiableUserId()); |
| | | // 判断负责人名称 |
| | | liableUserName = liableUserName == null ? user.getNickName() : liableUserName + "," + user.getNickName(); |
| | | } |
| | | // 负责人ID列表 |
| | | projectDto.setLiableUserIdList(liableUserIdList); |
| | | // 负责人名称 |
| | | projectDto.setLiableUserName(liableUserName); |
| | | } |
| | | |
| | | ProjectTaskSummary projectTaskSummary = projectTaskRepository.findSummaryByProjectId(project.getId()); |
| | | projectDto.setTaskStartDate(projectTaskSummary.getTaskStartDate()); |
| | | projectDto.setTaskEndDate(projectTaskSummary.getTaskEndDate()); |
| | |
| | | |
| | | ProjectCostSummary projectCostSummary = projectCostRepository.findSummaryByProjectId(project.getId()); |
| | | projectDto.setTotalLaborCost(projectCostSummary.getTotalLaborCost()); |
| | | |
| | | // 其他项目成本 |
| | | List<ProjectCostOther> projectCostOtherList = projectCostOtherRepository.findByProjectId(project.getId()); |
| | | projectDto.setTotalOtherCost(projectCostOtherList.stream().map(ProjectCostOther::getProjectCost).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | |
| | | // 查询项目的任务数据 |
| | | TaskInterface taskInterface = taskRepository.collectByProjectId(project.getId()); |
| | | projectDto.setActualTaskTime(taskInterface.getPlanHours()); |
| | | |
| | | // 根据日期和项目ID取得日报信息 |
| | | List<TaskDailyInterface> taskDailyInterfaceList = taskDaliyRepository.collectByProjectIdGroupByUserIdAndFillDate(project.getId()); |
| | | Map<Long, List<TaskDailyInterface>> collectMap = taskDailyInterfaceList.stream().collect(Collectors.groupingBy(TaskDailyInterface::getUserId)); |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | // 实际消耗成本 |
| | | BigDecimal actualCost = BigDecimal.valueOf(0.0); |
| | | for (Entry<Long, List<TaskDailyInterface>> entry : collectMap.entrySet()) { |
| | | List<TaskDailyInterface> taskDaliyListSub = entry.getValue(); |
| | | // 最小日期 |
| | | TaskDailyInterface taskDaliyFirst = taskDaliyListSub.stream().min(Comparator.comparing(taskDaliy -> taskDaliy.getFillDate())).get(); |
| | | // 最大日期 |
| | | TaskDailyInterface taskDaliyLast = taskDaliyListSub.stream().max(Comparator.comparing(taskDaliy -> taskDaliy.getFillDate())).get(); |
| | | Map<String, Double> costHourMap = new HashMap<String, Double>(); |
| | | taskDaliyListSub.forEach(taskDaliy -> { |
| | | costHourMap.put(sdf.format(taskDaliy.getFillDate()), taskDaliy.getConsumedHours()); |
| | | }); |
| | | // 根据员工成本单金算出当前工作的成本 |
| | | actualCost = actualCost.add(projectCostService.calcUserCostByDate(entry.getKey(), new Timestamp(taskDaliyFirst.getFillDate().getTime()), new Timestamp(taskDaliyLast.getFillDate().getTime()), costHourMap)); |
| | | } |
| | | // 实际消耗成本 |
| | | projectDto.setActualLaborCost(actualCost); |
| | | |
| | | // 返回处理好的Dto |
| | | return projectDto; |
| | |
| | | // 查询用户角色 |
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId); |
| | | if (roleSet.stream().anyMatch(role -> DataScopeEnum.find(role.getDataScope()) == DataScopeEnum.THIS_LEVEL)) { |
| | | criteria.setLiableUserId(userId); |
| | | criteria.setLiableUserId("-" + userId + "-"); |
| | | } |
| | | } |
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | |
| | | } |
| | | criteria.setIdInList(totalProjectIdList); |
| | | } |
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | // 项目列表 |
| | | List<ProjectDto> projectDtoList = projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | // 循环项目列表 |
| | | for (int i = 0; i < projectDtoList.size(); i ++) { |
| | | // 项目 |
| | | ProjectDto projectDto = projectDtoList.get(i); |
| | | |
| | | if (projectDto.getLiableUserId() != null && !"".equals(projectDto.getLiableUserId())) { |
| | | // 负责人ID列表 |
| | | List<Long> liableUserIdList = new ArrayList<>(); |
| | | // 负责人ID |
| | | String handleLiableUserId = projectDto.getLiableUserId().replace("-", ""); |
| | | // 负责人ID列表 |
| | | String[] handleLiableUserIdList = handleLiableUserId.split(","); |
| | | // 循环负责人ID列表 |
| | | for (String liableUserId : handleLiableUserIdList) { |
| | | // 负责人ID列表 |
| | | liableUserIdList.add(Long.valueOf(liableUserId)); |
| | | } |
| | | // 负责人ID列表 |
| | | projectDto.setLiableUserIdList(liableUserIdList); |
| | | } |
| | | } |
| | | return projectDtoList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteAll(Long[] ids) { |
| | | for (Long id : ids) { |
| | | projectRepository.deleteById(id); |
| | | // 根据项目ID查询任务日报 |
| | | List<TaskDaliy> taskDaliyList = taskDaliyRepository.findByProjectId(id); |
| | | // 判断任务日报数量 |
| | | if (taskDaliyList.size() == 0) { |
| | | projectRepository.deleteById(id); |
| | | projectTaskRepository.deleteByProjectId(id); |
| | | projectCostRepository.deleteByProjectId(id); |
| | | projectProgressRepository.deleteByProjectId(id); |
| | | projectPerformanceRepository.deleteByProjectId(id); |
| | | projectPerformanceDetailRepository.deleteByProjectId(id); |
| | | costRepository.deleteByProjectId(id); |
| | | taskRepository.deleteByProjectId(id); |
| | | taskUserRepository.deleteByProjectId(id); |
| | | taskDaliyRepository.deleteByProjectId(id); |
| | | contractProjectRepository.deleteByProjectId(id); |
| | | } else { |
| | | throw new BadRequestException("存在任务日报的项目无法删除!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProjectAdmit(Long[] ids){ |
| | | for (Long id : ids) { |
| | | // 查询项目 |
| | | Project project = projectRepository.findByIdUpdate(id); |
| | | project.setApproveStatus(Constant.APPROVE_STATUS_ACKNOWLEDGED); |
| | | // 更新项目 |
| | | update(project); |
| | | List<ProjectTask> list= projectTaskRepository.findByProjectId(id); |
| | | if(list.size()>0){ |
| | | for(int i = 0;i<list.size();i++){ |
| | | // 查询项目任务 |
| | | List<ProjectTask> projectTaskList = projectTaskRepository.findByProjectId(id); |
| | | // 查询任务 |
| | | List<Task> taskList = taskRepository.findByProjectId(id); |
| | | // 判断项目任务数量和任务数量 |
| | | if(projectTaskList.size() != 0 && taskList.size() == 0) { |
| | | // 从项目任务拷贝到任务中 |
| | | for(int i = 0; i < projectTaskList.size(); i++){ |
| | | Task task = new Task(); |
| | | task.setProjectId(list.get(i).getProjectId()); |
| | | task.setName(list.get(i).getName()); |
| | | task.setTaskClassification(list.get(i).getTaskClassification()); |
| | | if(list.get(i).getDescription() != null){ |
| | | task.setDescription(list.get(i).getDescription()); |
| | | task.setProjectId(projectTaskList.get(i).getProjectId()); |
| | | task.setName(projectTaskList.get(i).getName()); |
| | | task.setTaskClassification(projectTaskList.get(i).getTaskClassification()); |
| | | if(projectTaskList.get(i).getDescription() != null){ |
| | | task.setDescription(projectTaskList.get(i).getDescription()); |
| | | } |
| | | task.setPlanHours(list.get(i).getPlanHours()); |
| | | if(list.get(i).getPlanWorkload()!=null){ |
| | | task.setPlanWorkload(list.get(i).getPlanWorkload()); |
| | | task.setPlanHours(projectTaskList.get(i).getPlanHours()); |
| | | if(projectTaskList.get(i).getPlanWorkload() != null){ |
| | | task.setPlanWorkload(projectTaskList.get(i).getPlanWorkload()); |
| | | } |
| | | if(list.get(i).getPlanWorkloadUnit() != null){ |
| | | task.setPlanWorkloadUnit(list.get(i).getPlanWorkloadUnit()); |
| | | if(projectTaskList.get(i).getPlanWorkloadUnit() != null){ |
| | | task.setPlanWorkloadUnit(projectTaskList.get(i).getPlanWorkloadUnit()); |
| | | } |
| | | if(list.get(i).getRemarks() != null ){ |
| | | task.setRemarks(list.get(i).getRemarks()); |
| | | if(projectTaskList.get(i).getRemarks() != null ){ |
| | | task.setRemarks(projectTaskList.get(i).getRemarks()); |
| | | } |
| | | task.setPriority(Constant.PRIORITY_LOW); |
| | | // 绩效区分 |
| | | task.setPerformanceType(projectTaskList.get(i).getPerformanceType()); |
| | | // 未开始 |
| | | task.setTaskStatus(Constant.TASK_STATUS_NOT_STARTED); |
| | | task.setPlanStartTime(list.get(i).getPlanStartTime()); |
| | | task.setPlanEndTime(list.get(i).getPlanEndTime()); |
| | | task.setPlanStartTime(projectTaskList.get(i).getPlanStartTime()); |
| | | task.setPlanEndTime(projectTaskList.get(i).getPlanEndTime()); |
| | | taskRepository.save(task); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateProjectDisavow(Long[] ids){ |
| | | for (Long id : ids) { |
| | | // 查询项目 |
| | | Project project = projectRepository.findByIdUpdate(id); |
| | | project.setApproveStatus(Constant.APPROVE_STATUS_UNRECOGNIZED); |
| | | // 更新项目 |
| | | update(project); |
| | | } |
| | | } |
| | | |
| | |
| | | String projectStatus = project.getProjectStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PROJECT_STATUS, project.getProjectStatus()).getLabel() : ""; |
| | | String approveStatus = project.getApproveStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.APPROVE_STATUS, project.getApproveStatus()).getLabel() : ""; |
| | | String unitCurrency = project.getUnitCurrency() != null ? dictDetailRepository.findByDictNameAndValue(Constant.STANDARD_UNIT_CURRENCY, project.getUnitCurrency()).getLabel() : ""; |
| | | String getLiableUser = project.getLiableUserId() != null ? userRepository.findById(project.getLiableUserId()).orElseGet(User::new).getNickName() : ""; |
| | | // 负责人名称 |
| | | String liableUserName = null; |
| | | |
| | | if (project.getLiableUserId() != null && !"".equals(project.getLiableUserId())) { |
| | | // 处理后负责人ID |
| | | String handleLiableUserId = project.getLiableUserId().replace("-", ""); |
| | | // 处理后负责人ID列表 |
| | | String[] handleLiableUserIdList = handleLiableUserId.split(","); |
| | | // 循环处理后负责人ID列表 |
| | | for (String liableUserId : handleLiableUserIdList) { |
| | | // 根据负责人ID查询用户信息 |
| | | User user = userRepository.findById(Long.valueOf(liableUserId)).orElseGet(User::new); |
| | | // 判断负责人名称 |
| | | liableUserName = liableUserName == null ? user.getNickName() : liableUserName + "," + user.getNickName(); |
| | | } |
| | | } |
| | | |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("名称", project.getName()); |
| | | map.put("项目类型",projectTypeName); |
| | |
| | | // TODO |
| | | // map.put("单价金额", project.getUnitPrice()); |
| | | // map.put("报价金额", project.getTotalPrice()); |
| | | map.put("责任人", getLiableUser); |
| | | map.put("责任人", liableUserName); |
| | | map.put("计划开始日期", project.getPlanStartDate()); |
| | | map.put("计划结束日期", project.getPlanEndDate()); |
| | | map.put("项目状态", projectStatus); |
| | |
| | | criteria.setIdInList(partakeProjectIds); |
| | | return projectMapper.toDto(projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> querySubgroupTurnover(ProjectQueryCriteria criteria){ |
| | | // 根据字典名称查询 |
| | | List<DictDetail> dictDetailList = dictDetailRepository.findByDictName(Constant.PROJECT_DISTINGUISH); |
| | | // 根据目标年份查询分组营业额 |
| | | List<ProjectSummary> projectSummaryList = projectRepository.findSubgroupTurnoverByTargetYear(criteria.getTargetYear()); |
| | | // 根据目标年份查询分组目标金额 |
| | | SysGoalSettingQueryCriteria sysGoalSettingQueryCriteria = new SysGoalSettingQueryCriteria(); |
| | | sysGoalSettingQueryCriteria.setTargetYear(criteria.getTargetYear()); |
| | | List<SysGoalSettingDto> sysGoalSettingDtoList = sysGoalSettingService.queryAll(sysGoalSettingQueryCriteria); |
| | | // 返回列表 |
| | | List<Map<String, Object>> returnList = new ArrayList<>(); |
| | | // 循环项目区分 |
| | | for (int i = 0; i < dictDetailList.size(); i ++) { |
| | | // 返回集合 |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | // 当前项目区分 |
| | | DictDetail dictDetail = dictDetailList.get(i); |
| | | // 返回集合 |
| | | returnMap.put("projectDistinguish", dictDetail.getLabel()); |
| | | // 循环分组营业额 |
| | | for (int j = 0; j < projectSummaryList.size(); j ++) { |
| | | // 判断与项目区分是否一致 |
| | | if (dictDetail.getValue().equals(projectSummaryList.get(j).getProjectDistinguish())) { |
| | | // 返回集合 |
| | | returnMap.put("contractPrice", projectSummaryList.get(j).getContractPrice()); |
| | | break; |
| | | } |
| | | // 判断循环是否结束 |
| | | if (j == projectSummaryList.size() - 1) { |
| | | // 返回集合 |
| | | returnMap.put("contractPrice", new BigDecimal(0)); |
| | | } |
| | | } |
| | | // 循环分组目标金额 |
| | | for (int j = 0; j < sysGoalSettingDtoList.size(); j ++) { |
| | | // 判断与项目区分是否一致 |
| | | if (dictDetail.getValue().equals(sysGoalSettingDtoList.get(j).getProjectDistinguish())) { |
| | | // 返回集合 |
| | | returnMap.put("targetAmount", sysGoalSettingDtoList.get(j).getTargetAmount()); |
| | | break; |
| | | } |
| | | // 判断循环是否结束 |
| | | if (j == sysGoalSettingDtoList.size() - 1) { |
| | | // 返回集合 |
| | | returnMap.put("targetAmount", new BigDecimal(0)); |
| | | } |
| | | } |
| | | // 返回列表 |
| | | returnList.add(returnMap); |
| | | } |
| | | return returnList; |
| | | } |
| | | } |