diff --git a/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/ITaskService.java b/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/ITaskService.java index cd0113a..7b254d4 100644 --- a/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/ITaskService.java +++ b/src/main/java/cn/edu/hfut/rmdjzz/projectmanagement/service/ITaskService.java @@ -13,6 +13,9 @@ import java.util.List; */ public interface ITaskService extends IService { List getTaskList(String token,Integer projectId,Long fatherId) throws BadRequestException; + List> getTaskAndSubTask(Long taskId); + Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException; + Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException; Boolean checkHolder(Integer staffId,Long taskId); Boolean checkHolder(String token,Long taskId); List getMyTaskList(String token,Integer projectId) throws BadRequestException; 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 ade0e7a..8e107d8 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 @@ -19,6 +19,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * @author 张韬 @@ -36,6 +37,59 @@ public class TaskServiceImpl extends ServiceImpl implements IT return baseMapper.selectList(Wrappers.lambdaQuery().eq(Task::getTaskProjectId,projectId).eq(Task::getTaskFatherId,fatherId)); } + @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); + } + return resList; + } + + @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; + } + } + + @Override + public Boolean closeTaskAndSubTask(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.update(null, Wrappers.lambdaUpdate().in(Task::getTaskId, list).set(Task::getTaskType, "关闭")); + } + return true; + } catch (Exception e) { + return false; + } + } + @Override public Boolean checkHolder(Integer staffId,Long taskId){ try{