refactor(oa):优化奖金池分配逻辑并增强数据过滤

- 在项目、进度和步骤数据流中增加 null 过滤- 明确注释说明过滤空昵称而非一般空值
- 将单条合并昵称插入改为循环逐条插入分配记录
- 更新日志描述,体现去重后负责人数量
- 保留原有事务回滚机制及关联表插入逻辑
This commit is contained in:
2025-10-24 15:26:41 +08:00
parent 3dbe097772
commit 74cd7dda48

View File

@@ -169,11 +169,12 @@ public class OaBonusPoolServiceImpl implements IOaBonusPoolService {
return false; return false;
} }
projects.stream() projects.stream()
.filter(Objects::nonNull) // 过滤null项目对象
.map(SysOaProject::getFunctionary) .map(SysOaProject::getFunctionary)
.filter(StrUtil::isNotBlank) // 过滤空 .filter(StrUtil::isNotBlank) // 过滤空昵称
.forEach(allNickNames::add); // 添加到Set自动去重 .forEach(allNickNames::add); // Set自动去重
// 2.2 通过项目ID查询进度主表获取schedule_id // 通过项目ID查询进度主表获取schedule_id
List<OaProjectSchedule> schedules = projectScheduleMapper.selectList( List<OaProjectSchedule> schedules = projectScheduleMapper.selectList(
Wrappers.<OaProjectSchedule>lambdaQuery() Wrappers.<OaProjectSchedule>lambdaQuery()
.in(OaProjectSchedule::getProjectId, bo.getProjectIds()) .in(OaProjectSchedule::getProjectId, bo.getProjectIds())
@@ -181,11 +182,12 @@ public class OaBonusPoolServiceImpl implements IOaBonusPoolService {
.select(OaProjectSchedule::getScheduleId) .select(OaProjectSchedule::getScheduleId)
); );
//收集进度负责人oa_project_schedule_step.header // 收集进度负责人oa_project_schedule_step.header
if (CollUtil.isEmpty(schedules)) { if (CollUtil.isEmpty(schedules)) {
Log.warn("项目ID对应的进度主表记录为空仅收集项目负责人"); Log.warn("项目ID对应的进度主表记录为空仅收集项目负责人");
} else { } else {
List<Long> scheduleIds = schedules.stream() List<Long> scheduleIds = schedules.stream()
.filter(Objects::nonNull) // 过滤null进度对象
.map(OaProjectSchedule::getScheduleId) .map(OaProjectSchedule::getScheduleId)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -196,9 +198,10 @@ public class OaBonusPoolServiceImpl implements IOaBonusPoolService {
.select(OaProjectScheduleStep::getHeader) .select(OaProjectScheduleStep::getHeader)
); );
scheduleSteps.stream() scheduleSteps.stream()
.filter(Objects::nonNull) // 过滤null步骤对象
.map(OaProjectScheduleStep::getHeader) .map(OaProjectScheduleStep::getHeader)
.filter(StrUtil::isNotBlank) // 过滤空 .filter(StrUtil::isNotBlank) // 过滤空昵称
.forEach(allNickNames::add); // 添加到Set自动去重 .forEach(allNickNames::add); // Set自动去重
} }
// 校验去重后的昵称集合 // 校验去重后的昵称集合
@@ -207,22 +210,22 @@ public class OaBonusPoolServiceImpl implements IOaBonusPoolService {
return false; return false;
} }
// 拼接所有昵称(逗号分隔) // 循环插入奖金池分配表
String mergedNickNames = String.join(",", allNickNames); for (String nickName : allNickNames) {
// 插入奖金池分配表(单条记录)
OaBonusAllocation allocation = new OaBonusAllocation(); OaBonusAllocation allocation = new OaBonusAllocation();
allocation.setPoolId(poolId); allocation.setPoolId(poolId); // 关联当前奖金池ID
allocation.setNickName(mergedNickNames); allocation.setNickName(nickName); // 单个负责人昵称
allocation.setAllocationRatio(new BigDecimal("0.00")); allocation.setAllocationRatio(new BigDecimal("0.00")); // 默认分配比例
allocation.setCreateBy(LoginHelper.getUsername()); allocation.setCreateBy(LoginHelper.getUsername()); // 创建人
allocation.setCreateTime(new Date()); allocation.setCreateTime(new Date()); // 创建时间
allocation.setDelFlag("0"); allocation.setDelFlag("0"); // 未删除
int insertResult = bonusAllocationMapper.insert(allocation); int insertResult = bonusAllocationMapper.insert(allocation);
if (insertResult <= 0) { if (insertResult <= 0) {
Log.error("插入奖金池分配记录失败poolId={}"); Log.error("插入奖金池分配记录失败poolId={}, nickName={}");
throw new RuntimeException("分配记录插入失败,触发回滚"); throw new RuntimeException("分配记录插入失败,触发回滚");
} }
}
// 插入奖金池与项目关联表 // 插入奖金池与项目关联表
for (Long projectId : bo.getProjectIds()) { for (Long projectId : bo.getProjectIds()) {
@@ -239,7 +242,7 @@ public class OaBonusPoolServiceImpl implements IOaBonusPoolService {
} }
} }
Log.info("奖金池批量创建成功poolId={}负责人:{}"); Log.info("奖金池批量创建成功poolId={}去重后负责人数量={}");
return true; return true;
} }
} }