Browse Source

抽取拒绝只能抽取上一轮次

master
WendyYang 1 year ago
parent
commit
af1a58146c
4 changed files with 39 additions and 20 deletions
  1. +9
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/InviteCacheDTO.java
  2. +13
    -8
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertInviteManage.java
  3. +2
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java
  4. +15
    -10
      pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertInviteTask.java

+ 9
- 1
pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/InviteCacheDTO.java View File

@@ -2,6 +2,8 @@ package com.ningdatech.pmapi.meeting.entity.dto;


import lombok.Data; import lombok.Data;


import java.time.LocalDateTime;

/** /**
* <p> * <p>
* MeetingInviteDTO * MeetingInviteDTO
@@ -17,10 +19,16 @@ public final class InviteCacheDTO {


private Boolean invitedRefused; 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(); InviteCacheDTO bo = new InviteCacheDTO();
bo.setMeetingId(meetingId); bo.setMeetingId(meetingId);
bo.setInvitedRefused(invitedRefused); bo.setInvitedRefused(invitedRefused);
bo.setTaskStartTime(startTime);
return bo; return bo;
} }



+ 13
- 8
pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/ExpertInviteManage.java View File

@@ -36,6 +36,7 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;


import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -332,8 +333,8 @@ public class ExpertInviteManage {
* @param randomRule 随机抽取 * @param randomRule 随机抽取
* @param invitedExperts 已抽取人员 * @param invitedExperts 已抽取人员
* @param count 抽取数量 * @param count 抽取数量
* @param start 会议开始时间
* @param end 会议结束时间
* @param msTime 会议开始时间
* @param meTime 会议结束时间
* @return {@link ExpertChooseDTO} * @return {@link ExpertChooseDTO}
* @author WendyYang * @author WendyYang
**/ **/
@@ -341,8 +342,9 @@ public class ExpertInviteManage {
RandomInviteRuleDTO randomRule, RandomInviteRuleDTO randomRule,
Collection<MeetingExpert> invitedExperts, Collection<MeetingExpert> invitedExperts,
Integer count, Integer count,
LocalDateTime start,
LocalDateTime end,
LocalDateTime msTime,
LocalDateTime meTime,
LocalDateTime tsTime,
boolean invitedRefused) { boolean invitedRefused) {
ExpertChooseDTO result = new ExpertChooseDTO(new ArrayList<>(), 0); ExpertChooseDTO result = new ExpertChooseDTO(new ArrayList<>(), 0);
// 合并标签、字典 // 合并标签、字典
@@ -373,16 +375,16 @@ public class ExpertInviteManage {
return result; return result;
} }
} }
List<Long> lockExpertIds = expertInviteHelper.listInvitedExpertByTime(start, end);
List<Long> lockExpertIds = expertInviteHelper.listInvitedExpertByTime(msTime, meTime);
expertIdsIn.removeIf(lockExpertIds::contains); expertIdsIn.removeIf(lockExpertIds::contains);
if (expertIdsIn.isEmpty()) { if (expertIdsIn.isEmpty()) {
return result; return result;
} }
} else if (CollUtil.isNotEmpty(avoidRule.getExpertIds())) { } else if (CollUtil.isNotEmpty(avoidRule.getExpertIds())) {
Set<Long> notInExpertIds = expertInviteHelper.getAvoidExpert(avoidRule.getExpertIds(), null, start, end);
Set<Long> notInExpertIds = expertInviteHelper.getAvoidExpert(avoidRule.getExpertIds(), null, msTime, meTime);
expertIdsNotIn.addAll(notInExpertIds); expertIdsNotIn.addAll(notInExpertIds);
} else { } else {
Set<Long> notInUserIds = expertInviteHelper.listExpertLeaveOrInvited(start, end);
Set<Long> notInUserIds = expertInviteHelper.listExpertLeaveOrInvited(msTime, meTime);
expertIdsNotIn.addAll(notInUserIds); expertIdsNotIn.addAll(notInUserIds);
} }
Map<ExpertAttendStatusEnum, List<MeetingExpert>> expertGroupByStatus = invitedExperts.stream() Map<ExpertAttendStatusEnum, List<MeetingExpert>> expertGroupByStatus = invitedExperts.stream()
@@ -402,7 +404,10 @@ public class ExpertInviteManage {
// 拒绝参加的不可以被再次抽中 // 拒绝参加的不可以被再次抽中
List<MeetingExpert> refusedExperts = expertGroupByStatus.get(REFUSED); List<MeetingExpert> refusedExperts = expertGroupByStatus.get(REFUSED);
if (refusedExperts.size() > 0) { if (refusedExperts.size() > 0) {
List<Long> refusedExpertIds = CollUtils.fieldList(refusedExperts, MeetingExpert::getExpertId);
List<Long> refusedExpertIds = refusedExperts.stream()
.filter(w -> w.getCreateOn().isBefore(tsTime))
.map(MeetingExpert::getExpertId)
.collect(Collectors.toList());
expertIdsNotIn.addAll(refusedExpertIds); expertIdsNotIn.addAll(refusedExpertIds);
} }
} }


