| | |
| | | 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 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>(){ |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public TaskUserDto create(TaskUser resources) throws Exception { |
| | | //查询任务名称 |
| | | ProjectTask projectTask = projectTaskRepository.findById(resources.getTaskId()).orElseGet(ProjectTask::new); |
| | | Task task = taskRepository.findById(resources.getTaskId()).orElseGet(Task::new); |
| | | //查询字典 |
| | | DictDetail dict = dictDetailRepository.seleteByValue(resources.getTaskStatus()); |
| | | //发送钉钉给审批人 |
| | |
| | | User user = userRepository.findById(resources.getUserId()).orElseGet(User::new); |
| | | sendList.add(user.getDingding()); |
| | | opaiDingTalkService.sendNotice(sendList, "任务创建提醒", "### 任务创建提示 \n >" + |
| | | " \n 任务名称:" + projectTask.getName() + |
| | | " \n 任务名称:" + task.getName() + |
| | | " \n 当前任务状态: " + dict.getLabel() + |
| | | " \n 任务创建成功,请登录PMS系统查看。", "card"); |
| | | return taskUserMapper.toDto(taskUserRepository.save(resources)); |
| | |
| | | //查询字典 |
| | | DictDetail dict = dictDetailRepository.seleteByValue(resources.getTaskStatus()); |
| | | //查询任务名称 |
| | | ProjectTask projectTask = projectTaskRepository.findById(resources.getTaskId()).orElseGet(ProjectTask::new); |
| | | Task task = taskRepository.findById(resources.getTaskId()).orElseGet(Task::new); |
| | | //发送钉钉给审批人 |
| | | List<String> sendList = new ArrayList<>(); |
| | | //查询所属用户信息 |
| | |
| | | sendList.add(user.getDingding()); |
| | | opaiDingTalkService.sendNotice(sendList, "任务变更提醒", "### 任务变更提示 \n >" + |
| | | "项目名称:" + project.getName() + |
| | | " \n 任务名称:" + projectTask.getName() + |
| | | " \n 任务名称:" + task.getName() + |
| | | " \n 当前任务状态: " + dict.getLabel() + |
| | | " \n 当前任务有新的变更,请登录PMS系统查看。", "card"); |
| | | } |
| | |
| | | taskUserRepository.save(taskUser); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Long> queryTaskUserIds(TaskUserQueryCriteria criteria){ |
| | | return taskUserRepository.findUserIdByTaskId(criteria.getTaskId()); |
| | | } |
| | | } |