refactor(oa): 优化个人报表项目统计逻辑

- 调整getProjectStats方法参数,使用项目ID列表进行精确查询
- 重构项目统计逻辑,支持按指定项目ID列表统计项目信息
- 增强项目摘要信息,添加项目状态、类型、优先级等字段
- 完善任务统计方法,支持按项目ID列表筛选任务数据
- 优化空项目列表处理逻辑,避免空指针异常
- 补充项目时间、负责人及资金信息到项目摘要中
This commit is contained in:
2025-11-20 16:43:07 +08:00
parent 9099e55367
commit 20a3bfaec9
2 changed files with 88 additions and 66 deletions

View File

@@ -7,6 +7,7 @@ import com.ruoyi.oa.domain.SysOaTask;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
@@ -116,12 +117,24 @@ public class PersonalReportDTO {
*/
@Data
public static class ProjectSummary {
/** 项目ID */
private Long projectId;
/** 项目状态 */
private String status;
/** 项目名称 */
private String projectName;
/** 项目编号 */
private String projectNum;
//类型
private String type;
//优先级
private String priority;
// 设置项目时间信息
private Date beginTime;
private Date finishTime;
// 设置项目负责人
private String functionary;
// 设置项目总款
private BigDecimal funds;
/** 参与角色 */
private String role;
/** 参与天数 */

View File

@@ -471,13 +471,13 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
result.setBusinessTripStats(getBusinessTripStats(userId, startTime, endTime));
// 3. 统计项目信息
result.setProjectStats(getProjectStats(userId, nickName, startTime, endTime));
result.setProjectStats(getProjectStats(projectIds));
// // 4. 统计进度信息
// result.setProgressStats(getProgressStats(nickName, startDate, endDate));
// 5. 统计任务信息
result.setTaskStats(getTaskStats(userId, startTime, endTime));
result.setTaskStats(getTaskStats(userId, startTime, endTime,projectIds));
// 6. 统计工程异常信息
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();
// 通过报工记录查询参与的项目
LambdaQueryWrapper<OaProjectReport> reportWrapper = Wrappers.<OaProjectReport>lambdaQuery()
.eq(OaProjectReport::getUserId, userId)
.eq(OaProjectReport::getDelFlag, 0);
// if (startDate != null && endDate != null) {
// reportWrapper.between(OaProjectReport::getCreateTime, startDate, endDate);
// }
List<OaProjectReport> reports = projectReportMapper.selectList(reportWrapper);
Set<Long> participatedProjectIds = reports.stream()
.map(OaProjectReport::getProjectId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// 查询负责的项目
LambdaQueryWrapper<SysOaProject> projectWrapper = Wrappers.<SysOaProject>lambdaQuery()
.eq(SysOaProject::getFunctionary, nickName);
List<SysOaProject> responsibleProjectList = projectMapper.selectList(projectWrapper);
stats.setTotalProjects(participatedProjectIds.size());
stats.setResponsibleProjects(responsibleProjectList.size());
stats.setParticipatedProjects(participatedProjectIds.size());
// 构建项目清单
// 如果没有项目ID列表直接返回空统计
if (projectIds == null || projectIds.isEmpty()) {
stats.setTotalProjects(0);
stats.setResponsibleProjects(0);
stats.setParticipatedProjects(0);
stats.setProjectList(new ArrayList<>());
return stats;
}
// 查询指定ID的项目列表
List<SysOaProject> projects = projectMapper.selectList(
Wrappers.<SysOaProject>lambdaQuery()
.in(SysOaProject::getProjectId, projectIds)
);
// 统计项目总数
stats.setTotalProjects(projects.size());
// 初始化项目清单
List<PersonalReportDTO.ProjectSummary> projectList = new ArrayList<>();
// 添加负责的项目
for (SysOaProject project : responsibleProjectList) {
// 遍历项目并构建摘要信息
for (SysOaProject project : projects) {
PersonalReportDTO.ProjectSummary summary = new PersonalReportDTO.ProjectSummary();
summary.setProjectId(project.getProjectId());
summary.setProjectName(project.getProjectName());
summary.setProjectNum(project.getProjectNum());
summary.setRole("负责人");
// 计算参与天数
//TODO 项目负责人是不报工的
long participationDays = reports.stream()
.filter(report -> project.getProjectId().equals(report.getProjectId()))
.count();
summary.setParticipationDays(BigDecimal.valueOf(participationDays));
// 设置项目状态描述
String status = "未知";
if ("0".equals(project.getProjectStatus())) {
status = "进行中";
} else if ("1".equals(project.getProjectStatus())) {
status = "完结";
}
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);
}
// 添加参与的其他项目
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);
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();
// 查询发放的任务(创建的任务)
@@ -683,6 +686,9 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
if (startDate != null && endDate != null) {
assignedWrapper.between(SysOaTask::getBeginTime, startDate, endDate);
}
if (projectIds != null && !projectIds.isEmpty()) {
assignedWrapper.in(SysOaTask::getProjectId, projectIds);
}
List<SysOaTask> assignedTasks = taskMapper.selectList(assignedWrapper);
@@ -693,6 +699,9 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS
if (startDate != null && endDate != null) {
undertakenWrapper.between(SysOaTask::getBeginTime, startDate, endDate);
}
if (projectIds != null && !projectIds.isEmpty()) {
undertakenWrapper.in(SysOaTask::getProjectId, projectIds);
}
List<SysOaTask> undertakenTasks = taskMapper.selectList(undertakenWrapper);