|
|
@@ -3,6 +3,7 @@ package com.hz.pm.api.meeting.manage; |
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.hz.pm.api.common.exception.ReturnException; |
|
|
|
import com.hz.pm.api.common.util.BizUtils; |
|
|
|
import com.hz.pm.api.expert.entity.ExpertAvoidCompany; |
|
|
|
import com.hz.pm.api.expert.entity.ExpertGovBusinessStrip; |
|
|
@@ -29,7 +30,6 @@ import com.hz.pm.api.meta.model.entity.ExpertDictionary; |
|
|
|
import com.hz.pm.api.meta.model.entity.ExpertTag; |
|
|
|
import com.hz.pm.api.meta.service.IExpertDictionaryService; |
|
|
|
import com.hz.pm.api.meta.service.IExpertTagService; |
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
@@ -79,7 +79,7 @@ public class ExpertInviteManage { |
|
|
|
|
|
|
|
private static final Predicate<Collection<?>> COLL_EMPTY = (coll) -> coll != null && coll.isEmpty(); |
|
|
|
|
|
|
|
private LambdaQueryWrapper<ExpertUserFullInfo> buildBaseExpertQuery() { |
|
|
|
private static LambdaQueryWrapper<ExpertUserFullInfo> buildBaseExpertQuery() { |
|
|
|
return Wrappers.lambdaQuery(ExpertUserFullInfo.class) |
|
|
|
.select(ExpertUserFullInfo::getUserId, |
|
|
|
ExpertUserFullInfo::getId, |
|
|
@@ -89,7 +89,7 @@ public class ExpertInviteManage { |
|
|
|
ExpertUserFullInfo::getPhoneNo); |
|
|
|
} |
|
|
|
|
|
|
|
private void buildAvoidCompanyAndBusinessStrip(LambdaQueryWrapper<ExpertUserFullInfo> query, List<String> units, List<String> strips) { |
|
|
|
private static void buildAvoidCompanyAndBusinessStrip(LambdaQueryWrapper<ExpertUserFullInfo> query, List<String> units, List<String> strips) { |
|
|
|
if (CollUtil.isNotEmpty(units)) { |
|
|
|
String unitStr = BizUtils.inSqlJoin(units); |
|
|
|
query.notExists("select 1 from expert_avoid_company eac where eac.user_id = nd_expert_user_full_info.user_id" + |
|
|
@@ -303,19 +303,18 @@ public class ExpertInviteManage { |
|
|
|
if (merge.isSkip()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
boolean hasAvoidExpert = CollUtil.isNotEmpty(avoidRule.getExpertIds()); |
|
|
|
boolean hasAvoidCompany = CollUtil.isNotEmpty(avoidRule.getAvoidUnitIdList()); |
|
|
|
Set<String> avoidCompanyUniqCodes = new HashSet<>(); |
|
|
|
if (hasAvoidCompany) { |
|
|
|
avoidCompanyUniqCodes.addAll(avoidRule.getAvoidUnitIdList()); |
|
|
|
} |
|
|
|
Set<String> avoidUnitCodes = new HashSet<>(); |
|
|
|
BizUtils.notEmpty(avoidRule.getAvoidUnitIdList(), avoidUnitCodes::addAll); |
|
|
|
|
|
|
|
LambdaQueryWrapper<ExpertUserFullInfo> query = buildBaseExpertQuery(); |
|
|
|
AvoidTypeEnum avoidType = avoidRule.getAvoidType() == null ? AvoidTypeEnum.NONE : AvoidTypeEnum.getByCode(avoidRule.getAvoidType()); |
|
|
|
if (CollUtil.isNotEmpty(invitedExpertIds)) { |
|
|
|
List<String> tmpCompanyUniqCodes = expertUserFullInfoService.listCompanyUniqCodeByUserIds(invitedExpertIds); |
|
|
|
avoidCompanyUniqCodes.addAll(tmpCompanyUniqCodes); |
|
|
|
buildAvoidUnitStripForQuery(invitedExpertIds, avoidType, avoidUnitCodes, query); |
|
|
|
} |
|
|
|
// 处理专家层级 |
|
|
|
addRegionLimit(query, randomRule); |
|
|
|
// 回避信息 |
|
|
|
LambdaQueryWrapper<ExpertUserFullInfo> query = buildBaseExpertQuery(); |
|
|
|
query.notIn(!avoidCompanyUniqCodes.isEmpty(), ExpertUserFullInfo::getCompanyUniqCode, avoidCompanyUniqCodes); |
|
|
|
query.notIn(!avoidUnitCodes.isEmpty(), ExpertUserFullInfo::getCompanyUniqCode, avoidUnitCodes); |
|
|
|
// 处理回避单位与回避条线 |
|
|
|
buildAvoidCompanyAndBusinessStrip(query, avoidRule.getAvoidUnitIdList(), avoidRule.getAvoidOrgIdList()); |
|
|
|
Set<Long> expertIdsIn = new HashSet<>(); |
|
|
@@ -326,34 +325,24 @@ public class ExpertInviteManage { |
|
|
|
expertIdsNotIn.addAll(merge.getExpertIdsNotIn()); |
|
|
|
} |
|
|
|
// 处理回避专家次数 |
|
|
|
if (avoidRule.getWeekInviteCount() != null) { |
|
|
|
Integer weekInviteCount = avoidRule.getWeekInviteCount(); |
|
|
|
BizUtils.notNull(avoidRule.getWeekInviteCount(), weekInviteCount -> { |
|
|
|
List<Long> tmpExpertIdsNotIn = listAgreedUserIdByRecentMeetings(weekInviteCount, recentDays, meetingCreateOn); |
|
|
|
expertIdsNotIn.addAll(tmpExpertIdsNotIn); |
|
|
|
} |
|
|
|
// 处理专家层级 |
|
|
|
addRegionLimit(query, randomRule); |
|
|
|
}); |
|
|
|
|
|
|
|
if (!expertIdsIn.isEmpty()) { |
|
|
|
if (hasAvoidExpert) { |
|
|
|
expertIdsIn.removeIf(w -> avoidRule.getExpertIds().contains(w)); |
|
|
|
if (expertIdsIn.isEmpty()) { |
|
|
|
// 字典、标签、履职意向地 筛选出的专家ID移除需要回避的专家ID、如果为空则说明没有符合条件的 |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
if (CollUtil.isNotEmpty(invitedExpertIds)) { |
|
|
|
expertIdsIn.removeIf(invitedExpertIds::contains); |
|
|
|
if (expertIdsIn.isEmpty()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
BizUtils.notEmpty(avoidRule.getExpertIds(), w -> expertIdsIn.removeIf(w::contains)); |
|
|
|
BizUtils.notEmpty(invitedExpertIds, w -> expertIdsIn.removeIf(w::contains)); |
|
|
|
if (expertIdsIn.isEmpty()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
// 过滤掉已参加会议的专家 |
|
|
|
List<Long> expertIdsLockByMeeting = expertInviteHelper.listInvitedExpertByTime(sTime, eTime); |
|
|
|
expertIdsIn.removeIf(expertIdsLockByMeeting::contains); |
|
|
|
List<Long> lockedExpertIds = expertInviteHelper.listInvitedExpertIds(sTime, eTime); |
|
|
|
expertIdsIn.removeIf(lockedExpertIds::contains); |
|
|
|
if (expertIdsIn.isEmpty()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
} else if (hasAvoidExpert || CollUtil.isNotEmpty(invitedExpertIds)) { |
|
|
|
} else if (CollUtil.isNotEmpty(avoidRule.getExpertIds()) || CollUtil.isNotEmpty(invitedExpertIds)) { |
|
|
|
Set<Long> tmpExpert = expertInviteHelper.getAvoidExpert(invitedExpertIds, avoidRule, sTime, eTime); |
|
|
|
expertIdsNotIn.addAll(tmpExpert); |
|
|
|
} else { |
|
|
@@ -365,11 +354,11 @@ public class ExpertInviteManage { |
|
|
|
} else if (!expertIdsNotIn.isEmpty()) { |
|
|
|
query.notIn(ExpertUserFullInfo::getUserId, expertIdsNotIn); |
|
|
|
} |
|
|
|
// 开始进行专家抽取 |
|
|
|
List<ExpertUserFullInfo> userInfoList = expertUserFullInfoService.list(query); |
|
|
|
if (userInfoList.isEmpty()) { |
|
|
|
return result; |
|
|
|
} |
|
|
|
AvoidTypeEnum avoidType = avoidRule.getAvoidType() == null ? AvoidTypeEnum.CURR_UNIT : AvoidTypeEnum.getByCode(avoidRule.getAvoidType()); |
|
|
|
switch (avoidType) { |
|
|
|
case NONE: |
|
|
|
result.setExperts(inviteRandom(userInfoList, expertsByRecentMeeting(), randomRule.getCount())); |
|
|
@@ -395,6 +384,22 @@ public class ExpertInviteManage { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private void buildAvoidUnitStripForQuery(List<Long> invitedExpertIds, AvoidTypeEnum avoidType, Set<String> avoidUnitCodes, LambdaQueryWrapper<ExpertUserFullInfo> query) { |
|
|
|
if (AvoidTypeEnum.CURR_UNIT.equals(avoidType)) { |
|
|
|
List<ExpertUserFullInfo> tmpInvitedExperts = expertUserFullInfoService.listByUserIds(invitedExpertIds); |
|
|
|
Set<String> tmpUnitCodes = CollUtils.fieldSet(tmpInvitedExperts, ExpertUserFullInfo::getCompanyUniqCode); |
|
|
|
avoidUnitCodes.addAll(tmpUnitCodes); |
|
|
|
} else if (AvoidTypeEnum.CURR_STRIP.equals(avoidType)) { |
|
|
|
List<ExpertGovBusinessStrip> expertStrips = expertGovBusinessStripService.listByUserIds(invitedExpertIds); |
|
|
|
if (CollUtil.isNotEmpty(expertStrips)) { |
|
|
|
Set<String> businessStripCodes = CollUtils.fieldSet(expertStrips, ExpertGovBusinessStrip::getBusinessStripCode); |
|
|
|
query.notExists("select 1 from expert_gov_business_strip egbs " + |
|
|
|
"where egbs.expertUserId = nd_expert_user_full_info.user_id " + |
|
|
|
"and egbs.business_strip_code in " + BizUtils.inSqlJoin(businessStripCodes)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 专家替换、补充 |
|
|
|
* |
|
|
@@ -431,15 +436,14 @@ public class ExpertInviteManage { |
|
|
|
} |
|
|
|
LambdaQueryWrapper<ExpertUserFullInfo> query = buildBaseExpertQuery(); |
|
|
|
// 设置回避单位 |
|
|
|
Set<String> notInCompanyUniqCodeList = new HashSet<>(avoidRule.getAvoidUnitIdList()); |
|
|
|
Set<String> avoidUnitCodes = new HashSet<>(avoidRule.getAvoidUnitIdList()); |
|
|
|
// 处理回避单位与回避条线 |
|
|
|
buildAvoidCompanyAndBusinessStrip(query, avoidRule.getAvoidUnitIdList(), avoidRule.getAvoidOrgIdList()); |
|
|
|
// 处理回避专家次数 |
|
|
|
if (avoidRule.getWeekInviteCount() != null) { |
|
|
|
Integer weekInviteCount = avoidRule.getWeekInviteCount(); |
|
|
|
BizUtils.notNull(avoidRule.getWeekInviteCount(), weekInviteCount -> { |
|
|
|
List<Long> tmpExpertIdsNotIn = listAgreedUserIdByRecentMeetings(weekInviteCount, recentDays, msTime); |
|
|
|
expertIdsNotIn.addAll(tmpExpertIdsNotIn); |
|
|
|
} |
|
|
|
}); |
|
|
|
// 处理专家层级 |
|
|
|
addRegionLimit(query, randomRule); |
|
|
|
|
|
|
@@ -451,8 +455,8 @@ public class ExpertInviteManage { |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
List<Long> lockExpertIds = expertInviteHelper.listInvitedExpertByTime(msTime, meTime); |
|
|
|
expertIdsIn.removeIf(lockExpertIds::contains); |
|
|
|
List<Long> lockedExpertIds = expertInviteHelper.listInvitedExpertIds(msTime, meTime); |
|
|
|
expertIdsIn.removeIf(lockedExpertIds::contains); |
|
|
|
if (expertIdsIn.isEmpty()) { |
|
|
|
return result; |
|
|
|
} |
|
|
@@ -473,19 +477,7 @@ public class ExpertInviteManage { |
|
|
|
List<Long> agreeOrNoticingExpertIds = CollUtils.fieldList(agreeOrNoticing, MeetingExpert::getExpertId); |
|
|
|
if (!agreeOrNoticingExpertIds.isEmpty()) { |
|
|
|
expertIdsNotIn.addAll(agreeOrNoticingExpertIds); |
|
|
|
if (AvoidTypeEnum.CURR_UNIT.equals(avoidType)) { |
|
|
|
List<ExpertUserFullInfo> agreeOrNoticingUserInfos = expertUserFullInfoService.listByUserIds(agreeOrNoticingExpertIds); |
|
|
|
Set<String> tmpUniqCompanyCodes = CollUtils.fieldSet(agreeOrNoticingUserInfos, ExpertUserFullInfo::getCompanyUniqCode); |
|
|
|
notInCompanyUniqCodeList.addAll(tmpUniqCompanyCodes); |
|
|
|
} else if (AvoidTypeEnum.CURR_STRIP.equals(avoidType)) { |
|
|
|
List<ExpertGovBusinessStrip> expertStrips = expertGovBusinessStripService.listByUserIds(agreeOrNoticingExpertIds); |
|
|
|
if (CollUtil.isNotEmpty(expertStrips)) { |
|
|
|
Set<String> businessStripCodes = CollUtils.fieldSet(expertStrips, ExpertGovBusinessStrip::getBusinessStripCode); |
|
|
|
query.notExists("select 1 from expert_gov_business_strip egbs " + |
|
|
|
"where egbs.expertUserId = nd_expert_user_full_info.user_id " + |
|
|
|
"and egbs.business_strip_code in " + BizUtils.inSqlJoin(businessStripCodes)); |
|
|
|
} |
|
|
|
} |
|
|
|
buildAvoidUnitStripForQuery(agreeOrNoticingExpertIds, avoidType, avoidUnitCodes, query); |
|
|
|
} |
|
|
|
// 已请假的专家不再抽取 |
|
|
|
List<MeetingExpert> expertsOnLeave = expertGroupByStatus.get(ON_LEAVE); |
|
|
@@ -519,7 +511,7 @@ public class ExpertInviteManage { |
|
|
|
} else if (hasExpertIdNotIn) { |
|
|
|
query.notIn(ExpertUserFullInfo::getUserId, expertIdsNotIn); |
|
|
|
} |
|
|
|
query.notIn(!notInCompanyUniqCodeList.isEmpty(), ExpertUserFullInfo::getCompanyUniqCode, notInCompanyUniqCodeList); |
|
|
|
query.notIn(!avoidUnitCodes.isEmpty(), ExpertUserFullInfo::getCompanyUniqCode, avoidUnitCodes); |
|
|
|
List<ExpertUserFullInfo> userFullInfos = expertUserFullInfoService.list(query); |
|
|
|
if (userFullInfos.isEmpty()) { |
|
|
|
return result; |
|
|
@@ -591,7 +583,7 @@ public class ExpertInviteManage { |
|
|
|
randomRules.forEach(rule -> { |
|
|
|
ExpertChoseDTO tmpExperts = expertInviteByRandomRule(avoidRule, rule, chooseExpertIds, sTime, eTime, createOn); |
|
|
|
if (tmpExperts.getTotal() < rule.getCount()) { |
|
|
|
throw BizException.wrap("可抽取专家数量不足"); |
|
|
|
throw ReturnException.wrap("可抽取专家数量不足"); |
|
|
|
} |
|
|
|
expertsByRandom.add(tmpExperts); |
|
|
|
chooseExpertIds.addAll(CollUtils.fieldList(tmpExperts.getExperts(), ExpertUserFullInfo::getUserId)); |
|
|
|