refactor(oa): 优化个人报表项目统计逻辑
- 调整getProjectStats方法参数,使用项目ID列表进行精确查询 - 重构项目统计逻辑,支持按指定项目ID列表统计项目信息 - 增强项目摘要信息,添加项目状态、类型、优先级等字段 - 完善任务统计方法,支持按项目ID列表筛选任务数据 - 优化空项目列表处理逻辑,避免空指针异常 - 补充项目时间、负责人及资金信息到项目摘要中
This commit is contained in:
@@ -7,6 +7,7 @@ import com.ruoyi.oa.domain.SysOaTask;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -116,12 +117,24 @@ public class PersonalReportDTO {
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public static class ProjectSummary {
|
public static class ProjectSummary {
|
||||||
/** 项目ID */
|
|
||||||
private Long projectId;
|
private Long projectId;
|
||||||
|
/** 项目状态 */
|
||||||
|
private String status;
|
||||||
/** 项目名称 */
|
/** 项目名称 */
|
||||||
private String projectName;
|
private String projectName;
|
||||||
/** 项目编号 */
|
/** 项目编号 */
|
||||||
private String projectNum;
|
private String projectNum;
|
||||||
|
//类型
|
||||||
|
private String type;
|
||||||
|
//优先级
|
||||||
|
private String priority;
|
||||||
|
// 设置项目时间信息
|
||||||
|
private Date beginTime;
|
||||||
|
private Date finishTime;
|
||||||
|
// 设置项目负责人
|
||||||
|
private String functionary;
|
||||||
|
// 设置项目总款
|
||||||
|
private BigDecimal funds;
|
||||||
/** 参与角色 */
|
/** 参与角色 */
|
||||||
private String role;
|
private String role;
|
||||||
/** 参与天数 */
|
/** 参与天数 */
|
||||||
|
|||||||
@@ -471,13 +471,13 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
|
|||||||
result.setBusinessTripStats(getBusinessTripStats(userId, startTime, endTime));
|
result.setBusinessTripStats(getBusinessTripStats(userId, startTime, endTime));
|
||||||
|
|
||||||
// 3. 统计项目信息
|
// 3. 统计项目信息
|
||||||
result.setProjectStats(getProjectStats(userId, nickName, startTime, endTime));
|
result.setProjectStats(getProjectStats(projectIds));
|
||||||
|
|
||||||
// // 4. 统计进度信息
|
// // 4. 统计进度信息
|
||||||
// result.setProgressStats(getProgressStats(nickName, startDate, endDate));
|
// result.setProgressStats(getProgressStats(nickName, startDate, endDate));
|
||||||
|
|
||||||
// 5. 统计任务信息
|
// 5. 统计任务信息
|
||||||
result.setTaskStats(getTaskStats(userId, startTime, endTime));
|
result.setTaskStats(getTaskStats(userId, startTime, endTime,projectIds));
|
||||||
|
|
||||||
// 6. 统计工程异常信息
|
// 6. 统计工程异常信息
|
||||||
result.setExceptionStats(getExceptionStats(nickName, startTime, endTime));
|
result.setExceptionStats(getExceptionStats(nickName, startTime, endTime));
|
||||||
@@ -594,76 +594,79 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
|
|||||||
/**
|
/**
|
||||||
* 统计项目信息
|
* 统计项目信息
|
||||||
*/
|
*/
|
||||||
private PersonalReportDTO.ProjectStats getProjectStats(Long userId, String nickName, Date startDate, Date endDate) {
|
private PersonalReportDTO.ProjectStats getProjectStats(List<Long> projectIds) {
|
||||||
PersonalReportDTO.ProjectStats stats = new PersonalReportDTO.ProjectStats();
|
PersonalReportDTO.ProjectStats stats = new PersonalReportDTO.ProjectStats();
|
||||||
|
|
||||||
// 通过报工记录查询参与的项目
|
// 如果没有项目ID列表,直接返回空统计
|
||||||
LambdaQueryWrapper<OaProjectReport> reportWrapper = Wrappers.<OaProjectReport>lambdaQuery()
|
if (projectIds == null || projectIds.isEmpty()) {
|
||||||
.eq(OaProjectReport::getUserId, userId)
|
stats.setTotalProjects(0);
|
||||||
.eq(OaProjectReport::getDelFlag, 0);
|
stats.setResponsibleProjects(0);
|
||||||
|
stats.setParticipatedProjects(0);
|
||||||
// if (startDate != null && endDate != null) {
|
stats.setProjectList(new ArrayList<>());
|
||||||
// reportWrapper.between(OaProjectReport::getCreateTime, startDate, endDate);
|
return stats;
|
||||||
// }
|
}
|
||||||
|
|
||||||
List<OaProjectReport> reports = projectReportMapper.selectList(reportWrapper);
|
// 查询指定ID的项目列表
|
||||||
Set<Long> participatedProjectIds = reports.stream()
|
List<SysOaProject> projects = projectMapper.selectList(
|
||||||
.map(OaProjectReport::getProjectId)
|
Wrappers.<SysOaProject>lambdaQuery()
|
||||||
.filter(Objects::nonNull)
|
.in(SysOaProject::getProjectId, projectIds)
|
||||||
.collect(Collectors.toSet());
|
);
|
||||||
|
|
||||||
// 查询负责的项目
|
// 统计项目总数
|
||||||
LambdaQueryWrapper<SysOaProject> projectWrapper = Wrappers.<SysOaProject>lambdaQuery()
|
stats.setTotalProjects(projects.size());
|
||||||
.eq(SysOaProject::getFunctionary, nickName);
|
|
||||||
List<SysOaProject> responsibleProjectList = projectMapper.selectList(projectWrapper);
|
// 初始化项目清单
|
||||||
|
|
||||||
stats.setTotalProjects(participatedProjectIds.size());
|
|
||||||
stats.setResponsibleProjects(responsibleProjectList.size());
|
|
||||||
stats.setParticipatedProjects(participatedProjectIds.size());
|
|
||||||
|
|
||||||
// 构建项目清单
|
|
||||||
List<PersonalReportDTO.ProjectSummary> projectList = new ArrayList<>();
|
List<PersonalReportDTO.ProjectSummary> projectList = new ArrayList<>();
|
||||||
|
|
||||||
// 添加负责的项目
|
// 遍历项目并构建摘要信息
|
||||||
for (SysOaProject project : responsibleProjectList) {
|
for (SysOaProject project : projects) {
|
||||||
PersonalReportDTO.ProjectSummary summary = new PersonalReportDTO.ProjectSummary();
|
PersonalReportDTO.ProjectSummary summary = new PersonalReportDTO.ProjectSummary();
|
||||||
summary.setProjectId(project.getProjectId());
|
summary.setProjectId(project.getProjectId());
|
||||||
summary.setProjectName(project.getProjectName());
|
summary.setProjectName(project.getProjectName());
|
||||||
summary.setProjectNum(project.getProjectNum());
|
summary.setProjectNum(project.getProjectNum());
|
||||||
summary.setRole("负责人");
|
|
||||||
|
// 设置项目状态描述
|
||||||
// 计算参与天数
|
String status = "未知";
|
||||||
//TODO 项目负责人是不报工的
|
if ("0".equals(project.getProjectStatus())) {
|
||||||
long participationDays = reports.stream()
|
status = "进行中";
|
||||||
.filter(report -> project.getProjectId().equals(report.getProjectId()))
|
} else if ("1".equals(project.getProjectStatus())) {
|
||||||
.count();
|
status = "完结";
|
||||||
summary.setParticipationDays(BigDecimal.valueOf(participationDays));
|
}
|
||||||
|
summary.setStatus(status);
|
||||||
|
|
||||||
|
// 设置项目类型描述
|
||||||
|
String type = "其他";
|
||||||
|
if ("1".equals(project.getProjectType())) {
|
||||||
|
type = "中标";
|
||||||
|
} else if ("2".equals(project.getProjectType())) {
|
||||||
|
type = "其他";
|
||||||
|
}
|
||||||
|
summary.setType(type);
|
||||||
|
|
||||||
|
// 设置优先级描述
|
||||||
|
String priority = "一般";
|
||||||
|
if ("0".equals(project.getProjectGrade())) {
|
||||||
|
priority = "一般";
|
||||||
|
} else if ("1".equals(project.getProjectGrade())) {
|
||||||
|
priority = "中";
|
||||||
|
} else if ("2".equals(project.getProjectGrade())) {
|
||||||
|
priority = "高";
|
||||||
|
}
|
||||||
|
summary.setPriority(priority);
|
||||||
|
|
||||||
|
// 设置项目时间信息
|
||||||
|
summary.setBeginTime(project.getBeginTime());
|
||||||
|
summary.setFinishTime(project.getFinishTime());
|
||||||
|
|
||||||
|
// 设置项目负责人
|
||||||
|
summary.setFunctionary(project.getFunctionary());
|
||||||
|
|
||||||
|
// 设置项目总款
|
||||||
|
summary.setFunds(project.getFunds());
|
||||||
|
|
||||||
projectList.add(summary);
|
projectList.add(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加参与的其他项目
|
|
||||||
for (Long projectId : participatedProjectIds) {
|
|
||||||
if (responsibleProjectList.stream().noneMatch(p -> p.getProjectId().equals(projectId))) {
|
|
||||||
SysOaProject project = projectMapper.selectById(projectId);
|
|
||||||
if (project != null) {
|
|
||||||
PersonalReportDTO.ProjectSummary summary = new PersonalReportDTO.ProjectSummary();
|
|
||||||
summary.setProjectId(project.getProjectId());
|
|
||||||
summary.setProjectName(project.getProjectName());
|
|
||||||
summary.setProjectNum(project.getProjectNum());
|
|
||||||
summary.setRole("参与者");
|
|
||||||
|
|
||||||
// 计算参与天数
|
|
||||||
long participationDays = reports.stream()
|
|
||||||
.filter(report -> projectId.equals(report.getProjectId()))
|
|
||||||
.count();
|
|
||||||
summary.setParticipationDays(BigDecimal.valueOf(participationDays));
|
|
||||||
|
|
||||||
projectList.add(summary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stats.setProjectList(projectList);
|
stats.setProjectList(projectList);
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
@@ -673,7 +676,7 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
|
|||||||
/**
|
/**
|
||||||
* 统计任务信息
|
* 统计任务信息
|
||||||
*/
|
*/
|
||||||
private PersonalReportDTO.TaskStats getTaskStats(Long userId, Date startDate, Date endDate) {
|
private PersonalReportDTO.TaskStats getTaskStats(Long userId, Date startDate, Date endDate, List<Long> projectIds) {
|
||||||
PersonalReportDTO.TaskStats stats = new PersonalReportDTO.TaskStats();
|
PersonalReportDTO.TaskStats stats = new PersonalReportDTO.TaskStats();
|
||||||
|
|
||||||
// 查询发放的任务(创建的任务)
|
// 查询发放的任务(创建的任务)
|
||||||
@@ -683,6 +686,9 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
|
|||||||
if (startDate != null && endDate != null) {
|
if (startDate != null && endDate != null) {
|
||||||
assignedWrapper.between(SysOaTask::getBeginTime, startDate, endDate);
|
assignedWrapper.between(SysOaTask::getBeginTime, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
if (projectIds != null && !projectIds.isEmpty()) {
|
||||||
|
assignedWrapper.in(SysOaTask::getProjectId, projectIds);
|
||||||
|
}
|
||||||
|
|
||||||
List<SysOaTask> assignedTasks = taskMapper.selectList(assignedWrapper);
|
List<SysOaTask> assignedTasks = taskMapper.selectList(assignedWrapper);
|
||||||
|
|
||||||
@@ -693,6 +699,9 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
|
|||||||
if (startDate != null && endDate != null) {
|
if (startDate != null && endDate != null) {
|
||||||
undertakenWrapper.between(SysOaTask::getBeginTime, startDate, endDate);
|
undertakenWrapper.between(SysOaTask::getBeginTime, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
if (projectIds != null && !projectIds.isEmpty()) {
|
||||||
|
undertakenWrapper.in(SysOaTask::getProjectId, projectIds);
|
||||||
|
}
|
||||||
|
|
||||||
List<SysOaTask> undertakenTasks = taskMapper.selectList(undertakenWrapper);
|
List<SysOaTask> undertakenTasks = taskMapper.selectList(undertakenWrapper);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user