优化了代码和添加了注释
parent
2b964c907d
commit
92a93bce6b
|
@ -71,6 +71,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
}
|
||||
try {
|
||||
List<Long> res = new ArrayList<>();
|
||||
// 添加根任务点Id,获得子节点数目
|
||||
res.add(taskId);
|
||||
Task task = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, taskId));
|
||||
Task fatherTask = baseMapper.selectOne(Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, task.getTaskFatherId()));
|
||||
|
@ -79,14 +80,18 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
if (baseMapper.update(fatherTask, Wrappers.<Task>lambdaQuery().eq(Task::getTaskId, fatherTask.getTaskId())) != 1) {
|
||||
throw new BadRequestException("删除失败");
|
||||
}
|
||||
while (true) {
|
||||
// 每次按照广度优先搜索的方式,按照树形的任务结构向下层寻找
|
||||
for(int depth = 1; depth <= 20; depth++) {
|
||||
// 寻找下一层的所有任务
|
||||
List<Task> list = baseMapper.selectList(
|
||||
Wrappers.<Task>lambdaQuery()
|
||||
.in(Task::getTaskFatherId, res));
|
||||
// 删除这一层的所有任务
|
||||
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, res).set(Task::getChildrenCount, 0));
|
||||
baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, res));
|
||||
|
||||
// 该层为空
|
||||
if (list == null || list.isEmpty()) break;
|
||||
// 获得下一层的任务id
|
||||
res = list.stream().map(Task::getTaskId).collect(Collectors.toList());
|
||||
}
|
||||
return true;
|
||||
|
@ -108,14 +113,17 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
}
|
||||
try {
|
||||
List<Long> res = new ArrayList<>();
|
||||
// 获得初始的任务Id
|
||||
res.add(taskId);
|
||||
while (true) {
|
||||
for(int depth = 1; depth <= 20; depth++) {
|
||||
// 获得下一层所有任务
|
||||
List<Task> list = baseMapper.selectList(
|
||||
Wrappers.<Task>lambdaQuery()
|
||||
.in(Task::getTaskFatherId, res)
|
||||
.ne(Task::getTaskStatus, Task.STATUS_COMPLETED)
|
||||
.ne(Task::getTaskStatus, Task.STATUS_CLOSED)
|
||||
);
|
||||
// 修改该层任务,为关闭状态
|
||||
baseMapper.update(
|
||||
null,
|
||||
Wrappers.<Task>lambdaUpdate()
|
||||
|
@ -124,6 +132,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
.set(Task::getTaskClosedTime, LocalDateTime.now())
|
||||
);
|
||||
if (list == null || list.isEmpty()) break;
|
||||
// 获得下一层的任务Id
|
||||
res = list.stream().map(Task::getTaskId).collect(Collectors.toList());
|
||||
}
|
||||
return true;
|
||||
|
@ -358,17 +367,22 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
return task;
|
||||
}
|
||||
|
||||
// 完成任务数目概况统计
|
||||
@Override
|
||||
public Map<String, List<TaskTrendDTO>> getProjectTaskTrend(String token, Integer projectId) throws ForbiddenException {
|
||||
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
|
||||
}
|
||||
// 起止日期
|
||||
LocalDate endDate = LocalDate.now();
|
||||
LocalDate startDate = endDate.plusDays(-14);
|
||||
// 返回结果
|
||||
Map<String, List<TaskTrendDTO>> res = new HashMap<>();
|
||||
|
||||
// 获得开始时间之前的所有任务的数据
|
||||
List<TaskTrendDTO> resList = getResultTaskStatus(projectId, startDate);
|
||||
|
||||
// 分别获得该项目在起止时间之间所有未关闭的和关闭的任务任务
|
||||
TaskTrendDTO lastTaskTrend = new TaskTrendDTO();
|
||||
lastTaskTrend.setTaskDate(endDate.plusDays(1));
|
||||
List<TaskTrendDTO> unclosedList = baseMapper.selectTaskUnclosedNum(projectId, startDate, endDate);
|
||||
|
@ -376,6 +390,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
List<TaskTrendDTO> closedList = baseMapper.selectTaskClosedNum(projectId, startDate, endDate);
|
||||
closedList.add(lastTaskTrend);
|
||||
|
||||
// 各个状态分别进行统计
|
||||
for (TaskTrendDTO iterTask : resList) {
|
||||
List<TaskTrendDTO> taskList = new ArrayList<>();
|
||||
ListIterator<TaskTrendDTO> closedIter = closedList.listIterator();
|
||||
|
@ -383,9 +398,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
TaskTrendDTO closedTaskTrend = null;
|
||||
TaskTrendDTO unclosedTaskTrend = null;
|
||||
|
||||
// 关闭与未关闭的任务的中间累加对象
|
||||
closedTaskTrend = closedIter.next();
|
||||
unclosedTaskTrend = unclosedIter.next();
|
||||
|
||||
//按照时间顺序进行统计
|
||||
Long lastNum = iterTask.getTaskNum();
|
||||
LocalDate iterDate = startDate;
|
||||
while (!iterDate.isAfter(endDate)) {
|
||||
|
@ -393,29 +410,26 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
taskTrend.setTaskDate(iterDate);
|
||||
taskTrend.setTaskStatus(iterTask.getTaskStatus());
|
||||
taskTrend.setTaskNum(lastNum);
|
||||
while (true) {
|
||||
if (iterDate.isBefore(unclosedTaskTrend.getTaskDate())) {
|
||||
break;
|
||||
}
|
||||
// 将之前日期之前的所有统计数据叠加
|
||||
while (iterDate.isBefore(unclosedTaskTrend.getTaskDate())) {
|
||||
taskTrend.changeForUnclosed(unclosedTaskTrend);
|
||||
if (unclosedIter.hasNext()) {
|
||||
unclosedTaskTrend = unclosedIter.next();
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
if (iterDate.isBefore(closedTaskTrend.getTaskDate())) {
|
||||
break;
|
||||
}
|
||||
while (iterDate.isBefore(closedTaskTrend.getTaskDate())) {
|
||||
taskTrend.changeForClosed(closedTaskTrend);
|
||||
if (closedIter.hasNext()) {
|
||||
closedTaskTrend = closedIter.next();
|
||||
}
|
||||
}
|
||||
// 将统计数据放入返回值时
|
||||
taskList.add(taskTrend);
|
||||
iterDate = iterDate.plusDays(1);
|
||||
lastNum = taskTrend.getTaskNum();
|
||||
// System.out.println(taskTrend.toString());
|
||||
}
|
||||
// 各个状态返回
|
||||
res.put(iterTask.getTaskStatus(), taskList);
|
||||
}
|
||||
return res;
|
||||
|
|
Loading…
Reference in New Issue