diff --git a/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java b/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java index 8665ab4..e69dea9 100644 --- a/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java +++ b/src/main/java/io/qyi/e5/config/security/filter/LinkTokenAuthenticationFilter.java @@ -37,10 +37,10 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter { if (token != null) { RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class); if (redisUtil.hasKey("token:" + token)) { - Map userInfo = redisUtil.hmget("token:" +token); + Map userInfo = redisUtil.hmget("token:" + token); // 将未认证的Authentication转换成自定义的用户认证Token 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")); authenticationToken1.setDetails(authenticationToken); SecurityContextHolder.getContext().setAuthentication(authenticationToken1); @@ -50,7 +50,7 @@ public class LinkTokenAuthenticationFilter extends OncePerRequestFilter { System.out.println("--------------Token鉴权---------------"); /*设置跨域*/ 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-Methods", "GET, HEAD, POST"); response.setHeader("Access-Control-Max-Age", "3600"); diff --git a/src/main/java/io/qyi/e5/controller/TestController.java b/src/main/java/io/qyi/e5/controller/TestController.java index e6b1314..3475272 100644 --- a/src/main/java/io/qyi/e5/controller/TestController.java +++ b/src/main/java/io/qyi/e5/controller/TestController.java @@ -5,6 +5,7 @@ import com.google.gson.Gson; import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.service.IOutlookService; import io.qyi.e5.service.task.ITask; +import io.qyi.e5.util.redis.RedisUtil; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; @@ -33,8 +34,18 @@ public class TestController { @Autowired ITask Task; + @Autowired + RedisUtil redisUtil; + @GetMapping("/send") - public void aaa() { + public void send() { Task.sendTaskOutlookMQ(19658189); } + @GetMapping("/sendAll") + public String sendAll() { + Task.sendTaskOutlookMQALL(); + return "ok"; + } + + } diff --git a/src/main/java/io/qyi/e5/controller/web/WebController.java b/src/main/java/io/qyi/e5/controller/web/WebController.java index 5b1f373..48390a1 100644 --- a/src/main/java/io/qyi/e5/controller/web/WebController.java +++ b/src/main/java/io/qyi/e5/controller/web/WebController.java @@ -1,12 +1,21 @@ package io.qyi.e5.controller.web; 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_log.service.IOutlookLogService; import io.qyi.e5.util.ResultUtil; +import io.qyi.e5.util.redis.RedisUtil; 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.RestController; +import java.util.HashMap; +import java.util.Map; + /** * @program: e5 * @description: @@ -19,9 +28,48 @@ public class WebController { @Autowired IOutlookService outlookService; + @Autowired + IGithubService GithubService; + + @Autowired + IOutlookLogService iOutlookLogService; + + @Autowired + RedisUtil redisUtil; + @RequestMapping("/") public Result index() { 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 map = new HashMap<>(); + map.put("outlooklog", outlooklog); + map.put("outlook", outlook); + map.put("github", github); + return ResultUtil.success(map); + + } + } diff --git a/src/main/java/io/qyi/e5/github/service/IGithubService.java b/src/main/java/io/qyi/e5/github/service/IGithubService.java index 9d1fb0a..3cc2a32 100644 --- a/src/main/java/io/qyi/e5/github/service/IGithubService.java +++ b/src/main/java/io/qyi/e5/github/service/IGithubService.java @@ -23,4 +23,6 @@ public interface IGithubService extends IService { Github selectOne(QueryWrapper queryWrapper); void insert(Github github); + + int deleteInfo(int github_id); } diff --git a/src/main/java/io/qyi/e5/github/service/impl/GithubServiceImpl.java b/src/main/java/io/qyi/e5/github/service/impl/GithubServiceImpl.java index b762a0d..b3849a3 100644 --- a/src/main/java/io/qyi/e5/github/service/impl/GithubServiceImpl.java +++ b/src/main/java/io/qyi/e5/github/service/impl/GithubServiceImpl.java @@ -3,6 +3,7 @@ package io.qyi.e5.github.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.qyi.e5.github.entity.Github; import io.qyi.e5.github.entity.UserInfo; @@ -103,4 +104,19 @@ public class GithubServiceImpl extends ServiceImpl impleme public void insert(Github github) { baseMapper.insert(github); } + + /** + * 删除此用户 + * @Description: + * @param: * @param + * @return: void + * @Author: 落叶随风 + * @Date: 2020/4/17 + */ + @Override + public int deleteInfo(int github_id) { + QueryWrapper githubQueryWrapper = new QueryWrapper<>(); + githubQueryWrapper.eq("github_id", github_id); + return baseMapper.delete(githubQueryWrapper); + } } diff --git a/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java b/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java index 68b51b5..f87b938 100644 --- a/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java +++ b/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java @@ -25,4 +25,5 @@ public interface IOutlookService extends IService { List findAll(); + int deleteInfo(int github_id); } diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java index a1f9cb8..c17658a 100644 --- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java @@ -132,6 +132,21 @@ public class OutlookServiceImpl extends ServiceImpl impl 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 outlookQueryWrapper = new QueryWrapper<>(); + outlookQueryWrapper.eq("github_id", github_id); + return baseMapper.delete(outlookQueryWrapper); + } + @Override public boolean getMailList(Outlook outlook) { try { diff --git a/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java b/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java index 6adddd3..91d65fc 100644 --- a/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java +++ b/src/main/java/io/qyi/e5/outlook_log/service/IOutlookLogService.java @@ -13,5 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface IOutlookLogService extends IService { void addLog(int githubId, String msg,int result,String original_msg); - + int deleteInfo(int github_id); } diff --git a/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java b/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java index 6ee9857..1b260f4 100644 --- a/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook_log/service/impl/OutlookLogServiceImpl.java @@ -1,5 +1,6 @@ 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.mapper.OutlookLogMapper; import io.qyi.e5.outlook_log.service.IOutlookLogService; @@ -27,4 +28,11 @@ public class OutlookLogServiceImpl extends ServiceImpl outlookLogQueryWrapper = new QueryWrapper<>(); + outlookLogQueryWrapper.eq("github_id", github_id); + return baseMapper.delete(outlookLogQueryWrapper); + } } diff --git a/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java b/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java index 987858a..f062aaa 100644 --- a/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java +++ b/src/main/java/io/qyi/e5/service/rabbitMQ/impl/ListenerImpl.java @@ -38,11 +38,14 @@ public class ListenerImpl { @RabbitListener(queues = "delay_queue2", containerFactory = "rabbitListenerContainerFactory") public void listen(Message message, Channel channel) throws IOException { logger.info("消费者1开始处理消息: {},时间戳:{}" ,message,System.currentTimeMillis()); + System.out.println("消费者1开始处理消息:"+System.currentTimeMillis()); int github_id = Integer.valueOf(new String(message.getBody())); try { Outlook Outlook = outlookService.getOne(new QueryWrapper().eq("github_id", github_id)); if (Outlook == null) { logger.warn("未找到此用户,github_id: {}",github_id); + /*这里也发送ack,不然会照成队列堆积*/ + channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); return; } outlookService.getMailList(Outlook); diff --git a/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java b/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java index 5d4559d..4cfa034 100644 --- a/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java +++ b/src/main/java/io/qyi/e5/service/task/impl/TaskImpl.java @@ -36,14 +36,13 @@ public class TaskImpl implements ITask { @Override @Async public void sendTaskOutlookMQ(int github_id) { - CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); Outlook Outlook = outlookService.getOne(new QueryWrapper().eq("github_id", github_id)); if (Outlook == null) { logger.warn("未找到此用户,github_id: {}",github_id); return; } /*根据用户设置生成随机数*/ - String Expiration = getRandom( Outlook.getCronTimeRandomEnd(),Outlook.getCronTimeRandomEnd()); + String Expiration = getRandom( Outlook.getCronTimeRandomStart(),Outlook.getCronTimeRandomEnd()); send(github_id,Expiration); } @@ -56,7 +55,7 @@ public class TaskImpl implements ITask { while (iterator.hasNext()) { Outlook next = iterator.next(); /*根据用户设置生成随机数*/ - String Expiration = getRandom( next.getCronTimeRandomEnd(),next.getCronTimeRandomEnd()); + String Expiration = getRandom( next.getCronTimeRandomStart(),next.getCronTimeRandomEnd()); send(next.getGithubId(), Expiration); } } @@ -92,7 +91,7 @@ public class TaskImpl implements ITask { */ public String getRandom(int start, int end){ 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; } } diff --git a/src/test/java/io/qyi/e5/string/dome01.java b/src/test/java/io/qyi/e5/string/dome01.java index e9e4cdc..8694502 100644 --- a/src/test/java/io/qyi/e5/string/dome01.java +++ b/src/test/java/io/qyi/e5/string/dome01.java @@ -41,7 +41,15 @@ public class dome01 { @Test public void r(){ - Random r=new Random(); - System.out.println(r.nextInt(200-100+1)+100); + for (int i = 0; i < 30; i++) { + 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; } }