From f25af08cda609cc554cc70526a4489a964e488b2 Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Fri, 10 Mar 2023 10:56:17 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=9C=A8=E7=BA=BF=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=20cron=20=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../io/jpom/controller/ToolsController.java | 75 ++++++++++++++++++ .../build/repository/GitHubUtil.java | 22 ++++++ .../build/repository/GitLabUtil.java | 22 ++++++ .../build/repository/GiteaUtil.java | 22 ++++++ .../build/repository/GiteeUtil.java | 22 ++++++ .../controller/UserLoginLogController.java | 22 ++++++ .../func/user/model/UserLoginLogModel.java | 22 ++++++ .../func/user/server/UserLoginLogServer.java | 22 ++++++ .../src/main/resources/menus/index.json | 11 +++ modules/server/src/test/java/TestCron.java | 1 - web-vue/src/api/tools.js | 13 +++ web-vue/src/pages/build/list-info.vue | 12 ++- web-vue/src/pages/test/index.vue | 24 ------ web-vue/src/pages/tools/cron.vue | 79 +++++++++++++++++++ web-vue/src/router/index.js | 5 ++ web-vue/src/router/route-menu.js | 1 + 17 files changed, 348 insertions(+), 28 deletions(-) create mode 100644 modules/server/src/main/java/io/jpom/controller/ToolsController.java create mode 100644 web-vue/src/api/tools.js delete mode 100644 web-vue/src/pages/test/index.vue create mode 100644 web-vue/src/pages/tools/cron.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 402a68aaf..2d5912b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 1. 【server】新增 导入仓库支持 `gitea` 系统 (感谢 [@Smith](https://gitee.com/autools) [Gitee pr 173](https://gitee.com/dromara/Jpom/pulls/173) ) 2. 【server】新增 用户登录日志(取消用户登录生成操作日志的执行日志) +3. 【server】新增 在线工具验证 cron 表达式 (感谢@奇奇) ### 🐞 解决BUG、优化功能 diff --git a/modules/server/src/main/java/io/jpom/controller/ToolsController.java b/modules/server/src/main/java/io/jpom/controller/ToolsController.java new file mode 100644 index 000000000..a343ced1c --- /dev/null +++ b/modules/server/src/main/java/io/jpom/controller/ToolsController.java @@ -0,0 +1,75 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package io.jpom.controller; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.cron.pattern.CronPatternUtil; +import io.jpom.common.JsonMessage; +import io.jpom.common.validator.ValidatorItem; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author bwcx_jzy + * @since 2023/3/10 + */ +@RestController +@RequestMapping(value = "/tools") +public class ToolsController { + + @GetMapping(value = "cron", produces = MediaType.APPLICATION_JSON_VALUE) + public JsonMessage> cron(@ValidatorItem String cron, @ValidatorItem int count, String date, boolean isMatchSecond) { + Date startDate = null; + Date endDate = null; + if (StrUtil.isNotEmpty(date)) { + List split = StrUtil.splitTrim(date, "~"); + try { + startDate = DateUtil.parse(split.get(0)); + startDate = DateUtil.beginOfDay(startDate); + endDate = DateUtil.parse(split.get(1)); + endDate = DateUtil.endOfDay(endDate); + } catch (Exception e) { + return new JsonMessage<>(405, "日期格式错误:" + e.getMessage()); + } + } + try { + List dateList; + if (startDate != null) { + dateList = CronPatternUtil.matchedDates(cron, startDate, endDate, count, isMatchSecond); + } else { + dateList = CronPatternUtil.matchedDates(cron, DateTime.now(), count, isMatchSecond); + } + return JsonMessage.success("", dateList.stream().map(Date::getTime).collect(Collectors.toList())); + } catch (Exception e) { + return new JsonMessage<>(405, "cron 表达式不正确," + e.getMessage()); + } + } +} diff --git a/modules/server/src/main/java/io/jpom/controller/build/repository/GitHubUtil.java b/modules/server/src/main/java/io/jpom/controller/build/repository/GitHubUtil.java index 6ef0977c8..22baf55f5 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/repository/GitHubUtil.java +++ b/modules/server/src/main/java/io/jpom/controller/build/repository/GitHubUtil.java @@ -1,3 +1,25 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ package io.jpom.controller.build.repository; import cn.hutool.db.Page; diff --git a/modules/server/src/main/java/io/jpom/controller/build/repository/GitLabUtil.java b/modules/server/src/main/java/io/jpom/controller/build/repository/GitLabUtil.java index 7e8b5a109..ce8adda6d 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/repository/GitLabUtil.java +++ b/modules/server/src/main/java/io/jpom/controller/build/repository/GitLabUtil.java @@ -1,3 +1,25 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ package io.jpom.controller.build.repository; import cn.hutool.core.convert.Convert; diff --git a/modules/server/src/main/java/io/jpom/controller/build/repository/GiteaUtil.java b/modules/server/src/main/java/io/jpom/controller/build/repository/GiteaUtil.java index 39cc9ea49..bbae0c531 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/repository/GiteaUtil.java +++ b/modules/server/src/main/java/io/jpom/controller/build/repository/GiteaUtil.java @@ -1,3 +1,25 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ package io.jpom.controller.build.repository; import cn.hutool.core.convert.Convert; diff --git a/modules/server/src/main/java/io/jpom/controller/build/repository/GiteeUtil.java b/modules/server/src/main/java/io/jpom/controller/build/repository/GiteeUtil.java index 7c68311a5..fdedd7bfe 100644 --- a/modules/server/src/main/java/io/jpom/controller/build/repository/GiteeUtil.java +++ b/modules/server/src/main/java/io/jpom/controller/build/repository/GiteeUtil.java @@ -1,3 +1,25 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ package io.jpom.controller.build.repository; import cn.hutool.core.convert.Convert; diff --git a/modules/server/src/main/java/io/jpom/func/user/controller/UserLoginLogController.java b/modules/server/src/main/java/io/jpom/func/user/controller/UserLoginLogController.java index 276c49479..fe96065ec 100644 --- a/modules/server/src/main/java/io/jpom/func/user/controller/UserLoginLogController.java +++ b/modules/server/src/main/java/io/jpom/func/user/controller/UserLoginLogController.java @@ -1,3 +1,25 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ package io.jpom.func.user.controller; import io.jpom.common.BaseServerController; diff --git a/modules/server/src/main/java/io/jpom/func/user/model/UserLoginLogModel.java b/modules/server/src/main/java/io/jpom/func/user/model/UserLoginLogModel.java index f9ba081d8..662add597 100644 --- a/modules/server/src/main/java/io/jpom/func/user/model/UserLoginLogModel.java +++ b/modules/server/src/main/java/io/jpom/func/user/model/UserLoginLogModel.java @@ -1,3 +1,25 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ package io.jpom.func.user.model; import io.jpom.model.BaseUserModifyDbModel; diff --git a/modules/server/src/main/java/io/jpom/func/user/server/UserLoginLogServer.java b/modules/server/src/main/java/io/jpom/func/user/server/UserLoginLogServer.java index a2188fb98..1327f237d 100644 --- a/modules/server/src/main/java/io/jpom/func/user/server/UserLoginLogServer.java +++ b/modules/server/src/main/java/io/jpom/func/user/server/UserLoginLogServer.java @@ -1,3 +1,25 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Code Technology Studio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ package io.jpom.func.user.server; import cn.hutool.core.util.CharsetUtil; diff --git a/modules/server/src/main/resources/menus/index.json b/modules/server/src/main/resources/menus/index.json index bb306cba0..8d8c15ac4 100644 --- a/modules/server/src/main/resources/menus/index.json +++ b/modules/server/src/main/resources/menus/index.json @@ -136,5 +136,16 @@ "title": "操作监控" } ] + }, + { + "title": "在线工具", + "icon_v3": "tool", + "id": "tools", + "childs": [ + { + "id": "cronTools", + "title": "Cron表达式" + } + ] } ] diff --git a/modules/server/src/test/java/TestCron.java b/modules/server/src/test/java/TestCron.java index 06c5349ca..62450da8a 100644 --- a/modules/server/src/test/java/TestCron.java +++ b/modules/server/src/test/java/TestCron.java @@ -20,7 +20,6 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; diff --git a/web-vue/src/api/tools.js b/web-vue/src/api/tools.js new file mode 100644 index 000000000..0ed57f760 --- /dev/null +++ b/web-vue/src/api/tools.js @@ -0,0 +1,13 @@ +import axios from "./config"; + +/** + * + * @param data + */ +export function cronTools(data) { + return axios({ + url: "/tools/cron", + method: "get", + params: data, + }); +} diff --git a/web-vue/src/pages/build/list-info.vue b/web-vue/src/pages/build/list-info.vue index 18b731b05..4b45e60d6 100644 --- a/web-vue/src/pages/build/list-info.vue +++ b/web-vue/src/pages/build/list-info.vue @@ -1169,7 +1169,7 @@ export default { buildConfirmVisible: false, columns: [ { title: "名称", dataIndex: "name", sorter: true, width: 200, ellipsis: true, scopedSlots: { customRender: "name" } }, - + { title: "分组", dataIndex: "group", width: 100, ellipsis: true, scopedSlots: { customRender: "tooltip" } }, { title: "分支/标签", dataIndex: "branchName", @@ -1177,7 +1177,7 @@ export default { width: 100, scopedSlots: { customRender: "branchName" }, }, - { title: "产物", dataIndex: "resultDirFile", ellipsis: true, scopedSlots: { customRender: "tooltip" } }, + { title: "产物", dataIndex: "resultDirFile", width: 100, ellipsis: true, scopedSlots: { customRender: "tooltip" } }, { title: "方式", dataIndex: "buildMode", align: "center", width: "80px", sorter: true, ellipsis: true, scopedSlots: { customRender: "buildMode" } }, { title: "状态", dataIndex: "status", align: "center", width: "100px", ellipsis: true, scopedSlots: { customRender: "status" } }, { @@ -1212,7 +1212,13 @@ export default { ellipsis: true, scopedSlots: { customRender: "releaseMethod" }, }, - + { + title: "定时构建", + dataIndex: "autoBuildCron", + width: 100, + ellipsis: true, + scopedSlots: { customRender: "tooltip" }, + }, { title: "操作", dataIndex: "operation", diff --git a/web-vue/src/pages/test/index.vue b/web-vue/src/pages/test/index.vue deleted file mode 100644 index 01eec5958..000000000 --- a/web-vue/src/pages/test/index.vue +++ /dev/null @@ -1,24 +0,0 @@ - - - - - diff --git a/web-vue/src/pages/tools/cron.vue b/web-vue/src/pages/tools/cron.vue new file mode 100644 index 000000000..fce8ddec5 --- /dev/null +++ b/web-vue/src/pages/tools/cron.vue @@ -0,0 +1,79 @@ + + diff --git a/web-vue/src/router/index.js b/web-vue/src/router/index.js index 05691a96c..0af19df4e 100644 --- a/web-vue/src/router/index.js +++ b/web-vue/src/router/index.js @@ -129,6 +129,11 @@ const children = [ name: "script-env-list", component: () => import("../pages/script/env"), }, + { + path: "/tools/cron", + name: "cron-tools", + component: () => import("../pages/tools/cron"), + }, ]; const management = [ diff --git a/web-vue/src/router/route-menu.js b/web-vue/src/router/route-menu.js index 9ffa29526..5bdee86f8 100644 --- a/web-vue/src/router/route-menu.js +++ b/web-vue/src/router/route-menu.js @@ -47,6 +47,7 @@ const routeMenuMap = { machine_ssh_info: "/system/assets/ssh-list", machine_docker_info: "/system/assets/docker-list", configWorkspaceEnv: "/script/env-list", + cronTools: "/tools/cron", }; export default routeMenuMap;