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