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