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 -> {