diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/dto/ExpertChoseDTO.java b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/dto/ExpertChoseDTO.java index d49be38..0ce1f2c 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/dto/ExpertChoseDTO.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/entity/dto/ExpertChoseDTO.java @@ -22,4 +22,8 @@ public class ExpertChoseDTO { private Integer total; + public boolean notEmpty() { + return total != null && total > 0; + } + } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/task/ExpertRandomInviteTask.java b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/task/ExpertRandomInviteTask.java index a4cde9d..063d973 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/meeting/task/ExpertRandomInviteTask.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/meeting/task/ExpertRandomInviteTask.java @@ -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 tmpExperts = meetingExpertService.listExpertLastByMeetingId(meetingId); - Map expertMap = CollUtils.listToMap(tmpExperts, MeetingExpert::getExpertId); + ruleMap.forEach((ruleId, rule) -> { + List newestExperts = meetingExpertService.listExpertLastByMeetingId(meetingId); // 统计通知中与同意参加专家数量 - Map countMap = countByAttendStatus(expertMap); + Map 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 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 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 buildSaveExpert(Long meetingId, Long ruleId, List 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 countByAttendStatus(Map expertMap) { - Map 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 expertAttendStatusCount(List 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