修改了设置为关闭和删除子任务操作

master
yang.yongquan 2022-07-05 20:04:53 +08:00
parent 4ca6b5a164
commit ba7ac7f36c
1 changed files with 45 additions and 38 deletions

View File

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