|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.util.ArrayUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.hz.pm.api.common.util.SpringContextHolder; |
|
|
|
import com.hz.pm.api.expert.entity.ExpertUserFullInfo; |
|
|
|
import com.hz.pm.api.meeting.builder.ExpertInviteBuilder; |
|
|
|
import com.hz.pm.api.meeting.entity.domain.Meeting; |
|
|
|
import com.hz.pm.api.meeting.entity.domain.MeetingExpert; |
|
|
@@ -41,13 +42,13 @@ import java.time.Instant; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalTime; |
|
|
|
import java.time.temporal.ChronoUnit; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentMap; |
|
|
|
import java.util.concurrent.ScheduledFuture; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@@ -274,33 +275,29 @@ public class ExpertRandomInviteTask { |
|
|
|
AtomicInteger notSupportCnt = new AtomicInteger(0); |
|
|
|
LocalDateTime msTime = meeting.getStartTime(); |
|
|
|
LocalDateTime meTime = meeting.getStartTime(); |
|
|
|
ruleMap.forEach((ruleId, value) -> { |
|
|
|
List<MeetingExpert> tmpExperts = meetingExpertService.listExpertLastByMeetingId(meetingId); |
|
|
|
Map<Long, MeetingExpert> expertMap = CollUtils.listToMap(tmpExperts, MeetingExpert::getExpertId); |
|
|
|
ruleMap.forEach((ruleId, rule) -> { |
|
|
|
List<MeetingExpert> newestExperts = meetingExpertService.listExpertLastByMeetingId(meetingId); |
|
|
|
// 统计通知中与同意参加专家数量 |
|
|
|
Map<Long, ExpertCntBO> countMap = countByAttendStatus(expertMap); |
|
|
|
Map<Long, ExpertCntBO> countMap = expertAttendStatusCount(newestExperts); |
|
|
|
ExpertCntBO cnt = countMap.getOrDefault(ruleId, ExpertCntBO.zeroInit()); |
|
|
|
int wouldAttendCnt = cnt.getAgreeCnt() + cnt.getNoticeCnt(); |
|
|
|
if (wouldAttendCnt == value.getCount()) { |
|
|
|
if (cnt.getAgreeCnt().equals(value.getCount())) { |
|
|
|
if (wouldAttendCnt == rule.getCount()) { |
|
|
|
if (cnt.getAgreeCnt().equals(rule.getCount())) { |
|
|
|
notIgnoreCnt.decrementAndGet(); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
int needInviteCnt = value.getCount() - wouldAttendCnt; |
|
|
|
ExpertChoseDTO expertChoose = expertInviteManage.expertReplaceByRandomRule(avoidRule, value, |
|
|
|
tmpExperts, needInviteCnt, msTime, meTime, tsTime, reInvite); |
|
|
|
|
|
|
|
if (expertChoose.getTotal() > 0) { |
|
|
|
List<MeetingExpert> expertMeetings = CollUtils.convert(expertChoose.getExperts(), w -> { |
|
|
|
MeetingExpert expert = ExpertInviteBuilder.getExpertByRandom(meetingId, w, ruleId); |
|
|
|
expert.setStatus(ExpertAttendStatusEnum.NOTICING.getCode()); |
|
|
|
return expert; |
|
|
|
}); |
|
|
|
int needInviteCnt = rule.getCount() - wouldAttendCnt; |
|
|
|
// 查询可抽取的专家 |
|
|
|
ExpertChoseDTO choseByRule = expertInviteManage.expertReplaceByRandomRule(avoidRule, rule, |
|
|
|
newestExperts, needInviteCnt, msTime, meTime, tsTime, reInvite); |
|
|
|
|
|
|
|
if (choseByRule.notEmpty()) { |
|
|
|
List<MeetingExpert> choseExperts = buildSaveExpert(meetingId, ruleId, choseByRule.getExperts()); |
|
|
|
// 短信或电话提醒 |
|
|
|
meetingNotifyHelper.notifyExperts(meeting, expertMeetings); |
|
|
|
log.info("会议:{} 后台抽取专家:{}名", meetingId, expertMeetings.size()); |
|
|
|
meetingExpertService.saveBatch(expertMeetings); |
|
|
|
meetingNotifyHelper.notifyExperts(meeting, choseExperts); |
|
|
|
meetingExpertService.saveBatch(choseExperts); |
|
|
|
log.info("会议:{} 抽取专家:{} 名", meetingId, choseExperts.size()); |
|
|
|
} else { |
|
|
|
// 抽取人数不够 |
|
|
|
notSupportCnt.incrementAndGet(); |
|
|
@@ -324,6 +321,14 @@ public class ExpertRandomInviteTask { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static List<MeetingExpert> buildSaveExpert(Long meetingId, Long ruleId, List<ExpertUserFullInfo> expertUsers) { |
|
|
|
return CollUtils.convert(expertUsers, w -> { |
|
|
|
MeetingExpert expert = ExpertInviteBuilder.getExpertByRandom(meetingId, w, ruleId); |
|
|
|
expert.setStatus(ExpertAttendStatusEnum.NOTICING.getCode()); |
|
|
|
return expert; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void killTaskAndDelCacheMeetingId(Long meetingId) { |
|
|
|
cachePlusOps.hDel(cacheKey(meetingId)); |
|
|
|
ScheduledFuture<?> future = INVITE_TASK_MAP.get(meetingId); |
|
|
@@ -344,18 +349,19 @@ public class ExpertRandomInviteTask { |
|
|
|
|
|
|
|
//================================================================================================================== |
|
|
|
|
|
|
|
private Map<Long, ExpertCntBO> countByAttendStatus(Map<Long, MeetingExpert> expertMap) { |
|
|
|
Map<Long, ExpertCntBO> cntMap = new HashMap<>(8); |
|
|
|
expertMap.values().forEach(w -> { |
|
|
|
Long ruleId = w.getRuleId(); |
|
|
|
ExpertCntBO cnt = cntMap.computeIfAbsent(ruleId, k -> ExpertCntBO.zeroInit()); |
|
|
|
if (ExpertAttendStatusEnum.AGREED.eq(w.getStatus())) { |
|
|
|
cnt.incrAgreeCnt(); |
|
|
|
} else if (ExpertAttendStatusEnum.NOTICING.eq(w.getStatus())) { |
|
|
|
cnt.incrNoticeCnt(); |
|
|
|
} |
|
|
|
}); |
|
|
|
return cntMap; |
|
|
|
private static Map<Long, ExpertCntBO> expertAttendStatusCount(List<MeetingExpert> experts) { |
|
|
|
return experts.stream().collect(Collectors.groupingBy(MeetingExpert::getRuleId, |
|
|
|
Collectors.collectingAndThen(Collectors.toList(), w -> { |
|
|
|
ExpertCntBO cnt = ExpertCntBO.zeroInit(); |
|
|
|
for (MeetingExpert expert : w) { |
|
|
|
if (ExpertAttendStatusEnum.AGREED.eq(expert.getStatus())) { |
|
|
|
cnt.incrAgreeCnt(); |
|
|
|
} else if (ExpertAttendStatusEnum.NOTICING.eq(expert.getStatus())) { |
|
|
|
cnt.incrNoticeCnt(); |
|
|
|
} |
|
|
|
} |
|
|
|
return cnt; |
|
|
|
}))); |
|
|
|
} |
|
|
|
|
|
|
|
@Data |
|
|
|