From 823bfbdbd235d3518c39f7838356636d5922e4fc Mon Sep 17 00:00:00 2001 From: APLS Date: Mon, 23 Mar 2020 22:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=85=E6=B7=BB=E5=8A=A0=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=98=9F=E5=88=97=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/qyi/e5/bean/result/ResultEnum.java | 3 +- .../qyi/e5/controller/web/WebController.java | 2 +- .../outlook/controller/OutlookController.java | 17 ++++++++-- .../service/impl/OutlookServiceImpl.java | 13 +++++++- src/main/resources/templates/user/home.ftl | 32 +++++++++++++++++-- 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/qyi/e5/bean/result/ResultEnum.java b/src/main/java/io/qyi/e5/bean/result/ResultEnum.java index 85b53c8..9455970 100644 --- a/src/main/java/io/qyi/e5/bean/result/ResultEnum.java +++ b/src/main/java/io/qyi/e5/bean/result/ResultEnum.java @@ -18,7 +18,8 @@ public enum ResultEnum { NO_ROBOT_FOUND(-10006,"No QQ robot corresponding to this token was found"), NO_ROBOT_FOUND_(-10007,"No QQ robot corresponding to this token was found"), STATE_HAS_EXPIRED(-10008,"state has expired, please re-authorize."), - INVALID_EMAIL(-10009,"Invalid Email!"); + INVALID_EMAIL(-10009,"Invalid Email!"), + INVALID_format(-10010, "Invalid format"); private Integer code; private String msg; 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 b97ea22..e63832d 100644 --- a/src/main/java/io/qyi/e5/controller/web/WebController.java +++ b/src/main/java/io/qyi/e5/controller/web/WebController.java @@ -46,7 +46,7 @@ public class WebController { if (one != null) { model.addAttribute("client_id", one.getClientId()); model.addAttribute("client_secret", one.getClientSecret()); - model.addAttribute("cron_time", one.getCronTime()); + model.addAttribute("cron_time", one.getCronTime().toString()); model.addAttribute("cron_time_random_start", one.getCronTimeRandomStart()); model.addAttribute("cron_time_random_end", one.getCronTimeRandomEnd()); } else { 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 3a3a754..85dba61 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java @@ -36,9 +36,22 @@ public class OutlookController { } @PostMapping("/saveRandomTime") - public Result saveRandomTime(@RequestParam int cronTime, @RequestParam int crondomTime) { + public Result saveRandomTime(@RequestParam int cronTime, @RequestParam String crondomTime) { + String[] split = crondomTime.split("-"); + if (split.length != 2) { + return ResultUtil.error(ResultEnum.INVALID_format); + } + int cron_time_random_start; + int cron_time_random_end; + try { + cron_time_random_start = Integer.valueOf(split[0]); + cron_time_random_end = Integer.valueOf(split[1]); + } catch (NumberFormatException e) { + e.printStackTrace(); + return ResultUtil.error(ResultEnum.INVALID_format); + } UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); - if (outlookService.saveRandomTime(authentication.getGithub_id(), cronTime, 0, 0)) { + if (outlookService.saveRandomTime(authentication.getGithub_id(), cronTime, cron_time_random_start, cron_time_random_end)) { return ResultUtil.success(); } return ResultUtil.error(ResultEnum.UNKNOWN_ERROR); 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 ff6e556..5286c7d 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 @@ -109,7 +109,18 @@ public class OutlookServiceImpl extends ServiceImpl impl @Override public boolean saveRandomTime(int github_id, int cron_time, int cron_time_random_start, int cron_time_random_end) { - + if (github_id == 0) { + return false; + } + UpdateWrapper Wrapper = new UpdateWrapper<>(); + Wrapper.eq("github_id", github_id); + Outlook outlook = new Outlook(); + outlook.setCronTime(cron_time).setCronTimeRandomStart(cron_time_random_start).setCronTimeRandomEnd(cron_time_random_end); + int update = baseMapper.update(outlook, Wrapper); +// 有数据 + if (update > 0) { + return true; + } return false; } diff --git a/src/main/resources/templates/user/home.ftl b/src/main/resources/templates/user/home.ftl index de1a732..c2a785c 100644 --- a/src/main/resources/templates/user/home.ftl +++ b/src/main/resources/templates/user/home.ftl @@ -48,11 +48,11 @@
- +
-
    @@ -72,6 +72,32 @@ var url = "/outlookLog/findLog" window.open(url, '_blank') }) + //保存随机时间 + $("#save_random_time").click(function () { + var cron_time = $("#cron_time").val(); + var cron_time_random = $("#cron_time_random").val(); + if ((cron_time || cron_time_random) == "") { + alert("cron_time 或 cron_time_random 不能为空!") + return; + } + ; + $.post("/outlook/outlook/saveRandomTime", { + cronTime: cron_time, + crondomTime: cron_time_random + }, function (data, status) { + console.log(data); + if (status != "success") { + alert("未知错误,请联系管理员!") + return; + } + if (data.code == 0) { + alert("保存成功!"); + } else { + alert("错误: " + data.msg); + } + + }) + }) // 授权 $("#authorization").click(function () { var url = "/outlook/auth2/getAuthorizeUrl" @@ -98,7 +124,7 @@ if (data.code == 0) { alert("保存成功!"); } else { - alert("错误: + " + data.msg); + alert("错误: " + data.msg); } })