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 83e33af..39fa7ef 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 @@ -44,6 +44,7 @@ import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.ningdatech.pmapi.meeting.entity.enumeration.ExpertAttendStatusEnum.*; import static com.ningdatech.pmapi.meeting.helper.ExpertInviteHelper.getExpertInviteRule; /** @@ -336,25 +337,23 @@ public class ExpertInviteManage { ExpertChooseDTO result = new ExpertChooseDTO(new ArrayList<>(), 0); // 合并标签、字典 List expertIdsIn = mergeExpertIdsByCondition(randomRule, avoidRule); + List expertIdsNotIn = new ArrayList<>(); if (expertIdsIn == null) { return result; } LambdaQueryWrapper query = buildBaseExpertQuery(); - query.notIn(ExpertUserFullInfo::getCompanyUniqCode, avoidRule.getAvoidUnitIdList()); + // 设置回避单位 + Set notInCompanyUniqCodeList = new HashSet<>(avoidRule.getAvoidUnitIdList()); 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.getAvoidOrgIdList())); - + " and company_uniq_code in ({0})", CollUtils.joinByComma(avoidRule.getAvoidUnitIdList())); // 处理专家层级 - if (StrUtils.isNotBlank(randomRule.getExpertRegionCode())) { - query.eq(ExpertUserFullInfo::getRegionCode, randomRule.getExpertRegionCode()); - query.eq(ExpertUserFullInfo::getRegionLevel, randomRule.getExpertRegionLevel()); - } + addRegionLimit(query, randomRule); + if (expertIdsIn.size() > 0) { if (CollectionUtils.isNotEmpty(avoidRule.getExpertIds())) { expertIdsIn.removeIf(w -> avoidRule.getExpertIds().contains(w)); if (expertIdsIn.isEmpty()) { - // 字典、标签、履职意向地筛选出的专家ID移除需要回避的专家ID - // 如果为空则说明没有符合条件的 + // 字典、标签、履职意向地筛选出的专家ID移除需要回避的专家ID、如果为空则说明没有符合条件的 return result; } } @@ -363,37 +362,52 @@ public class ExpertInviteManage { if (expertIdsIn.isEmpty()) { return result; } - query.in(ExpertUserFullInfo::getUserId, expertIdsIn); } else if (CollUtil.isNotEmpty(avoidRule.getExpertIds())) { Set notInExpertIds = expertInviteHelper.getAvoidExpert(avoidRule.getExpertIds(), null, start, end); - query.notIn(ExpertUserFullInfo::getUserId, notInExpertIds); + expertIdsNotIn.addAll(notInExpertIds); } else { Set notInUserIds = expertInviteHelper.listExpertLeaveOrInvited(start, end); - if (notInUserIds.size() > 0) { - query.notIn(ExpertUserFullInfo::getUserId, notInUserIds); - } - } - List userFullInfos = expertUserFullInfoService.list(query); - if (userFullInfos.size() == 0) { - return result; + expertIdsNotIn.addAll(notInUserIds); } Map> expertGroupByStatus = invitedExperts.stream() .collect(Collectors.groupingBy(w -> ExpertAttendStatusEnum.getByCode(w.getStatus()))); // 回避同单位其他专家 - List removeExpertByCompany = new ArrayList<>(); - BizUtils.notEmpty(expertGroupByStatus.get(ExpertAttendStatusEnum.AGREED), removeExpertByCompany::addAll); - BizUtils.notEmpty(expertGroupByStatus.get(ExpertAttendStatusEnum.NOTICING), removeExpertByCompany::addAll); - List removeExpertIds = new ArrayList<>(); + List agreeOrNoticing = new ArrayList<>(); + BizUtils.notEmpty(expertGroupByStatus.get(AGREED), agreeOrNoticing::addAll); + BizUtils.notEmpty(expertGroupByStatus.get(NOTICING), agreeOrNoticing::addAll); + List agreeOrNoticingExpertIds = CollUtils.fieldList(agreeOrNoticing, MeetingExpert::getExpertId); + if (agreeOrNoticingExpertIds.size() > 0) { + expertIdsNotIn.addAll(agreeOrNoticingExpertIds); + List agreeOrNoticingUserInfos = expertUserFullInfoService.listByUserIds(agreeOrNoticingExpertIds); + List tmpUniqCompanyCodes = CollUtils.fieldList(agreeOrNoticingUserInfos, ExpertUserFullInfo::getCompanyUniqCode); + notInCompanyUniqCodeList.addAll(tmpUniqCompanyCodes); + } if (invitedRefused) { // 拒绝参加的不可以被再次抽中 - BizUtils.notEmpty(expertGroupByStatus.get(ExpertAttendStatusEnum.REFUSED), w -> { - List tempRefused = CollUtils.fieldList(w, MeetingExpert::getExpertId); - removeExpertIds.addAll(tempRefused); - }); + List refusedExperts = expertGroupByStatus.get(REFUSED); + if (refusedExperts.size() > 0) { + List refusedExpertIds = CollUtils.fieldList(refusedExperts, MeetingExpert::getExpertId); + expertIdsNotIn.addAll(refusedExpertIds); + } + } + boolean hasExpertIdIn = !expertIdsIn.isEmpty(); + boolean hasExpertIdNotIn = !expertIdsNotIn.isEmpty(); + if (hasExpertIdIn && hasExpertIdNotIn) { + expertIdsIn.removeAll(expertIdsNotIn); + if (expertIdsIn.isEmpty()) { + return result; + } + query.in(ExpertUserFullInfo::getUserId, expertIdsIn); + } else if (hasExpertIdIn) { + query.in(ExpertUserFullInfo::getUserId, expertIdsIn); + } else if (hasExpertIdNotIn) { + query.notIn(ExpertUserFullInfo::getUserId, expertIdsNotIn); + } + query.notIn(notInCompanyUniqCodeList.size() > 0, ExpertUserFullInfo::getCompanyUniqCode, notInCompanyUniqCodeList); + List userFullInfos = expertUserFullInfoService.list(query); + if (userFullInfos.size() == 0) { + return result; } - List tempExpertIds = CollUtils.fieldList(removeExpertByCompany, MeetingExpert::getExpertId); - // 移除确认参加、通知中的、拒绝参加、已取消 - userFullInfos.removeIf(w -> tempExpertIds.contains(w.getUserId()) || removeExpertIds.contains(w.getUserId())); Map> userGroupByUnit = CollUtils.group(userFullInfos, ExpertUserFullInfo::getCompanyUniqCode); result.setTotal(userGroupByUnit.size()); result.setExperts(inviteGroupByCompany(userGroupByUnit, count)); @@ -538,7 +552,7 @@ public class ExpertInviteManage { Long ruleId = randoms.get(i).getId(); expertsByRandom.get(i).getExperts().forEach(w -> { MeetingExpert expert = ExpertInviteBuilder.getExpertByRandom(meeting.getId(), w, ruleId); - expert.setStatus(ExpertAttendStatusEnum.NOTICING.getCode()); + expert.setStatus(NOTICING.getCode()); expertInserts.add(expert); }); }