update cronjob

This commit is contained in:
骑着蜗牛追导弹 2022-03-01 17:43:58 +08:00
parent bd4b180546
commit 7ee745b7c3
3 changed files with 46 additions and 171 deletions

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询定时任务调度列表 // 查询定时任务调度列表
export function listJob(query) { export function listJob(query) {
return request({ return request({
url: '/monitor/job/list', url: '/api/v1/monitor/cronJob/list',
method: 'get', method: 'get',
params: query params: query
}) })
@ -12,7 +12,7 @@ export function listJob(query) {
// 查询定时任务调度详细 // 查询定时任务调度详细
export function getJob(jobId) { export function getJob(jobId) {
return request({ return request({
url: '/monitor/job/' + jobId, url: '/api/v1/monitor/cronJob/' + jobId,
method: 'get' method: 'get'
}) })
} }
@ -20,7 +20,7 @@ export function getJob(jobId) {
// 新增定时任务调度 // 新增定时任务调度
export function addJob(data) { export function addJob(data) {
return request({ return request({
url: '/monitor/job', url: '/api/v1/monitor/cronJob/create',
method: 'post', method: 'post',
data: data data: data
}) })
@ -29,37 +29,29 @@ export function addJob(data) {
// 修改定时任务调度 // 修改定时任务调度
export function updateJob(data) { export function updateJob(data) {
return request({ return request({
url: '/monitor/job', url: '/api/v1/monitor/cronJob/modify',
method: 'put', method: 'put',
data: data data: data
}) })
} }
// 删除定时任务调度 // 删除定时任务调度
export function delJob(jobId) { export function delJob(jobId, funcAlias) {
return request({ return request({
url: '/monitor/job/' + jobId, url: `/api/v1/monitor/cronJob/${jobId}/${funcAlias}`,
method: 'delete' method: 'delete'
}) })
} }
// 导出定时任务调度
export function exportJob(query) {
return request({
url: '/monitor/job/export',
method: 'get',
params: query
})
}
// 任务状态修改 // 任务状态修改
export function changeJobStatus(jobId, status) { export function changeJobStatus(jobId, funcAlias, status) {
const data = { const data = {
jobId, jobId,
funcAlias,
status status
} }
return request({ return request({
url: '/monitor/job/changeStatus', url: '/api/v1/monitor/cronJob/changeStatus',
method: 'put', method: 'put',
data: data data: data
}) })
@ -67,13 +59,13 @@ export function changeJobStatus(jobId, status) {
// 定时任务立即执行一次 // 定时任务立即执行一次
export function runJob(jobId, jobGroup) { export function runJob(jobId, funcAlias) {
const data = { const data = {
jobId, jobId,
jobGroup funcAlias
} }
return request({ return request({
url: '/monitor/job/run', url: '/api/v1/monitor/cronJob/run',
method: 'put', method: 'put',
data: data data: data
}) })

View File

@ -10,16 +10,6 @@
@keyup.enter.native="handleQuery" @keyup.enter.native="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="任务组名" prop="jobGroup">
<el-select v-model="queryParams.jobGroup" placeholder="请选择任务组名" clearable size="small">
<el-option
v-for="dict in jobGroupOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item label="任务状态" prop="status"> <el-form-item label="任务状态" prop="status">
<el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable size="small"> <el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable size="small">
<el-option <el-option
@ -39,73 +29,56 @@
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="primary"
plain
icon="el-icon-plus" icon="el-icon-plus"
size="mini" size="mini"
@click="handleAdd" @click="handleAdd"
v-hasPermi="['monitor:job:add']" v-hasPermi="['monitor:job:add']"
>新增</el-button> ></el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="success" type="primary"
plain
icon="el-icon-edit" icon="el-icon-edit"
size="mini" size="mini"
:disabled="single" :disabled="single"
@click="handleUpdate" @click="handleUpdate"
v-hasPermi="['monitor:job:edit']" v-hasPermi="['monitor:job:edit']"
>修改</el-button> ></el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="danger" type="danger"
plain
icon="el-icon-delete" icon="el-icon-delete"
size="mini" size="mini"
:disabled="multiple" :disabled="multiple"
@click="handleDelete" @click="handleDelete"
v-hasPermi="['monitor:job:remove']" v-hasPermi="['monitor:job:remove']"
>删除</el-button> ></el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
:loading="exportLoading"
@click="handleExport"
v-hasPermi="['monitor:job:export']"
>导出</el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="info" type="info"
plain
icon="el-icon-s-operation" icon="el-icon-s-operation"
size="mini" size="mini"
@click="handleJobLog" @click="handleJobLog"
v-hasPermi="['monitor:job:query']" v-hasPermi="['monitor:job:query']"
>日志</el-button> ></el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
<el-table v-loading="loading" :data="jobList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="jobList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="任务编号" align="center" prop="jobId" /> <el-table-column label="任务编号" align="center" prop="jobId" :show-overflow-tooltip="true" />
<el-table-column label="任务名称" align="center" prop="jobName" :show-overflow-tooltip="true" /> <el-table-column label="任务名称" align="center" prop="jobName" :show-overflow-tooltip="true" />
<el-table-column label="任务组名" align="center" prop="jobGroup" :formatter="jobGroupFormat" /> <el-table-column label="调用目标字符串" align="center" prop="funcAlias" :show-overflow-tooltip="true" />
<el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" /> <el-table-column label="cron执行表达式" align="center" prop="jobCron" :show-overflow-tooltip="true" />
<el-table-column label="cron执行表达式" align="center" prop="cronExpression" :show-overflow-tooltip="true" />
<el-table-column label="状态" align="center"> <el-table-column label="状态" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
v-model="scope.row.status" v-model="scope.row.status"
active-value="0" active-value="1"
inactive-value="1" inactive-value="0"
@change="handleStatusChange(scope.row)" @change="handleStatusChange(scope.row)"
></el-switch> ></el-switch>
</template> </template>
@ -114,18 +87,18 @@
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
size="mini" size="mini"
type="text" type="primary"
icon="el-icon-edit" icon="el-icon-edit"
@click="handleUpdate(scope.row)" @click="handleUpdate(scope.row)"
v-hasPermi="['monitor:job:edit']" v-hasPermi="['monitor:job:edit']"
>修改</el-button> ></el-button>
<el-button <el-button
size="mini" size="mini"
type="text" type="danger"
icon="el-icon-delete" icon="el-icon-delete"
@click="handleDelete(scope.row)" @click="handleDelete(scope.row)"
v-hasPermi="['monitor:job:remove']" v-hasPermi="['monitor:job:remove']"
>删除</el-button> ></el-button>
<el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"> <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
<el-button icon="el-icon-more" type="info" size="mini"></el-button> <el-button icon="el-icon-more" type="info" size="mini"></el-button>
@ -160,54 +133,14 @@
<el-input v-model="form.jobName" placeholder="请输入任务名称" /> <el-input v-model="form.jobName" placeholder="请输入任务名称" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12">
<el-form-item label="任务分组" prop="jobGroup">
<el-select v-model="form.jobGroup" placeholder="请选择">
<el-option
v-for="dict in jobGroupOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item prop="invokeTarget"> <el-form-item label="调用目标字符串" prop="funcAlias">
<span slot="label"> <el-input v-model="form.funcAlias" placeholder="请输入调用目标字符串" />
调用方法
<el-tooltip placement="top">
<div slot="content">
Bean调用示例ryTask.ryParams('ry')
<br />Class类调用示例com.ruoyi.quartz.task.RyTask.ryParams('ry')
<br />参数说明支持字符串布尔类型长整型浮点型整型
</div>
<i class="el-icon-question"></i>
</el-tooltip>
</span>
<el-input v-model="form.invokeTarget" placeholder="请输入调用目标字符串" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="cron表达式" prop="cronExpression"> <el-form-item label="Cron表达式" prop="jobCron">
<el-input v-model="form.cronExpression" placeholder="请输入cron执行表达式" /> <el-input v-model="form.jobCron" placeholder="请输入Cron执行表达式" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="是否并发" prop="concurrent">
<el-radio-group v-model="form.concurrent" size="small">
<el-radio-button label="0">允许</el-radio-button>
<el-radio-button label="1">禁止</el-radio-button>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="错误策略" prop="misfirePolicy">
<el-radio-group v-model="form.misfirePolicy" size="small">
<el-radio-button label="1">立即执行</el-radio-button>
<el-radio-button label="2">执行一次</el-radio-button>
<el-radio-button label="3">放弃执行</el-radio-button>
</el-radio-group>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
@ -238,7 +171,6 @@
<el-form-item label="任务名称:">{{ form.jobName }}</el-form-item> <el-form-item label="任务名称:">{{ form.jobName }}</el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="任务分组:">{{ jobGroupFormat(form) }}</el-form-item>
<el-form-item label="创建时间:">{{ form.createTime }}</el-form-item> <el-form-item label="创建时间:">{{ form.createTime }}</el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
@ -248,7 +180,7 @@
<el-form-item label="下次执行时间:">{{ parseTime(form.nextValidTime) }}</el-form-item> <el-form-item label="下次执行时间:">{{ parseTime(form.nextValidTime) }}</el-form-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="调用目标方法:">{{ form.invokeTarget }}</el-form-item> <el-form-item label="调用目标方法:">{{ form.funcAlias }}</el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="任务状态:"> <el-form-item label="任务状态:">
@ -288,8 +220,6 @@ export default {
return { return {
// //
loading: true, loading: true,
//
exportLoading: false,
// //
ids: [], ids: [],
// //
@ -308,8 +238,6 @@ export default {
open: false, open: false,
// //
openView: false, openView: false,
//
jobGroupOptions: [],
// //
statusOptions: [], statusOptions: [],
// //
@ -317,7 +245,6 @@ export default {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
jobName: undefined, jobName: undefined,
jobGroup: undefined,
status: undefined status: undefined
}, },
// //
@ -327,10 +254,10 @@ export default {
jobName: [ jobName: [
{ required: true, message: "任务名称不能为空", trigger: "blur" } { required: true, message: "任务名称不能为空", trigger: "blur" }
], ],
invokeTarget: [ funcAlias: [
{ required: true, message: "调用目标字符串不能为空", trigger: "blur" } { required: true, message: "调用目标字符串不能为空", trigger: "blur" }
], ],
cronExpression: [ jobCron: [
{ required: true, message: "cron执行表达式不能为空", trigger: "blur" } { required: true, message: "cron执行表达式不能为空", trigger: "blur" }
] ]
} }
@ -338,9 +265,6 @@ export default {
}, },
created() { created() {
this.getList(); this.getList();
this.getDicts("sys_job_group").then(response => {
this.jobGroupOptions = response.data;
});
this.getDicts("sys_job_status").then(response => { this.getDicts("sys_job_status").then(response => {
this.statusOptions = response.data; this.statusOptions = response.data;
}); });
@ -350,15 +274,11 @@ export default {
getList() { getList() {
this.loading = true; this.loading = true;
listJob(this.queryParams).then(response => { listJob(this.queryParams).then(response => {
this.jobList = response.rows; this.jobList = response.data.list;
this.total = response.total; this.total = response.data.total;
this.loading = false; this.loading = false;
}); });
}, },
//
jobGroupFormat(row, column) {
return this.selectDictLabel(this.jobGroupOptions, row.jobGroup);
},
// //
statusFormat(row, column) { statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status); return this.selectDictLabel(this.statusOptions, row.status);
@ -373,9 +293,8 @@ export default {
this.form = { this.form = {
jobId: undefined, jobId: undefined,
jobName: undefined, jobName: undefined,
jobGroup: undefined, funcAlias: undefined,
invokeTarget: undefined, jobCron: undefined,
cronExpression: undefined,
misfirePolicy: 1, misfirePolicy: 1,
concurrent: 1, concurrent: 1,
status: "0" status: "0"
@ -395,7 +314,7 @@ export default {
// //
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.ids = selection.map(item => item.jobId); this.ids = selection.map(item => item.jobId);
this.single = selection.length != 1; this.single = selection.length !== 1;
this.multiple = !selection.length; this.multiple = !selection.length;
}, },
// //
@ -416,13 +335,13 @@ export default {
}, },
// //
handleStatusChange(row) { handleStatusChange(row) {
let text = row.status === "0" ? "启用" : "停用"; let text = row.status === "1" ? "启用" : "停用";
this.$confirm('确认要"' + text + '""' + row.jobName + '"任务吗?', "警告", { this.$confirm('确认要"' + text + '""' + row.jobName + '"任务吗?', "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"
}).then(function() { }).then(function() {
return changeJobStatus(row.jobId, row.status); return changeJobStatus(row.jobId, row.funcAlias, row.status);
}).then(() => { }).then(() => {
this.msgSuccess(text + "成功"); this.msgSuccess(text + "成功");
}).catch(function() { }).catch(function() {
@ -436,7 +355,7 @@ export default {
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"
}).then(function() { }).then(function() {
return runJob(row.jobId, row.jobGroup); return runJob(row.jobId);
}).then(() => { }).then(() => {
this.msgSuccess("执行成功"); this.msgSuccess("执行成功");
}).catch(() => {}); }).catch(() => {});
@ -497,26 +416,11 @@ export default {
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"
}).then(function() { }).then(function() {
return delJob(jobIds); return delJob(jobIds, row.funcAlias);
}).then(() => { }).then(() => {
this.getList(); this.getList();
this.msgSuccess("删除成功"); this.msgSuccess("删除成功");
}).catch(() => {}); }).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm("是否确认导出所有定时任务数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
this.exportLoading = true;
return exportJob(queryParams);
}).then(response => {
this.download(response.msg);
this.exportLoading = false;
}).catch(() => {});
} }
} }
}; };

View File

@ -11,22 +11,6 @@
@keyup.enter.native="handleQuery" @keyup.enter.native="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="任务组名" prop="jobGroup">
<el-select
v-model="queryParams.jobGroup"
placeholder="请任务组名"
clearable
size="small"
style="width: 240px"
>
<el-option
v-for="dict in jobGroupOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item label="执行状态" prop="status"> <el-form-item label="执行状态" prop="status">
<el-select <el-select
v-model="queryParams.status" v-model="queryParams.status"
@ -65,18 +49,16 @@
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="danger" type="danger"
plain
icon="el-icon-delete" icon="el-icon-delete"
size="mini" size="mini"
:disabled="multiple" :disabled="multiple"
@click="handleDelete" @click="handleDelete"
v-hasPermi="['monitor:job:remove']" v-hasPermi="['monitor:job:remove']"
>删除</el-button> ></el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="danger" type="danger"
plain
icon="el-icon-delete" icon="el-icon-delete"
size="mini" size="mini"
@click="handleClean" @click="handleClean"
@ -86,22 +68,20 @@
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="warning" type="warning"
plain
icon="el-icon-download" icon="el-icon-download"
size="mini" size="mini"
:loading="exportLoading" :loading="exportLoading"
@click="handleExport" @click="handleExport"
v-hasPermi="['monitor:job:export']" v-hasPermi="['monitor:job:export']"
>导出</el-button> ></el-button>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
type="warning" type="warning"
plain
icon="el-icon-close" icon="el-icon-close"
size="mini" size="mini"
@click="handleClose" @click="handleClose"
>关闭</el-button> ></el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -110,7 +90,6 @@
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="日志编号" width="80" align="center" prop="jobLogId" /> <el-table-column label="日志编号" width="80" align="center" prop="jobLogId" />
<el-table-column label="任务名称" align="center" prop="jobName" :show-overflow-tooltip="true" /> <el-table-column label="任务名称" align="center" prop="jobName" :show-overflow-tooltip="true" />
<el-table-column label="任务组名" align="center" prop="jobGroup" :formatter="jobGroupFormat" :show-overflow-tooltip="true" />
<el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" /> <el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" />
<el-table-column label="日志信息" align="center" prop="jobMessage" :show-overflow-tooltip="true" /> <el-table-column label="日志信息" align="center" prop="jobMessage" :show-overflow-tooltip="true" />
<el-table-column label="执行状态" align="center" prop="status" :formatter="statusFormat" /> <el-table-column label="执行状态" align="center" prop="status" :formatter="statusFormat" />