feat 在线工具验证 cron 表达式

This commit is contained in:
bwcx_jzy 2023-03-10 10:56:17 +08:00
parent fe190aceb9
commit f25af08cda
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
17 changed files with 348 additions and 28 deletions

View File

@ -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、优化功能

View File

@ -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<List<Long>> cron(@ValidatorItem String cron, @ValidatorItem int count, String date, boolean isMatchSecond) {
Date startDate = null;
Date endDate = null;
if (StrUtil.isNotEmpty(date)) {
List<String> 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<Date> 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());
}
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -136,5 +136,16 @@
"title": "操作监控"
}
]
},
{
"title": "在线工具",
"icon_v3": "tool",
"id": "tools",
"childs": [
{
"id": "cronTools",
"title": "Cron表达式"
}
]
}
]

View File

@ -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;

13
web-vue/src/api/tools.js Normal file
View File

@ -0,0 +1,13 @@
import axios from "./config";
/**
*
* @param data
*/
export function cronTools(data) {
return axios({
url: "/tools/cron",
method: "get",
params: data,
});
}

View File

@ -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",

View File

@ -1,24 +0,0 @@
<template>
<code-editor v-model="code" showTool @checkJson="checkJson" :options="{ mode: 'application/json' }"> </code-editor>
</template>
<script>
import codeEditor from "@/components/codeEditor";
export default {
components: {
codeEditor,
},
data() {
return {
code: "",
};
},
methods: {
checkJson() {
console.log(11);
},
},
};
</script>
<style></style>

View File

@ -0,0 +1,79 @@
<template>
<div>
<a-row justify="center" type="flex">
<a-col :span="18">
<a-alert message="此工具用于检查 cron 表达式是否正确,以及计划运行时间" type="info" />
<a-form-model :model="temp" ref="form" :rules="rules" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }">
<a-form-model-item label="cron表达式" prop="cron">
<a-input v-model="temp.cron" placeholder="请输入要检查的 cron 表达式" />
</a-form-model-item>
<a-form-model-item label="计划次数" prop="count">
<a-input-number v-model="temp.count" :min="1" placeholder="请输入获取的计划运行次数" style="width: 100%" />
</a-form-model-item>
<a-form-model-item label="匹配秒">
<a-switch v-model="temp.isMatchSecond" checked-children="" un-checked-children="" />
</a-form-model-item>
<a-form-model-item label="时间范围" prop="date" help="默认是当前时间到今年结束">
<a-range-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" separator="至" v-model="temp.date" style="width: 100%" />
</a-form-model-item>
</a-form-model>
<a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
<a-button type="primary" @click="onSubmit"> 检查 </a-button>
</a-form-model-item>
</a-col>
<a-col :span="10">
<a-list bordered :data-source="resultList" :locale="locale">
<a-list-item slot="renderItem" slot-scope="item">
{{ parseTime(item) }}
</a-list-item>
<div slot="header">结果</div>
</a-list>
</a-col>
</a-row>
</div>
</template>
<script>
import { cronTools } from "@/api/tools";
import { parseTime } from "@/utils/const";
export default {
data() {
return {
temp: {
count: 10,
},
locale: {
emptyText: "暂无数据",
},
resultList: [],
//
rules: {
cron: [{ required: true, message: "请输入要检查的 cron 表达式", trigger: "blur" }],
count: [{ required: true, message: "请输入获取的计划运行次数", trigger: "blur" }],
},
};
},
methods: {
parseTime,
onSubmit() {
this.$refs["form"].validate((valid) => {
if (!valid) {
return false;
}
this.resultList = [];
this.locale = {
emptyText: "暂无数据",
};
const temp = { ...this.temp, date: this.temp.date && this.temp.date[0] + " ~ " + this.temp.date[1] };
cronTools(temp).then((res) => {
// console.log(res);
this.resultList = res.data || [];
this.locale = {
emptyText: res.msg,
};
});
});
},
},
};
</script>

View File

@ -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 = [

View File

@ -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;