From ba7ac7f36c6ab93935e2e2f5e81727571b7ca16e Mon Sep 17 00:00:00 2001 From: "yang.yongquan" <3395816735@qq.com> Date: Tue, 5 Jul 2022 20:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=BA=E5=85=B3=E9=97=AD=E5=92=8C=E5=88=A0=E9=99=A4=E5=AD=90?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TaskServiceImpl.java | 83 ++++++++++--------- 1 file changed, 45 insertions(+), 38 deletions(-) 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; } }