| | |
| | | */ |
| | | package me.zhengjie.modules.task.service.impl; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.service.RoleService; |
| | | import me.zhengjie.modules.system.service.dto.RoleSmallDto; |
| | | import me.zhengjie.modules.task.domain.Task; |
| | | import me.zhengjie.modules.task.domain.TaskDaliy; |
| | | import me.zhengjie.modules.task.domain.TaskUser; |
| | | import me.zhengjie.modules.task.repository.TaskDaliyRepository; |
| | | import me.zhengjie.modules.task.repository.TaskUserRepository; |
| | | import me.zhengjie.utils.*; |
| | |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final RoleService roleService; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(TaskQueryCriteria criteria, Pageable pageable){ |
| | | // 获取登录用户角色等级 |
| | | List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
| | | // 登录用户最大角色等级 |
| | | int min = Collections.min(levels); |
| | | // 判断角色等级 |
| | | if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) { |
| | | // 根据用户ID查询参与的项目ID |
| | | List<Long> taskUserProjectIdList = taskUserRepository.findProjectIdByUserId(SecurityUtils.getCurrentUserId()); |
| | | // 根据用户ID查询负责的项目ID |
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId()); |
| | | // 检索条件 |
| | | 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.setProjectIdInList(totalProjectIdList); |
| | | } |
| | | // 判断检索条件 |
| | | if (criteria.getName() == null) { |
| | | // 检索条件 |
| | |
| | | ValidationUtil.isNull(project.getId(),"Project","id",taskDto.getProjectId()); |
| | | // 项目名称 |
| | | taskDto.setProjectName(project.getName()); |
| | | |
| | | if (project.getLiableUserId() != null && !"".equals(project.getLiableUserId())) { |
| | | // 负责人ID列表 |
| | | List<Long> projectLiableUserIdList = new ArrayList<>(); |
| | | // 项目责任人ID |
| | | String projectLiableUserId = project.getLiableUserId().replace("-", ""); |
| | | String[] projectLiableUserIds = projectLiableUserId.split(","); |
| | | // 循环负责人ID列表 |
| | | for (String liableUserId : projectLiableUserIds) { |
| | | // 负责人ID列表 |
| | | projectLiableUserIdList.add(Long.valueOf(liableUserId)); |
| | | } |
| | | // 项目责任人ID |
| | | taskDto.setProjectLiableUserIdList(projectLiableUserIdList); |
| | | } |
| | | |
| | | // 判断父级任务ID是否为空 |
| | | if (taskDto.getPid() != null) { |
| | | // 根据父级任务ID查询任务信息 |
| | |
| | | taskDto.setDivideWorkload(sumTaskWorkload); |
| | | // 已完成工时 |
| | | Double completedHours = 0D; |
| | | // 根据项目ID、任务ID查询各用户填报的最大任务进度日报信息 |
| | | List<Map> taskDaliyMapList = taskDaliyRepository.findMaxTaskProgressByProjectIdAndTaskId(taskDto.getProjectId(), taskDto.getId()); |
| | | // 循环最大任务进度日报 |
| | | for (int i = 0; i < taskDaliyMapList.size(); i ++) { |
| | | // 最大任务进度日报信息 |
| | | Map taskDaliyMap = taskDaliyMapList.get(i); |
| | | // 已完成工时 |
| | | completedHours += Double.valueOf(taskDaliyMap.get("task_hours").toString()) * (Double.valueOf(taskDaliyMap.get("task_progress").toString()) / 100); |
| | | if (Constant.PERFORMANCE_TYPE_ON.equals(taskDto.getPerformanceType())) { |
| | | // 根据项目ID、任务ID查询各用户填报的最大任务进度日报信息 |
| | | List<Map> taskDaliyMapList = taskDaliyRepository.findMaxTaskProgressByProjectIdAndTaskId(taskDto.getProjectId(), taskDto.getId()); |
| | | // 循环最大任务进度日报 |
| | | for (int i = 0; i < taskDaliyMapList.size(); i ++) { |
| | | // 最大任务进度日报信息 |
| | | Map taskDaliyMap = taskDaliyMapList.get(i); |
| | | // 已完成工时 |
| | | completedHours += new BigDecimal(taskDaliyMap.get("task_hours").toString()).multiply(new BigDecimal(taskDaliyMap.get("task_progress").toString())).doubleValue() / 100; |
| | | } |
| | | } else { |
| | | List<TaskDaliy> taskDaliyList = taskDaliyRepository.findByProjectIdAndTaskId(taskDto.getProjectId(), taskDto.getId()); |
| | | for (TaskDaliy taskDaliy : taskDaliyList) { |
| | | completedHours += taskDaliy.getConsumedHours(); |
| | | } |
| | | } |
| | | // 已完成工时 |
| | | taskDto.setCompletedHours(completedHours); |
| | |
| | | |
| | | @Override |
| | | public void deleteAll(Long[] ids) { |
| | | // 根据多任务ID查询任务分配列表 |
| | | List<TaskUser> taskUserList = taskUserRepository.findByTaskIdIn(Arrays.asList(ids)); |
| | | // 判断任务分配列表长度 |
| | | if (taskUserList.size() > 0) { |
| | | throw new BadRequestException("已分配的任务无法删除!"); |
| | | } |
| | | for (Long id : ids) { |
| | | taskRepository.deleteById(id); |
| | | } |
| | |
| | | String priority = task.getPriority() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PRIORITY, task.getPriority()).getLabel() : ""; |
| | | String taskClassification = task.getTaskClassification() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_CLASSIFICATION, task.getTaskClassification()).getLabel() : ""; |
| | | String planWorkloadUnit = task.getPlanWorkloadUnit() != null ? dictDetailRepository.findByDictNameAndValue(Constant.STANDARD_WORKLOAD_UNIT, task.getPlanWorkloadUnit()).getLabel() : ""; |
| | | String taskStatus = task.getTaskStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.TASK_STATUS, task.getTaskStatus()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("项目名称", projectName); |
| | | map.put("父任务名称", pidName); |
| | |
| | | map.put("计划工时", task.getPlanHours()); |
| | | map.put("计划工作量", task.getPlanWorkload()); |
| | | map.put("计划工作量单位", planWorkloadUnit); |
| | | map.put("任务状态", taskStatus); |
| | | map.put("备注", task.getRemarks()); |
| | | map.put("创建者", task.getCreateBy()); |
| | | map.put("创建时间", task.getCreateTime()); |
| | |
| | | } |
| | | // 项目检索条件 |
| | | criteria.setIdInList(partakeTaskIds); |
| | | criteria.setTaskStatusNotEqual(Constant.TASK_STATUS_COMPLETED); |
| | | return taskMapper.toDto(taskRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | } |
| | | } |