diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/MergeExpertIdDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/MergeExpertIdDTO.java new file mode 100644 index 0000000..328e14a --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/MergeExpertIdDTO.java @@ -0,0 +1,30 @@ +package com.ningdatech.pmapi.meeting.entity.dto; + +import lombok.Data; + +import java.util.List; + +/** + *

+ * MergeExpertIdDTO + *

+ * + * @author WendyYang + * @since 2023/4/14 + **/ +@Data +public class MergeExpertIdDTO { + + private List expertIdsIn; + + private List expertIdsNotIn; + + private Boolean skip; + + public static MergeExpertIdDTO noExpert() { + MergeExpertIdDTO condition = new MergeExpertIdDTO(); + condition.setSkip(Boolean.TRUE); + return condition; + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertInviteManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertInviteManage.java index 4183bf4..08adf25 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertInviteManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertInviteManage.java @@ -16,10 +16,7 @@ import com.ningdatech.pmapi.meeting.builder.ExpertInviteBuilder; import com.ningdatech.pmapi.meeting.entity.domain.ExpertInviteRule; import com.ningdatech.pmapi.meeting.entity.domain.Meeting; import com.ningdatech.pmapi.meeting.entity.domain.MeetingExpert; -import com.ningdatech.pmapi.meeting.entity.dto.AvoidRuleDTO; -import com.ningdatech.pmapi.meeting.entity.dto.ExpertChooseDTO; -import com.ningdatech.pmapi.meeting.entity.dto.ExpertDictChooseDTO; -import com.ningdatech.pmapi.meeting.entity.dto.RandomInviteRuleDTO; +import com.ningdatech.pmapi.meeting.entity.dto.*; import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertAttendStatusEnum; import com.ningdatech.pmapi.meeting.helper.ExpertInviteHelper; import com.ningdatech.pmapi.meeting.helper.YxtCallOrSmsHelper; @@ -124,30 +121,32 @@ public class ExpertInviteManage { return new ArrayList<>(); } LambdaQueryWrapper query = Wrappers.lambdaQuery(ExpertAvoidCompany.class) + .select(ExpertAvoidCompany::getUserId) .in(ExpertAvoidCompany::getCompanyUniqCode, unitCodeList); List expertAvoidCompanyList = expertAvoidCompanyService.list(query); return CollUtils.fieldList(expertAvoidCompanyList, ExpertAvoidCompany::getUserId); } - private List mergeExpertIdsByCondition(RandomInviteRuleDTO rule, AvoidRuleDTO avoidInfo) { + private MergeExpertIdDTO mergeExpertIdsByCondition(RandomInviteRuleDTO rule, AvoidRuleDTO avoidInfo) { // 处理履职意向地 List expertIdsByIntentionRegion = expertIdsByRegion(rule); if (COLL_EMPTY.evaluate(expertIdsByIntentionRegion)) { - return null; + return MergeExpertIdDTO.noExpert(); } // 处理专家标签 List expertIdsByTag = expertIdsByTag(rule); if (COLL_EMPTY.evaluate(expertIdsByTag)) { - return null; + return MergeExpertIdDTO.noExpert(); } // 处理专家字典 List expertIdsByDict = expertIdsByDict(rule); if (COLL_EMPTY.evaluate(expertIdsByDict)) { - return null; + return MergeExpertIdDTO.noExpert(); } // 处理专家回避单位 与 抽取回避单位是否相同 - List avoidCompanyExpertIds = avoidCompanyExpertIds(avoidInfo.getAvoidUnitIdList()); + List avoidExpertIdsByUnit = avoidCompanyExpertIds(avoidInfo.getAvoidUnitIdList()); + MergeExpertIdDTO merge = new MergeExpertIdDTO(); // 聚合用户ID List expertIdsIn = new ArrayList<>(); if (ObjectUtils.anyNotNull(expertIdsByDict, expertIdsByTag, expertIdsByIntentionRegion)) { @@ -167,17 +166,22 @@ public class ExpertInviteManage { } }); if (expertIdsIn.isEmpty()) { - return null; + return MergeExpertIdDTO.noExpert(); } + merge.setExpertIdsIn(expertIdsIn); } - - if (CollUtil.isNotEmpty(avoidCompanyExpertIds)) { - expertIdsIn.removeIf(avoidCompanyExpertIds::contains); + if (CollUtil.isNotEmpty(avoidExpertIdsByUnit)) { if (expertIdsIn.isEmpty()) { - return null; + merge.setExpertIdsNotIn(avoidExpertIdsByUnit); + } else { + expertIdsIn.removeIf(avoidExpertIdsByUnit::contains); + if (expertIdsIn.isEmpty()) { + return MergeExpertIdDTO.noExpert(); + } } } - return expertIdsIn; + merge.setSkip(Boolean.FALSE); + return merge; } /** @@ -253,8 +257,8 @@ public class ExpertInviteManage { LocalDateTime sTime, LocalDateTime eTime) { ExpertChooseDTO result = new ExpertChooseDTO(new ArrayList<>(), 0); - List expertIdsIn = mergeExpertIdsByCondition(randomRule, avoidRule); - if (expertIdsIn == null) { + MergeExpertIdDTO merge = mergeExpertIdsByCondition(randomRule, avoidRule); + if (merge.getSkip()) { return result; } boolean avoidExpert = CollUtil.isNotEmpty(avoidRule.getExpertIds()); @@ -270,14 +274,20 @@ public class ExpertInviteManage { query.notExists("select 1 from expert_avoid_company eac where eac.user_id = nd_expert_user_full_info.user_id" + " and company_uniq_code in ({0})", CollUtils.joinByComma(avoidRule.getAvoidUnitIdList())); } + Set expertIdsIn = new HashSet<>(); + Set expertIdsNotIn = new HashSet<>(); + if (CollUtil.isNotEmpty(merge.getExpertIdsIn())) { + expertIdsIn.addAll(merge.getExpertIdsIn()); + } else { + expertIdsNotIn.addAll(merge.getExpertIdsNotIn()); + } // 处理专家层级 addRegionLimit(query, randomRule); if (!expertIdsIn.isEmpty()) { if (avoidExpert) { expertIdsIn.removeIf(w -> avoidRule.getExpertIds().contains(w)); if (expertIdsIn.isEmpty()) { - // 字典、标签、履职意向地筛选出的专家ID移除需要回避的专家ID - // 如果为空则说明没有符合条件的 + // 字典、标签、履职意向地 筛选出的专家ID移除需要回避的专家ID、如果为空则说明没有符合条件的 return result; } } @@ -293,15 +303,17 @@ public class ExpertInviteManage { if (expertIdsIn.isEmpty()) { return result; } - query.in(ExpertUserFullInfo::getUserId, expertIdsIn); } else if (avoidExpert || CollUtil.isNotEmpty(appointExpertIds)) { - Set tempExperts = expertInviteHelper.getAvoidExpert(appointExpertIds, avoidRule, sTime, eTime); - query.notIn(ExpertUserFullInfo::getUserId, tempExperts); + Set tmpExpert = expertInviteHelper.getAvoidExpert(appointExpertIds, avoidRule, sTime, eTime); + expertIdsNotIn.addAll(tmpExpert); } else { - Set notInUserIds = expertInviteHelper.listExpertLeaveOrInvited(sTime, eTime); - if (!notInUserIds.isEmpty()) { - query.notIn(ExpertUserFullInfo::getUserId, notInUserIds); - } + Set tmpNotInUserIds = expertInviteHelper.listExpertLeaveOrInvited(sTime, eTime); + expertIdsNotIn.addAll(tmpNotInUserIds); + } + if (!expertIdsIn.isEmpty()) { + query.in(ExpertUserFullInfo::getUserId, expertIdsIn); + } else if (!expertIdsNotIn.isEmpty()) { + query.notIn(ExpertUserFullInfo::getUserId, expertIdsNotIn); } List userInfoList = expertUserFullInfoService.list(query); if (userInfoList.isEmpty()) { @@ -334,11 +346,17 @@ public class ExpertInviteManage { boolean invitedRefused) { ExpertChooseDTO result = new ExpertChooseDTO(new ArrayList<>(), 0); // 合并标签、字典 - List expertIdsIn = mergeExpertIdsByCondition(randomRule, avoidRule); - List expertIdsNotIn = new ArrayList<>(); - if (expertIdsIn == null) { + MergeExpertIdDTO merge = mergeExpertIdsByCondition(randomRule, avoidRule); + if (merge.getSkip()) { return result; } + Set expertIdsIn = new HashSet<>(); + Set expertIdsNotIn = new HashSet<>(); + if (CollUtil.isNotEmpty(merge.getExpertIdsIn())) { + expertIdsIn.addAll(merge.getExpertIdsIn()); + } else { + expertIdsNotIn.addAll(merge.getExpertIdsNotIn()); + } LambdaQueryWrapper query = buildBaseExpertQuery(); // 设置回避单位 Set notInCompanyUniqCodeList = new HashSet<>(avoidRule.getAvoidUnitIdList());