+ 2
- 1
pmapi/src/main/java/com/ningdatech/pmapi/meeting/manage/MeetingManage.java View File

@@ -236,8 +236,9 @@ public class MeetingManage {
AvoidRuleDTO avoidInfo = req.getAvoidRule(); AvoidRuleDTO avoidInfo = req.getAvoidRule();
Assert.notNull(avoidInfo, "回避信息不能为空"); Assert.notNull(avoidInfo, "回避信息不能为空");
// 随机抽取的话则需进行抽取数量校验 // 随机抽取的话则需进行抽取数量校验
LocalDateTime now = LocalDateTime.now();
expertInviteManage.expertInviteByMeetingCreate(meeting, randomRules, avoidInfo); expertInviteManage.expertInviteByMeetingCreate(meeting, randomRules, avoidInfo);
expertInviteTask.addInviteTaskByMeetingCreate(meeting.getId(), 5);
expertInviteTask.addInviteTaskByMeetingCreate(meeting.getId(), 5, now);
LambdaUpdateWrapper<Meeting> mUpdate = Wrappers.lambdaUpdate(Meeting.class) LambdaUpdateWrapper<Meeting> mUpdate = Wrappers.lambdaUpdate(Meeting.class)
.set(Meeting::getInviteStatus, false) .set(Meeting::getInviteStatus, false)
.eq(Meeting::getId, meeting.getId()); .eq(Meeting::getId, meeting.getId());


+ 15
- 10
pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertInviteTask.java View File

@@ -112,7 +112,8 @@ public class ExpertInviteTask {
Integer inviteDelay = properties.getInviteDelay(); Integer inviteDelay = properties.getInviteDelay();
for (InviteCacheDTO cache : caches.values()) { for (InviteCacheDTO cache : caches.values()) {
Boolean invitedRefused = cache.getInvitedRefused(); 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) { if (!added) {
cachePlusOps.hDel(getCacheKey(cache.getMeetingId())); cachePlusOps.hDel(getCacheKey(cache.getMeetingId()));
} }
@@ -162,13 +163,13 @@ public class ExpertInviteTask {
tmpInvitedRefused = invitedRefused[0]; tmpInvitedRefused = invitedRefused[0];
} }
if (!INVITE_TASK_MAP.containsKey(meetingId)) { 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); log.info("重置会议的随机抽取状态:{}", meetingId);
LambdaUpdateWrapper<Meeting> update = Wrappers.lambdaUpdate(Meeting.class); LambdaUpdateWrapper<Meeting> update = Wrappers.lambdaUpdate(Meeting.class);
update.set(Meeting::getInviteStatus, false); update.set(Meeting::getInviteStatus, false);
update.eq(Meeting::getId, meetingId); update.eq(Meeting::getId, meetingId);
meetingService.update(update); meetingService.update(update);
InviteCacheDTO cacheVal = InviteCacheDTO.of(meetingId, tmpInvitedRefused);
InviteCacheDTO cacheVal = InviteCacheDTO.of(meetingId, tmpInvitedRefused, LocalDateTime.now());
cachePlusOps.hSet(getCacheKey(meetingId), cacheVal); cachePlusOps.hSet(getCacheKey(meetingId), cacheVal);
} }
} }
@@ -184,7 +185,7 @@ public class ExpertInviteTask {
* @return 是否添加任务成功 * @return 是否添加任务成功
* @author WendyYang * @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)) { if (checked && !inviteCountCheck(meetingId)) {
// 如果抽取数量满足直接返回 // 如果抽取数量满足直接返回
return Boolean.FALSE; return Boolean.FALSE;
@@ -193,7 +194,7 @@ public class ExpertInviteTask {
ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> { ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(() -> {
ExpertInviteTask bean = SpringContextHolder.getBean(ExpertInviteTask.class); ExpertInviteTask bean = SpringContextHolder.getBean(ExpertInviteTask.class);
try { try {
bean.invite(meetingId, invitedRefused);
bean.invite(meetingId, invitedRefused, tsTime);
} catch (Exception e) { } catch (Exception e) {
log.error("执行专家邀请任务异常:{}", meetingId, e); log.error("执行专家邀请任务异常:{}", meetingId, e);
} }
@@ -208,12 +209,13 @@ public class ExpertInviteTask {
* *
* @param meetingId 会议ID * @param meetingId 会议ID
* @param delayedMinutes 延迟时间 * @param delayedMinutes 延迟时间
* @param tsTime 开始时间
* @author WendyYang * @author WendyYang
**/ **/
public void addInviteTaskByMeetingCreate(Long meetingId, int delayedMinutes) {
public void addInviteTaskByMeetingCreate(Long meetingId, int delayedMinutes, LocalDateTime tsTime) {
Assert.isTrue(properties.getEnable(), "随机邀请已关闭"); 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); cachePlusOps.hSet(getCacheKey(meetingId), cacheVal);
} }


@@ -222,9 +224,10 @@ public class ExpertInviteTask {
* *
* @param meetingId 会议ID * @param meetingId 会议ID
* @param invitedRefused 是否可以邀请已拒绝的专家 * @param invitedRefused 是否可以邀请已拒绝的专家
* @param tsTime 任务开启时间
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void invite(Long meetingId, Boolean invitedRefused) {
public void invite(Long meetingId, Boolean invitedRefused, LocalDateTime tsTime) {
log.info("开始进行专家后台抽取:{}", meetingId); log.info("开始进行专家后台抽取:{}", meetingId);
Meeting meeting = meetingService.getById(meetingId); Meeting meeting = meetingService.getById(meetingId);
if (meeting.getStartTime().isBefore(LocalDateTime.now())) { if (meeting.getStartTime().isBefore(LocalDateTime.now())) {
@@ -239,6 +242,8 @@ public class ExpertInviteTask {
// 还需要抽取的规则数量 // 还需要抽取的规则数量
AtomicInteger notIgnoreCnt = new AtomicInteger(ruleMap.size()); AtomicInteger notIgnoreCnt = new AtomicInteger(ruleMap.size());
AtomicInteger notSupportCnt = new AtomicInteger(0); AtomicInteger notSupportCnt = new AtomicInteger(0);
LocalDateTime msTime = meeting.getStartTime();
LocalDateTime meTime = meeting.getStartTime();
ruleMap.forEach((ruleId, value) -> { ruleMap.forEach((ruleId, value) -> {
List<MeetingExpert> tmpExperts = meetingExpertService.listExpertLastByMeetingId(meetingId); List<MeetingExpert> tmpExperts = meetingExpertService.listExpertLastByMeetingId(meetingId);
Map<Long, MeetingExpert> expertMap = CollUtils.listToMap(tmpExperts, MeetingExpert::getExpertId); Map<Long, MeetingExpert> expertMap = CollUtils.listToMap(tmpExperts, MeetingExpert::getExpertId);
@@ -254,7 +259,7 @@ public class ExpertInviteTask {
} }
int needInviteCnt = value.getCount() - wouldAttendCnt; int needInviteCnt = value.getCount() - wouldAttendCnt;
ExpertChooseDTO expertChoose = expertInviteManage.expertReplaceByRandomRule(avoidRule, value, ExpertChooseDTO expertChoose = expertInviteManage.expertReplaceByRandomRule(avoidRule, value,
tmpExperts, needInviteCnt, meeting.getStartTime(), meeting.getEndTime(), invitedRefused);
tmpExperts, needInviteCnt, msTime, meTime, tsTime, invitedRefused);


if (expertChoose.getTotal() > 0) { if (expertChoose.getTotal() > 0) {
List<MeetingExpert> expertMeetings = CollUtils.convert(expertChoose.getExperts(), w -> { List<MeetingExpert> expertMeetings = CollUtils.convert(expertChoose.getExperts(), w -> {


Loading…
Cancel
Save