mirror of
https://github.com/luoye663/e5.git
synced 2024-12-26 11:48:50 +00:00
修复正式环境无法取到reids信息问题
This commit is contained in:
parent
28e60a054b
commit
6591358b8c
@ -37,10 +37,10 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
if (token != null) {
|
if (token != null) {
|
||||||
RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
|
RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);
|
||||||
if (redisUtil.hasKey("token:" + token)) {
|
if (redisUtil.hasKey("token:" + token)) {
|
||||||
Map<Object, Object> userInfo = redisUtil.hmget("token:" +token);
|
Map<Object, Object> userInfo = redisUtil.hmget("token:" + token);
|
||||||
// 将未认证的Authentication转换成自定义的用户认证Token
|
// 将未认证的Authentication转换成自定义的用户认证Token
|
||||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken();
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken();
|
||||||
UsernamePasswordAuthenticationToken authenticationToken1 = new UsernamePasswordAuthenticationToken(userInfo.get("github_name").toString(),
|
UsernamePasswordAuthenticationToken authenticationToken1 = new UsernamePasswordAuthenticationToken(userInfo.get("github_name") == null ? "" : userInfo.get("github_name").toString(),
|
||||||
userInfo.get("avatar_url").toString(), (int) userInfo.get("github_id"), AuthorityUtils.createAuthorityList("user"));
|
userInfo.get("avatar_url").toString(), (int) userInfo.get("github_id"), AuthorityUtils.createAuthorityList("user"));
|
||||||
authenticationToken1.setDetails(authenticationToken);
|
authenticationToken1.setDetails(authenticationToken);
|
||||||
SecurityContextHolder.getContext().setAuthentication(authenticationToken1);
|
SecurityContextHolder.getContext().setAuthentication(authenticationToken1);
|
||||||
@ -50,7 +50,7 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
System.out.println("--------------Token鉴权---------------");
|
System.out.println("--------------Token鉴权---------------");
|
||||||
/*设置跨域*/
|
/*设置跨域*/
|
||||||
HttpServletResponse response = httpServletResponse;
|
HttpServletResponse response = httpServletResponse;
|
||||||
response.setHeader("Access-Control-Allow-Origin","*");
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST");
|
response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST");
|
||||||
response.setHeader("Access-Control-Max-Age", "3600");
|
response.setHeader("Access-Control-Max-Age", "3600");
|
||||||
|
@ -5,6 +5,7 @@ import com.google.gson.Gson;
|
|||||||
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.springframework.amqp.core.MessageProperties;
|
import org.springframework.amqp.core.MessageProperties;
|
||||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
@ -33,8 +34,18 @@ public class TestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ITask Task;
|
ITask Task;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
@GetMapping("/send")
|
@GetMapping("/send")
|
||||||
public void aaa() {
|
public void send() {
|
||||||
Task.sendTaskOutlookMQ(19658189);
|
Task.sendTaskOutlookMQ(19658189);
|
||||||
}
|
}
|
||||||
|
@GetMapping("/sendAll")
|
||||||
|
public String sendAll() {
|
||||||
|
Task.sendTaskOutlookMQALL();
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,21 @@
|
|||||||
package io.qyi.e5.controller.web;
|
package io.qyi.e5.controller.web;
|
||||||
|
|
||||||
import io.qyi.e5.bean.result.Result;
|
import io.qyi.e5.bean.result.Result;
|
||||||
|
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
|
||||||
|
import io.qyi.e5.github.service.IGithubService;
|
||||||
import io.qyi.e5.outlook.service.IOutlookService;
|
import io.qyi.e5.outlook.service.IOutlookService;
|
||||||
|
import io.qyi.e5.outlook_log.service.IOutlookLogService;
|
||||||
import io.qyi.e5.util.ResultUtil;
|
import io.qyi.e5.util.ResultUtil;
|
||||||
|
import io.qyi.e5.util.redis.RedisUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @program: e5
|
* @program: e5
|
||||||
* @description:
|
* @description:
|
||||||
@ -19,9 +28,48 @@ public class WebController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
IOutlookService outlookService;
|
IOutlookService outlookService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
IGithubService GithubService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
IOutlookLogService iOutlookLogService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RedisUtil redisUtil;
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public Result index() {
|
public Result index() {
|
||||||
return ResultUtil.error(-1, "This is api server!");
|
return ResultUtil.error(-1, "This is api server!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 删除用户信息
|
||||||
|
* @Description:
|
||||||
|
* @param: * @param
|
||||||
|
* @return: io.qyi.e5.bean.result.Result
|
||||||
|
* @Author: 落叶随风
|
||||||
|
* @Date: 2020/4/17
|
||||||
|
*/
|
||||||
|
@GetMapping("/user/delete")
|
||||||
|
public Result delete(){
|
||||||
|
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
/*删除数据库信息*/
|
||||||
|
int outlooklog = iOutlookLogService.deleteInfo(authentication.getGithub_id());
|
||||||
|
int outlook = outlookService.deleteInfo(authentication.getGithub_id());
|
||||||
|
int github = GithubService.deleteInfo(authentication.getGithub_id());
|
||||||
|
/*删除redis中信息*/
|
||||||
|
String token = authentication.getToken();
|
||||||
|
if (redisUtil.hasKey("token:" + token)) {
|
||||||
|
redisUtil.del("token:" + token);
|
||||||
|
}
|
||||||
|
/*返回结果信息*/
|
||||||
|
Map<String, Integer> map = new HashMap<>();
|
||||||
|
map.put("outlooklog", outlooklog);
|
||||||
|
map.put("outlook", outlook);
|
||||||
|
map.put("github", github);
|
||||||
|
return ResultUtil.success(map);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,4 +23,6 @@ public interface IGithubService extends IService<Github> {
|
|||||||
Github selectOne(QueryWrapper<Github> queryWrapper);
|
Github selectOne(QueryWrapper<Github> queryWrapper);
|
||||||
|
|
||||||
void insert(Github github);
|
void insert(Github github);
|
||||||
|
|
||||||
|
int deleteInfo(int github_id);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package io.qyi.e5.github.service.impl;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import io.qyi.e5.github.entity.Github;
|
import io.qyi.e5.github.entity.Github;
|
||||||
import io.qyi.e5.github.entity.UserInfo;
|
import io.qyi.e5.github.entity.UserInfo;
|
||||||
@ -103,4 +104,19 @@ public class GithubServiceImpl extends ServiceImpl<GithubMapper, Github> impleme
|
|||||||
public void insert(Github github) {
|
public void insert(Github github) {
|
||||||
baseMapper.insert(github);
|
baseMapper.insert(github);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除此用户
|
||||||
|
* @Description:
|
||||||
|
* @param: * @param
|
||||||
|
* @return: void
|
||||||
|
* @Author: 落叶随风
|
||||||
|
* @Date: 2020/4/17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteInfo(int github_id) {
|
||||||
|
QueryWrapper<Github> githubQueryWrapper = new QueryWrapper<>();
|
||||||
|
githubQueryWrapper.eq("github_id", github_id);
|
||||||
|
return baseMapper.delete(githubQueryWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,5 @@ public interface IOutlookService extends IService<Outlook> {
|
|||||||
|
|
||||||
List<Outlook> findAll();
|
List<Outlook> findAll();
|
||||||
|
|
||||||
|
int deleteInfo(int github_id);
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,21 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
|
|||||||
return baseMapper.selectList(null);
|
return baseMapper.selectList(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除用户outlook
|
||||||
|
* @Description:
|
||||||
|
* @param: * @param github_id
|
||||||
|
* @return: int
|
||||||
|
* @Author: 落叶随风
|
||||||
|
* @Date: 2020/4/17
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteInfo(int github_id) {
|
||||||
|
QueryWrapper<Outlook> outlookQueryWrapper = new QueryWrapper<>();
|
||||||
|
outlookQueryWrapper.eq("github_id", github_id);
|
||||||
|
return baseMapper.delete(outlookQueryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getMailList(Outlook outlook) {
|
public boolean getMailList(Outlook outlook) {
|
||||||
try {
|
try {
|
||||||
|
@ -13,5 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
*/
|
*/
|
||||||
public interface IOutlookLogService extends IService<OutlookLog> {
|
public interface IOutlookLogService extends IService<OutlookLog> {
|
||||||
void addLog(int githubId, String msg,int result,String original_msg);
|
void addLog(int githubId, String msg,int result,String original_msg);
|
||||||
|
int deleteInfo(int github_id);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package io.qyi.e5.outlook_log.service.impl;
|
package io.qyi.e5.outlook_log.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import io.qyi.e5.outlook_log.entity.OutlookLog;
|
import io.qyi.e5.outlook_log.entity.OutlookLog;
|
||||||
import io.qyi.e5.outlook_log.mapper.OutlookLogMapper;
|
import io.qyi.e5.outlook_log.mapper.OutlookLogMapper;
|
||||||
import io.qyi.e5.outlook_log.service.IOutlookLogService;
|
import io.qyi.e5.outlook_log.service.IOutlookLogService;
|
||||||
@ -27,4 +28,11 @@ public class OutlookLogServiceImpl extends ServiceImpl<OutlookLogMapper, Outlook
|
|||||||
|
|
||||||
baseMapper.insert(outlookLog);
|
baseMapper.insert(outlookLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteInfo(int github_id) {
|
||||||
|
QueryWrapper<OutlookLog> outlookLogQueryWrapper = new QueryWrapper<>();
|
||||||
|
outlookLogQueryWrapper.eq("github_id", github_id);
|
||||||
|
return baseMapper.delete(outlookLogQueryWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,14 @@ public class ListenerImpl {
|
|||||||
@RabbitListener(queues = "delay_queue2", containerFactory = "rabbitListenerContainerFactory")
|
@RabbitListener(queues = "delay_queue2", containerFactory = "rabbitListenerContainerFactory")
|
||||||
public void listen(Message message, Channel channel) throws IOException {
|
public void listen(Message message, Channel channel) throws IOException {
|
||||||
logger.info("消费者1开始处理消息: {},时间戳:{}" ,message,System.currentTimeMillis());
|
logger.info("消费者1开始处理消息: {},时间戳:{}" ,message,System.currentTimeMillis());
|
||||||
|
System.out.println("消费者1开始处理消息:"+System.currentTimeMillis());
|
||||||
int github_id = Integer.valueOf(new String(message.getBody()));
|
int github_id = Integer.valueOf(new String(message.getBody()));
|
||||||
try {
|
try {
|
||||||
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) {
|
||||||
logger.warn("未找到此用户,github_id: {}",github_id);
|
logger.warn("未找到此用户,github_id: {}",github_id);
|
||||||
|
/*这里也发送ack,不然会照成队列堆积*/
|
||||||
|
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
outlookService.getMailList(Outlook);
|
outlookService.getMailList(Outlook);
|
||||||
|
@ -36,14 +36,13 @@ public class TaskImpl implements ITask {
|
|||||||
@Override
|
@Override
|
||||||
@Async
|
@Async
|
||||||
public void sendTaskOutlookMQ(int github_id) {
|
public void sendTaskOutlookMQ(int github_id) {
|
||||||
CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
|
|
||||||
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) {
|
||||||
logger.warn("未找到此用户,github_id: {}",github_id);
|
logger.warn("未找到此用户,github_id: {}",github_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*根据用户设置生成随机数*/
|
/*根据用户设置生成随机数*/
|
||||||
String Expiration = getRandom( Outlook.getCronTimeRandomEnd(),Outlook.getCronTimeRandomEnd());
|
String Expiration = getRandom( Outlook.getCronTimeRandomStart(),Outlook.getCronTimeRandomEnd());
|
||||||
send(github_id,Expiration);
|
send(github_id,Expiration);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -56,7 +55,7 @@ public class TaskImpl implements ITask {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Outlook next = iterator.next();
|
Outlook next = iterator.next();
|
||||||
/*根据用户设置生成随机数*/
|
/*根据用户设置生成随机数*/
|
||||||
String Expiration = getRandom( next.getCronTimeRandomEnd(),next.getCronTimeRandomEnd());
|
String Expiration = getRandom( next.getCronTimeRandomStart(),next.getCronTimeRandomEnd());
|
||||||
send(next.getGithubId(), Expiration);
|
send(next.getGithubId(), Expiration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +91,7 @@ public class TaskImpl implements ITask {
|
|||||||
*/
|
*/
|
||||||
public String getRandom(int start, int end){
|
public String getRandom(int start, int end){
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
String Expiration = String.valueOf((r.nextInt(end - start + 1) + end) * 1000);
|
String Expiration = String.valueOf((r.nextInt(end - start + 1) + start) * 1000);
|
||||||
return Expiration;
|
return Expiration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,15 @@ public class dome01 {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void r(){
|
public void r(){
|
||||||
Random r=new Random();
|
for (int i = 0; i < 30; i++) {
|
||||||
System.out.println(r.nextInt(200-100+1)+100);
|
System.out.println(getRandom(60,120));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRandom(int start, int end){
|
||||||
|
Random r = new Random();
|
||||||
|
String Expiration = String.valueOf((r.nextInt(end-start +1) + start));
|
||||||
|
return Expiration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user