修改了SQL语句,将未查询到的部分在后端加入返回列表

master
yang.yongquan 2022-07-11 16:36:30 +08:00
parent 16200365d9
commit 614a629c55
2 changed files with 28 additions and 9 deletions

View File

@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.validation.constraints.NotNull;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@ -125,7 +126,28 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) { if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT); throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
} }
return baseMapper.selectProjectProcessOfStaff(projectId, staffId); List<StaffProcessDTO> resList = baseMapper.selectProjectProcessOfStaff(projectId, staffId);
addResultProjectProcess(resList, Task.TYPE_ASSIGNMENT);
addResultProjectProcess(resList, Task.TYPE_DEFECT);
addResultProjectProcess(resList, Task.TYPE_DEMAND);
return resList;
}
@NotNull
private void addResultProjectProcess(List<StaffProcessDTO> resList, String projectType) {
Boolean typeExist = false;
for(StaffProcessDTO staffProcessDTO: resList) {
if(Objects.equals(staffProcessDTO.getTaskType(), projectType)) {
typeExist = true;
}
}
if(!typeExist) {
StaffProcessDTO staffProcessDTO = new StaffProcessDTO();
staffProcessDTO.setTaskType(projectType);
staffProcessDTO.setCompleteNum(0L);
staffProcessDTO.setTotalNum(0L);
resList.add(staffProcessDTO);
}
} }
@Override @Override

View File

@ -33,20 +33,17 @@
</select> </select>
<select id="selectProjectProcessOfStaff" <select id="selectProjectProcessOfStaff"
resultType="cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.StaffProcessDTO"> resultType="cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.StaffProcessDTO">
SELECT t2.task_type, SELECT task_type,
IF(complete_num IS NULL, 0, complete_num) AS complete_num,
IF(total_num IS NULL, 0, total_num) AS total_num
FROM (SELECT task_type,
SUM(IF(task_status = '已完成' OR task_status = '关闭', 1, 0)) AS complete_num, SUM(IF(task_status = '已完成' OR task_status = '关闭', 1, 0)) AS complete_num,
COUNT(task_status) AS total_num COUNT(task_status) AS total_num
FROM task FROM task
WHERE is_deleted = false WHERE is_deleted = false
AND task_project_id != 0 AND task_project_id != 0
AND task_project_id = #{projectId} AND task_project_id = #{projectId}
<if test="staffId != null">AND task_holder_id = #{staffId}</if> <if test="staffId != null">
GROUP BY task_type) AS t1 AND task_holder_id = #{staffId}
RIGHT JOIN (SELECT DISTINCT task_type FROM task) AS t2 </if>
ON t1.task_type = t2.task_type GROUP BY task_type
</select> </select>
<select id="selectTaskClosedNum" resultType="cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.TaskTrendDTO"> <select id="selectTaskClosedNum" resultType="cn.edu.hfut.rmdjzz.projectmanagement.entity.dto.TaskTrendDTO">
SELECT closed_date AS task_date, SELECT closed_date AS task_date,