From e3efe64926f33d85e93f420974423dfe5f8cb8bc Mon Sep 17 00:00:00 2001 From: APLS Date: Thu, 10 Dec 2020 23:08:50 +0800 Subject: [PATCH] ~ --- .gitignore | 2 ++ .../e5/config/security/SecurityConfig.java | 1 + .../GithubLoginAuthenticationFilter.java | 1 + .../service/impl/GithubServiceImpl.java | 2 +- .../qyi/e5/outlook/bean/bo/SaveRandomBo.java | 15 +++++++++++ .../io/qyi/e5/outlook/bean/bo/UpdateBo.java | 16 +++++++++++ .../outlook/controller/OutlookController.java | 27 ++++++++++++++----- .../service/impl/OutlookServiceImpl.java | 6 ++--- 8 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 src/main/java/io/qyi/e5/outlook/bean/bo/SaveRandomBo.java create mode 100644 src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java diff --git a/.gitignore b/.gitignore index 542b110..90057dc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /target/ /src/main/resources/application-online.properties.bak /src/main/resources/application.properties +/src/main/resources/application-online.properties.bak +/src/main/resources/application.properties diff --git a/src/main/java/io/qyi/e5/config/security/SecurityConfig.java b/src/main/java/io/qyi/e5/config/security/SecurityConfig.java index 6f3a2bb..0b83817 100644 --- a/src/main/java/io/qyi/e5/config/security/SecurityConfig.java +++ b/src/main/java/io/qyi/e5/config/security/SecurityConfig.java @@ -73,6 +73,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { /*验证token*/ http.addFilterBefore(new LinkTokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); http.csrf().disable().apply(githubAuth2AuthenticationConfig); +// http.addFilterAt(githubAuth2AuthenticationConfig, UsernamePasswordAuthenticationFilter.class); /*添加自定义权限管理器*/ http.authorizeRequests().anyRequest().authenticated().withObjectPostProcessor(filterSecurityInterceptorObjectPostProcessor()); /*关闭创建session*/ diff --git a/src/main/java/io/qyi/e5/config/security/filter/GithubLoginAuthenticationFilter.java b/src/main/java/io/qyi/e5/config/security/filter/GithubLoginAuthenticationFilter.java index d4f3164..21a158c 100644 --- a/src/main/java/io/qyi/e5/config/security/filter/GithubLoginAuthenticationFilter.java +++ b/src/main/java/io/qyi/e5/config/security/filter/GithubLoginAuthenticationFilter.java @@ -41,6 +41,7 @@ public class GithubLoginAuthenticationFilter extends AbstractAuthenticationProce public GithubLoginAuthenticationFilter() { super(new AntPathRequestMatcher("/auth2/receive", "GET")); + log.info("注册 LoginAuthenticationFilter"); } 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 75c8cb8..2cef9d2 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 @@ -10,9 +10,9 @@ import io.qyi.e5.github.entity.UserInfo; import io.qyi.e5.github.mapper.GithubMapper; import io.qyi.e5.github.service.IGithubService; import io.qyi.e5.util.StringUtil; -import io.qyi.e5.util.netRequest.OkHttpClientUtil; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import io.qyi.e5.util.netRequest.*; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/io/qyi/e5/outlook/bean/bo/SaveRandomBo.java b/src/main/java/io/qyi/e5/outlook/bean/bo/SaveRandomBo.java new file mode 100644 index 0000000..c5f91ff --- /dev/null +++ b/src/main/java/io/qyi/e5/outlook/bean/bo/SaveRandomBo.java @@ -0,0 +1,15 @@ +package io.qyi.e5.outlook.bean.bo; + +import lombok.Data; + +/** + * @program: e5 + * @description: + * @author: 落叶随风 + * @create: 2020-12-10 22:46 + **/ +@Data +public class SaveRandomBo { + private int cronTime; + private String crondomTime; +} diff --git a/src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java b/src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java new file mode 100644 index 0000000..66d9f46 --- /dev/null +++ b/src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java @@ -0,0 +1,16 @@ +package io.qyi.e5.outlook.bean.bo; + +import lombok.Data; + +/** + * @program: e5 + * @description: + * @author: 落叶随风 + * @create: 2020-12-10 22:36 + **/ +@Data +public class UpdateBo { + private String client_id; + private String client_secret; + private int outlook_id; +} diff --git a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java index fb2ece7..59d8c7e 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java @@ -8,6 +8,8 @@ import io.qyi.e5.config.ResultVO; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.bean.OutlookListVo; import io.qyi.e5.outlook.bean.OutlookVo; +import io.qyi.e5.outlook.bean.bo.SaveRandomBo; +import io.qyi.e5.outlook.bean.bo.UpdateBo; import io.qyi.e5.outlook.bean.bo.insertOneBO; import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.service.IOutlookService; @@ -47,18 +49,28 @@ public class OutlookController { } @PostMapping("/save") - public ResultVO save(@RequestParam String client_id, @RequestParam String client_secret,@RequestParam int outlook_id) { + public ResultVO save(@RequestBody UpdateBo bo) { UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); - if (outlookService.save(client_id, client_secret, outlook_id, authentication.getGithub_id())) { + if (outlookService.save(bo.getClient_id(), bo.getClient_secret(), bo.getOutlook_id(), authentication.getGithub_id())) { return new ResultVO<>(); } return new ResultVO<>(); } - + /** + * 保存调用时间 + * @title saveRandomTime + * @description + * @author 落叶随风 + * @param: cronTime + * @param: crondomTime + * @updateTime 2020/12/10 21:49 + * @return: io.qyi.e5.bean.result.Result + * @throws + */ @PostMapping("/saveRandomTime") - public Result saveRandomTime(@RequestParam int cronTime, @RequestParam String crondomTime) { - String[] split = crondomTime.split("-"); + public Result saveRandomTime(@RequestBody SaveRandomBo bo) { + String[] split = bo.getCrondomTime().split("-"); if (split.length != 2) { return ResultUtil.error(ResultEnum.INVALID_format); } @@ -84,18 +96,19 @@ public class OutlookController { return ResultUtil.error(-1, "最大间隔时间为 6 小时"); } UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); - if (outlookService.saveRandomTime(authentication.getGithub_id(), cronTime, cron_time_random_start, cron_time_random_end)) { + if (outlookService.saveRandomTime(authentication.getGithub_id(), bo.getCronTime(), cron_time_random_start, cron_time_random_end)) { return ResultUtil.success(); } return ResultUtil.error(ResultEnum.UNKNOWN_ERROR); } @GetMapping("/getOutlookInfo") - public Result getOutlookInfo() { + public Result getOutlookInfo(@RequestParam int id) { UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("github_id", github_id); + queryWrapper.eq("id", id); Outlook one = outlookService.getOne(queryWrapper); OutlookVo vo = new OutlookVo(); if (one != null) { 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 03d050c..8840b06 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 @@ -13,7 +13,7 @@ import io.qyi.e5.config.exception.APIException; import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.mapper.OutlookMapper; import io.qyi.e5.outlook.service.IOutlookService; -import io.qyi.e5.util.netRequest.OkHttpClientUtil; +import io.qyi.e5.util.netRequest.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,7 +98,7 @@ public class OutlookServiceImpl extends ServiceImpl impl if (github_id == 0) { throw new APIException(APiCode.OUTLOOK_NAME_NOT_NULL); } - if (outlook_id == 0) { + if (outlook_id == 0 || StringUtils.isBlank(client_id) || StringUtils.isBlank(client_secret)) { throw new APIException("缺少参数!"); } QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -110,7 +110,7 @@ public class OutlookServiceImpl extends ServiceImpl impl /*2020-12-10 mybatis plus问题导致会被截断*/ // Outlook outlook1 = baseMapper.selectOne(queryWrapper); - Outlook outlook1 = baseMapper.selectOutlookOne(outlook_id,github_id ); + Outlook outlook1 = baseMapper.selectOutlookOne(outlook_id, github_id); if (outlook1 == null) { throw new APIException("未查询到此条记录!"); }