diff --git a/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaBonusPoolServiceImpl.java b/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaBonusPoolServiceImpl.java index 59321c1..04226a0 100644 --- a/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaBonusPoolServiceImpl.java +++ b/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaBonusPoolServiceImpl.java @@ -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 schedules = projectScheduleMapper.selectList( Wrappers.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 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; } }