| | |
| | | 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.TaskRepository; |
| | |
| | | // 根据用户ID查询负责的项目ID |
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(SecurityUtils.getCurrentUserId()); |
| | | // 检索条件 |
| | | criteria.setProjectIdInList(Stream.of(taskUserProjectIdList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList())); |
| | | 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(重写) |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public TaskDaliyDto create(TaskDaliy resources) { |
| | | // 新增修改删除验证 |
| | | checkAddOrUpdateOrDelete(resources); |
| | | // 新增修改验证 |
| | | checkAddOrUpdate(resources); |
| | | return taskDaliyMapper.toDto(taskDaliyRepository.save(resources)); |
| | |
| | | public void update(TaskDaliy resources) { |
| | | TaskDaliy taskDaliy = taskDaliyRepository.findById(resources.getId()).orElseGet(TaskDaliy::new); |
| | | ValidationUtil.isNull( taskDaliy.getId(),"TaskDaliy","id",resources.getId()); |
| | | // 新增修改删除验证 |
| | | checkAddOrUpdateOrDelete(taskDaliy); |
| | | // 修改删除验证 |
| | | checkUpdateOrDelete(taskDaliy); |
| | | // 新增修改验证 |
| | |
| | | for (Long id : ids) { |
| | | TaskDaliy taskDaliy = taskDaliyRepository.findById(id).orElseGet(TaskDaliy::new); |
| | | ValidationUtil.isNull( taskDaliy.getId(),"TaskDaliy","id",id); |
| | | // 新增修改删除验证 |
| | | checkAddOrUpdateOrDelete(taskDaliy); |
| | | // 修改删除验证 |
| | | checkUpdateOrDelete(taskDaliy); |
| | | taskDaliyRepository.deleteById(id); |
| | |
| | | // 判断旧记录结算状态 |
| | | if (Constant.SETTLEMENT_STATUS_SETTLED.equals(resources.getSettlementStatus())) { |
| | | throw new BadRequestException("已结算的任务日报无法修改/删除!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 新增修改删除验证 |
| | | * @param resources |
| | | */ |
| | | private void checkAddOrUpdateOrDelete(TaskDaliy resources) { |
| | | // 获取登录用户角色等级 |
| | | 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) { |
| | | // 判断是否是自己的日报 |
| | | if (SecurityUtils.getCurrentUserId().longValue() != resources.getUserId().longValue()) { |
| | | throw new BadRequestException("只能新增修改自己的任务日报!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | // 日历类 |
| | | return cal; |
| | | } |
| | | |
| | | @Override |
| | | public Double queryTaskTotalConsumedHours(TaskDaliyQueryCriteria criteria) { |
| | | // 根据项目ID、任务ID、用户ID查询总消耗工时、总消耗工作量、最大任务进度 |
| | | TaskDailyInterface taskDailyInterface = taskDaliyRepository.findSumConsumedHoursAndSumConsumedWorkloadAndMaxTaskProgressByProjectIdAndTaskIdAndUserId(criteria.getProjectId(), criteria.getTaskId(), criteria.getUserId()); |
| | | // 返回 |
| | | return taskDailyInterface.getConsumedHours(); |
| | | } |
| | | } |