| | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.domain.ProjectTask; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.project.repository.ProjectTaskRepository; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.system.domain.DictDetail; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | 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.TaskDailyInterface; |
| | | 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.TaskRepository; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.task.repository.TaskUserRepository; |
| | | import me.zhengjie.modules.task.service.TaskUserService; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import java.util.*; |
| | | import java.io.IOException; |
| | | 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 UserRepository userRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final OpaiDingTalkService opaiDingTalkService; |
| | | private final ProjectTaskRepository projectTaskRepository; |
| | | private final RoleService roleService; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(TaskUserQueryCriteria 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 = taskDaliyRepository.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); |
| | | } |
| | | Page<TaskUser> page = taskUserRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | // 将实体类转换为DTO(重写) |
| | | Function<TaskUser, TaskUserDto> func = new Function<TaskUser, TaskUserDto>(){ |
| | |
| | | ValidationUtil.isNull(user.getId(),"User","id",taskUserDto.getUserId()); |
| | | // 用户昵称 |
| | | taskUserDto.setUserNickName(user.getNickName()); |
| | | // 根据项目ID、任务ID、用户ID查询总消耗工时、总消耗工作量、最大任务进度 |
| | | TaskDailyInterface taskDailyInterface = taskDaliyRepository.findSumConsumedHoursAndSumConsumedWorkloadAndMaxTaskProgressByProjectIdAndTaskIdAndUserId(taskUserDto.getProjectId(), taskUserDto.getTaskId(), taskUserDto.getUserId()); |
| | | // 消耗工时 |
| | | taskUserDto.setConsumedHours(taskDailyInterface.getConsumedHours()); |
| | | // 消耗工作量 |
| | | taskUserDto.setConsumedWorkload(taskDailyInterface.getConsumedWorkload()); |
| | | // 任务进度 |
| | | taskUserDto.setTaskProgress(taskDailyInterface.getTaskProgress()); |
| | | // 返回处理好的DTO |
| | | return taskUserDto; |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public TaskUserDto create(TaskUser resources) { |
| | | public TaskUserDto create(TaskUser resources) throws Exception { |
| | | //查询任务名称 |
| | | Task task = taskRepository.findById(resources.getTaskId()).orElseGet(Task::new); |
| | | //查询字典 |
| | | DictDetail dict = dictDetailRepository.seleteByValue(resources.getTaskStatus()); |
| | | //发送钉钉给审批人 |
| | | List<String> sendList = new ArrayList<>(); |
| | | //查询所属用户信息 |
| | | User user = userRepository.findById(resources.getUserId()).orElseGet(User::new); |
| | | sendList.add(user.getDingding()); |
| | | opaiDingTalkService.sendNotice(sendList, "任务创建提醒", "### 任务创建提示 \n >" + |
| | | " \n 任务名称:" + task.getName() + |
| | | " \n 当前任务状态: " + dict.getLabel() + |
| | | " \n 任务创建成功,请登录PMS系统查看。", "card"); |
| | | return taskUserMapper.toDto(taskUserRepository.save(resources)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(TaskUser resources) { |
| | | public void update(TaskUser resources) throws Exception { |
| | | TaskUser taskUser = taskUserRepository.findById(resources.getId()).orElseGet(TaskUser::new); |
| | | ValidationUtil.isNull( taskUser.getId(),"TaskUser","id",resources.getId()); |
| | | taskUser.copy(resources); |
| | | taskUserRepository.save(taskUser); |
| | | // 根据项目ID查询项目信息 |
| | | Project project = projectRepository.findById(resources.getProjectId()).orElseGet(Project::new); |
| | | //查询字典 |
| | | DictDetail dict = dictDetailRepository.seleteByValue(resources.getTaskStatus()); |
| | | //查询任务名称 |
| | | Task task = taskRepository.findById(resources.getTaskId()).orElseGet(Task::new); |
| | | //发送钉钉给审批人 |
| | | List<String> sendList = new ArrayList<>(); |
| | | //查询所属用户信息 |
| | | User user = userRepository.findById(resources.getUserId()).orElseGet(User::new); |
| | | sendList.add(user.getDingding()); |
| | | opaiDingTalkService.sendNotice(sendList, "任务变更提醒", "### 任务变更提示 \n >" + |
| | | "项目名称:" + project.getName() + |
| | | " \n 任务名称:" + task.getName() + |
| | | " \n 当前任务状态: " + dict.getLabel() + |
| | | " \n 当前任务有新的变更,请登录PMS系统查看。", "card"); |
| | | } |
| | | |
| | | @Override |