From 74cd7dda48ba2817638318405b22fe4c5234f542 Mon Sep 17 00:00:00 2001 From: Joshi <3040996759@qq.com> Date: Fri, 24 Oct 2025 15:26:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor(oa):=E4=BC=98=E5=8C=96=E5=A5=96?= =?UTF-8?q?=E9=87=91=E6=B1=A0=E5=88=86=E9=85=8D=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E6=95=B0=E6=8D=AE=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在项目、进度和步骤数据流中增加 null 过滤- 明确注释说明过滤空昵称而非一般空值 - 将单条合并昵称插入改为循环逐条插入分配记录 - 更新日志描述,体现去重后负责人数量 - 保留原有事务回滚机制及关联表插入逻辑 --- .../service/impl/OaBonusPoolServiceImpl.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) 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; } }