|
|
|
|
@ -1,14 +1,22 @@ |
|
|
|
|
package org.springblade.system.user.util; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import org.springblade.resource.enums.SysTypeEnum; |
|
|
|
|
import org.springblade.resource.feign.IMessageClient; |
|
|
|
|
import org.springblade.system.user.entity.Train; |
|
|
|
|
import org.springblade.system.user.entity.TrainPerson; |
|
|
|
|
import org.springblade.system.user.entity.TrainSpeak; |
|
|
|
|
import org.springblade.system.user.service.ITrainPersonService; |
|
|
|
|
import org.springblade.system.user.service.ITrainService; |
|
|
|
|
import org.springblade.system.user.service.ITrainSpeakService; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.data.redis.connection.Message; |
|
|
|
|
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; |
|
|
|
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* redis监听器,监听key过期事件并处理 |
|
|
|
|
* @author ytl |
|
|
|
|
@ -19,6 +27,15 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene |
|
|
|
|
@Autowired |
|
|
|
|
private ITrainService trainService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IMessageClient messageClient; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ITrainSpeakService trainSpeakService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ITrainPersonService trainPersonService; |
|
|
|
|
|
|
|
|
|
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { |
|
|
|
|
super(listenerContainer); |
|
|
|
|
} |
|
|
|
|
@ -27,11 +44,25 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene |
|
|
|
|
public void onMessage(Message message, byte[] pattern) { |
|
|
|
|
// 获取到失效的 key,进行取消订单业务处理
|
|
|
|
|
String expiredKey = message.toString(); |
|
|
|
|
System.out.println("缓存过期的key为:" + expiredKey); |
|
|
|
|
// System.out.println("缓存过期的key为:" + expiredKey);
|
|
|
|
|
LambdaQueryWrapper<Train> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
queryWrapper.eq(Train::getId,expiredKey); |
|
|
|
|
Train train = trainService.getOne(queryWrapper); |
|
|
|
|
System.out.println(train.getName()); |
|
|
|
|
//这里可以根据培训的id查询到培训的具体信息,然后再实现通知功能
|
|
|
|
|
//获取培训人员信息并发消息
|
|
|
|
|
LambdaQueryWrapper<TrainPerson> personWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
personWrapper.eq(TrainPerson::getTrainId, train.getId()); |
|
|
|
|
List<TrainPerson> list = trainPersonService.list(personWrapper); |
|
|
|
|
for(TrainPerson person : list){ |
|
|
|
|
messageClient.event(SysTypeEnum.INFORM.getValue(), "会议提醒", |
|
|
|
|
"您有新的会议将在" + train.getDuration() + "分钟后开始,请准时参加!", 1, 5, person.getPersonName(), "/train/project"); |
|
|
|
|
} |
|
|
|
|
//获取讲师信息并发消息
|
|
|
|
|
LambdaQueryWrapper<TrainSpeak> speakWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
speakWrapper.eq(TrainSpeak::getTrainId, train.getId()); |
|
|
|
|
TrainSpeak teacher = trainSpeakService.getOne(speakWrapper); |
|
|
|
|
messageClient.event(SysTypeEnum.INFORM.getValue(), "会议提醒", |
|
|
|
|
"您有新的会议将在" + train.getDuration() + "分钟后开始,请准时参加!", 1, 5, teacher.getSpeakName(), "/train/project"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|