From 1cf4593feddb89c3d6323f4e17c30e868570b582 Mon Sep 17 00:00:00 2001 From: APLS Date: Sun, 13 Dec 2020 21:13:08 +0800 Subject: [PATCH] ~ --- .../e5/outlook/controller/AuthController.java | 16 ++++++---- .../outlook/controller/OutlookController.java | 23 +++++++++++++- .../e5/outlook/service/IOutlookService.java | 4 +++ .../service/impl/OutlookServiceImpl.java | 30 +++++++++++++++++-- .../controller/OutlookLogController.java | 25 ++++------------ .../qyi/e5/outlook_log/entity/OutlookLog.java | 5 ++++ 6 files changed, 75 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java index 23ea46e..45dc705 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java @@ -3,6 +3,8 @@ package io.qyi.e5.outlook.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.qyi.e5.bean.result.Result; import io.qyi.e5.bean.result.ResultEnum; +import io.qyi.e5.config.ResultVO; +import io.qyi.e5.config.exception.APIException; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.service.IOutlookService; @@ -49,7 +51,7 @@ public class AuthController { @RequestMapping("/receive") public Result Receive(String code, String state, String session_state) throws Exception { if (!redisUtil.hasKey(states + state)) { - return ResultUtil.error(-1, "state已过期,请到用户中心重新授权!"); + throw new APIException("state已过期,请到用户中心重新授权!"); } /*这里不应该查询,在进行授权时因该把基础数据丢到redis*/ QueryWrapper outlookQueryWrapper = new QueryWrapper<>(); @@ -58,13 +60,13 @@ public class AuthController { /*删除redis中的此键*/ redisUtil.del(states + state); if (outlook == null) { - return ResultUtil.error(-2, "没有查询到此用户,请检查是否在系统中注册!"); + throw new APIException("没有查询到此用户,请检查是否在系统中注册!"); } System.out.println(outlook); boolean authorization_code = outlookService.getTokenAndSave(code, outlook.getClientId(), outlook.getClientSecret(), "https://e5.qyi.io/outlook/auth2/receive" , "authorization_code"); if (!authorization_code) { - return ResultUtil.error(-3, "clientId 或 clientSecret 填写错误!授权失败!"); + throw new APIException("clientId 或 clientSecret 填写错误!授权失败!"); } /*添加此用户进消息队列*/ Task.sendTaskOutlookMQ(outlook.getGithubId()); @@ -72,16 +74,17 @@ public class AuthController { } @RequestMapping("/getAuthorizeUrl") - public Result getAuthorizeUrl() { + public Result getAuthorizeUrl(int id) { // 查询此用户的github_id与 QueryWrapper outlookQueryWrapper = new QueryWrapper<>(); UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); outlookQueryWrapper.eq("github_id", authentication.getGithub_id()); + outlookQueryWrapper.eq("id", id); Outlook outlook = outlookService.getOne(outlookQueryWrapper); if (outlook != null) { if (outlook.getClientId().length() < 1 || outlook.getClientSecret().length() < 1) { - return ResultUtil.error(ResultEnum.NO_DATA_FOUND); + throw new APIException("没有设置key你授权啥呢!!!"); } // 生成随机uuid标识用户 String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString()); @@ -89,7 +92,8 @@ public class AuthController { String url = String.format(authorizeUrl, outlook.getClientId(), "https://e5.qyi.io/outlook/auth2/receive", state); return ResultUtil.success(url); } else { - return ResultUtil.error(ResultEnum.NO_DATA_FOUND); + throw new APIException("没有此记录"); + } } 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 7df704d..58f5091 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java @@ -134,6 +134,27 @@ public class OutlookController { }); return ResultUtil.success(vo); } - + /** + * 设置状态暂停状态 + * @title setPause + * @description + * @author 落叶随风 + * @param: id outlook id + * @updateTime 2020/12/13 19:24 + * @return: io.qyi.e5.bean.result.Result + * @throws + */ + @GetMapping("/setPause") + public Result setPause(@RequestParam int id) { + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + outlookService.setPause(authentication.getGithub_id(),id); + return ResultUtil.success(); + } + @GetMapping("/setStart") + public Result setStart(@RequestParam int id) { + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + outlookService.setStart(authentication.getGithub_id(),id); + return ResultUtil.success(); + } } 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 9e7e49e..1a86146 100644 --- a/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java +++ b/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java @@ -30,4 +30,8 @@ public interface IOutlookService extends IService { int deleteInfo(int github_id); List getOutlooklist(int github_id); + + void setPause(int github_id, int outlookId); + + void setStart(int github_id, int outlookId); } 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 72a8dfc..fd3ceb0 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 @@ -117,7 +117,8 @@ public class OutlookServiceImpl extends ServiceImpl impl outlook1.setClientId(client_id); outlook1.setClientSecret(client_secret); outlook1.setStep(1) - .setStatus(8);; + .setStatus(8); + ; if (baseMapper.update(outlook1, queryWrapper) != 1) { throw new APIException("更新记录失败!"); } @@ -125,7 +126,7 @@ public class OutlookServiceImpl extends ServiceImpl impl } @Override - public boolean saveRandomTime(int github_id, int cron_time, int outlook_id ,int cron_time_random_start, int cron_time_random_end) { + public boolean saveRandomTime(int github_id, int cron_time, int outlook_id, int cron_time_random_start, int cron_time_random_end) { if (github_id == 0 || outlook_id == 0) { throw new APIException("缺少参数!"); } @@ -302,5 +303,30 @@ public class OutlookServiceImpl extends ServiceImpl impl List outlooks = baseMapper.selectList(qw); return outlooks; } + @Override + public void setPause(int github_id, int outlookId) { + UpdateWrapper up = new UpdateWrapper<>(); + up.eq("github_id", github_id).eq("id", outlookId); + Outlook outlook = baseMapper.selectOne(up); + if (outlook == null) { + throw new APIException("查无此记录!"); + } + /*只允许运行状态的应用设置暂停*/ + if (outlook.getStatus() != 2) { + throw new APIException("只允许 运行状态 的应用设置暂停!"); + } + if (baseMapper.update(new Outlook().setStatus(2), up) != 1) { + throw new APIException("更新失败!"); + } + } + + @Override + public void setStart(int github_id, int outlookId) { + UpdateWrapper up = new UpdateWrapper<>(); + up.eq("github_id", github_id).eq("id", outlookId); + if (baseMapper.update(new Outlook().setStatus(6), up) != 1) { + throw new APIException("更新失败!"); + } + } } diff --git a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java index 7007393..2d5d793 100644 --- a/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java +++ b/src/main/java/io/qyi/e5/outlook_log/controller/OutlookLogController.java @@ -2,14 +2,13 @@ package io.qyi.e5.outlook_log.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.google.gson.Gson; +import io.qyi.e5.bean.result.Result; import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken; -import io.qyi.e5.outlook.entity.Outlook; import io.qyi.e5.outlook.service.IOutlookService; import io.qyi.e5.outlook_log.bena.LogVo; import io.qyi.e5.outlook_log.entity.OutlookLog; import io.qyi.e5.outlook_log.service.IOutlookLogService; -import org.apache.commons.lang.time.DateUtils; +import io.qyi.e5.util.ResultUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; @@ -17,9 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.util.Iterator; @@ -53,12 +52,12 @@ public class OutlookLogController { @GetMapping("/findLog") @ResponseBody - public String findLog(){ + public Result findLog(@RequestParam int outlookId){ UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("github_id", github_id).orderByDesc("call_time"); + queryWrapper.eq("github_id", github_id).eq("outlook_id", outlookId).orderByAsc("call_time"); List list = outlookLogService.list(queryWrapper); Iterator iterator = list.iterator(); List logVo = new LinkedList<>(); @@ -68,19 +67,7 @@ public class OutlookLogController { BeanUtils.copyProperties(next,vo); logVo.add(vo); } - Gson gson = new Gson(); - return gson.toJson(logVo); - } - - @GetMapping("/exec111111") - public void s() throws Exception { - List list = outlookService.findAll(); - logger.info(String.valueOf(list.size())); - for (Outlook outlook :list) { - logger.info(outlook.toString()); - outlookService.getMailList(outlook); - } - + return ResultUtil.success(logVo); } } diff --git a/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java b/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java index c845f31..e64e0b0 100644 --- a/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java +++ b/src/main/java/io/qyi/e5/outlook_log/entity/OutlookLog.java @@ -30,6 +30,11 @@ public class OutlookLog implements Serializable { */ private Integer githubId; + /** + * outlook_id + */ + private Integer outlookId; + /** * 调用时间 */