| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import me.zhengjie.modules.task.domain.*; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | 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.modules.task.repository.TaskUserRepository; |
| | |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | |
| | | /** |
| | | * @author 赵士淞 |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @author 赵士淞 |
| | | * @date 2022-12-30 |
| | | **/ |
| | | @Service |
| | |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final RoleService roleService; |
| | | private final MongoTemplate mongoTemplate; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(TaskDaliyQueryCriteria 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); |
| | | } |
| | | Page<TaskDaliy> page = taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | // 将实体类转换为DTO(重写) |
| | | Function<TaskDaliy, TaskDaliyDto> func = new Function<TaskDaliy, TaskDaliyDto>(){ |
| | | @Override |
| | | public TaskDaliyDto apply(TaskDaliy t) { |
| | | // 将实体类转换成DTO |
| | | TaskDaliyDto taskDaliyDto = taskDaliyMapper.toDto(t); |
| | | // 根据项目ID查询项目信息 |
| | | Project project = projectRepository.findById(taskDaliyDto.getProjectId()).orElseGet(Project::new); |
| | | ValidationUtil.isNull(project.getId(),"Project","id",taskDaliyDto.getProjectId()); |
| | | // 项目名称 |
| | | taskDaliyDto.setProjectName(project.getName()); |
| | | // 根据任务ID查询任务信息 |
| | | Task task = taskRepository.findById(taskDaliyDto.getTaskId()).orElseGet(Task::new); |
| | | ValidationUtil.isNull(task.getId(),"Task","id",taskDaliyDto.getTaskId()); |
| | | // 任务名称 |
| | | taskDaliyDto.setTaskName(task.getName()); |
| | | // 任务工作量单位 |
| | | taskDaliyDto.setTaskWorkloadUnit(task.getPlanWorkloadUnit()); |
| | | // 根据用户ID查询用户信息 |
| | | User user = userRepository.findById(taskDaliyDto.getUserId()).orElseGet(User::new); |
| | | ValidationUtil.isNull(user.getId(),"User","id",taskDaliyDto.getUserId()); |
| | | // 用户昵称 |
| | | taskDaliyDto.setUserNickName(user.getNickName()); |
| | | // 返回处理好的DTO |
| | | return taskDaliyDto; |
| | | } |
| | | }; |
| | | return PageUtil.toPage(page.map(func)); |
| | | |
| | | Query query = Query.query(new Criteria("userId").is(SecurityUtils.getCurrentUserId())); |
| | | |
| | | mongoTemplate.count(query,TaskUserMongo.class); |
| | | List<TaskUserMongo> taskUserList = mongoTemplate.find(query, TaskUserMongo.class); |
| | | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 新增修改验证 |
| | | * |
| | | * @param resources |
| | | */ |
| | | private void checkAddOrUpdate(TaskDaliy resources) { |
| | |
| | | |
| | | /** |
| | | * 修改删除验证 |
| | | * |
| | | * @param resources |
| | | */ |
| | | private void checkUpdateOrDelete(TaskDaliy resources) { |
| | |
| | | |
| | | /** |
| | | * 新增修改删除验证 |
| | | * |
| | | * @param resources |
| | | */ |
| | | private void checkAddOrUpdateOrDelete(TaskDaliy resources) { |
| | |
| | | |
| | | /** |
| | | * 设置日历类 |
| | | * |
| | | * @return |
| | | */ |
| | | private Calendar setUpCalendar(String targetYearMonth) { |