From 5c498c3f47f9233dc61472601894f5cbafeab9e4 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 13 Mar 2023 10:39:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ningdatech/pmapi/meeting/manage/MeetingManage.java | 2 +- .../com/ningdatech/pmapi/meeting/task/ExpertInviteTask.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) 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 30f61d5..47fa752 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 @@ -209,7 +209,7 @@ public class MeetingManage { Assert.isTrue(checkCount >= inviteCount, "可供抽取的专家数量不足"); } expertInviteManage.expertInviteByMeetingCreate(meeting, randomRules, avoidInfo); - expertInviteTask.addInviteExpertTaskByMeetingCreate(meeting.getId(), 5); + expertInviteTask.addInviteTaskByMeetingCreate(meeting.getId(), 5); LambdaUpdateWrapper update = Wrappers.lambdaUpdate(Meeting.class); update.set(Meeting::getInviteStatus, false); update.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 f58915e..cd6b57c 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 @@ -109,7 +109,7 @@ public class ExpertInviteTask { return; } for (InviteCacheDTO cache : caches.values()) { - addInviteExpertTask(cache.getMeetingId(), true, properties.getInviteDelay(), cache.getInvitedRefused()); + addInviteTask(cache.getMeetingId(), true, properties.getInviteDelay(), cache.getInvitedRefused()); } } @@ -156,7 +156,7 @@ public class ExpertInviteTask { tmpInvitedRefused = invitedRefused[0]; } if (!INVITE_MAP.containsKey(meetingId)) { - addInviteExpertTask(meetingId, false, properties.getInviteDelay(), tmpInvitedRefused); + addInviteTask(meetingId, false, properties.getInviteDelay(), tmpInvitedRefused); log.info("重置会议的随机抽取状态:{}", meetingId); LambdaUpdateWrapper update = Wrappers.lambdaUpdate(Meeting.class); update.set(Meeting::getInviteStatus, false); @@ -176,7 +176,7 @@ public class ExpertInviteTask { * @param invitedRefused 是否可以邀请被拒绝的专家 * @author WendyYang **/ - public void addInviteExpertTask(Long meetingId, boolean checked, int delayedMinutes, boolean invitedRefused) { + public void addInviteTask(Long meetingId, boolean checked, int delayedMinutes, boolean invitedRefused) { if (checked && !inviteCountCheck(meetingId)) { // 如果抽取数量满足直接返回 return; @@ -201,9 +201,9 @@ public class ExpertInviteTask { * @param delayedMinutes 延迟时间 * @author WendyYang **/ - public void addInviteExpertTaskByMeetingCreate(Long meetingId, int delayedMinutes) { + public void addInviteTaskByMeetingCreate(Long meetingId, int delayedMinutes) { Assert.isTrue(properties.getEnable(), "随机邀请已关闭"); - addInviteExpertTask(meetingId, false, delayedMinutes, false); + addInviteTask(meetingId, false, delayedMinutes, false); InviteCacheDTO cacheVal = InviteCacheDTO.of(meetingId, false); cachePlusOps.hSet(getCacheKey(meetingId), cacheVal); } From d9953c41c71dd45e2a1a2bc0e7698c7e2b0ecc5e Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 13 Mar 2023 10:46:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/meeting/task/ExpertInviteTask.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 cd6b57c..8b0b0ac 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 @@ -78,9 +78,9 @@ public class ExpertInviteTask { private final YxtCallOrSmsHelper yxtCallOrSmsHelper; /** - * 用来存入线程执行情况, 方便于停止定时任务时使用 + * 用来存入线程执行句柄, 停止定时任务时使用 */ - protected static final ConcurrentMap> INVITE_MAP = new ConcurrentHashMap<>(); + private static final ConcurrentMap> INVITE_TASK_MAP = new ConcurrentHashMap<>(); public ExpertInviteTask currProxy() { return (ExpertInviteTask) AopContext.currentProxy(); @@ -155,7 +155,7 @@ public class ExpertInviteTask { if (ArrayUtil.isNotEmpty(invitedRefused)) { tmpInvitedRefused = invitedRefused[0]; } - if (!INVITE_MAP.containsKey(meetingId)) { + if (!INVITE_TASK_MAP.containsKey(meetingId)) { addInviteTask(meetingId, false, properties.getInviteDelay(), tmpInvitedRefused); log.info("重置会议的随机抽取状态:{}", meetingId); LambdaUpdateWrapper update = Wrappers.lambdaUpdate(Meeting.class); @@ -190,7 +190,7 @@ public class ExpertInviteTask { log.error("执行专家邀请任务异常:{}", meetingId, e); } }, startTime, Duration.ofMinutes(properties.getInviteFixedRate())); - INVITE_MAP.putIfAbsent(meetingId, future); + INVITE_TASK_MAP.putIfAbsent(meetingId, future); log.info("添加专家抽取后台任务:{}", meetingId); } @@ -208,6 +208,12 @@ public class ExpertInviteTask { cachePlusOps.hSet(getCacheKey(meetingId), cacheVal); } + /** + * 抽取过程 + * + * @param meetingId 会议ID + * @param invitedRefused 是否可以邀请已拒绝的专家 + */ @Transactional(rollbackFor = Exception.class) public void invite(Long meetingId, Boolean invitedRefused) { log.info("开始进行专家后台抽取:{}", meetingId); @@ -269,9 +275,9 @@ public class ExpertInviteTask { log.info("终止专家抽取:{}", meetingId); meetingService.stopRandomInvite(meetingId); cachePlusOps.hDel(getCacheKey(meetingId)); - ScheduledFuture future = INVITE_MAP.get(meetingId); + ScheduledFuture future = INVITE_TASK_MAP.get(meetingId); if (future != null) { - INVITE_MAP.remove(meetingId); + INVITE_TASK_MAP.remove(meetingId); if (!future.isCancelled()) { future.cancel(true); }