mirror of
https://github.com/luoye663/e5.git
synced 2024-12-26 11:48:50 +00:00
修复能重复添加队列问题
新用户授权后自动添加进队列 (待添加功能,1、执行过程中授权失败将取消此api添加进队列2、)
This commit is contained in:
parent
8a5f152315
commit
516812f380
@ -47,5 +47,12 @@ public class TestController {
|
|||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/emptyRedis")
|
||||||
|
public String emptyRedis() {
|
||||||
|
redisUtil.deleteALL();
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import io.qyi.e5.bean.result.ResultEnum;
|
|||||||
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
|
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
|
||||||
import io.qyi.e5.outlook.entity.Outlook;
|
import io.qyi.e5.outlook.entity.Outlook;
|
||||||
import io.qyi.e5.outlook.service.IOutlookService;
|
import io.qyi.e5.outlook.service.IOutlookService;
|
||||||
|
import io.qyi.e5.service.task.ITask;
|
||||||
import io.qyi.e5.util.EncryptUtil;
|
import io.qyi.e5.util.EncryptUtil;
|
||||||
import io.qyi.e5.util.ResultUtil;
|
import io.qyi.e5.util.ResultUtil;
|
||||||
import io.qyi.e5.util.redis.RedisUtil;
|
import io.qyi.e5.util.redis.RedisUtil;
|
||||||
@ -42,6 +43,9 @@ public class AuthController {
|
|||||||
@Value("${outlook.authorize.url}")
|
@Value("${outlook.authorize.url}")
|
||||||
String authorizeUrl;
|
String authorizeUrl;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ITask Task;
|
||||||
|
|
||||||
@RequestMapping("/receive")
|
@RequestMapping("/receive")
|
||||||
public Result Receive(String code, String state, String session_state) throws Exception {
|
public Result Receive(String code, String state, String session_state) throws Exception {
|
||||||
if (!redisUtil.hasKey(states + state)) {
|
if (!redisUtil.hasKey(states + state)) {
|
||||||
@ -62,6 +66,8 @@ public class AuthController {
|
|||||||
if (!authorization_code) {
|
if (!authorization_code) {
|
||||||
return ResultUtil.error(-3, "clientId 或 clientSecret 填写错误!授权失败!");
|
return ResultUtil.error(-3, "clientId 或 clientSecret 填写错误!授权失败!");
|
||||||
}
|
}
|
||||||
|
/*添加此用户进消息队列*/
|
||||||
|
Task.executeE5(outlook.getGithubId());
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import io.qyi.e5.outlook.entity.Outlook;
|
import io.qyi.e5.outlook.entity.Outlook;
|
||||||
import io.qyi.e5.outlook.service.IOutlookService;
|
import io.qyi.e5.outlook.service.IOutlookService;
|
||||||
import io.qyi.e5.service.task.ITask;
|
import io.qyi.e5.service.task.ITask;
|
||||||
|
import io.qyi.e5.util.redis.RedisUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.amqp.core.MessageProperties;
|
import org.springframework.amqp.core.MessageProperties;
|
||||||
@ -33,6 +34,9 @@ public class TaskImpl implements ITask {
|
|||||||
@Autowired
|
@Autowired
|
||||||
RabbitTemplate rabbitTemplate;
|
RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Async
|
@Async
|
||||||
public void sendTaskOutlookMQ(int github_id) {
|
public void sendTaskOutlookMQ(int github_id) {
|
||||||
@ -42,9 +46,12 @@ public class TaskImpl implements ITask {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*根据用户设置生成随机数*/
|
/*根据用户设置生成随机数*/
|
||||||
String Expiration = getRandom(Outlook.getCronTimeRandomStart(), Outlook.getCronTimeRandomEnd());
|
int Expiration = getRandom(Outlook.getCronTimeRandomStart(), Outlook.getCronTimeRandomEnd());
|
||||||
send(github_id, Expiration);
|
/*将此用户信息加入redis,如果存在则代表在队列中,同时提前10秒过期*/
|
||||||
|
if (!redisUtil.hasKey("user.mq:" + github_id)) {
|
||||||
|
redisUtil.set("user.mq:" + github_id, 0, Expiration - 10);
|
||||||
|
send(github_id, Expiration* 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,14 +62,16 @@ public class TaskImpl implements ITask {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Outlook next = iterator.next();
|
Outlook next = iterator.next();
|
||||||
/*根据用户设置生成随机数*/
|
/*根据用户设置生成随机数*/
|
||||||
String Expiration = getRandom(next.getCronTimeRandomStart(), next.getCronTimeRandomEnd());
|
int Expiration = getRandom(next.getCronTimeRandomStart(), next.getCronTimeRandomEnd());
|
||||||
// System.out.println("生成随机调用时间,github ID" + next.getGithubId() + ",时间:" + Expiration);
|
/*将此用户信息加入redis,如果存在则代表在队列中,同时提前10秒过期*/
|
||||||
send(next.getGithubId(), Expiration);
|
if (!redisUtil.hasKey("user.mq:" + next.getGithubId())) {
|
||||||
|
redisUtil.set("user.mq:" + next.getGithubId(), 0, Expiration - 10);
|
||||||
|
send(next.getGithubId(), Expiration * 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Async
|
|
||||||
public void executeE5(int github_id) {
|
public void executeE5(int github_id) {
|
||||||
Outlook Outlook = outlookService.getOne(new QueryWrapper<Outlook>().eq("github_id", github_id));
|
Outlook Outlook = outlookService.getOne(new QueryWrapper<Outlook>().eq("github_id", github_id));
|
||||||
if (Outlook == null) {
|
if (Outlook == null) {
|
||||||
@ -82,7 +91,7 @@ public class TaskImpl implements ITask {
|
|||||||
* @Author: 落叶随风
|
* @Author: 落叶随风
|
||||||
* @Date: 2020/4/16
|
* @Date: 2020/4/16
|
||||||
*/
|
*/
|
||||||
public void send(Object msg, String Expiration) {
|
public void send(Object msg, int Expiration) {
|
||||||
CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
|
CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
|
||||||
|
|
||||||
rabbitTemplate.convertAndSend("delay", "delay", msg, message -> {
|
rabbitTemplate.convertAndSend("delay", "delay", msg, message -> {
|
||||||
@ -90,7 +99,7 @@ public class TaskImpl implements ITask {
|
|||||||
// 设置这条消息的过期时间
|
// 设置这条消息的过期时间
|
||||||
// messageProperties.setExpiration(Expiration);
|
// messageProperties.setExpiration(Expiration);
|
||||||
|
|
||||||
messageProperties.setHeader("x-delay",Expiration);
|
messageProperties.setHeader("x-delay", Expiration);
|
||||||
return message;
|
return message;
|
||||||
}, correlationData);
|
}, correlationData);
|
||||||
}
|
}
|
||||||
@ -105,9 +114,9 @@ public class TaskImpl implements ITask {
|
|||||||
* @Author: 落叶随风
|
* @Author: 落叶随风
|
||||||
* @Date: 2020/4/16
|
* @Date: 2020/4/16
|
||||||
*/
|
*/
|
||||||
public String getRandom(int start, int end) {
|
public int getRandom(int start, int end) {
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
String Expiration = String.valueOf((r.nextInt(end - start + 1) + start) * 1000);
|
int Expiration = (r.nextInt(end - start + 1) + start);
|
||||||
return Expiration;
|
return Expiration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,19 @@ public class RedisUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除所有键值对
|
||||||
|
* @title deleteALl
|
||||||
|
* @description
|
||||||
|
* @author 落叶随风
|
||||||
|
* @updateTime 2020/4/22 22:53
|
||||||
|
* @throws
|
||||||
|
*/
|
||||||
|
public void deleteALL() {
|
||||||
|
Set<String> keys = redisTemplate.keys("*");
|
||||||
|
redisTemplate.delete(keys);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据key 获取过期时间
|
* 根据key 获取过期时间
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user