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

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:
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override
public List<List<Long>> getTaskAndSubTask(Long taskId) {
List<List<Long>> resList = new ArrayList<>();
List<Long> res = new ArrayList<>();
res.add(taskId);
resList.add(res);
while (true) {
List<Task> list = baseMapper.selectList(Wrappers.<Task>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<Long> res = new ArrayList<>();
res.add(taskId);
while (true) {
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;
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<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 {
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<List<Long>> resList = getTaskAndSubTask(taskId);
try {
for (List<Long> list : resList) {
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, list).set(Task::getTaskStatus, "关闭"));
List<Long> res = new ArrayList<>();
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;
} catch (Exception e) {
@ -96,7 +103,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
}
@Override
public Boolean checkHolder(Integer staffId, Long taskId) {
public Integer checkHolder(Integer staffId, Long taskId) {
try {
Task task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, taskId));
if (task == null || staffId <= 0)
@ -113,12 +120,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> 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;
}
}