From af1a58146c8b6c1ea61dfbd2ee8a124c211b6ed4 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Fri, 14 Apr 2023 15:41:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E6=8B=92=E7=BB=9D=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E6=8A=BD=E5=8F=96=E4=B8=8A=E4=B8=80=E8=BD=AE=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/meeting/entity/dto/InviteCacheDTO.java | 10 ++++++++- .../pmapi/meeting/manage/ExpertInviteManage.java | 21 +++++++++++------- .../pmapi/meeting/manage/MeetingManage.java | 3 ++- .../pmapi/meeting/task/ExpertInviteTask.java | 25 +++++++++++++--------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/InviteCacheDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/InviteCacheDTO.java index b7ed771..e8cbc0d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/InviteCacheDTO.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/InviteCacheDTO.java @@ -2,6 +2,8 @@ package com.ningdatech.pmapi.meeting.entity.dto; import lombok.Data; +import java.time.LocalDateTime; + /** *

* MeetingInviteDTO @@ -17,10 +19,16 @@ public final class InviteCacheDTO { private Boolean invitedRefused; - public static InviteCacheDTO of(Long meetingId, Boolean invitedRefused) { + /** + * 任务触发时间 + */ + private LocalDateTime taskStartTime; + + public static InviteCacheDTO of(Long meetingId, Boolean invitedRefused, LocalDateTime startTime) { InviteCacheDTO bo = new InviteCacheDTO(); bo.setMeetingId(meetingId); bo.setInvitedRefused(invitedRefused); + bo.setTaskStartTime(startTime); return bo; } 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 08adf25..2138639 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 @@ -36,6 +36,7 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.RandomUtils; import org.springframework.stereotype.Component; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -332,8 +333,8 @@ public class ExpertInviteManage { * @param randomRule 随机抽取 * @param invitedExperts 已抽取人员 * @param count 抽取数量 - * @param start 会议开始时间 - * @param end 会议结束时间 + * @param msTime 会议开始时间 + * @param meTime 会议结束时间 * @return {@link ExpertChooseDTO} * @author WendyYang **/ @@ -341,8 +342,9 @@ public class ExpertInviteManage { RandomInviteRuleDTO randomRule, Collection invitedExperts, Integer count, - LocalDateTime start, - LocalDateTime end, + LocalDateTime msTime, + LocalDateTime meTime, + LocalDateTime tsTime, boolean invitedRefused) { ExpertChooseDTO result = new ExpertChooseDTO(new ArrayList<>(), 0); // 合并标签、字典 @@ -373,16 +375,16 @@ public class ExpertInviteManage { return result; } } - List lockExpertIds = expertInviteHelper.listInvitedExpertByTime(start, end); + List lockExpertIds = expertInviteHelper.listInvitedExpertByTime(msTime, meTime); expertIdsIn.removeIf(lockExpertIds::contains); if (expertIdsIn.isEmpty()) { return result; } } else if (CollUtil.isNotEmpty(avoidRule.getExpertIds())) { - Set notInExpertIds = expertInviteHelper.getAvoidExpert(avoidRule.getExpertIds(), null, start, end); + Set notInExpertIds = expertInviteHelper.getAvoidExpert(avoidRule.getExpertIds(), null, msTime, meTime); expertIdsNotIn.addAll(notInExpertIds); } else { - Set notInUserIds = expertInviteHelper.listExpertLeaveOrInvited(start, end); + Set notInUserIds = expertInviteHelper.listExpertLeaveOrInvited(msTime, meTime); expertIdsNotIn.addAll(notInUserIds); } Map> expertGroupByStatus = invitedExperts.stream() @@ -402,7 +404,10 @@ public class ExpertInviteManage { // 拒绝参加的不可以被再次抽中 List refusedExperts = expertGroupByStatus.get(REFUSED); if (refusedExperts.size() > 0) { - List refusedExpertIds = CollUtils.fieldList(refusedExperts, MeetingExpert::getExpertId); + List refusedExpertIds = refusedExperts.stream() + .filter(w -> w.getCreateOn().isBefore(tsTime)) + .map(MeetingExpert::getExpertId) + .collect(Collectors.toList()); expertIdsNotIn.addAll(refusedExpertIds); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java index 52d7af7..ec3d202 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java @@ -236,8 +236,9 @@ public class MeetingManage { AvoidRuleDTO avoidInfo = req.getAvoidRule(); Assert.notNull(avoidInfo, "回避信息不能为空"); // 随机抽取的话则需进行抽取数量校验 + LocalDateTime now = LocalDateTime.now(); expertInviteManage.expertInviteByMeetingCreate(meeting, randomRules, avoidInfo); - expertInviteTask.addInviteTaskByMeetingCreate(meeting.getId(), 5); + expertInviteTask.addInviteTaskByMeetingCreate(meeting.getId(), 5, now); LambdaUpdateWrapper mUpdate = Wrappers.lambdaUpdate(Meeting.class) .set(Meeting::getInviteStatus, false) .eq(Meeting::getId, meeting.getId()); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertInviteTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertInviteTask.java index 25e97d5..157114d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertInviteTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertInviteTask.java @@ -112,7 +112,8 @@ public class ExpertInviteTask { Integer inviteDelay = properties.getInviteDelay(); for (InviteCacheDTO cache : caches.values()) { Boolean invitedRefused = cache.getInvitedRefused(); - boolean added = addInviteTask(cache.getMeetingId(), true, inviteDelay, invitedRefused); + LocalDateTime tsTime = cache.getTaskStartTime(); + boolean added = addInviteTask(cache.getMeetingId(), true, inviteDelay, invitedRefused, tsTime); if (!added) { cachePlusOps.hDel(getCacheKey(cache.getMeetingId())); } @@ -162,13 +163,13 @@ public class ExpertInviteTask { tmpInvitedRefused = invitedRefused[0]; } if (!INVITE_TASK_MAP.containsKey(meetingId)) { - if (addInviteTask(meetingId, false, properties.getInviteDelay(), tmpInvitedRefused)) { + if (addInviteTask(meetingId, false, properties.getInviteDelay(), tmpInvitedRefused, LocalDateTime.now())) { log.info("重置会议的随机抽取状态:{}", meetingId); LambdaUpdateWrapper update = Wrappers.lambdaUpdate(Meeting.class); update.set(Meeting::getInviteStatus, false); update.eq(Meeting::getId, meetingId); meetingService.update(update); - InviteCacheDTO cacheVal = InviteCacheDTO.of(meetingId, tmpInvitedRefused); + InviteCacheDTO cacheVal = InviteCacheDTO.of(meetingId, tmpInvitedRefused, LocalDateTime.now()); cachePlusOps.hSet(getCacheKey(meetingId), cacheVal); } } @@ -184,7 +185,7 @@ public class ExpertInviteTask { * @return 是否添加任务成功 * @author WendyYang **/ - public boolean addInviteTask(Long meetingId, boolean checked, int delayedMinutes, boolean invitedRefused) { + public boolean addInviteTask(Long meetingId, boolean checked, int delayedMinutes, boolean invitedRefused, LocalDateTime tsTime) { if (checked && !inviteCountCheck(meetingId)) { // 如果抽取数量满足直接返回 return Boolean.FALSE; @@ -193,7 +194,7 @@ public class ExpertInviteTask { ScheduledFuture future = scheduler.scheduleAtFixedRate(() -> { ExpertInviteTask bean = SpringContextHolder.getBean(ExpertInviteTask.class); try { - bean.invite(meetingId, invitedRefused); + bean.invite(meetingId, invitedRefused, tsTime); } catch (Exception e) { log.error("执行专家邀请任务异常:{}", meetingId, e); } @@ -208,12 +209,13 @@ public class ExpertInviteTask { * * @param meetingId 会议ID * @param delayedMinutes 延迟时间 + * @param tsTime 开始时间 * @author WendyYang **/ - public void addInviteTaskByMeetingCreate(Long meetingId, int delayedMinutes) { + public void addInviteTaskByMeetingCreate(Long meetingId, int delayedMinutes, LocalDateTime tsTime) { Assert.isTrue(properties.getEnable(), "随机邀请已关闭"); - addInviteTask(meetingId, false, delayedMinutes, false); - InviteCacheDTO cacheVal = InviteCacheDTO.of(meetingId, false); + addInviteTask(meetingId, false, delayedMinutes, false, tsTime); + InviteCacheDTO cacheVal = InviteCacheDTO.of(meetingId, false, tsTime); cachePlusOps.hSet(getCacheKey(meetingId), cacheVal); } @@ -222,9 +224,10 @@ public class ExpertInviteTask { * * @param meetingId 会议ID * @param invitedRefused 是否可以邀请已拒绝的专家 + * @param tsTime 任务开启时间 */ @Transactional(rollbackFor = Exception.class) - public void invite(Long meetingId, Boolean invitedRefused) { + public void invite(Long meetingId, Boolean invitedRefused, LocalDateTime tsTime) { log.info("开始进行专家后台抽取:{}", meetingId); Meeting meeting = meetingService.getById(meetingId); if (meeting.getStartTime().isBefore(LocalDateTime.now())) { @@ -239,6 +242,8 @@ public class ExpertInviteTask { // 还需要抽取的规则数量 AtomicInteger notIgnoreCnt = new AtomicInteger(ruleMap.size()); 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); @@ -254,7 +259,7 @@ public class ExpertInviteTask { } int needInviteCnt = value.getCount() - wouldAttendCnt; ExpertChooseDTO expertChoose = expertInviteManage.expertReplaceByRandomRule(avoidRule, value, - tmpExperts, needInviteCnt, meeting.getStartTime(), meeting.getEndTime(), invitedRefused); + tmpExperts, needInviteCnt, msTime, meTime, tsTime, invitedRefused); if (expertChoose.getTotal() > 0) { List expertMeetings = CollUtils.convert(expertChoose.getExperts(), w -> {