diff --git a/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/impl/TaskServiceImpl.java b/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/impl/TaskServiceImpl.java index f9d9981..e64f09e 100644 --- a/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/impl/TaskServiceImpl.java +++ b/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/impl/TaskServiceImpl.java @@ -39,55 +39,62 @@ public class TaskServiceImpl extends ServiceImpl implements IT } //FIXME: + @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class) @Override - public List> getTaskAndSubTask(Long taskId) { - List> resList = new ArrayList<>(); - List res = new ArrayList<>(); - res.add(taskId); - resList.add(res); - while (true) { - List list = baseMapper.selectList(Wrappers.lambdaQuery().in(Task::getTaskFatherId, res)); - if (list == null || list.isEmpty()) break; - res = list.stream().map(Task::getTaskId).collect(Collectors.toList()); - resList.add(res); + public Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException { + Integer level = checkHolder(token, taskId); + if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) { + throw new BadRequestException("错误参数"); + } + if (level == 0 || level == 3) { + throw new BadRequestException("错误父级参数"); + } + try { + List res = new ArrayList<>(); + res.add(taskId); + while (true) { + List list = baseMapper.selectList( + Wrappers.lambdaQuery() + .in(Task::getTaskFatherId, res) + .ne(Task::getTaskStatus, "已完成")); + baseMapper.delete(Wrappers.lambdaQuery().in(Task::getTaskId, res)); + if (list == null || list.isEmpty()) break; + res = list.stream().map(Task::getTaskId).collect(Collectors.toList()); + } + return true; + } catch (Exception e) { + return false; } - return resList; } //FIXME: @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class) @Override - public Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException { - if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) { - throw new BadRequestException("错误参数"); - } - if (!checkHolder(token, taskId)) { - throw new BadRequestException("错误父级参数"); - } - List> resList = getTaskAndSubTask(taskId); - try { - for (List list : resList) { - baseMapper.delete(Wrappers.lambdaQuery().in(Task::getTaskId, list)); - } - return true; - } catch (Exception e) { - return false; - } - } - - //FIXME: - @Override public Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException { + Integer level = checkHolder(token, taskId); if (projectGroupService.getUserLevelInGroup(token, projectId) == 0) { throw new BadRequestException("错误参数"); } - if (!checkHolder(token, taskId)) { + if (level == 0) { throw new BadRequestException("错误父级参数"); } - List> resList = getTaskAndSubTask(taskId); try { - for (List list : resList) { - baseMapper.update(null, Wrappers.lambdaUpdate().in(Task::getTaskId, list).set(Task::getTaskStatus, "关闭")); + List res = new ArrayList<>(); + res.add(taskId); + while (true) { + List list = baseMapper.selectList( + Wrappers.lambdaQuery() + .in(Task::getTaskFatherId, res) + .ne(Task::getTaskStatus, "已完成") + ); + baseMapper.update( + null, + Wrappers.lambdaUpdate() + .in(Task::getTaskId, res) + .set(Task::getTaskStatus, "关闭") + ); + if (list == null || list.isEmpty()) break; + res = list.stream().map(Task::getTaskId).collect(Collectors.toList()); } return true; } catch (Exception e) { @@ -96,7 +103,7 @@ public class TaskServiceImpl extends ServiceImpl implements IT } @Override - public Boolean checkHolder(Integer staffId, Long taskId) { + public Integer checkHolder(Integer staffId, Long taskId) { try { Task task = baseMapper.selectOne(Wrappers.lambdaQuery().eq(Task::getTaskId, taskId)); if (task == null || staffId <= 0) @@ -113,12 +120,12 @@ public class TaskServiceImpl extends ServiceImpl implements IT } @Override - public Boolean checkHolder(String token, Long taskId) { + public Integer checkHolder(String token, Long taskId) { try { Integer staffId = TokenUtils.getStaffId(token); return checkHolder(staffId, taskId); } catch (Exception e) { - return false; + return 0; } }