Compare commits

..

3 Commits

3 changed files with 48 additions and 30 deletions

View File

@ -1,6 +1,8 @@
package cn.edu.hfut.rmdjzz.projectmanagement.controller;
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Task;
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectGroupService;
import cn.edu.hfut.rmdjzz.projectmanagement.service.ITaskService;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
@ -20,6 +22,9 @@ public class TaskController {
@Autowired
private ITaskService taskService;
@Autowired
private IProjectGroupService projectGroupService;
@SneakyThrows
@GetMapping("/subtask/{fatherId}")
public ResponseList<Task> getSubTaskList(
@ -39,14 +44,14 @@ public class TaskController {
}
@SneakyThrows
@PostMapping
@PostMapping("/subtask/exist")
public ResponseMap createTask(
@RequestHeader("Token") String token,
@PathVariable("projectId") Integer projectId,
@RequestBody Task task
@RequestParam("taskId") Long taskId
) {
task.setTaskProjectId(projectId);
task = taskService.insertTask(token, task);
return ResponseMap.ofSuccess("新建成功", task);
return ResponseMap.ofSuccess("返回成功")
.put("existSubTask" ,taskService.existSubTask(token, projectId, taskId));
}
}

View File

@ -13,7 +13,7 @@ import java.util.List;
*/
public interface ITaskService extends IService<Task> {
List<Task> getTaskList(String token,Integer projectId,Long fatherId) throws BadRequestException;
List<List<Long>> getTaskAndSubTask(Long taskId);
Boolean existSubTask(String token, Integer projectId, Long taskId) throws BadRequestException;
Boolean deleteTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException;
Boolean closeTaskAndSubTask(String token, Integer projectId, Long taskId) throws BadRequestException;
Integer checkHolder(Integer staffId,Long taskId);

View File

@ -38,36 +38,35 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().eq(Task::getTaskProjectId, projectId).eq(Task::getTaskFatherId, fatherId));
}
//FIXME:
@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 existSubTask(String token, Integer projectId, Long taskId) throws BadRequestException {
if(projectGroupService.getUserLevelInGroup(token, projectId) == 0) {
throw new BadRequestException("请求参数错误");
}
return resList;
return baseMapper.exists(Wrappers.<Task>lambdaQuery().eq(Task::getTaskFatherId, taskId));
}
//FIXME:
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override
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 (!checkHolder(token, taskId)) {
if (level == 0 || level == 3) {
throw new BadRequestException("错误父级参数");
}
List<List<Long>> resList = getTaskAndSubTask(taskId);
try {
for (List<Long> list : resList) {
baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, list));
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) {
@ -75,19 +74,33 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
}
}
//FIXME:
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@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) {
@ -181,7 +194,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
if (!task.checkInsert()) {
throw new BadRequestException("工作项参数错误");
}
if (!checkHolder(token, task.getTaskFatherId())) {
if (checkHolder(token, task.getTaskFatherId()) == 0) {
throw new BadRequestException("非法的父级参数");
}
try {