mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 02:08:15 +08:00
同步代码
This commit is contained in:
parent
fee1f4969f
commit
ca2cb70cf9
@ -0,0 +1,11 @@
|
|||||||
|
package com.ruoyi.demo.init;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 延迟队列执行器
|
||||||
|
* Created by LPB on 2021/04/20.
|
||||||
|
*/
|
||||||
|
public interface RedisDelayQueueHandle<T> {
|
||||||
|
|
||||||
|
void execute(T t);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package com.ruoyi.demo.init;/*
|
||||||
|
package cn.dbtalents.checktalents.init;
|
||||||
|
import cn.dbtalents.checktalents.enums.RedisDelayQueueEnum;
|
||||||
|
import cn.dbtalents.checktalents.handle.RedisDelayQueueHandle;
|
||||||
|
import cn.dbtalents.checktalents.util.RedisDelayQueueUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 启动延迟队列
|
||||||
|
*//*
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class RedisDelayQueueRunner implements CommandLineRunner {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisDelayQueueUtil redisDelayQueueUtil;
|
||||||
|
*/
|
||||||
|
/* @Autowired
|
||||||
|
private ThreadPoolTaskExecutor threadPool;
|
||||||
|
ThreadPoolExecutor executorService = new ThreadPoolExecutor(10, 50, 30, TimeUnit.SECONDS,
|
||||||
|
new LinkedBlockingQueue<Runnable>(1000), Executors.defaultThreadFactory());*//*
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(String... args) {
|
||||||
|
*/
|
||||||
|
/* threadPool.execute(() -> {
|
||||||
|
while (true){*//*
|
||||||
|
|
||||||
|
try {
|
||||||
|
RedisDelayQueueEnum[] queueEnums = RedisDelayQueueEnum.values();
|
||||||
|
for (RedisDelayQueueEnum queueEnum : queueEnums) {
|
||||||
|
Object value = redisDelayQueueUtil.getDelayQueue(queueEnum.getCode());
|
||||||
|
if (value != null) {
|
||||||
|
RedisDelayQueueHandle redisDelayQueueHandle = SpringUtil.getBean(queueEnum.getBeanId());
|
||||||
|
redisDelayQueueHandle.execute(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("(Redis延迟队列异常中断) {}", e.getMessage());
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
log.info("(Redis延迟队列启动成功)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
package com.ruoyi.demo.init;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.redisson.api.RBlockingQueue;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis 延时队列初始化
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class RedisDelayedQueueInit implements ApplicationContextAware {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取应用上下文并获取相应的接口实现类
|
||||||
|
* @param applicationContext
|
||||||
|
* @throws BeansException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
Map<String, RedisDelayQueueHandle> map = applicationContext.getBeansOfType(RedisDelayQueueHandle.class);
|
||||||
|
for (Map.Entry<String, RedisDelayQueueHandle> taskEventListenerEntry : map.entrySet()) {
|
||||||
|
String listenerName = taskEventListenerEntry.getValue().getClass().getName();
|
||||||
|
startThread(listenerName, taskEventListenerEntry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动线程获取队列
|
||||||
|
* @param queueName 队列名称
|
||||||
|
* @param redisDelayedQueueListener 任务回调监听
|
||||||
|
*/
|
||||||
|
private <T> void startThread(String queueName, RedisDelayQueueHandle redisDelayedQueueListener) {
|
||||||
|
RBlockingQueue<T> blockingFairQueue = redissonClient.getBlockingQueue(queueName);
|
||||||
|
//由于此线程需要常驻,可以新建线程,不用交给线程池管理
|
||||||
|
Thread thread = new Thread(() -> {
|
||||||
|
log.info("启动监听队列线程" + queueName);
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
T t = blockingFairQueue.take();
|
||||||
|
log.info("监听队列线程{},获取到值:{}", queueName, t);
|
||||||
|
redisDelayedQueueListener.execute(t);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("监听队列线程错误,", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.setName(queueName);
|
||||||
|
thread.start();
|
||||||
|
log.info("(Redis延迟队列启动成功)");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi-vue-plus</artifactId>
|
<artifactId>ruoyi-vue-plus</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>4.6.0</version>
|
<version>4.7.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
34
ruoyi-rabbitmq/pom.xml
Normal file
34
ruoyi-rabbitmq/pom.xml
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>ruoyi-vue-plus</artifactId>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<version>4.7.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<artifactId>ruoyi-rabbitmq</artifactId>
|
||||||
|
|
||||||
|
<description>
|
||||||
|
消息队列
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 通用工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--rabbitmq-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi-vue-plus</artifactId>
|
<artifactId>ruoyi-vue-plus</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>4.6.0</version>
|
<version>4.7.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@ -115,8 +115,8 @@ public class SysLoginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 小程序登录
|
* 邮箱登录
|
||||||
* @param xcxCode
|
* @param
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String emailLogin(String email, String emailCode) {
|
public String emailLogin(String email, String emailCode) {
|
||||||
@ -125,7 +125,7 @@ public class SysLoginService {
|
|||||||
|
|
||||||
checkLogin(LoginType.EMAIL, user.getUserName(), () -> !validateEmailCode(email, emailCode));
|
checkLogin(LoginType.EMAIL, user.getUserName(), () -> !validateEmailCode(email, emailCode));
|
||||||
// 此处可根据登录用户的数据不同 自行创建 loginUser
|
// 此处可根据登录用户的数据不同 自行创建 loginUser
|
||||||
LoginUser loginUser = buildLoginUser(user);
|
LoginUser loginUser = buildLoginSysUser(user);
|
||||||
// 生成token
|
// 生成token
|
||||||
LoginHelper.loginByDevice(loginUser, DeviceType.APP);
|
LoginHelper.loginByDevice(loginUser, DeviceType.APP);
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ public class SysLoginService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SysUser loadUserByEmail(String email) {
|
private SysUser loadUserByEmail(String email) {
|
||||||
SysUser user = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
SysUser user = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
||||||
.select(SysUser::getPhonenumber, SysUser::getStatus)
|
.select(SysUser::getPhonenumber, SysUser::getStatus)
|
||||||
.eq(SysUser::getEmail, email));
|
.eq(SysUser::getEmail, email));
|
||||||
if (ObjectUtil.isNull(user)) {
|
if (ObjectUtil.isNull(user)) {
|
||||||
@ -267,7 +267,7 @@ public class SysLoginService {
|
|||||||
log.info("登录用户:{} 已被停用.", email);
|
log.info("登录用户:{} 已被停用.", email);
|
||||||
throw new UserException("user.blocked", email);
|
throw new UserException("user.blocked", email);
|
||||||
}
|
}
|
||||||
return userMapper.selectUserByEmail(email);
|
return sysUserMapper.selectUserByEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SysUser loadUserByOpenid(String openid) {
|
private SysUser loadUserByOpenid(String openid) {
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>ruoyi-vue-plus</artifactId>
|
<artifactId>ruoyi-vue-plus</artifactId>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<version>4.6.0</version>
|
<version>4.7.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user