正在显示
42 个修改的文件
包含
3323 行增加
和
23 行删除
ruoyi-ui/src/api/monitor/job.js
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 查询定时任务调度列表 | ||
| 4 | +export function listJob(query) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/monitor/job/list', | ||
| 7 | + method: 'get', | ||
| 8 | + params: query | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +// 查询定时任务调度详细 | ||
| 13 | +export function getJob(jobId) { | ||
| 14 | + return request({ | ||
| 15 | + url: '/monitor/job/' + jobId, | ||
| 16 | + method: 'get' | ||
| 17 | + }) | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +// 新增定时任务调度 | ||
| 21 | +export function addJob(data) { | ||
| 22 | + return request({ | ||
| 23 | + url: '/monitor/job', | ||
| 24 | + method: 'post', | ||
| 25 | + data: data | ||
| 26 | + }) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// 修改定时任务调度 | ||
| 30 | +export function updateJob(data) { | ||
| 31 | + return request({ | ||
| 32 | + url: '/monitor/job', | ||
| 33 | + method: 'put', | ||
| 34 | + data: data | ||
| 35 | + }) | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +// 删除定时任务调度 | ||
| 39 | +export function delJob(jobId) { | ||
| 40 | + return request({ | ||
| 41 | + url: '/monitor/job/' + jobId, | ||
| 42 | + method: 'delete' | ||
| 43 | + }) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// 导出定时任务调度 | ||
| 47 | +export function exportJob(query) { | ||
| 48 | + return request({ | ||
| 49 | + url: '/monitor/job/export', | ||
| 50 | + method: 'get', | ||
| 51 | + params: query | ||
| 52 | + }) | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +// 任务状态修改 | ||
| 56 | +export function changeJobStatus(jobId, status) { | ||
| 57 | + const data = { | ||
| 58 | + jobId, | ||
| 59 | + status | ||
| 60 | + } | ||
| 61 | + return request({ | ||
| 62 | + url: '/monitor/job/changeStatus', | ||
| 63 | + method: 'put', | ||
| 64 | + data: data | ||
| 65 | + }) | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | + | ||
| 69 | +// 定时任务立即执行一次 | ||
| 70 | +export function runJob(jobId, jobGroup) { | ||
| 71 | + const data = { | ||
| 72 | + jobId, | ||
| 73 | + jobGroup | ||
| 74 | + } | ||
| 75 | + return request({ | ||
| 76 | + url: '/monitor/job/run', | ||
| 77 | + method: 'put', | ||
| 78 | + data: data | ||
| 79 | + }) | ||
| 80 | +} |
ruoyi-ui/src/api/monitor/jobLog.js
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 查询调度日志列表 | ||
| 4 | +export function listJobLog(query) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/monitor/jobLog/list', | ||
| 7 | + method: 'get', | ||
| 8 | + params: query | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +// 删除调度日志 | ||
| 13 | +export function delJobLog(jobLogId) { | ||
| 14 | + return request({ | ||
| 15 | + url: '/monitor/jobLog/' + jobLogId, | ||
| 16 | + method: 'delete' | ||
| 17 | + }) | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +// 清空调度日志 | ||
| 21 | +export function cleanJobLog() { | ||
| 22 | + return request({ | ||
| 23 | + url: '/monitor/jobLog/clean', | ||
| 24 | + method: 'delete' | ||
| 25 | + }) | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +// 导出调度日志 | ||
| 29 | +export function exportJobLog(query) { | ||
| 30 | + return request({ | ||
| 31 | + url: '/monitor/jobLog/export', | ||
| 32 | + method: 'get', | ||
| 33 | + params: query | ||
| 34 | + }) | ||
| 35 | +} |
| 1 | <template> | 1 | <template> |
| 2 | <div v-if="isExternal" :style="styleExternalIcon" class="svg-external-icon svg-icon" v-on="$listeners" /> | 2 | <div v-if="isExternal" :style="styleExternalIcon" class="svg-external-icon svg-icon" v-on="$listeners" /> |
| 3 | <svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners"> | 3 | <svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners"> |
| 4 | - <use :xlink:href="iconName" /> | 4 | + <use :href="iconName" /> |
| 5 | </svg> | 5 | </svg> |
| 6 | </template> | 6 | </template> |
| 7 | 7 |
| @@ -158,7 +158,7 @@ export default { | @@ -158,7 +158,7 @@ export default { | ||
| 158 | toLastView(visitedViews, view) { | 158 | toLastView(visitedViews, view) { |
| 159 | const latestView = visitedViews.slice(-1)[0] | 159 | const latestView = visitedViews.slice(-1)[0] |
| 160 | if (latestView) { | 160 | if (latestView) { |
| 161 | - this.$router.push(latestView) | 161 | + this.$router.push(latestView.fullPath) |
| 162 | } else { | 162 | } else { |
| 163 | // now the default is to redirect to the home page if there is no tags-view, | 163 | // now the default is to redirect to the home page if there is no tags-view, |
| 164 | // you can adjust it according to your needs. | 164 | // you can adjust it according to your needs. |
| @@ -93,6 +93,19 @@ export const constantRoutes = [ | @@ -93,6 +93,19 @@ export const constantRoutes = [ | ||
| 93 | ] | 93 | ] |
| 94 | }, | 94 | }, |
| 95 | { | 95 | { |
| 96 | + path: '/job', | ||
| 97 | + component: Layout, | ||
| 98 | + hidden: true, | ||
| 99 | + children: [ | ||
| 100 | + { | ||
| 101 | + path: 'log', | ||
| 102 | + component: () => import('@/views/monitor/job/log'), | ||
| 103 | + name: 'JobLog', | ||
| 104 | + meta: { title: '调度日志' } | ||
| 105 | + } | ||
| 106 | + ] | ||
| 107 | + }, | ||
| 108 | + { | ||
| 96 | path: '/gen', | 109 | path: '/gen', |
| 97 | component: Layout, | 110 | component: Layout, |
| 98 | hidden: true, | 111 | hidden: true, |
| @@ -28,13 +28,8 @@ const mutations = { | @@ -28,13 +28,8 @@ const mutations = { | ||
| 28 | } | 28 | } |
| 29 | }, | 29 | }, |
| 30 | DEL_CACHED_VIEW: (state, view) => { | 30 | DEL_CACHED_VIEW: (state, view) => { |
| 31 | - for (const i of state.cachedViews) { | ||
| 32 | - if (i === view.name) { | ||
| 33 | - const index = state.cachedViews.indexOf(i) | ||
| 34 | - state.cachedViews.splice(index, 1) | ||
| 35 | - break | ||
| 36 | - } | ||
| 37 | - } | 31 | + const index = state.cachedViews.indexOf(view.name) |
| 32 | + index > -1 && state.cachedViews.splice(index, 1) | ||
| 38 | }, | 33 | }, |
| 39 | 34 | ||
| 40 | DEL_OTHERS_VISITED_VIEWS: (state, view) => { | 35 | DEL_OTHERS_VISITED_VIEWS: (state, view) => { |
| @@ -43,12 +38,10 @@ const mutations = { | @@ -43,12 +38,10 @@ const mutations = { | ||
| 43 | }) | 38 | }) |
| 44 | }, | 39 | }, |
| 45 | DEL_OTHERS_CACHED_VIEWS: (state, view) => { | 40 | DEL_OTHERS_CACHED_VIEWS: (state, view) => { |
| 46 | - for (const i of state.cachedViews) { | ||
| 47 | - if (i === view.name) { | ||
| 48 | - const index = state.cachedViews.indexOf(i) | 41 | + if (index > -1) { |
| 49 | state.cachedViews = state.cachedViews.slice(index, index + 1) | 42 | state.cachedViews = state.cachedViews.slice(index, index + 1) |
| 50 | - break | ||
| 51 | - } | 43 | + } else { |
| 44 | + state.cachedViews = [] | ||
| 52 | } | 45 | } |
| 53 | }, | 46 | }, |
| 54 | 47 |
| 1 | <template> | 1 | <template> |
| 2 | <div class="app-container"> | 2 | <div class="app-container"> |
| 3 | - 定时任务 | 3 | + <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px"> |
| 4 | + <el-form-item label="任务名称" prop="jobName"> | ||
| 5 | + <el-input | ||
| 6 | + v-model="queryParams.jobName" | ||
| 7 | + placeholder="请输入任务名称" | ||
| 8 | + clearable | ||
| 9 | + size="small" | ||
| 10 | + @keyup.enter.native="handleQuery" | ||
| 11 | + /> | ||
| 12 | + </el-form-item> | ||
| 13 | + <el-form-item label="任务组名" prop="jobGroup"> | ||
| 14 | + <el-select v-model="queryParams.jobGroup" placeholder="请选择任务组名" clearable size="small"> | ||
| 15 | + <el-option | ||
| 16 | + v-for="dict in jobGroupOptions" | ||
| 17 | + :key="dict.dictValue" | ||
| 18 | + :label="dict.dictLabel" | ||
| 19 | + :value="dict.dictValue" | ||
| 20 | + /> | ||
| 21 | + </el-select> | ||
| 22 | + </el-form-item> | ||
| 23 | + <el-form-item label="任务状态" prop="status"> | ||
| 24 | + <el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable size="small"> | ||
| 25 | + <el-option | ||
| 26 | + v-for="dict in statusOptions" | ||
| 27 | + :key="dict.dictValue" | ||
| 28 | + :label="dict.dictLabel" | ||
| 29 | + :value="dict.dictValue" | ||
| 30 | + /> | ||
| 31 | + </el-select> | ||
| 32 | + </el-form-item> | ||
| 33 | + <el-form-item> | ||
| 34 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | ||
| 35 | + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | ||
| 36 | + </el-form-item> | ||
| 37 | + </el-form> | ||
| 38 | + | ||
| 39 | + <el-row :gutter="10" class="mb8"> | ||
| 40 | + <el-col :span="1.5"> | ||
| 41 | + <el-button | ||
| 42 | + type="primary" | ||
| 43 | + icon="el-icon-plus" | ||
| 44 | + size="mini" | ||
| 45 | + @click="handleAdd" | ||
| 46 | + v-hasPermi="['monitor:job:add']" | ||
| 47 | + >新增</el-button> | ||
| 48 | + </el-col> | ||
| 49 | + <el-col :span="1.5"> | ||
| 50 | + <el-button | ||
| 51 | + type="success" | ||
| 52 | + icon="el-icon-edit" | ||
| 53 | + size="mini" | ||
| 54 | + :disabled="single" | ||
| 55 | + @click="handleUpdate" | ||
| 56 | + v-hasPermi="['monitor:job:edit']" | ||
| 57 | + >修改</el-button> | ||
| 58 | + </el-col> | ||
| 59 | + <el-col :span="1.5"> | ||
| 60 | + <el-button | ||
| 61 | + type="danger" | ||
| 62 | + icon="el-icon-delete" | ||
| 63 | + size="mini" | ||
| 64 | + :disabled="multiple" | ||
| 65 | + @click="handleDelete" | ||
| 66 | + v-hasPermi="['monitor:job:remove']" | ||
| 67 | + >删除</el-button> | ||
| 68 | + </el-col> | ||
| 69 | + <el-col :span="1.5"> | ||
| 70 | + <el-button | ||
| 71 | + type="warning" | ||
| 72 | + icon="el-icon-download" | ||
| 73 | + size="mini" | ||
| 74 | + @click="handleExport" | ||
| 75 | + v-hasPermi="['monitor:job:export']" | ||
| 76 | + >导出</el-button> | ||
| 77 | + </el-col> | ||
| 78 | + <el-col :span="1.5"> | ||
| 79 | + <el-button | ||
| 80 | + type="info" | ||
| 81 | + icon="el-icon-s-operation" | ||
| 82 | + size="mini" | ||
| 83 | + @click="handleJobLog" | ||
| 84 | + v-hasPermi="['monitor:job:query']" | ||
| 85 | + >日志</el-button> | ||
| 86 | + </el-col> | ||
| 87 | + </el-row> | ||
| 88 | + | ||
| 89 | + <el-table v-loading="loading" :data="jobList" @selection-change="handleSelectionChange"> | ||
| 90 | + <el-table-column type="selection" width="55" align="center" /> | ||
| 91 | + <el-table-column label="任务编号" align="center" prop="jobId" /> | ||
| 92 | + <el-table-column label="任务名称" align="center" prop="jobName" :show-overflow-tooltip="true" /> | ||
| 93 | + <el-table-column label="任务组名" align="center" prop="jobGroup" :formatter="jobGroupFormat" /> | ||
| 94 | + <el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" /> | ||
| 95 | + <el-table-column label="cron执行表达式" align="center" prop="cronExpression" :show-overflow-tooltip="true" /> | ||
| 96 | + <el-table-column label="状态" align="center"> | ||
| 97 | + <template slot-scope="scope"> | ||
| 98 | + <el-switch | ||
| 99 | + v-model="scope.row.status" | ||
| 100 | + active-value="0" | ||
| 101 | + inactive-value="1" | ||
| 102 | + @change="handleStatusChange(scope.row)" | ||
| 103 | + ></el-switch> | ||
| 104 | + </template> | ||
| 105 | + </el-table-column> | ||
| 106 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 107 | + <template slot-scope="scope"> | ||
| 108 | + <el-button | ||
| 109 | + size="mini" | ||
| 110 | + type="text" | ||
| 111 | + icon="el-icon-caret-right" | ||
| 112 | + @click="handleRun(scope.row)" | ||
| 113 | + v-hasPermi="['monitor:job:edit']" | ||
| 114 | + >执行一次</el-button> | ||
| 115 | + <el-button | ||
| 116 | + size="mini" | ||
| 117 | + type="text" | ||
| 118 | + icon="el-icon-view" | ||
| 119 | + @click="handleView(scope.row)" | ||
| 120 | + v-hasPermi="['monitor:job:query']" | ||
| 121 | + >详细</el-button> | ||
| 122 | + </template> | ||
| 123 | + </el-table-column> | ||
| 124 | + </el-table> | ||
| 125 | + | ||
| 126 | + <pagination | ||
| 127 | + v-show="total>0" | ||
| 128 | + :total="total" | ||
| 129 | + :page.sync="queryParams.pageNum" | ||
| 130 | + :limit.sync="queryParams.pageSize" | ||
| 131 | + @pagination="getList" | ||
| 132 | + /> | ||
| 133 | + | ||
| 134 | + <!-- 添加或修改定时任务对话框 --> | ||
| 135 | + <el-dialog :title="title" :visible.sync="open" width="700px"> | ||
| 136 | + <el-form ref="form" :model="form" :rules="rules" label-width="100px"> | ||
| 137 | + <el-row> | ||
| 138 | + <el-col :span="12"> | ||
| 139 | + <el-form-item label="任务名称" prop="jobName"> | ||
| 140 | + <el-input v-model="form.jobName" placeholder="请输入任务名称" /> | ||
| 141 | + </el-form-item> | ||
| 142 | + </el-col> | ||
| 143 | + <el-col :span="12"> | ||
| 144 | + <el-form-item label="任务分组" prop="jobGroup"> | ||
| 145 | + <el-select v-model="form.jobGroup" placeholder="请选择"> | ||
| 146 | + <el-option | ||
| 147 | + v-for="dict in jobGroupOptions" | ||
| 148 | + :key="dict.dictValue" | ||
| 149 | + :label="dict.dictLabel" | ||
| 150 | + :value="dict.dictValue" | ||
| 151 | + ></el-option> | ||
| 152 | + </el-select> | ||
| 153 | + </el-form-item> | ||
| 154 | + </el-col> | ||
| 155 | + <el-col :span="24"> | ||
| 156 | + <el-form-item prop="invokeTarget"> | ||
| 157 | + <span slot="label"> | ||
| 158 | + 调用方法 | ||
| 159 | + <el-tooltip placement="top"> | ||
| 160 | + <div slot="content"> | ||
| 161 | + Bean调用示例:ryTask.ryParams('ry') | ||
| 162 | + <br />Class类调用示例:com.ruoyi.quartz.task.RyTask.ryParams('ry') | ||
| 163 | + <br />参数说明:支持字符串,布尔类型,长整型,浮点型,整型 | ||
| 164 | + </div> | ||
| 165 | + <i class="el-icon-question"></i> | ||
| 166 | + </el-tooltip> | ||
| 167 | + </span> | ||
| 168 | + <el-input v-model="form.invokeTarget" placeholder="请输入调用目标字符串" /> | ||
| 169 | + </el-form-item> | ||
| 170 | + </el-col> | ||
| 171 | + <el-col :span="12"> | ||
| 172 | + <el-form-item label="cron表达式" prop="cronExpression"> | ||
| 173 | + <el-input v-model="form.cronExpression" placeholder="请输入cron执行表达式" /> | ||
| 174 | + </el-form-item> | ||
| 175 | + </el-col> | ||
| 176 | + <el-col :span="12"> | ||
| 177 | + <el-form-item label="是否并发" prop="concurrent"> | ||
| 178 | + <el-radio-group v-model="form.concurrent" size="small"> | ||
| 179 | + <el-radio-button label="0">允许</el-radio-button> | ||
| 180 | + <el-radio-button label="1">禁止</el-radio-button> | ||
| 181 | + </el-radio-group> | ||
| 182 | + </el-form-item> | ||
| 183 | + </el-col> | ||
| 184 | + <el-col :span="24"> | ||
| 185 | + <el-form-item label="错误策略" prop="misfirePolicy"> | ||
| 186 | + <el-radio-group v-model="form.misfirePolicy" size="small"> | ||
| 187 | + <el-radio-button label="1">立即执行</el-radio-button> | ||
| 188 | + <el-radio-button label="2">执行一次</el-radio-button> | ||
| 189 | + <el-radio-button label="3">放弃执行</el-radio-button> | ||
| 190 | + </el-radio-group> | ||
| 191 | + </el-form-item> | ||
| 192 | + </el-col> | ||
| 193 | + <el-col :span="24"> | ||
| 194 | + <el-form-item label="状态"> | ||
| 195 | + <el-radio-group v-model="form.status"> | ||
| 196 | + <el-radio | ||
| 197 | + v-for="dict in statusOptions" | ||
| 198 | + :key="dict.dictValue" | ||
| 199 | + :label="dict.dictValue" | ||
| 200 | + >{{dict.dictLabel}}</el-radio> | ||
| 201 | + </el-radio-group> | ||
| 202 | + </el-form-item> | ||
| 203 | + </el-col> | ||
| 204 | + </el-row> | ||
| 205 | + </el-form> | ||
| 206 | + <div slot="footer" class="dialog-footer"> | ||
| 207 | + <el-button type="primary" @click="submitForm">确 定</el-button> | ||
| 208 | + <el-button @click="cancel">取 消</el-button> | ||
| 209 | + </div> | ||
| 210 | + </el-dialog> | ||
| 211 | + | ||
| 212 | + <!-- 任务日志详细 --> | ||
| 213 | + <el-dialog title="任务详细" :visible.sync="openView" width="700px"> | ||
| 214 | + <el-form ref="form" :model="form" label-width="120px" size="mini"> | ||
| 215 | + <el-row> | ||
| 216 | + <el-col :span="12"> | ||
| 217 | + <el-form-item label="任务编号:">{{ form.jobId }}</el-form-item> | ||
| 218 | + <el-form-item label="任务名称:">{{ form.jobName }}</el-form-item> | ||
| 219 | + </el-col> | ||
| 220 | + <el-col :span="12"> | ||
| 221 | + <el-form-item label="任务分组:">{{ jobGroupFormat(form) }}</el-form-item> | ||
| 222 | + <el-form-item label="创建时间:">{{ form.createTime }}</el-form-item> | ||
| 223 | + </el-col> | ||
| 224 | + <el-col :span="12"> | ||
| 225 | + <el-form-item label="cron表达式:">{{ form.cronExpression }}</el-form-item> | ||
| 226 | + </el-col> | ||
| 227 | + <el-col :span="12"> | ||
| 228 | + <el-form-item label="下次执行时间:">{{ parseTime(form.nextValidTime) }}</el-form-item> | ||
| 229 | + </el-col> | ||
| 230 | + <el-col :span="24"> | ||
| 231 | + <el-form-item label="调用目标方法:">{{ form.invokeTarget }}</el-form-item> | ||
| 232 | + </el-col> | ||
| 233 | + <el-col :span="12"> | ||
| 234 | + <el-form-item label="任务状态:"> | ||
| 235 | + <div v-if="form.status == 0">正常</div> | ||
| 236 | + <div v-else-if="form.status == 1">失败</div> | ||
| 237 | + </el-form-item> | ||
| 238 | + </el-col> | ||
| 239 | + <el-col :span="12"> | ||
| 240 | + <el-form-item label="是否并发:"> | ||
| 241 | + <div v-if="form.status == 0">允许</div> | ||
| 242 | + <div v-else-if="form.status == 1">禁止</div> | ||
| 243 | + </el-form-item> | ||
| 244 | + </el-col> | ||
| 245 | + <el-col :span="12"> | ||
| 246 | + <el-form-item label="执行策略:"> | ||
| 247 | + <div v-if="form.misfirePolicy == 0">默认策略</div> | ||
| 248 | + <div v-else-if="form.misfirePolicy == 1">立即执行</div> | ||
| 249 | + <div v-else-if="form.misfirePolicy == 2">执行一次</div> | ||
| 250 | + <div v-else-if="form.misfirePolicy == 3">放弃执行</div> | ||
| 251 | + </el-form-item> | ||
| 252 | + </el-col> | ||
| 253 | + </el-row> | ||
| 254 | + </el-form> | ||
| 255 | + <div slot="footer" class="dialog-footer"> | ||
| 256 | + <el-button @click="openView = false">关 闭</el-button> | ||
| 257 | + </div> | ||
| 258 | + </el-dialog> | ||
| 4 | </div> | 259 | </div> |
| 5 | </template> | 260 | </template> |
| 261 | + | ||
| 262 | +<script> | ||
| 263 | +import { listJob, getJob, delJob, addJob, updateJob, exportJob, runJob, changeJobStatus } from "@/api/monitor/job"; | ||
| 264 | + | ||
| 265 | +export default { | ||
| 266 | + name: "Job", | ||
| 267 | + data() { | ||
| 268 | + return { | ||
| 269 | + // 遮罩层 | ||
| 270 | + loading: true, | ||
| 271 | + // 选中数组 | ||
| 272 | + ids: [], | ||
| 273 | + // 非单个禁用 | ||
| 274 | + single: true, | ||
| 275 | + // 非多个禁用 | ||
| 276 | + multiple: true, | ||
| 277 | + // 总条数 | ||
| 278 | + total: 0, | ||
| 279 | + // 定时任务表格数据 | ||
| 280 | + jobList: [], | ||
| 281 | + // 弹出层标题 | ||
| 282 | + title: "", | ||
| 283 | + // 是否显示弹出层 | ||
| 284 | + open: false, | ||
| 285 | + // 是否显示详细弹出层 | ||
| 286 | + openView: false, | ||
| 287 | + // 任务组名字典 | ||
| 288 | + jobGroupOptions: [], | ||
| 289 | + // 状态字典 | ||
| 290 | + statusOptions: [], | ||
| 291 | + // 查询参数 | ||
| 292 | + queryParams: { | ||
| 293 | + pageNum: 1, | ||
| 294 | + pageSize: 10, | ||
| 295 | + jobName: undefined, | ||
| 296 | + jobGroup: undefined, | ||
| 297 | + status: undefined | ||
| 298 | + }, | ||
| 299 | + // 表单参数 | ||
| 300 | + form: {}, | ||
| 301 | + // 表单校验 | ||
| 302 | + rules: { | ||
| 303 | + jobName: [ | ||
| 304 | + { required: true, message: "任务名称不能为空", trigger: "blur" } | ||
| 305 | + ], | ||
| 306 | + invokeTarget: [ | ||
| 307 | + { required: true, message: "调用目标字符串不能为空", trigger: "blur" } | ||
| 308 | + ], | ||
| 309 | + cronExpression: [ | ||
| 310 | + { required: true, message: "cron执行表达式不能为空", trigger: "blur" } | ||
| 311 | + ] | ||
| 312 | + } | ||
| 313 | + }; | ||
| 314 | + }, | ||
| 315 | + created() { | ||
| 316 | + this.getList(); | ||
| 317 | + this.getDicts("sys_job_group").then(response => { | ||
| 318 | + this.jobGroupOptions = response.data; | ||
| 319 | + }); | ||
| 320 | + this.getDicts("sys_job_status").then(response => { | ||
| 321 | + this.statusOptions = response.data; | ||
| 322 | + }); | ||
| 323 | + }, | ||
| 324 | + methods: { | ||
| 325 | + /** 查询定时任务列表 */ | ||
| 326 | + getList() { | ||
| 327 | + this.loading = true; | ||
| 328 | + listJob(this.queryParams).then(response => { | ||
| 329 | + this.jobList = response.rows; | ||
| 330 | + this.total = response.total; | ||
| 331 | + this.loading = false; | ||
| 332 | + }); | ||
| 333 | + }, | ||
| 334 | + // 任务组名字典翻译 | ||
| 335 | + jobGroupFormat(row, column) { | ||
| 336 | + return this.selectDictLabel(this.jobGroupOptions, row.jobGroup); | ||
| 337 | + }, | ||
| 338 | + // 状态字典翻译 | ||
| 339 | + statusFormat(row, column) { | ||
| 340 | + return this.selectDictLabel(this.statusOptions, row.status); | ||
| 341 | + }, | ||
| 342 | + // 取消按钮 | ||
| 343 | + cancel() { | ||
| 344 | + this.open = false; | ||
| 345 | + this.reset(); | ||
| 346 | + }, | ||
| 347 | + // 表单重置 | ||
| 348 | + reset() { | ||
| 349 | + this.form = { | ||
| 350 | + jobId: undefined, | ||
| 351 | + jobName: undefined, | ||
| 352 | + jobGroup: undefined, | ||
| 353 | + invokeTarget: undefined, | ||
| 354 | + cronExpression: undefined, | ||
| 355 | + misfirePolicy: 1, | ||
| 356 | + concurrent: 1, | ||
| 357 | + status: "0" | ||
| 358 | + }; | ||
| 359 | + this.resetForm("form"); | ||
| 360 | + }, | ||
| 361 | + /** 搜索按钮操作 */ | ||
| 362 | + handleQuery() { | ||
| 363 | + this.queryParams.pageNum = 1; | ||
| 364 | + this.getList(); | ||
| 365 | + }, | ||
| 366 | + /** 重置按钮操作 */ | ||
| 367 | + resetQuery() { | ||
| 368 | + this.resetForm("queryForm"); | ||
| 369 | + this.handleQuery(); | ||
| 370 | + }, | ||
| 371 | + // 多选框选中数据 | ||
| 372 | + handleSelectionChange(selection) { | ||
| 373 | + this.ids = selection.map(item => item.jobId); | ||
| 374 | + this.single = selection.length != 1; | ||
| 375 | + this.multiple = !selection.length; | ||
| 376 | + }, | ||
| 377 | + // 任务状态修改 | ||
| 378 | + handleStatusChange(row) { | ||
| 379 | + let text = row.status === "0" ? "启用" : "停用"; | ||
| 380 | + this.$confirm('确认要"' + text + '""' + row.jobName + '"任务吗?', "警告", { | ||
| 381 | + confirmButtonText: "确定", | ||
| 382 | + cancelButtonText: "取消", | ||
| 383 | + type: "warning" | ||
| 384 | + }).then(function() { | ||
| 385 | + return changeJobStatus(row.jobId, row.status); | ||
| 386 | + }).then(() => { | ||
| 387 | + this.msgSuccess(text + "成功"); | ||
| 388 | + }).catch(function() { | ||
| 389 | + row.status = row.status === "0" ? "1" : "0"; | ||
| 390 | + }); | ||
| 391 | + }, | ||
| 392 | + /* 立即执行一次 */ | ||
| 393 | + handleRun(row) { | ||
| 394 | + this.$confirm('确认要立即执行一次"' + row.jobName + '"任务吗?', "警告", { | ||
| 395 | + confirmButtonText: "确定", | ||
| 396 | + cancelButtonText: "取消", | ||
| 397 | + type: "warning" | ||
| 398 | + }).then(function() { | ||
| 399 | + return runJob(row.jobId, row.jobGroup); | ||
| 400 | + }).then(function() { | ||
| 401 | + this.msgSuccess("执行成功"); | ||
| 402 | + }).catch(function() {}); | ||
| 403 | + }, | ||
| 404 | + /** 任务详细信息 */ | ||
| 405 | + handleView(row) { | ||
| 406 | + getJob(row.jobId).then(response => { | ||
| 407 | + this.form = response.data; | ||
| 408 | + this.openView = true; | ||
| 409 | + }); | ||
| 410 | + }, | ||
| 411 | + /** 任务日志列表查询 */ | ||
| 412 | + handleJobLog() { | ||
| 413 | + this.$router.push("/job/log"); | ||
| 414 | + }, | ||
| 415 | + /** 新增按钮操作 */ | ||
| 416 | + handleAdd() { | ||
| 417 | + this.reset(); | ||
| 418 | + this.open = true; | ||
| 419 | + this.title = "添加任务"; | ||
| 420 | + }, | ||
| 421 | + /** 修改按钮操作 */ | ||
| 422 | + handleUpdate(row) { | ||
| 423 | + this.reset(); | ||
| 424 | + const jobId = row.jobId || this.ids; | ||
| 425 | + getJob(jobId).then(response => { | ||
| 426 | + this.form = response.data; | ||
| 427 | + this.open = true; | ||
| 428 | + this.title = "修改任务"; | ||
| 429 | + }); | ||
| 430 | + }, | ||
| 431 | + /** 提交按钮 */ | ||
| 432 | + submitForm: function() { | ||
| 433 | + this.$refs["form"].validate(valid => { | ||
| 434 | + if (valid) { | ||
| 435 | + if (this.form.jobId != undefined) { | ||
| 436 | + updateJob(this.form).then(response => { | ||
| 437 | + if (response.code === 200) { | ||
| 438 | + this.msgSuccess("修改成功"); | ||
| 439 | + this.open = false; | ||
| 440 | + this.getList(); | ||
| 441 | + } else { | ||
| 442 | + this.msgError(response.msg); | ||
| 443 | + } | ||
| 444 | + }); | ||
| 445 | + } else { | ||
| 446 | + addJob(this.form).then(response => { | ||
| 447 | + if (response.code === 200) { | ||
| 448 | + this.msgSuccess("新增成功"); | ||
| 449 | + this.open = false; | ||
| 450 | + this.getList(); | ||
| 451 | + } else { | ||
| 452 | + this.msgError(response.msg); | ||
| 453 | + } | ||
| 454 | + }); | ||
| 455 | + } | ||
| 456 | + } | ||
| 457 | + }); | ||
| 458 | + }, | ||
| 459 | + /** 删除按钮操作 */ | ||
| 460 | + handleDelete(row) { | ||
| 461 | + const jobIds = row.jobId || this.ids; | ||
| 462 | + this.$confirm('是否确认删除定时任务编号为"' + jobIds + '"的数据项?', "警告", { | ||
| 463 | + confirmButtonText: "确定", | ||
| 464 | + cancelButtonText: "取消", | ||
| 465 | + type: "warning" | ||
| 466 | + }).then(function() { | ||
| 467 | + return delJob(jobIds); | ||
| 468 | + }).then(() => { | ||
| 469 | + this.getList(); | ||
| 470 | + this.msgSuccess("删除成功"); | ||
| 471 | + }).catch(function() {}); | ||
| 472 | + }, | ||
| 473 | + /** 导出按钮操作 */ | ||
| 474 | + handleExport() { | ||
| 475 | + const queryParams = this.queryParams; | ||
| 476 | + this.$confirm("是否确认导出所有定时任务数据项?", "警告", { | ||
| 477 | + confirmButtonText: "确定", | ||
| 478 | + cancelButtonText: "取消", | ||
| 479 | + type: "warning" | ||
| 480 | + }).then(function() { | ||
| 481 | + return exportJob(queryParams); | ||
| 482 | + }).then(response => { | ||
| 483 | + this.download(response.msg); | ||
| 484 | + }).catch(function() {}); | ||
| 485 | + } | ||
| 486 | + } | ||
| 487 | +}; | ||
| 488 | +</script> |
ruoyi-ui/src/views/monitor/job/log.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="app-container"> | ||
| 3 | + <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px"> | ||
| 4 | + <el-form-item label="任务名称" prop="jobName"> | ||
| 5 | + <el-input | ||
| 6 | + v-model="queryParams.jobName" | ||
| 7 | + placeholder="请输入任务名称" | ||
| 8 | + clearable | ||
| 9 | + size="small" | ||
| 10 | + style="width: 240px" | ||
| 11 | + @keyup.enter.native="handleQuery" | ||
| 12 | + /> | ||
| 13 | + </el-form-item> | ||
| 14 | + <el-form-item label="任务组名" prop="jobGroup"> | ||
| 15 | + <el-select | ||
| 16 | + v-model="queryParams.jobGroup" | ||
| 17 | + placeholder="请任务组名" | ||
| 18 | + clearable | ||
| 19 | + size="small" | ||
| 20 | + style="width: 240px" | ||
| 21 | + > | ||
| 22 | + <el-option | ||
| 23 | + v-for="dict in jobGroupOptions" | ||
| 24 | + :key="dict.dictValue" | ||
| 25 | + :label="dict.dictLabel" | ||
| 26 | + :value="dict.dictValue" | ||
| 27 | + /> | ||
| 28 | + </el-select> | ||
| 29 | + </el-form-item> | ||
| 30 | + <el-form-item label="执行状态" prop="status"> | ||
| 31 | + <el-select | ||
| 32 | + v-model="queryParams.status" | ||
| 33 | + placeholder="请选择执行状态" | ||
| 34 | + clearable | ||
| 35 | + size="small" | ||
| 36 | + style="width: 240px" | ||
| 37 | + > | ||
| 38 | + <el-option | ||
| 39 | + v-for="dict in statusOptions" | ||
| 40 | + :key="dict.dictValue" | ||
| 41 | + :label="dict.dictLabel" | ||
| 42 | + :value="dict.dictValue" | ||
| 43 | + /> | ||
| 44 | + </el-select> | ||
| 45 | + </el-form-item> | ||
| 46 | + <el-form-item label="执行时间"> | ||
| 47 | + <el-date-picker | ||
| 48 | + v-model="dateRange" | ||
| 49 | + size="small" | ||
| 50 | + style="width: 240px" | ||
| 51 | + value-format="yyyy-MM-dd" | ||
| 52 | + type="daterange" | ||
| 53 | + range-separator="-" | ||
| 54 | + start-placeholder="开始日期" | ||
| 55 | + end-placeholder="结束日期" | ||
| 56 | + ></el-date-picker> | ||
| 57 | + </el-form-item> | ||
| 58 | + <el-form-item> | ||
| 59 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | ||
| 60 | + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | ||
| 61 | + </el-form-item> | ||
| 62 | + </el-form> | ||
| 63 | + | ||
| 64 | + <el-row :gutter="10" class="mb8"> | ||
| 65 | + <el-col :span="1.5"> | ||
| 66 | + <el-button | ||
| 67 | + type="danger" | ||
| 68 | + icon="el-icon-delete" | ||
| 69 | + size="mini" | ||
| 70 | + :disabled="multiple" | ||
| 71 | + @click="handleDelete" | ||
| 72 | + v-hasPermi="['monitor:job:remove']" | ||
| 73 | + >删除</el-button> | ||
| 74 | + </el-col> | ||
| 75 | + <el-col :span="1.5"> | ||
| 76 | + <el-button | ||
| 77 | + type="danger" | ||
| 78 | + icon="el-icon-delete" | ||
| 79 | + size="mini" | ||
| 80 | + @click="handleClean" | ||
| 81 | + v-hasPermi="['monitor:job:remove']" | ||
| 82 | + >清空</el-button> | ||
| 83 | + </el-col> | ||
| 84 | + <el-col :span="1.5"> | ||
| 85 | + <el-button | ||
| 86 | + type="warning" | ||
| 87 | + icon="el-icon-download" | ||
| 88 | + size="mini" | ||
| 89 | + @click="handleExport" | ||
| 90 | + v-hasPermi="['monitor:jobLog:export']" | ||
| 91 | + >导出</el-button> | ||
| 92 | + </el-col> | ||
| 93 | + </el-row> | ||
| 94 | + | ||
| 95 | + <el-table v-loading="loading" :data="jobLogList" @selection-change="handleSelectionChange"> | ||
| 96 | + <el-table-column type="selection" width="55" align="center" /> | ||
| 97 | + <el-table-column label="日志编号" width="80" align="center" prop="jobLogId" /> | ||
| 98 | + <el-table-column label="任务名称" align="center" prop="jobName" :show-overflow-tooltip="true" /> | ||
| 99 | + <el-table-column label="任务组名" align="center" prop="jobGroup" :formatter="jobGroupFormat" :show-overflow-tooltip="true" /> | ||
| 100 | + <el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" /> | ||
| 101 | + <el-table-column label="日志信息" align="center" prop="jobMessage" :show-overflow-tooltip="true" /> | ||
| 102 | + <el-table-column label="执行状态" align="center" prop="status" :formatter="statusFormat" /> | ||
| 103 | + <el-table-column label="执行时间" align="center" prop="createTime" width="180"> | ||
| 104 | + <template slot-scope="scope"> | ||
| 105 | + <span>{{ parseTime(scope.row.createTime) }}</span> | ||
| 106 | + </template> | ||
| 107 | + </el-table-column> | ||
| 108 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 109 | + <template slot-scope="scope"> | ||
| 110 | + <el-button | ||
| 111 | + size="mini" | ||
| 112 | + type="text" | ||
| 113 | + icon="el-icon-view" | ||
| 114 | + @click="handleView(scope.row)" | ||
| 115 | + v-hasPermi="['monitor:job:query']" | ||
| 116 | + >详细</el-button> | ||
| 117 | + </template> | ||
| 118 | + </el-table-column> | ||
| 119 | + </el-table> | ||
| 120 | + | ||
| 121 | + <pagination | ||
| 122 | + v-show="total>0" | ||
| 123 | + :total="total" | ||
| 124 | + :page.sync="queryParams.pageNum" | ||
| 125 | + :limit.sync="queryParams.pageSize" | ||
| 126 | + @pagination="getList" | ||
| 127 | + /> | ||
| 128 | + | ||
| 129 | + <!-- 调度日志详细 --> | ||
| 130 | + <el-dialog title="调度日志详细" :visible.sync="open" width="700px"> | ||
| 131 | + <el-form ref="form" :model="form" label-width="100px" size="mini"> | ||
| 132 | + <el-row> | ||
| 133 | + <el-col :span="12"> | ||
| 134 | + <el-form-item label="日志序号:">{{ form.jobLogId }}</el-form-item> | ||
| 135 | + <el-form-item label="任务名称:">{{ form.jobName }}</el-form-item> | ||
| 136 | + </el-col> | ||
| 137 | + <el-col :span="12"> | ||
| 138 | + <el-form-item label="任务分组:">{{ form.jobGroup }}</el-form-item> | ||
| 139 | + <el-form-item label="执行时间:">{{ form.createTime }}</el-form-item> | ||
| 140 | + </el-col> | ||
| 141 | + <el-col :span="24"> | ||
| 142 | + <el-form-item label="调用方法:">{{ form.invokeTarget }}</el-form-item> | ||
| 143 | + </el-col> | ||
| 144 | + <el-col :span="24"> | ||
| 145 | + <el-form-item label="日志信息:">{{ form.jobMessage }}</el-form-item> | ||
| 146 | + </el-col> | ||
| 147 | + <el-col :span="24"> | ||
| 148 | + <el-form-item label="执行状态:"> | ||
| 149 | + <div v-if="form.status == 0">正常</div> | ||
| 150 | + <div v-else-if="form.status == 1">失败</div> | ||
| 151 | + </el-form-item> | ||
| 152 | + </el-col> | ||
| 153 | + <el-col :span="24"> | ||
| 154 | + <el-form-item label="异常信息:" v-if="form.status == 1">{{ form.exceptionInfo }}</el-form-item> | ||
| 155 | + </el-col> | ||
| 156 | + </el-row> | ||
| 157 | + </el-form> | ||
| 158 | + <div slot="footer" class="dialog-footer"> | ||
| 159 | + <el-button @click="open = false">关 闭</el-button> | ||
| 160 | + </div> | ||
| 161 | + </el-dialog> | ||
| 162 | + </div> | ||
| 163 | +</template> | ||
| 164 | + | ||
| 165 | +<script> | ||
| 166 | +import { listJobLog, delJobLog, exportJobLog, cleanJobLog } from "@/api/monitor/jobLog"; | ||
| 167 | + | ||
| 168 | +export default { | ||
| 169 | + name: "JobLog", | ||
| 170 | + data() { | ||
| 171 | + return { | ||
| 172 | + // 遮罩层 | ||
| 173 | + loading: true, | ||
| 174 | + // 选中数组 | ||
| 175 | + ids: [], | ||
| 176 | + // 非多个禁用 | ||
| 177 | + multiple: true, | ||
| 178 | + // 总条数 | ||
| 179 | + total: 0, | ||
| 180 | + // 调度日志表格数据 | ||
| 181 | + jobLogList: [], | ||
| 182 | + // 是否显示弹出层 | ||
| 183 | + open: false, | ||
| 184 | + // 日期范围 | ||
| 185 | + dateRange: [], | ||
| 186 | + // 表单参数 | ||
| 187 | + form: {}, | ||
| 188 | + // 执行状态字典 | ||
| 189 | + statusOptions: [], | ||
| 190 | + // 任务组名字典 | ||
| 191 | + jobGroupOptions: [], | ||
| 192 | + // 查询参数 | ||
| 193 | + queryParams: { | ||
| 194 | + pageNum: 1, | ||
| 195 | + pageSize: 10, | ||
| 196 | + jobName: undefined, | ||
| 197 | + jobGroup: undefined, | ||
| 198 | + status: undefined | ||
| 199 | + }, | ||
| 200 | + // 表单参数 | ||
| 201 | + form: {} | ||
| 202 | + }; | ||
| 203 | + }, | ||
| 204 | + created() { | ||
| 205 | + this.getList(); | ||
| 206 | + this.getDicts("sys_job_status").then(response => { | ||
| 207 | + this.statusOptions = response.data; | ||
| 208 | + }); | ||
| 209 | + this.getDicts("sys_job_group").then(response => { | ||
| 210 | + this.jobGroupOptions = response.data; | ||
| 211 | + }); | ||
| 212 | + }, | ||
| 213 | + methods: { | ||
| 214 | + /** 查询调度日志列表 */ | ||
| 215 | + getList() { | ||
| 216 | + this.loading = true; | ||
| 217 | + listJobLog(this.addDateRange(this.queryParams, this.dateRange)).then(response => { | ||
| 218 | + this.jobLogList = response.rows; | ||
| 219 | + this.total = response.total; | ||
| 220 | + this.loading = false; | ||
| 221 | + } | ||
| 222 | + ); | ||
| 223 | + }, | ||
| 224 | + // 执行状态字典翻译 | ||
| 225 | + statusFormat(row, column) { | ||
| 226 | + return this.selectDictLabel(this.statusOptions, row.status); | ||
| 227 | + }, | ||
| 228 | + // 任务组名字典翻译 | ||
| 229 | + jobGroupFormat(row, column) { | ||
| 230 | + return this.selectDictLabel(this.jobGroupOptions, row.jobGroup); | ||
| 231 | + }, | ||
| 232 | + /** 搜索按钮操作 */ | ||
| 233 | + handleQuery() { | ||
| 234 | + this.queryParams.pageNum = 1; | ||
| 235 | + this.getList(); | ||
| 236 | + }, | ||
| 237 | + /** 重置按钮操作 */ | ||
| 238 | + resetQuery() { | ||
| 239 | + this.dateRange = []; | ||
| 240 | + this.resetForm("queryForm"); | ||
| 241 | + this.handleQuery(); | ||
| 242 | + }, | ||
| 243 | + // 多选框选中数据 | ||
| 244 | + handleSelectionChange(selection) { | ||
| 245 | + this.ids = selection.map(item => item.jobLogId); | ||
| 246 | + this.multiple = !selection.length; | ||
| 247 | + }, | ||
| 248 | + /** 详细按钮操作 */ | ||
| 249 | + handleView(row) { | ||
| 250 | + this.open = true; | ||
| 251 | + this.form = row; | ||
| 252 | + }, | ||
| 253 | + /** 删除按钮操作 */ | ||
| 254 | + handleDelete(row) { | ||
| 255 | + const jobLogIds = this.ids; | ||
| 256 | + this.$confirm('是否确认删除调度日志编号为"' + jobLogIds + '"的数据项?', "警告", { | ||
| 257 | + confirmButtonText: "确定", | ||
| 258 | + cancelButtonText: "取消", | ||
| 259 | + type: "warning" | ||
| 260 | + }).then(function() { | ||
| 261 | + return delJobLog(jobLogIds); | ||
| 262 | + }).then(() => { | ||
| 263 | + this.getList(); | ||
| 264 | + this.msgSuccess("删除成功"); | ||
| 265 | + }).catch(function() {}); | ||
| 266 | + }, | ||
| 267 | + /** 清空按钮操作 */ | ||
| 268 | + handleClean() { | ||
| 269 | + this.$confirm("是否确认清空所有调度日志数据项?", "警告", { | ||
| 270 | + confirmButtonText: "确定", | ||
| 271 | + cancelButtonText: "取消", | ||
| 272 | + type: "warning" | ||
| 273 | + }).then(function() { | ||
| 274 | + return cleanJobLog(); | ||
| 275 | + }).then(() => { | ||
| 276 | + this.getList(); | ||
| 277 | + this.msgSuccess("清空成功"); | ||
| 278 | + }).catch(function() {}); | ||
| 279 | + }, | ||
| 280 | + /** 导出按钮操作 */ | ||
| 281 | + handleExport() { | ||
| 282 | + const queryParams = this.queryParams; | ||
| 283 | + this.$confirm("是否确认导出所有调度日志数据项?", "警告", { | ||
| 284 | + confirmButtonText: "确定", | ||
| 285 | + cancelButtonText: "取消", | ||
| 286 | + type: "warning" | ||
| 287 | + }).then(function() { | ||
| 288 | + return exportJobLog(queryParams); | ||
| 289 | + }).then(response => { | ||
| 290 | + this.download(response.msg); | ||
| 291 | + }).catch(function() {}); | ||
| 292 | + } | ||
| 293 | + } | ||
| 294 | +}; | ||
| 295 | +</script> |
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | 5 | ||
| 6 | <groupId>com.ruoyi</groupId> | 6 | <groupId>com.ruoyi</groupId> |
| 7 | <artifactId>ruoyi</artifactId> | 7 | <artifactId>ruoyi</artifactId> |
| 8 | - <version>2.1.0</version> | 8 | + <version>2.2.0</version> |
| 9 | <packaging>jar</packaging> | 9 | <packaging>jar</packaging> |
| 10 | 10 | ||
| 11 | <name>ruoyi</name> | 11 | <name>ruoyi</name> |
| @@ -224,6 +224,7 @@ | @@ -224,6 +224,7 @@ | ||
| 224 | <artifactId>poi-ooxml</artifactId> | 224 | <artifactId>poi-ooxml</artifactId> |
| 225 | <version>${poi.version}</version> | 225 | <version>${poi.version}</version> |
| 226 | </dependency> | 226 | </dependency> |
| 227 | + | ||
| 227 | <!--velocity代码生成使用模板 --> | 228 | <!--velocity代码生成使用模板 --> |
| 228 | <dependency> | 229 | <dependency> |
| 229 | <groupId>org.apache.velocity</groupId> | 230 | <groupId>org.apache.velocity</groupId> |
| @@ -231,6 +232,18 @@ | @@ -231,6 +232,18 @@ | ||
| 231 | <version>${velocity.version}</version> | 232 | <version>${velocity.version}</version> |
| 232 | </dependency> | 233 | </dependency> |
| 233 | 234 | ||
| 235 | + <!-- 定时任务 --> | ||
| 236 | + <dependency> | ||
| 237 | + <groupId>org.quartz-scheduler</groupId> | ||
| 238 | + <artifactId>quartz</artifactId> | ||
| 239 | + <exclusions> | ||
| 240 | + <exclusion> | ||
| 241 | + <groupId>com.mchange</groupId> | ||
| 242 | + <artifactId>c3p0</artifactId> | ||
| 243 | + </exclusion> | ||
| 244 | + </exclusions> | ||
| 245 | + </dependency> | ||
| 246 | + | ||
| 234 | </dependencies> | 247 | </dependencies> |
| 235 | 248 | ||
| 236 | <build> | 249 | <build> |
ruoyi/sql/quartz.sql
0 → 100644
| 1 | +-- ---------------------------- | ||
| 2 | +-- 1、存储每一个已配置的 jobDetail 的详细信息 | ||
| 3 | +-- ---------------------------- | ||
| 4 | +drop table if exists QRTZ_JOB_DETAILS; | ||
| 5 | +create table QRTZ_JOB_DETAILS ( | ||
| 6 | + sched_name varchar(120) not null, | ||
| 7 | + job_name varchar(200) not null, | ||
| 8 | + job_group varchar(200) not null, | ||
| 9 | + description varchar(250) null, | ||
| 10 | + job_class_name varchar(250) not null, | ||
| 11 | + is_durable varchar(1) not null, | ||
| 12 | + is_nonconcurrent varchar(1) not null, | ||
| 13 | + is_update_data varchar(1) not null, | ||
| 14 | + requests_recovery varchar(1) not null, | ||
| 15 | + job_data blob null, | ||
| 16 | + primary key (sched_name,job_name,job_group) | ||
| 17 | +) engine=innodb; | ||
| 18 | + | ||
| 19 | +-- ---------------------------- | ||
| 20 | +-- 2、 存储已配置的 Trigger 的信息 | ||
| 21 | +-- ---------------------------- | ||
| 22 | +drop table if exists QRTZ_TRIGGERS; | ||
| 23 | +create table QRTZ_TRIGGERS ( | ||
| 24 | + sched_name varchar(120) not null, | ||
| 25 | + trigger_name varchar(200) not null, | ||
| 26 | + trigger_group varchar(200) not null, | ||
| 27 | + job_name varchar(200) not null, | ||
| 28 | + job_group varchar(200) not null, | ||
| 29 | + description varchar(250) null, | ||
| 30 | + next_fire_time bigint(13) null, | ||
| 31 | + prev_fire_time bigint(13) null, | ||
| 32 | + priority integer null, | ||
| 33 | + trigger_state varchar(16) not null, | ||
| 34 | + trigger_type varchar(8) not null, | ||
| 35 | + start_time bigint(13) not null, | ||
| 36 | + end_time bigint(13) null, | ||
| 37 | + calendar_name varchar(200) null, | ||
| 38 | + misfire_instr smallint(2) null, | ||
| 39 | + job_data blob null, | ||
| 40 | + primary key (sched_name,trigger_name,trigger_group), | ||
| 41 | + foreign key (sched_name,job_name,job_group) references QRTZ_JOB_DETAILS(sched_name,job_name,job_group) | ||
| 42 | +) engine=innodb; | ||
| 43 | + | ||
| 44 | +-- ---------------------------- | ||
| 45 | +-- 3、 存储简单的 Trigger,包括重复次数,间隔,以及已触发的次数 | ||
| 46 | +-- ---------------------------- | ||
| 47 | +drop table if exists QRTZ_SIMPLE_TRIGGERS; | ||
| 48 | +create table QRTZ_SIMPLE_TRIGGERS ( | ||
| 49 | + sched_name varchar(120) not null, | ||
| 50 | + trigger_name varchar(200) not null, | ||
| 51 | + trigger_group varchar(200) not null, | ||
| 52 | + repeat_count bigint(7) not null, | ||
| 53 | + repeat_interval bigint(12) not null, | ||
| 54 | + times_triggered bigint(10) not null, | ||
| 55 | + primary key (sched_name,trigger_name,trigger_group), | ||
| 56 | + foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) | ||
| 57 | +) engine=innodb; | ||
| 58 | + | ||
| 59 | +-- ---------------------------- | ||
| 60 | +-- 4、 存储 Cron Trigger,包括 Cron 表达式和时区信息 | ||
| 61 | +-- ---------------------------- | ||
| 62 | +drop table if exists QRTZ_CRON_TRIGGERS; | ||
| 63 | +create table QRTZ_CRON_TRIGGERS ( | ||
| 64 | + sched_name varchar(120) not null, | ||
| 65 | + trigger_name varchar(200) not null, | ||
| 66 | + trigger_group varchar(200) not null, | ||
| 67 | + cron_expression varchar(200) not null, | ||
| 68 | + time_zone_id varchar(80), | ||
| 69 | + primary key (sched_name,trigger_name,trigger_group), | ||
| 70 | + foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) | ||
| 71 | +) engine=innodb; | ||
| 72 | + | ||
| 73 | +-- ---------------------------- | ||
| 74 | +-- 5、 Trigger 作为 Blob 类型存储(用于 Quartz 用户用 JDBC 创建他们自己定制的 Trigger 类型,JobStore 并不知道如何存储实例的时候) | ||
| 75 | +-- ---------------------------- | ||
| 76 | +drop table if exists QRTZ_BLOB_TRIGGERS; | ||
| 77 | +create table QRTZ_BLOB_TRIGGERS ( | ||
| 78 | + sched_name varchar(120) not null, | ||
| 79 | + trigger_name varchar(200) not null, | ||
| 80 | + trigger_group varchar(200) not null, | ||
| 81 | + blob_data blob null, | ||
| 82 | + primary key (sched_name,trigger_name,trigger_group), | ||
| 83 | + foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) | ||
| 84 | +) engine=innodb; | ||
| 85 | + | ||
| 86 | +-- ---------------------------- | ||
| 87 | +-- 6、 以 Blob 类型存储存放日历信息, quartz可配置一个日历来指定一个时间范围 | ||
| 88 | +-- ---------------------------- | ||
| 89 | +drop table if exists QRTZ_CALENDARS; | ||
| 90 | +create table QRTZ_CALENDARS ( | ||
| 91 | + sched_name varchar(120) not null, | ||
| 92 | + calendar_name varchar(200) not null, | ||
| 93 | + calendar blob not null, | ||
| 94 | + primary key (sched_name,calendar_name) | ||
| 95 | +) engine=innodb; | ||
| 96 | + | ||
| 97 | +-- ---------------------------- | ||
| 98 | +-- 7、 存储已暂停的 Trigger 组的信息 | ||
| 99 | +-- ---------------------------- | ||
| 100 | +drop table if exists QRTZ_PAUSED_TRIGGER_GRPS; | ||
| 101 | +create table QRTZ_PAUSED_TRIGGER_GRPS ( | ||
| 102 | + sched_name varchar(120) not null, | ||
| 103 | + trigger_group varchar(200) not null, | ||
| 104 | + primary key (sched_name,trigger_group) | ||
| 105 | +) engine=innodb; | ||
| 106 | + | ||
| 107 | +-- ---------------------------- | ||
| 108 | +-- 8、 存储与已触发的 Trigger 相关的状态信息,以及相联 Job 的执行信息 | ||
| 109 | +-- ---------------------------- | ||
| 110 | +drop table if exists QRTZ_FIRED_TRIGGERS; | ||
| 111 | +create table QRTZ_FIRED_TRIGGERS ( | ||
| 112 | + sched_name varchar(120) not null, | ||
| 113 | + entry_id varchar(95) not null, | ||
| 114 | + trigger_name varchar(200) not null, | ||
| 115 | + trigger_group varchar(200) not null, | ||
| 116 | + instance_name varchar(200) not null, | ||
| 117 | + fired_time bigint(13) not null, | ||
| 118 | + sched_time bigint(13) not null, | ||
| 119 | + priority integer not null, | ||
| 120 | + state varchar(16) not null, | ||
| 121 | + job_name varchar(200) null, | ||
| 122 | + job_group varchar(200) null, | ||
| 123 | + is_nonconcurrent varchar(1) null, | ||
| 124 | + requests_recovery varchar(1) null, | ||
| 125 | + primary key (sched_name,entry_id) | ||
| 126 | +) engine=innodb; | ||
| 127 | + | ||
| 128 | +-- ---------------------------- | ||
| 129 | +-- 9、 存储少量的有关 Scheduler 的状态信息,假如是用于集群中,可以看到其他的 Scheduler 实例 | ||
| 130 | +-- ---------------------------- | ||
| 131 | +drop table if exists QRTZ_SCHEDULER_STATE; | ||
| 132 | +create table QRTZ_SCHEDULER_STATE ( | ||
| 133 | + sched_name varchar(120) not null, | ||
| 134 | + instance_name varchar(200) not null, | ||
| 135 | + last_checkin_time bigint(13) not null, | ||
| 136 | + checkin_interval bigint(13) not null, | ||
| 137 | + primary key (sched_name,instance_name) | ||
| 138 | +) engine=innodb; | ||
| 139 | + | ||
| 140 | +-- ---------------------------- | ||
| 141 | +-- 10、 存储程序的悲观锁的信息(假如使用了悲观锁) | ||
| 142 | +-- ---------------------------- | ||
| 143 | +drop table if exists QRTZ_LOCKS; | ||
| 144 | +create table QRTZ_LOCKS ( | ||
| 145 | + sched_name varchar(120) not null, | ||
| 146 | + lock_name varchar(40) not null, | ||
| 147 | + primary key (sched_name,lock_name) | ||
| 148 | +) engine=innodb; | ||
| 149 | + | ||
| 150 | +drop table if exists QRTZ_SIMPROP_TRIGGERS; | ||
| 151 | +create table QRTZ_SIMPROP_TRIGGERS ( | ||
| 152 | + sched_name varchar(120) not null, | ||
| 153 | + trigger_name varchar(200) not null, | ||
| 154 | + trigger_group varchar(200) not null, | ||
| 155 | + str_prop_1 varchar(512) null, | ||
| 156 | + str_prop_2 varchar(512) null, | ||
| 157 | + str_prop_3 varchar(512) null, | ||
| 158 | + int_prop_1 int null, | ||
| 159 | + int_prop_2 int null, | ||
| 160 | + long_prop_1 bigint null, | ||
| 161 | + long_prop_2 bigint null, | ||
| 162 | + dec_prop_1 numeric(13,4) null, | ||
| 163 | + dec_prop_2 numeric(13,4) null, | ||
| 164 | + bool_prop_1 varchar(1) null, | ||
| 165 | + bool_prop_2 varchar(1) null, | ||
| 166 | + primary key (sched_name,trigger_name,trigger_group), | ||
| 167 | + foreign key (sched_name,trigger_name,trigger_group) references QRTZ_TRIGGERS(sched_name,trigger_name,trigger_group) | ||
| 168 | +) engine=innodb; | ||
| 169 | + | ||
| 170 | +commit; |
| @@ -14,7 +14,7 @@ public class RuoYiApplication | @@ -14,7 +14,7 @@ public class RuoYiApplication | ||
| 14 | { | 14 | { |
| 15 | public static void main(String[] args) | 15 | public static void main(String[] args) |
| 16 | { | 16 | { |
| 17 | - // System.setProperty("spring.devtools.restart.enabled", "false"); | 17 | + System.setProperty("spring.devtools.restart.enabled", "false"); |
| 18 | SpringApplication.run(RuoYiApplication.class, args); | 18 | SpringApplication.run(RuoYiApplication.class, args); |
| 19 | System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" + | 19 | System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" + |
| 20 | " .-------. ____ __ \n" + | 20 | " .-------. ____ __ \n" + |
| 1 | +package com.ruoyi.common.constant; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 任务调度通用常量 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public interface ScheduleConstants | ||
| 9 | +{ | ||
| 10 | + public static final String TASK_CLASS_NAME = "TASK_CLASS_NAME"; | ||
| 11 | + | ||
| 12 | + /** 执行目标key */ | ||
| 13 | + public static final String TASK_PROPERTIES = "TASK_PROPERTIES"; | ||
| 14 | + | ||
| 15 | + /** 默认 */ | ||
| 16 | + public static final String MISFIRE_DEFAULT = "0"; | ||
| 17 | + | ||
| 18 | + /** 立即触发执行 */ | ||
| 19 | + public static final String MISFIRE_IGNORE_MISFIRES = "1"; | ||
| 20 | + | ||
| 21 | + /** 触发一次执行 */ | ||
| 22 | + public static final String MISFIRE_FIRE_AND_PROCEED = "2"; | ||
| 23 | + | ||
| 24 | + /** 不触发立即执行 */ | ||
| 25 | + public static final String MISFIRE_DO_NOTHING = "3"; | ||
| 26 | + | ||
| 27 | + public enum Status | ||
| 28 | + { | ||
| 29 | + /** | ||
| 30 | + * 正常 | ||
| 31 | + */ | ||
| 32 | + NORMAL("0"), | ||
| 33 | + /** | ||
| 34 | + * 暂停 | ||
| 35 | + */ | ||
| 36 | + PAUSE("1"); | ||
| 37 | + | ||
| 38 | + private String value; | ||
| 39 | + | ||
| 40 | + private Status(String value) | ||
| 41 | + { | ||
| 42 | + this.value = value; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public String getValue() | ||
| 46 | + { | ||
| 47 | + return value; | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | +} |
| 1 | +package com.ruoyi.common.exception.job; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 计划策略异常 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public class TaskException extends Exception | ||
| 9 | +{ | ||
| 10 | + private static final long serialVersionUID = 1L; | ||
| 11 | + | ||
| 12 | + private Code code; | ||
| 13 | + | ||
| 14 | + public TaskException(String msg, Code code) | ||
| 15 | + { | ||
| 16 | + this(msg, code, null); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public TaskException(String msg, Code code, Exception nestedEx) | ||
| 20 | + { | ||
| 21 | + super(msg, nestedEx); | ||
| 22 | + this.code = code; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public Code getCode() | ||
| 26 | + { | ||
| 27 | + return code; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public enum Code | ||
| 31 | + { | ||
| 32 | + TASK_EXISTS, NO_TASK_EXISTS, TASK_ALREADY_STARTED, UNKNOWN, CONFIG_ERROR, TASK_NODE_NOT_AVAILABLE | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +package com.ruoyi.common.utils; | ||
| 2 | + | ||
| 3 | +import java.io.PrintWriter; | ||
| 4 | +import java.io.StringWriter; | ||
| 5 | +import org.apache.commons.lang3.exception.ExceptionUtils; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 错误信息处理类。 | ||
| 9 | + * | ||
| 10 | + * @author ruoyi | ||
| 11 | + */ | ||
| 12 | +public class ExceptionUtil | ||
| 13 | +{ | ||
| 14 | + /** | ||
| 15 | + * 获取exception的详细错误信息。 | ||
| 16 | + */ | ||
| 17 | + public static String getExceptionMessage(Throwable e) | ||
| 18 | + { | ||
| 19 | + StringWriter sw = new StringWriter(); | ||
| 20 | + e.printStackTrace(new PrintWriter(sw, true)); | ||
| 21 | + String str = sw.toString(); | ||
| 22 | + return str; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public static String getRootErrorMseeage(Exception e) | ||
| 26 | + { | ||
| 27 | + Throwable root = ExceptionUtils.getRootCause(e); | ||
| 28 | + root = (root == null ? e : root); | ||
| 29 | + if (root == null) | ||
| 30 | + { | ||
| 31 | + return ""; | ||
| 32 | + } | ||
| 33 | + String msg = root.getMessage(); | ||
| 34 | + if (msg == null) | ||
| 35 | + { | ||
| 36 | + return "null"; | ||
| 37 | + } | ||
| 38 | + return StringUtils.defaultString(msg); | ||
| 39 | + } | ||
| 40 | +} |
| 1 | +package com.ruoyi.common.utils.bean; | ||
| 2 | + | ||
| 3 | +import java.lang.reflect.Method; | ||
| 4 | +import java.util.ArrayList; | ||
| 5 | +import java.util.List; | ||
| 6 | +import java.util.regex.Matcher; | ||
| 7 | +import java.util.regex.Pattern; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * Bean 工具类 | ||
| 11 | + * | ||
| 12 | + * @author ruoyi | ||
| 13 | + */ | ||
| 14 | +public class BeanUtils extends org.springframework.beans.BeanUtils | ||
| 15 | +{ | ||
| 16 | + /** Bean方法名中属性名开始的下标 */ | ||
| 17 | + private static final int BEAN_METHOD_PROP_INDEX = 3; | ||
| 18 | + | ||
| 19 | + /** * 匹配getter方法的正则表达式 */ | ||
| 20 | + private static final Pattern GET_PATTERN = Pattern.compile("get(\\p{javaUpperCase}\\w*)"); | ||
| 21 | + | ||
| 22 | + /** * 匹配setter方法的正则表达式 */ | ||
| 23 | + private static final Pattern SET_PATTERN = Pattern.compile("set(\\p{javaUpperCase}\\w*)"); | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * Bean属性复制工具方法。 | ||
| 27 | + * | ||
| 28 | + * @param dest 目标对象 | ||
| 29 | + * @param src 源对象 | ||
| 30 | + */ | ||
| 31 | + public static void copyBeanProp(Object dest, Object src) | ||
| 32 | + { | ||
| 33 | + try | ||
| 34 | + { | ||
| 35 | + copyProperties(src, dest); | ||
| 36 | + } | ||
| 37 | + catch (Exception e) | ||
| 38 | + { | ||
| 39 | + e.printStackTrace(); | ||
| 40 | + } | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 获取对象的setter方法。 | ||
| 45 | + * | ||
| 46 | + * @param obj 对象 | ||
| 47 | + * @return 对象的setter方法列表 | ||
| 48 | + */ | ||
| 49 | + public static List<Method> getSetterMethods(Object obj) | ||
| 50 | + { | ||
| 51 | + // setter方法列表 | ||
| 52 | + List<Method> setterMethods = new ArrayList<Method>(); | ||
| 53 | + | ||
| 54 | + // 获取所有方法 | ||
| 55 | + Method[] methods = obj.getClass().getMethods(); | ||
| 56 | + | ||
| 57 | + // 查找setter方法 | ||
| 58 | + | ||
| 59 | + for (Method method : methods) | ||
| 60 | + { | ||
| 61 | + Matcher m = SET_PATTERN.matcher(method.getName()); | ||
| 62 | + if (m.matches() && (method.getParameterTypes().length == 1)) | ||
| 63 | + { | ||
| 64 | + setterMethods.add(method); | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + // 返回setter方法列表 | ||
| 68 | + return setterMethods; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 获取对象的getter方法。 | ||
| 73 | + * | ||
| 74 | + * @param obj 对象 | ||
| 75 | + * @return 对象的getter方法列表 | ||
| 76 | + */ | ||
| 77 | + | ||
| 78 | + public static List<Method> getGetterMethods(Object obj) | ||
| 79 | + { | ||
| 80 | + // getter方法列表 | ||
| 81 | + List<Method> getterMethods = new ArrayList<Method>(); | ||
| 82 | + // 获取所有方法 | ||
| 83 | + Method[] methods = obj.getClass().getMethods(); | ||
| 84 | + // 查找getter方法 | ||
| 85 | + for (Method method : methods) | ||
| 86 | + { | ||
| 87 | + Matcher m = GET_PATTERN.matcher(method.getName()); | ||
| 88 | + if (m.matches() && (method.getParameterTypes().length == 0)) | ||
| 89 | + { | ||
| 90 | + getterMethods.add(method); | ||
| 91 | + } | ||
| 92 | + } | ||
| 93 | + // 返回getter方法列表 | ||
| 94 | + return getterMethods; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * 检查Bean方法名中的属性名是否相等。<br> | ||
| 99 | + * 如getName()和setName()属性名一样,getName()和setAge()属性名不一样。 | ||
| 100 | + * | ||
| 101 | + * @param m1 方法名1 | ||
| 102 | + * @param m2 方法名2 | ||
| 103 | + * @return 属性名一样返回true,否则返回false | ||
| 104 | + */ | ||
| 105 | + | ||
| 106 | + public static boolean isMethodPropEquals(String m1, String m2) | ||
| 107 | + { | ||
| 108 | + return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX)); | ||
| 109 | + } | ||
| 110 | +} |
| @@ -21,7 +21,6 @@ public class HttpHelper | @@ -21,7 +21,6 @@ public class HttpHelper | ||
| 21 | 21 | ||
| 22 | public static String getBodyString(ServletRequest request) | 22 | public static String getBodyString(ServletRequest request) |
| 23 | { | 23 | { |
| 24 | - | ||
| 25 | StringBuilder sb = new StringBuilder(); | 24 | StringBuilder sb = new StringBuilder(); |
| 26 | BufferedReader reader = null; | 25 | BufferedReader reader = null; |
| 27 | try (InputStream inputStream = request.getInputStream()) | 26 | try (InputStream inputStream = request.getInputStream()) |
| 1 | +package com.ruoyi.common.utils.job; | ||
| 2 | + | ||
| 3 | +import java.util.Date; | ||
| 4 | +import org.quartz.Job; | ||
| 5 | +import org.quartz.JobExecutionContext; | ||
| 6 | +import org.quartz.JobExecutionException; | ||
| 7 | +import org.slf4j.Logger; | ||
| 8 | +import org.slf4j.LoggerFactory; | ||
| 9 | +import com.ruoyi.common.constant.Constants; | ||
| 10 | +import com.ruoyi.common.constant.ScheduleConstants; | ||
| 11 | +import com.ruoyi.common.utils.ExceptionUtil; | ||
| 12 | +import com.ruoyi.common.utils.StringUtils; | ||
| 13 | +import com.ruoyi.common.utils.bean.BeanUtils; | ||
| 14 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 15 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 16 | +import com.ruoyi.project.monitor.domain.SysJobLog; | ||
| 17 | +import com.ruoyi.project.monitor.service.ISysJobLogService; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * 抽象quartz调用 | ||
| 21 | + * | ||
| 22 | + * @author ruoyi | ||
| 23 | + */ | ||
| 24 | +public abstract class AbstractQuartzJob implements Job | ||
| 25 | +{ | ||
| 26 | + private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 线程本地变量 | ||
| 30 | + */ | ||
| 31 | + private static ThreadLocal<Date> threadLocal = new ThreadLocal<>(); | ||
| 32 | + | ||
| 33 | + @Override | ||
| 34 | + public void execute(JobExecutionContext context) throws JobExecutionException | ||
| 35 | + { | ||
| 36 | + SysJob sysJob = new SysJob(); | ||
| 37 | + BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES)); | ||
| 38 | + try | ||
| 39 | + { | ||
| 40 | + before(context, sysJob); | ||
| 41 | + if (sysJob != null) | ||
| 42 | + { | ||
| 43 | + doExecute(context, sysJob); | ||
| 44 | + } | ||
| 45 | + after(context, sysJob, null); | ||
| 46 | + } | ||
| 47 | + catch (Exception e) | ||
| 48 | + { | ||
| 49 | + log.error("任务执行异常 - :", e); | ||
| 50 | + after(context, sysJob, e); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 执行前 | ||
| 56 | + * | ||
| 57 | + * @param context 工作执行上下文对象 | ||
| 58 | + * @param sysJob 系统计划任务 | ||
| 59 | + */ | ||
| 60 | + protected void before(JobExecutionContext context, SysJob sysJob) | ||
| 61 | + { | ||
| 62 | + threadLocal.set(new Date()); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 执行后 | ||
| 67 | + * | ||
| 68 | + * @param context 工作执行上下文对象 | ||
| 69 | + * @param sysScheduleJob 系统计划任务 | ||
| 70 | + */ | ||
| 71 | + protected void after(JobExecutionContext context, SysJob sysJob, Exception e) | ||
| 72 | + { | ||
| 73 | + Date startTime = threadLocal.get(); | ||
| 74 | + threadLocal.remove(); | ||
| 75 | + | ||
| 76 | + final SysJobLog sysJobLog = new SysJobLog(); | ||
| 77 | + sysJobLog.setJobName(sysJob.getJobName()); | ||
| 78 | + sysJobLog.setJobGroup(sysJob.getJobGroup()); | ||
| 79 | + sysJobLog.setInvokeTarget(sysJob.getInvokeTarget()); | ||
| 80 | + sysJobLog.setStartTime(startTime); | ||
| 81 | + sysJobLog.setStopTime(new Date()); | ||
| 82 | + long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime(); | ||
| 83 | + sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒"); | ||
| 84 | + if (e != null) | ||
| 85 | + { | ||
| 86 | + sysJobLog.setStatus(Constants.FAIL); | ||
| 87 | + String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000); | ||
| 88 | + sysJobLog.setExceptionInfo(errorMsg); | ||
| 89 | + } | ||
| 90 | + else | ||
| 91 | + { | ||
| 92 | + sysJobLog.setStatus(Constants.SUCCESS); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + // 写入数据库当中 | ||
| 96 | + SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 执行方法,由子类重载 | ||
| 101 | + * | ||
| 102 | + * @param context 工作执行上下文对象 | ||
| 103 | + * @param sysJob 系统计划任务 | ||
| 104 | + * @throws Exception 执行过程中的异常 | ||
| 105 | + */ | ||
| 106 | + protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception; | ||
| 107 | +} |
| 1 | +package com.ruoyi.common.utils.job; | ||
| 2 | + | ||
| 3 | +import java.text.ParseException; | ||
| 4 | +import java.util.Date; | ||
| 5 | +import org.quartz.CronExpression; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * cron表达式工具类 | ||
| 9 | + * | ||
| 10 | + * @author ruoyi | ||
| 11 | + * | ||
| 12 | + */ | ||
| 13 | +public class CronUtils | ||
| 14 | +{ | ||
| 15 | + /** | ||
| 16 | + * 返回一个布尔值代表一个给定的Cron表达式的有效性 | ||
| 17 | + * | ||
| 18 | + * @param cronExpression Cron表达式 | ||
| 19 | + * @return boolean 表达式是否有效 | ||
| 20 | + */ | ||
| 21 | + public static boolean isValid(String cronExpression) | ||
| 22 | + { | ||
| 23 | + return CronExpression.isValidExpression(cronExpression); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 返回一个字符串值,表示该消息无效Cron表达式给出有效性 | ||
| 28 | + * | ||
| 29 | + * @param cronExpression Cron表达式 | ||
| 30 | + * @return String 无效时返回表达式错误描述,如果有效返回null | ||
| 31 | + */ | ||
| 32 | + public static String getInvalidMessage(String cronExpression) | ||
| 33 | + { | ||
| 34 | + try | ||
| 35 | + { | ||
| 36 | + new CronExpression(cronExpression); | ||
| 37 | + return null; | ||
| 38 | + } | ||
| 39 | + catch (ParseException pe) | ||
| 40 | + { | ||
| 41 | + return pe.getMessage(); | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 返回下一个执行时间根据给定的Cron表达式 | ||
| 47 | + * | ||
| 48 | + * @param cronExpression Cron表达式 | ||
| 49 | + * @return Date 下次Cron表达式执行时间 | ||
| 50 | + */ | ||
| 51 | + public static Date getNextExecution(String cronExpression) | ||
| 52 | + { | ||
| 53 | + try | ||
| 54 | + { | ||
| 55 | + CronExpression cron = new CronExpression(cronExpression); | ||
| 56 | + return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); | ||
| 57 | + } | ||
| 58 | + catch (ParseException e) | ||
| 59 | + { | ||
| 60 | + throw new IllegalArgumentException(e.getMessage()); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | +} |
| 1 | +package com.ruoyi.common.utils.job; | ||
| 2 | + | ||
| 3 | +import java.lang.reflect.InvocationTargetException; | ||
| 4 | +import java.lang.reflect.Method; | ||
| 5 | +import java.util.LinkedList; | ||
| 6 | +import java.util.List; | ||
| 7 | +import com.ruoyi.common.utils.StringUtils; | ||
| 8 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 9 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 任务执行工具 | ||
| 13 | + * | ||
| 14 | + * @author ruoyi | ||
| 15 | + */ | ||
| 16 | +public class JobInvokeUtil | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * 执行方法 | ||
| 20 | + * | ||
| 21 | + * @param sysJob 系统任务 | ||
| 22 | + */ | ||
| 23 | + public static void invokeMethod(SysJob sysJob) throws Exception | ||
| 24 | + { | ||
| 25 | + String invokeTarget = sysJob.getInvokeTarget(); | ||
| 26 | + String beanName = getBeanName(invokeTarget); | ||
| 27 | + String methodName = getMethodName(invokeTarget); | ||
| 28 | + List<Object[]> methodParams = getMethodParams(invokeTarget); | ||
| 29 | + | ||
| 30 | + if (!isValidClassName(beanName)) | ||
| 31 | + { | ||
| 32 | + Object bean = SpringUtils.getBean(beanName); | ||
| 33 | + invokeMethod(bean, methodName, methodParams); | ||
| 34 | + } | ||
| 35 | + else | ||
| 36 | + { | ||
| 37 | + Object bean = Class.forName(beanName).newInstance(); | ||
| 38 | + invokeMethod(bean, methodName, methodParams); | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 调用任务方法 | ||
| 44 | + * | ||
| 45 | + * @param bean 目标对象 | ||
| 46 | + * @param methodName 方法名称 | ||
| 47 | + * @param methodParams 方法参数 | ||
| 48 | + */ | ||
| 49 | + private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams) | ||
| 50 | + throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, | ||
| 51 | + InvocationTargetException | ||
| 52 | + { | ||
| 53 | + if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0) | ||
| 54 | + { | ||
| 55 | + Method method = bean.getClass().getDeclaredMethod(methodName, getMethodParamsType(methodParams)); | ||
| 56 | + method.invoke(bean, getMethodParamsValue(methodParams)); | ||
| 57 | + } | ||
| 58 | + else | ||
| 59 | + { | ||
| 60 | + Method method = bean.getClass().getDeclaredMethod(methodName); | ||
| 61 | + method.invoke(bean); | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 校验是否为为class包名 | ||
| 67 | + * | ||
| 68 | + * @param str 名称 | ||
| 69 | + * @return true是 false否 | ||
| 70 | + */ | ||
| 71 | + public static boolean isValidClassName(String invokeTarget) | ||
| 72 | + { | ||
| 73 | + return StringUtils.countMatches(invokeTarget, ".") > 1; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 获取bean名称 | ||
| 78 | + * | ||
| 79 | + * @param invokeTarget 目标字符串 | ||
| 80 | + * @return bean名称 | ||
| 81 | + */ | ||
| 82 | + public static String getBeanName(String invokeTarget) | ||
| 83 | + { | ||
| 84 | + String beanName = StringUtils.substringBefore(invokeTarget, "("); | ||
| 85 | + return StringUtils.substringBeforeLast(beanName, "."); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * 获取bean方法 | ||
| 90 | + * | ||
| 91 | + * @param invokeTarget 目标字符串 | ||
| 92 | + * @return method方法 | ||
| 93 | + */ | ||
| 94 | + public static String getMethodName(String invokeTarget) | ||
| 95 | + { | ||
| 96 | + String methodName = StringUtils.substringBefore(invokeTarget, "("); | ||
| 97 | + return StringUtils.substringAfterLast(methodName, "."); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 获取method方法参数相关列表 | ||
| 102 | + * | ||
| 103 | + * @param invokeTarget 目标字符串 | ||
| 104 | + * @return method方法相关参数列表 | ||
| 105 | + */ | ||
| 106 | + public static List<Object[]> getMethodParams(String invokeTarget) | ||
| 107 | + { | ||
| 108 | + String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")"); | ||
| 109 | + if (StringUtils.isEmpty(methodStr)) | ||
| 110 | + { | ||
| 111 | + return null; | ||
| 112 | + } | ||
| 113 | + String[] methodParams = methodStr.split(","); | ||
| 114 | + List<Object[]> classs = new LinkedList<>(); | ||
| 115 | + for (int i = 0; i < methodParams.length; i++) | ||
| 116 | + { | ||
| 117 | + String str = StringUtils.trimToEmpty(methodParams[i]); | ||
| 118 | + // String字符串类型,包含' | ||
| 119 | + if (StringUtils.contains(str, "'")) | ||
| 120 | + { | ||
| 121 | + classs.add(new Object[] { StringUtils.replace(str, "'", ""), String.class }); | ||
| 122 | + } | ||
| 123 | + // boolean布尔类型,等于true或者false | ||
| 124 | + else if (StringUtils.equals(str, "true") || StringUtils.equalsIgnoreCase(str, "false")) | ||
| 125 | + { | ||
| 126 | + classs.add(new Object[] { Boolean.valueOf(str), Boolean.class }); | ||
| 127 | + } | ||
| 128 | + // long长整形,包含L | ||
| 129 | + else if (StringUtils.containsIgnoreCase(str, "L")) | ||
| 130 | + { | ||
| 131 | + classs.add(new Object[] { Long.valueOf(StringUtils.replaceIgnoreCase(str, "L", "")), Long.class }); | ||
| 132 | + } | ||
| 133 | + // double浮点类型,包含D | ||
| 134 | + else if (StringUtils.containsIgnoreCase(str, "D")) | ||
| 135 | + { | ||
| 136 | + classs.add(new Object[] { Double.valueOf(StringUtils.replaceIgnoreCase(str, "D", "")), Double.class }); | ||
| 137 | + } | ||
| 138 | + // 其他类型归类为整形 | ||
| 139 | + else | ||
| 140 | + { | ||
| 141 | + classs.add(new Object[] { Integer.valueOf(str), Integer.class }); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + return classs; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + /** | ||
| 148 | + * 获取参数类型 | ||
| 149 | + * | ||
| 150 | + * @param methodParams 参数相关列表 | ||
| 151 | + * @return 参数类型列表 | ||
| 152 | + */ | ||
| 153 | + public static Class<?>[] getMethodParamsType(List<Object[]> methodParams) | ||
| 154 | + { | ||
| 155 | + Class<?>[] classs = new Class<?>[methodParams.size()]; | ||
| 156 | + int index = 0; | ||
| 157 | + for (Object[] os : methodParams) | ||
| 158 | + { | ||
| 159 | + classs[index] = (Class<?>) os[1]; | ||
| 160 | + index++; | ||
| 161 | + } | ||
| 162 | + return classs; | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + /** | ||
| 166 | + * 获取参数值 | ||
| 167 | + * | ||
| 168 | + * @param methodParams 参数相关列表 | ||
| 169 | + * @return 参数值列表 | ||
| 170 | + */ | ||
| 171 | + public static Object[] getMethodParamsValue(List<Object[]> methodParams) | ||
| 172 | + { | ||
| 173 | + Object[] classs = new Object[methodParams.size()]; | ||
| 174 | + int index = 0; | ||
| 175 | + for (Object[] os : methodParams) | ||
| 176 | + { | ||
| 177 | + classs[index] = (Object) os[0]; | ||
| 178 | + index++; | ||
| 179 | + } | ||
| 180 | + return classs; | ||
| 181 | + } | ||
| 182 | +} |
| 1 | +package com.ruoyi.common.utils.job; | ||
| 2 | + | ||
| 3 | +import org.quartz.DisallowConcurrentExecution; | ||
| 4 | +import org.quartz.JobExecutionContext; | ||
| 5 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 定时任务处理(禁止并发执行) | ||
| 9 | + * | ||
| 10 | + * @author ruoyi | ||
| 11 | + * | ||
| 12 | + */ | ||
| 13 | +@DisallowConcurrentExecution | ||
| 14 | +public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob | ||
| 15 | +{ | ||
| 16 | + @Override | ||
| 17 | + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception | ||
| 18 | + { | ||
| 19 | + JobInvokeUtil.invokeMethod(sysJob); | ||
| 20 | + } | ||
| 21 | +} |
| 1 | +package com.ruoyi.common.utils.job; | ||
| 2 | + | ||
| 3 | +import org.quartz.JobExecutionContext; | ||
| 4 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 定时任务处理(允许并发执行) | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + * | ||
| 11 | + */ | ||
| 12 | +public class QuartzJobExecution extends AbstractQuartzJob | ||
| 13 | +{ | ||
| 14 | + @Override | ||
| 15 | + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception | ||
| 16 | + { | ||
| 17 | + JobInvokeUtil.invokeMethod(sysJob); | ||
| 18 | + } | ||
| 19 | +} |
| 1 | +package com.ruoyi.common.utils.job; | ||
| 2 | + | ||
| 3 | +import org.quartz.CronScheduleBuilder; | ||
| 4 | +import org.quartz.CronTrigger; | ||
| 5 | +import org.quartz.Job; | ||
| 6 | +import org.quartz.JobBuilder; | ||
| 7 | +import org.quartz.JobDetail; | ||
| 8 | +import org.quartz.JobKey; | ||
| 9 | +import org.quartz.Scheduler; | ||
| 10 | +import org.quartz.SchedulerException; | ||
| 11 | +import org.quartz.TriggerBuilder; | ||
| 12 | +import org.quartz.TriggerKey; | ||
| 13 | +import com.ruoyi.common.constant.ScheduleConstants; | ||
| 14 | +import com.ruoyi.common.exception.job.TaskException; | ||
| 15 | +import com.ruoyi.common.exception.job.TaskException.Code; | ||
| 16 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * 定时任务工具类 | ||
| 20 | + * | ||
| 21 | + * @author ruoyi | ||
| 22 | + * | ||
| 23 | + */ | ||
| 24 | +public class ScheduleUtils | ||
| 25 | +{ | ||
| 26 | + /** | ||
| 27 | + * 得到quartz任务类 | ||
| 28 | + * | ||
| 29 | + * @param sysJob 执行计划 | ||
| 30 | + * @return 具体执行任务类 | ||
| 31 | + */ | ||
| 32 | + private static Class<? extends Job> getQuartzJobClass(SysJob sysJob) | ||
| 33 | + { | ||
| 34 | + boolean isConcurrent = "0".equals(sysJob.getConcurrent()); | ||
| 35 | + return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 构建任务触发对象 | ||
| 40 | + */ | ||
| 41 | + public static TriggerKey getTriggerKey(Long jobId, String jobGroup) | ||
| 42 | + { | ||
| 43 | + return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 构建任务键对象 | ||
| 48 | + */ | ||
| 49 | + public static JobKey getJobKey(Long jobId, String jobGroup) | ||
| 50 | + { | ||
| 51 | + return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 创建定时任务 | ||
| 56 | + */ | ||
| 57 | + public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException | ||
| 58 | + { | ||
| 59 | + Class<? extends Job> jobClass = getQuartzJobClass(job); | ||
| 60 | + // 构建job信息 | ||
| 61 | + Long jobId = job.getJobId(); | ||
| 62 | + String jobGroup = job.getJobGroup(); | ||
| 63 | + JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); | ||
| 64 | + | ||
| 65 | + // 表达式调度构建器 | ||
| 66 | + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); | ||
| 67 | + cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); | ||
| 68 | + | ||
| 69 | + // 按新的cronExpression表达式构建一个新的trigger | ||
| 70 | + CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) | ||
| 71 | + .withSchedule(cronScheduleBuilder).build(); | ||
| 72 | + | ||
| 73 | + // 放入参数,运行时的方法可以获取 | ||
| 74 | + jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); | ||
| 75 | + | ||
| 76 | + // 判断是否存在 | ||
| 77 | + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) | ||
| 78 | + { | ||
| 79 | + // 防止创建时存在数据问题 先移除,然后在执行创建操作 | ||
| 80 | + scheduler.deleteJob(getJobKey(jobId, jobGroup)); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + scheduler.scheduleJob(jobDetail, trigger); | ||
| 84 | + | ||
| 85 | + // 暂停任务 | ||
| 86 | + if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) | ||
| 87 | + { | ||
| 88 | + scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * 设置定时任务策略 | ||
| 94 | + */ | ||
| 95 | + public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb) | ||
| 96 | + throws TaskException | ||
| 97 | + { | ||
| 98 | + switch (job.getMisfirePolicy()) | ||
| 99 | + { | ||
| 100 | + case ScheduleConstants.MISFIRE_DEFAULT: | ||
| 101 | + return cb; | ||
| 102 | + case ScheduleConstants.MISFIRE_IGNORE_MISFIRES: | ||
| 103 | + return cb.withMisfireHandlingInstructionIgnoreMisfires(); | ||
| 104 | + case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED: | ||
| 105 | + return cb.withMisfireHandlingInstructionFireAndProceed(); | ||
| 106 | + case ScheduleConstants.MISFIRE_DO_NOTHING: | ||
| 107 | + return cb.withMisfireHandlingInstructionDoNothing(); | ||
| 108 | + default: | ||
| 109 | + throw new TaskException("The task misfire policy '" + job.getMisfirePolicy() | ||
| 110 | + + "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR); | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | +} |
| 1 | +package com.ruoyi.framework.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.context.annotation.Bean; | ||
| 4 | +import org.springframework.context.annotation.Configuration; | ||
| 5 | +import org.springframework.scheduling.quartz.SchedulerFactoryBean; | ||
| 6 | +import javax.sql.DataSource; | ||
| 7 | +import java.util.Properties; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 定时任务配置 | ||
| 11 | + * | ||
| 12 | + * @author ruoyi | ||
| 13 | + */ | ||
| 14 | +@Configuration | ||
| 15 | +public class ScheduleConfig | ||
| 16 | +{ | ||
| 17 | + @Bean | ||
| 18 | + public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) | ||
| 19 | + { | ||
| 20 | + SchedulerFactoryBean factory = new SchedulerFactoryBean(); | ||
| 21 | + factory.setDataSource(dataSource); | ||
| 22 | + | ||
| 23 | + // quartz参数 | ||
| 24 | + Properties prop = new Properties(); | ||
| 25 | + prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler"); | ||
| 26 | + prop.put("org.quartz.scheduler.instanceId", "AUTO"); | ||
| 27 | + // 线程池配置 | ||
| 28 | + prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); | ||
| 29 | + prop.put("org.quartz.threadPool.threadCount", "20"); | ||
| 30 | + prop.put("org.quartz.threadPool.threadPriority", "5"); | ||
| 31 | + // JobStore配置 | ||
| 32 | + prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); | ||
| 33 | + // 集群配置 | ||
| 34 | + prop.put("org.quartz.jobStore.isClustered", "true"); | ||
| 35 | + prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); | ||
| 36 | + prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); | ||
| 37 | + prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); | ||
| 38 | + | ||
| 39 | + // sqlserver 启用 | ||
| 40 | + // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); | ||
| 41 | + prop.put("org.quartz.jobStore.misfireThreshold", "12000"); | ||
| 42 | + prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); | ||
| 43 | + factory.setQuartzProperties(prop); | ||
| 44 | + | ||
| 45 | + factory.setSchedulerName("RuoyiScheduler"); | ||
| 46 | + // 延时启动 | ||
| 47 | + factory.setStartupDelay(1); | ||
| 48 | + factory.setApplicationContextSchedulerContextKey("applicationContextKey"); | ||
| 49 | + // 可选,QuartzScheduler | ||
| 50 | + // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 | ||
| 51 | + factory.setOverwriteExistingJobs(true); | ||
| 52 | + // 设置自动启动,默认为true | ||
| 53 | + factory.setAutoStartup(true); | ||
| 54 | + | ||
| 55 | + return factory; | ||
| 56 | + } | ||
| 57 | +} |
| @@ -99,6 +99,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -99,6 +99,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 99 | ).permitAll() | 99 | ).permitAll() |
| 100 | .antMatchers("/profile/**").anonymous() | 100 | .antMatchers("/profile/**").anonymous() |
| 101 | .antMatchers("/common/download**").anonymous() | 101 | .antMatchers("/common/download**").anonymous() |
| 102 | + .antMatchers("/common/download/resource**").anonymous() | ||
| 102 | .antMatchers("/swagger-ui.html").anonymous() | 103 | .antMatchers("/swagger-ui.html").anonymous() |
| 103 | .antMatchers("/swagger-resources/**").anonymous() | 104 | .antMatchers("/swagger-resources/**").anonymous() |
| 104 | .antMatchers("/webjars/**").anonymous() | 105 | .antMatchers("/webjars/**").anonymous() |
| @@ -59,7 +59,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor | @@ -59,7 +59,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor | ||
| 59 | nowDataMap.put(REPEAT_PARAMS, nowParams); | 59 | nowDataMap.put(REPEAT_PARAMS, nowParams); |
| 60 | nowDataMap.put(REPEAT_TIME, System.currentTimeMillis()); | 60 | nowDataMap.put(REPEAT_TIME, System.currentTimeMillis()); |
| 61 | 61 | ||
| 62 | - // 请求地址(作为存放session的key值) | 62 | + // 请求地址(作为存放cache的key值) |
| 63 | String url = request.getRequestURI(); | 63 | String url = request.getRequestURI(); |
| 64 | 64 | ||
| 65 | Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY); | 65 | Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY); |
| 1 | +package com.ruoyi.framework.task; | ||
| 2 | + | ||
| 3 | +import org.springframework.stereotype.Component; | ||
| 4 | +import com.ruoyi.common.utils.StringUtils; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 定时任务调度测试 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +@Component("ryTask") | ||
| 12 | +public class RyTask | ||
| 13 | +{ | ||
| 14 | + public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) | ||
| 15 | + { | ||
| 16 | + System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + public void ryParams(String params) | ||
| 20 | + { | ||
| 21 | + System.out.println("执行有参方法:" + params); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public void ryNoParams() | ||
| 25 | + { | ||
| 26 | + System.out.println("执行无参方法"); | ||
| 27 | + } | ||
| 28 | +} |
| @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping; | @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping; | ||
| 9 | import org.springframework.web.bind.annotation.PostMapping; | 9 | import org.springframework.web.bind.annotation.PostMapping; |
| 10 | import org.springframework.web.bind.annotation.RestController; | 10 | import org.springframework.web.bind.annotation.RestController; |
| 11 | import org.springframework.web.multipart.MultipartFile; | 11 | import org.springframework.web.multipart.MultipartFile; |
| 12 | +import com.ruoyi.common.constant.Constants; | ||
| 12 | import com.ruoyi.common.utils.StringUtils; | 13 | import com.ruoyi.common.utils.StringUtils; |
| 13 | import com.ruoyi.common.utils.file.FileUploadUtils; | 14 | import com.ruoyi.common.utils.file.FileUploadUtils; |
| 14 | import com.ruoyi.common.utils.file.FileUtils; | 15 | import com.ruoyi.common.utils.file.FileUtils; |
| @@ -86,4 +87,23 @@ public class CommonController | @@ -86,4 +87,23 @@ public class CommonController | ||
| 86 | return AjaxResult.error(e.getMessage()); | 87 | return AjaxResult.error(e.getMessage()); |
| 87 | } | 88 | } |
| 88 | } | 89 | } |
| 90 | + | ||
| 91 | + /** | ||
| 92 | + * 本地资源通用下载 | ||
| 93 | + */ | ||
| 94 | + @GetMapping("/common/download/resource") | ||
| 95 | + public void resourceDownload(String name, HttpServletRequest request, HttpServletResponse response) throws Exception | ||
| 96 | + { | ||
| 97 | + // 本地资源路径 | ||
| 98 | + String localPath = RuoYiConfig.getProfile(); | ||
| 99 | + // 数据库资源地址 | ||
| 100 | + String downloadPath = localPath + StringUtils.substringAfter(name, Constants.RESOURCE_PREFIX); | ||
| 101 | + // 下载名称 | ||
| 102 | + String downloadName = StringUtils.substringAfterLast(downloadPath, "/"); | ||
| 103 | + response.setCharacterEncoding("utf-8"); | ||
| 104 | + response.setContentType("multipart/form-data"); | ||
| 105 | + response.setHeader("Content-Disposition", | ||
| 106 | + "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName)); | ||
| 107 | + FileUtils.writeBytes(downloadPath, response.getOutputStream()); | ||
| 108 | + } | ||
| 89 | } | 109 | } |
| 1 | +package com.ruoyi.project.monitor.controller; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import org.quartz.SchedulerException; | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 7 | +import org.springframework.web.bind.annotation.DeleteMapping; | ||
| 8 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 9 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 10 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 11 | +import org.springframework.web.bind.annotation.PutMapping; | ||
| 12 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 14 | +import org.springframework.web.bind.annotation.RestController; | ||
| 15 | +import com.ruoyi.common.exception.job.TaskException; | ||
| 16 | +import com.ruoyi.common.utils.poi.ExcelUtil; | ||
| 17 | +import com.ruoyi.framework.aspectj.lang.annotation.Log; | ||
| 18 | +import com.ruoyi.framework.aspectj.lang.enums.BusinessType; | ||
| 19 | +import com.ruoyi.framework.web.controller.BaseController; | ||
| 20 | +import com.ruoyi.framework.web.domain.AjaxResult; | ||
| 21 | +import com.ruoyi.framework.web.page.TableDataInfo; | ||
| 22 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 23 | +import com.ruoyi.project.monitor.service.ISysJobService; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * 调度任务信息操作处理 | ||
| 27 | + * | ||
| 28 | + * @author ruoyi | ||
| 29 | + */ | ||
| 30 | +@RestController | ||
| 31 | +@RequestMapping("/monitor/job") | ||
| 32 | +public class SysJobController extends BaseController | ||
| 33 | +{ | ||
| 34 | + @Autowired | ||
| 35 | + private ISysJobService jobService; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 查询定时任务列表 | ||
| 39 | + */ | ||
| 40 | + @PreAuthorize("@ss.hasPermi('monitor:job:list')") | ||
| 41 | + @GetMapping("/list") | ||
| 42 | + public TableDataInfo list(SysJob sysJob) | ||
| 43 | + { | ||
| 44 | + startPage(); | ||
| 45 | + List<SysJob> list = jobService.selectJobList(sysJob); | ||
| 46 | + return getDataTable(list); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 导出定时任务列表 | ||
| 51 | + */ | ||
| 52 | + @PreAuthorize("@ss.hasPermi('monitor:job:export')") | ||
| 53 | + @Log(title = "定时任务", businessType = BusinessType.EXPORT) | ||
| 54 | + @GetMapping("/export") | ||
| 55 | + public AjaxResult export(SysJob sysJob) | ||
| 56 | + { | ||
| 57 | + List<SysJob> list = jobService.selectJobList(sysJob); | ||
| 58 | + ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class); | ||
| 59 | + return util.exportExcel(list, "定时任务"); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 获取定时任务详细信息 | ||
| 64 | + */ | ||
| 65 | + @PreAuthorize("@ss.hasPermi('monitor:job:query')") | ||
| 66 | + @GetMapping(value = "/{jobId}") | ||
| 67 | + public AjaxResult getInfo(@PathVariable("jobId") Long jobId) | ||
| 68 | + { | ||
| 69 | + return AjaxResult.success(jobService.selectJobById(jobId)); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 新增定时任务 | ||
| 74 | + */ | ||
| 75 | + @PreAuthorize("@ss.hasPermi('monitor:job:add')") | ||
| 76 | + @Log(title = "定时任务", businessType = BusinessType.INSERT) | ||
| 77 | + @PostMapping | ||
| 78 | + public AjaxResult add(@RequestBody SysJob sysJob) throws SchedulerException, TaskException | ||
| 79 | + { | ||
| 80 | + return toAjax(jobService.insertJob(sysJob)); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + /** | ||
| 84 | + * 修改定时任务 | ||
| 85 | + */ | ||
| 86 | + @PreAuthorize("@ss.hasPermi('monitor:job:edit')") | ||
| 87 | + @Log(title = "定时任务", businessType = BusinessType.UPDATE) | ||
| 88 | + @PutMapping | ||
| 89 | + public AjaxResult edit(@RequestBody SysJob sysJob) throws SchedulerException, TaskException | ||
| 90 | + { | ||
| 91 | + return toAjax(jobService.updateJob(sysJob)); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 定时任务状态修改 | ||
| 96 | + */ | ||
| 97 | + @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") | ||
| 98 | + @Log(title = "定时任务", businessType = BusinessType.UPDATE) | ||
| 99 | + @PutMapping("/changeStatus") | ||
| 100 | + public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException | ||
| 101 | + { | ||
| 102 | + SysJob newJob = jobService.selectJobById(job.getJobId()); | ||
| 103 | + newJob.setStatus(job.getStatus()); | ||
| 104 | + return toAjax(jobService.changeStatus(newJob)); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 定时任务立即执行一次 | ||
| 109 | + */ | ||
| 110 | + @PreAuthorize("@ss.hasPermi('monitor:job:changeStatus')") | ||
| 111 | + @Log(title = "定时任务", businessType = BusinessType.UPDATE) | ||
| 112 | + @PutMapping("/run") | ||
| 113 | + public AjaxResult run(@RequestBody SysJob job) throws SchedulerException | ||
| 114 | + { | ||
| 115 | + jobService.run(job); | ||
| 116 | + return AjaxResult.success(); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * 删除定时任务 | ||
| 121 | + */ | ||
| 122 | + @PreAuthorize("@ss.hasPermi('monitor:job:remove')") | ||
| 123 | + @Log(title = "定时任务", businessType = BusinessType.DELETE) | ||
| 124 | + @DeleteMapping("/{jobIds}") | ||
| 125 | + public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException | ||
| 126 | + { | ||
| 127 | + jobService.deleteJobByIds(jobIds); | ||
| 128 | + return AjaxResult.success(); | ||
| 129 | + } | ||
| 130 | +} |
| 1 | +package com.ruoyi.project.monitor.controller; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 7 | +import org.springframework.web.bind.annotation.DeleteMapping; | ||
| 8 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 9 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 10 | +import org.springframework.web.bind.annotation.RestController; | ||
| 11 | +import com.ruoyi.framework.aspectj.lang.annotation.Log; | ||
| 12 | +import com.ruoyi.framework.aspectj.lang.enums.BusinessType; | ||
| 13 | +import com.ruoyi.project.monitor.domain.SysJobLog; | ||
| 14 | +import com.ruoyi.project.monitor.service.ISysJobLogService; | ||
| 15 | +import com.ruoyi.framework.web.controller.BaseController; | ||
| 16 | +import com.ruoyi.framework.web.domain.AjaxResult; | ||
| 17 | +import com.ruoyi.common.utils.poi.ExcelUtil; | ||
| 18 | +import com.ruoyi.framework.web.page.TableDataInfo; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 调度日志操作处理 | ||
| 22 | + * | ||
| 23 | + * @author ruoyi | ||
| 24 | + */ | ||
| 25 | +@RestController | ||
| 26 | +@RequestMapping("/monitor/jobLog") | ||
| 27 | +public class SysJobLogController extends BaseController | ||
| 28 | +{ | ||
| 29 | + @Autowired | ||
| 30 | + private ISysJobLogService jobLogService; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 查询定时任务调度日志列表 | ||
| 34 | + */ | ||
| 35 | + @PreAuthorize("@ss.hasPermi('monitor:job:list')") | ||
| 36 | + @GetMapping("/list") | ||
| 37 | + public TableDataInfo list(SysJobLog sysJobLog) | ||
| 38 | + { | ||
| 39 | + startPage(); | ||
| 40 | + List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); | ||
| 41 | + return getDataTable(list); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 导出定时任务调度日志列表 | ||
| 46 | + */ | ||
| 47 | + @PreAuthorize("@ss.hasPermi('monitor:job:export')") | ||
| 48 | + @Log(title = "任务调度日志", businessType = BusinessType.EXPORT) | ||
| 49 | + @GetMapping("/export") | ||
| 50 | + public AjaxResult export(SysJobLog sysJobLog) | ||
| 51 | + { | ||
| 52 | + List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog); | ||
| 53 | + ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class); | ||
| 54 | + return util.exportExcel(list, "调度日志"); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 根据调度编号获取详细信息 | ||
| 59 | + */ | ||
| 60 | + @PreAuthorize("@ss.hasPermi('monitor:job:query')") | ||
| 61 | + @GetMapping(value = "/{configId}") | ||
| 62 | + public AjaxResult getInfo(@PathVariable Long jobLogId) | ||
| 63 | + { | ||
| 64 | + return AjaxResult.success(jobLogService.selectJobLogById(jobLogId)); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 删除定时任务调度日志 | ||
| 70 | + */ | ||
| 71 | + @PreAuthorize("@ss.hasPermi('monitor:job:remove')") | ||
| 72 | + @Log(title = "定时任务调度日志", businessType = BusinessType.DELETE) | ||
| 73 | + @DeleteMapping("/{jobLogIds}") | ||
| 74 | + public AjaxResult remove(@PathVariable Long[] jobLogIds) | ||
| 75 | + { | ||
| 76 | + return toAjax(jobLogService.deleteJobLogByIds(jobLogIds)); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @PreAuthorize("@ss.hasPermi('monitor:job:remove')") | ||
| 80 | + @Log(title = "调度日志", businessType = BusinessType.CLEAN) | ||
| 81 | + @DeleteMapping("/clean") | ||
| 82 | + public AjaxResult clean() | ||
| 83 | + { | ||
| 84 | + jobLogService.cleanJobLog(); | ||
| 85 | + return AjaxResult.success(); | ||
| 86 | + } | ||
| 87 | +} |
| 1 | +package com.ruoyi.project.monitor.domain; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | +import java.util.Date; | ||
| 5 | +import javax.validation.constraints.NotBlank; | ||
| 6 | +import javax.validation.constraints.Size; | ||
| 7 | +import org.apache.commons.lang3.builder.ToStringBuilder; | ||
| 8 | +import org.apache.commons.lang3.builder.ToStringStyle; | ||
| 9 | +import com.ruoyi.common.constant.ScheduleConstants; | ||
| 10 | +import com.ruoyi.common.utils.StringUtils; | ||
| 11 | +import com.ruoyi.common.utils.job.CronUtils; | ||
| 12 | +import com.ruoyi.framework.aspectj.lang.annotation.Excel; | ||
| 13 | +import com.ruoyi.framework.aspectj.lang.annotation.Excel.ColumnType; | ||
| 14 | +import com.ruoyi.framework.web.domain.BaseEntity; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * 定时任务调度表 sys_job | ||
| 18 | + * | ||
| 19 | + * @author ruoyi | ||
| 20 | + */ | ||
| 21 | +public class SysJob extends BaseEntity implements Serializable | ||
| 22 | +{ | ||
| 23 | + private static final long serialVersionUID = 1L; | ||
| 24 | + | ||
| 25 | + /** 任务ID */ | ||
| 26 | + @Excel(name = "任务序号", cellType = ColumnType.NUMERIC) | ||
| 27 | + private Long jobId; | ||
| 28 | + | ||
| 29 | + /** 任务名称 */ | ||
| 30 | + @Excel(name = "任务名称") | ||
| 31 | + private String jobName; | ||
| 32 | + | ||
| 33 | + /** 任务组名 */ | ||
| 34 | + @Excel(name = "任务组名") | ||
| 35 | + private String jobGroup; | ||
| 36 | + | ||
| 37 | + /** 调用目标字符串 */ | ||
| 38 | + @Excel(name = "调用目标字符串") | ||
| 39 | + private String invokeTarget; | ||
| 40 | + | ||
| 41 | + /** cron执行表达式 */ | ||
| 42 | + @Excel(name = "执行表达式 ") | ||
| 43 | + private String cronExpression; | ||
| 44 | + | ||
| 45 | + /** cron计划策略 */ | ||
| 46 | + @Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行") | ||
| 47 | + private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT; | ||
| 48 | + | ||
| 49 | + /** 是否并发执行(0允许 1禁止) */ | ||
| 50 | + @Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止") | ||
| 51 | + private String concurrent; | ||
| 52 | + | ||
| 53 | + /** 任务状态(0正常 1暂停) */ | ||
| 54 | + @Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停") | ||
| 55 | + private String status; | ||
| 56 | + | ||
| 57 | + public Long getJobId() | ||
| 58 | + { | ||
| 59 | + return jobId; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setJobId(Long jobId) | ||
| 63 | + { | ||
| 64 | + this.jobId = jobId; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @NotBlank(message = "任务名称不能为空") | ||
| 68 | + @Size(min = 0, max = 64, message = "任务名称不能超过64个字符") | ||
| 69 | + public String getJobName() | ||
| 70 | + { | ||
| 71 | + return jobName; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setJobName(String jobName) | ||
| 75 | + { | ||
| 76 | + this.jobName = jobName; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public String getJobGroup() | ||
| 80 | + { | ||
| 81 | + return jobGroup; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + public void setJobGroup(String jobGroup) | ||
| 85 | + { | ||
| 86 | + this.jobGroup = jobGroup; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @NotBlank(message = "调用目标字符串不能为空") | ||
| 90 | + @Size(min = 0, max = 1000, message = "调用目标字符串长度不能超过500个字符") | ||
| 91 | + public String getInvokeTarget() | ||
| 92 | + { | ||
| 93 | + return invokeTarget; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public void setInvokeTarget(String invokeTarget) | ||
| 97 | + { | ||
| 98 | + this.invokeTarget = invokeTarget; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + @NotBlank(message = "Cron执行表达式不能为空") | ||
| 102 | + @Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符") | ||
| 103 | + public String getCronExpression() | ||
| 104 | + { | ||
| 105 | + return cronExpression; | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + public void setCronExpression(String cronExpression) | ||
| 109 | + { | ||
| 110 | + this.cronExpression = cronExpression; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + public Date getNextValidTime() | ||
| 114 | + { | ||
| 115 | + if (StringUtils.isNotEmpty(cronExpression)) | ||
| 116 | + { | ||
| 117 | + return CronUtils.getNextExecution(cronExpression); | ||
| 118 | + } | ||
| 119 | + return null; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public String getMisfirePolicy() | ||
| 123 | + { | ||
| 124 | + return misfirePolicy; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + public void setMisfirePolicy(String misfirePolicy) | ||
| 128 | + { | ||
| 129 | + this.misfirePolicy = misfirePolicy; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public String getConcurrent() | ||
| 133 | + { | ||
| 134 | + return concurrent; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void setConcurrent(String concurrent) | ||
| 138 | + { | ||
| 139 | + this.concurrent = concurrent; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public String getStatus() | ||
| 143 | + { | ||
| 144 | + return status; | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + public void setStatus(String status) | ||
| 148 | + { | ||
| 149 | + this.status = status; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + @Override | ||
| 153 | + public String toString() { | ||
| 154 | + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||
| 155 | + .append("jobId", getJobId()) | ||
| 156 | + .append("jobName", getJobName()) | ||
| 157 | + .append("jobGroup", getJobGroup()) | ||
| 158 | + .append("cronExpression", getCronExpression()) | ||
| 159 | + .append("nextValidTime", getNextValidTime()) | ||
| 160 | + .append("misfirePolicy", getMisfirePolicy()) | ||
| 161 | + .append("concurrent", getConcurrent()) | ||
| 162 | + .append("status", getStatus()) | ||
| 163 | + .append("createBy", getCreateBy()) | ||
| 164 | + .append("createTime", getCreateTime()) | ||
| 165 | + .append("updateBy", getUpdateBy()) | ||
| 166 | + .append("updateTime", getUpdateTime()) | ||
| 167 | + .append("remark", getRemark()) | ||
| 168 | + .toString(); | ||
| 169 | + } | ||
| 170 | +} |
| 1 | +package com.ruoyi.project.monitor.domain; | ||
| 2 | + | ||
| 3 | +import java.util.Date; | ||
| 4 | +import org.apache.commons.lang3.builder.ToStringBuilder; | ||
| 5 | +import org.apache.commons.lang3.builder.ToStringStyle; | ||
| 6 | +import com.ruoyi.framework.aspectj.lang.annotation.Excel; | ||
| 7 | +import com.ruoyi.framework.web.domain.BaseEntity; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 定时任务调度日志表 sys_job_log | ||
| 11 | + * | ||
| 12 | + * @author ruoyi | ||
| 13 | + */ | ||
| 14 | +public class SysJobLog extends BaseEntity | ||
| 15 | +{ | ||
| 16 | + private static final long serialVersionUID = 1L; | ||
| 17 | + | ||
| 18 | + /** ID */ | ||
| 19 | + @Excel(name = "日志序号") | ||
| 20 | + private Long jobLogId; | ||
| 21 | + | ||
| 22 | + /** 任务名称 */ | ||
| 23 | + @Excel(name = "任务名称") | ||
| 24 | + private String jobName; | ||
| 25 | + | ||
| 26 | + /** 任务组名 */ | ||
| 27 | + @Excel(name = "任务组名") | ||
| 28 | + private String jobGroup; | ||
| 29 | + | ||
| 30 | + /** 调用目标字符串 */ | ||
| 31 | + @Excel(name = "调用目标字符串") | ||
| 32 | + private String invokeTarget; | ||
| 33 | + | ||
| 34 | + /** 日志信息 */ | ||
| 35 | + @Excel(name = "日志信息") | ||
| 36 | + private String jobMessage; | ||
| 37 | + | ||
| 38 | + /** 执行状态(0正常 1失败) */ | ||
| 39 | + @Excel(name = "执行状态", readConverterExp = "0=正常,1=失败") | ||
| 40 | + private String status; | ||
| 41 | + | ||
| 42 | + /** 异常信息 */ | ||
| 43 | + @Excel(name = "异常信息") | ||
| 44 | + private String exceptionInfo; | ||
| 45 | + | ||
| 46 | + /** 开始时间 */ | ||
| 47 | + private Date startTime; | ||
| 48 | + | ||
| 49 | + /** 停止时间 */ | ||
| 50 | + private Date stopTime; | ||
| 51 | + | ||
| 52 | + public Long getJobLogId() | ||
| 53 | + { | ||
| 54 | + return jobLogId; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setJobLogId(Long jobLogId) | ||
| 58 | + { | ||
| 59 | + this.jobLogId = jobLogId; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public String getJobName() | ||
| 63 | + { | ||
| 64 | + return jobName; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setJobName(String jobName) | ||
| 68 | + { | ||
| 69 | + this.jobName = jobName; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + public String getJobGroup() | ||
| 73 | + { | ||
| 74 | + return jobGroup; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public void setJobGroup(String jobGroup) | ||
| 78 | + { | ||
| 79 | + this.jobGroup = jobGroup; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public String getInvokeTarget() | ||
| 83 | + { | ||
| 84 | + return invokeTarget; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setInvokeTarget(String invokeTarget) | ||
| 88 | + { | ||
| 89 | + this.invokeTarget = invokeTarget; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + public String getJobMessage() | ||
| 93 | + { | ||
| 94 | + return jobMessage; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public void setJobMessage(String jobMessage) | ||
| 98 | + { | ||
| 99 | + this.jobMessage = jobMessage; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public String getStatus() | ||
| 103 | + { | ||
| 104 | + return status; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public void setStatus(String status) | ||
| 108 | + { | ||
| 109 | + this.status = status; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + public String getExceptionInfo() | ||
| 113 | + { | ||
| 114 | + return exceptionInfo; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public void setExceptionInfo(String exceptionInfo) | ||
| 118 | + { | ||
| 119 | + this.exceptionInfo = exceptionInfo; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public Date getStartTime() | ||
| 123 | + { | ||
| 124 | + return startTime; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + public void setStartTime(Date startTime) | ||
| 128 | + { | ||
| 129 | + this.startTime = startTime; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + public Date getStopTime() | ||
| 133 | + { | ||
| 134 | + return stopTime; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public void setStopTime(Date stopTime) | ||
| 138 | + { | ||
| 139 | + this.stopTime = stopTime; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + @Override | ||
| 143 | + public String toString() { | ||
| 144 | + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||
| 145 | + .append("jobLogId", getJobLogId()) | ||
| 146 | + .append("jobName", getJobName()) | ||
| 147 | + .append("jobGroup", getJobGroup()) | ||
| 148 | + .append("jobMessage", getJobMessage()) | ||
| 149 | + .append("status", getStatus()) | ||
| 150 | + .append("exceptionInfo", getExceptionInfo()) | ||
| 151 | + .append("startTime", getStartTime()) | ||
| 152 | + .append("stopTime", getStopTime()) | ||
| 153 | + .toString(); | ||
| 154 | + } | ||
| 155 | +} |
| 1 | +package com.ruoyi.project.monitor.mapper; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import com.ruoyi.project.monitor.domain.SysJobLog; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 调度任务日志信息 数据层 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public interface SysJobLogMapper | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * 获取quartz调度器日志的计划任务 | ||
| 15 | + * | ||
| 16 | + * @param jobLog 调度日志信息 | ||
| 17 | + * @return 调度任务日志集合 | ||
| 18 | + */ | ||
| 19 | + public List<SysJobLog> selectJobLogList(SysJobLog jobLog); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 查询所有调度任务日志 | ||
| 23 | + * | ||
| 24 | + * @return 调度任务日志列表 | ||
| 25 | + */ | ||
| 26 | + public List<SysJobLog> selectJobLogAll(); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 通过调度任务日志ID查询调度信息 | ||
| 30 | + * | ||
| 31 | + * @param jobLogId 调度任务日志ID | ||
| 32 | + * @return 调度任务日志对象信息 | ||
| 33 | + */ | ||
| 34 | + public SysJobLog selectJobLogById(Long jobLogId); | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 新增任务日志 | ||
| 38 | + * | ||
| 39 | + * @param jobLog 调度日志信息 | ||
| 40 | + * @return 结果 | ||
| 41 | + */ | ||
| 42 | + public int insertJobLog(SysJobLog jobLog); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 批量删除调度日志信息 | ||
| 46 | + * | ||
| 47 | + * @param logIds 需要删除的数据ID | ||
| 48 | + * @return 结果 | ||
| 49 | + */ | ||
| 50 | + public int deleteJobLogByIds(Long[] logIds); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 删除任务日志 | ||
| 54 | + * | ||
| 55 | + * @param jobId 调度日志ID | ||
| 56 | + * @return 结果 | ||
| 57 | + */ | ||
| 58 | + public int deleteJobLogById(Long jobId); | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 清空任务日志 | ||
| 62 | + */ | ||
| 63 | + public void cleanJobLog(); | ||
| 64 | +} |
| 1 | +package com.ruoyi.project.monitor.mapper; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 调度任务信息 数据层 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public interface SysJobMapper | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * 查询调度任务日志集合 | ||
| 15 | + * | ||
| 16 | + * @param job 调度信息 | ||
| 17 | + * @return 操作日志集合 | ||
| 18 | + */ | ||
| 19 | + public List<SysJob> selectJobList(SysJob job); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 查询所有调度任务 | ||
| 23 | + * | ||
| 24 | + * @return 调度任务列表 | ||
| 25 | + */ | ||
| 26 | + public List<SysJob> selectJobAll(); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 通过调度ID查询调度任务信息 | ||
| 30 | + * | ||
| 31 | + * @param jobId 调度ID | ||
| 32 | + * @return 角色对象信息 | ||
| 33 | + */ | ||
| 34 | + public SysJob selectJobById(Long jobId); | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 通过调度ID删除调度任务信息 | ||
| 38 | + * | ||
| 39 | + * @param jobId 调度ID | ||
| 40 | + * @return 结果 | ||
| 41 | + */ | ||
| 42 | + public int deleteJobById(Long jobId); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 批量删除调度任务信息 | ||
| 46 | + * | ||
| 47 | + * @param ids 需要删除的数据ID | ||
| 48 | + * @return 结果 | ||
| 49 | + */ | ||
| 50 | + public int deleteJobByIds(Long[] ids); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 修改调度任务信息 | ||
| 54 | + * | ||
| 55 | + * @param job 调度任务信息 | ||
| 56 | + * @return 结果 | ||
| 57 | + */ | ||
| 58 | + public int updateJob(SysJob job); | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 新增调度任务信息 | ||
| 62 | + * | ||
| 63 | + * @param job 调度任务信息 | ||
| 64 | + * @return 结果 | ||
| 65 | + */ | ||
| 66 | + public int insertJob(SysJob job); | ||
| 67 | +} |
| 1 | +package com.ruoyi.project.monitor.service; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import com.ruoyi.project.monitor.domain.SysJobLog; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 定时任务调度日志信息信息 服务层 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public interface ISysJobLogService | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * 获取quartz调度器日志的计划任务 | ||
| 15 | + * | ||
| 16 | + * @param jobLog 调度日志信息 | ||
| 17 | + * @return 调度任务日志集合 | ||
| 18 | + */ | ||
| 19 | + public List<SysJobLog> selectJobLogList(SysJobLog jobLog); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 通过调度任务日志ID查询调度信息 | ||
| 23 | + * | ||
| 24 | + * @param jobLogId 调度任务日志ID | ||
| 25 | + * @return 调度任务日志对象信息 | ||
| 26 | + */ | ||
| 27 | + public SysJobLog selectJobLogById(Long jobLogId); | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 新增任务日志 | ||
| 31 | + * | ||
| 32 | + * @param jobLog 调度日志信息 | ||
| 33 | + */ | ||
| 34 | + public void addJobLog(SysJobLog jobLog); | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 批量删除调度日志信息 | ||
| 38 | + * | ||
| 39 | + * @param logIds 需要删除的日志ID | ||
| 40 | + * @return 结果 | ||
| 41 | + */ | ||
| 42 | + public int deleteJobLogByIds(Long[] logIds); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 删除任务日志 | ||
| 46 | + * | ||
| 47 | + * @param jobId 调度日志ID | ||
| 48 | + * @return 结果 | ||
| 49 | + */ | ||
| 50 | + public int deleteJobLogById(Long jobId); | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 清空任务日志 | ||
| 54 | + */ | ||
| 55 | + public void cleanJobLog(); | ||
| 56 | +} |
| 1 | +package com.ruoyi.project.monitor.service; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import org.quartz.SchedulerException; | ||
| 5 | +import com.ruoyi.common.exception.job.TaskException; | ||
| 6 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 定时任务调度信息信息 服务层 | ||
| 10 | + * | ||
| 11 | + * @author ruoyi | ||
| 12 | + */ | ||
| 13 | +public interface ISysJobService | ||
| 14 | +{ | ||
| 15 | + /** | ||
| 16 | + * 获取quartz调度器的计划任务 | ||
| 17 | + * | ||
| 18 | + * @param job 调度信息 | ||
| 19 | + * @return 调度任务集合 | ||
| 20 | + */ | ||
| 21 | + public List<SysJob> selectJobList(SysJob job); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 通过调度任务ID查询调度信息 | ||
| 25 | + * | ||
| 26 | + * @param jobId 调度任务ID | ||
| 27 | + * @return 调度任务对象信息 | ||
| 28 | + */ | ||
| 29 | + public SysJob selectJobById(Long jobId); | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 暂停任务 | ||
| 33 | + * | ||
| 34 | + * @param job 调度信息 | ||
| 35 | + * @return 结果 | ||
| 36 | + */ | ||
| 37 | + public int pauseJob(SysJob job) throws SchedulerException; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 恢复任务 | ||
| 41 | + * | ||
| 42 | + * @param job 调度信息 | ||
| 43 | + * @return 结果 | ||
| 44 | + */ | ||
| 45 | + public int resumeJob(SysJob job) throws SchedulerException; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 删除任务后,所对应的trigger也将被删除 | ||
| 49 | + * | ||
| 50 | + * @param job 调度信息 | ||
| 51 | + * @return 结果 | ||
| 52 | + */ | ||
| 53 | + public int deleteJob(SysJob job) throws SchedulerException; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 批量删除调度信息 | ||
| 57 | + * | ||
| 58 | + * @param jobIds 需要删除的任务ID | ||
| 59 | + * @return 结果 | ||
| 60 | + */ | ||
| 61 | + public void deleteJobByIds(Long[] jobIds) throws SchedulerException; | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * 任务调度状态修改 | ||
| 65 | + * | ||
| 66 | + * @param job 调度信息 | ||
| 67 | + * @return 结果 | ||
| 68 | + */ | ||
| 69 | + public int changeStatus(SysJob job) throws SchedulerException; | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 立即运行任务 | ||
| 73 | + * | ||
| 74 | + * @param job 调度信息 | ||
| 75 | + * @return 结果 | ||
| 76 | + */ | ||
| 77 | + public void run(SysJob job) throws SchedulerException; | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 新增任务 | ||
| 81 | + * | ||
| 82 | + * @param job 调度信息 | ||
| 83 | + * @return 结果 | ||
| 84 | + */ | ||
| 85 | + public int insertJob(SysJob job) throws SchedulerException, TaskException; | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 更新任务 | ||
| 89 | + * | ||
| 90 | + * @param job 调度信息 | ||
| 91 | + * @return 结果 | ||
| 92 | + */ | ||
| 93 | + public int updateJob(SysJob job) throws SchedulerException, TaskException; | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * 校验cron表达式是否有效 | ||
| 97 | + * | ||
| 98 | + * @param cronExpression 表达式 | ||
| 99 | + * @return 结果 | ||
| 100 | + */ | ||
| 101 | + public boolean checkCronExpressionIsValid(String cronExpression); | ||
| 102 | +} |
| 1 | +package com.ruoyi.project.monitor.service.impl; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.stereotype.Service; | ||
| 6 | +import com.ruoyi.project.monitor.domain.SysJobLog; | ||
| 7 | +import com.ruoyi.project.monitor.mapper.SysJobLogMapper; | ||
| 8 | +import com.ruoyi.project.monitor.service.ISysJobLogService; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 定时任务调度日志信息 服务层 | ||
| 12 | + * | ||
| 13 | + * @author ruoyi | ||
| 14 | + */ | ||
| 15 | +@Service | ||
| 16 | +public class SysJobLogServiceImpl implements ISysJobLogService | ||
| 17 | +{ | ||
| 18 | + @Autowired | ||
| 19 | + private SysJobLogMapper jobLogMapper; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 获取quartz调度器日志的计划任务 | ||
| 23 | + * | ||
| 24 | + * @param jobLog 调度日志信息 | ||
| 25 | + * @return 调度任务日志集合 | ||
| 26 | + */ | ||
| 27 | + @Override | ||
| 28 | + public List<SysJobLog> selectJobLogList(SysJobLog jobLog) | ||
| 29 | + { | ||
| 30 | + return jobLogMapper.selectJobLogList(jobLog); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 通过调度任务日志ID查询调度信息 | ||
| 35 | + * | ||
| 36 | + * @param jobLogId 调度任务日志ID | ||
| 37 | + * @return 调度任务日志对象信息 | ||
| 38 | + */ | ||
| 39 | + @Override | ||
| 40 | + public SysJobLog selectJobLogById(Long jobLogId) | ||
| 41 | + { | ||
| 42 | + return jobLogMapper.selectJobLogById(jobLogId); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 新增任务日志 | ||
| 47 | + * | ||
| 48 | + * @param jobLog 调度日志信息 | ||
| 49 | + */ | ||
| 50 | + @Override | ||
| 51 | + public void addJobLog(SysJobLog jobLog) | ||
| 52 | + { | ||
| 53 | + jobLogMapper.insertJobLog(jobLog); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 批量删除调度日志信息 | ||
| 58 | + * | ||
| 59 | + * @param logIds 需要删除的数据ID | ||
| 60 | + * @return 结果 | ||
| 61 | + */ | ||
| 62 | + @Override | ||
| 63 | + public int deleteJobLogByIds(Long[] logIds) | ||
| 64 | + { | ||
| 65 | + return jobLogMapper.deleteJobLogByIds(logIds); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 删除任务日志 | ||
| 70 | + * | ||
| 71 | + * @param jobId 调度日志ID | ||
| 72 | + */ | ||
| 73 | + @Override | ||
| 74 | + public int deleteJobLogById(Long jobId) | ||
| 75 | + { | ||
| 76 | + return jobLogMapper.deleteJobLogById(jobId); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 清空任务日志 | ||
| 81 | + */ | ||
| 82 | + @Override | ||
| 83 | + public void cleanJobLog() | ||
| 84 | + { | ||
| 85 | + jobLogMapper.cleanJobLog(); | ||
| 86 | + } | ||
| 87 | +} |
| 1 | +package com.ruoyi.project.monitor.service.impl; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import javax.annotation.PostConstruct; | ||
| 5 | +import org.quartz.JobDataMap; | ||
| 6 | +import org.quartz.JobKey; | ||
| 7 | +import org.quartz.Scheduler; | ||
| 8 | +import org.quartz.SchedulerException; | ||
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.transaction.annotation.Transactional; | ||
| 12 | +import com.ruoyi.common.constant.ScheduleConstants; | ||
| 13 | +import com.ruoyi.common.exception.job.TaskException; | ||
| 14 | +import com.ruoyi.common.utils.job.CronUtils; | ||
| 15 | +import com.ruoyi.common.utils.job.ScheduleUtils; | ||
| 16 | +import com.ruoyi.project.monitor.domain.SysJob; | ||
| 17 | +import com.ruoyi.project.monitor.mapper.SysJobMapper; | ||
| 18 | +import com.ruoyi.project.monitor.service.ISysJobService; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 定时任务调度信息 服务层 | ||
| 22 | + * | ||
| 23 | + * @author ruoyi | ||
| 24 | + */ | ||
| 25 | +@Service | ||
| 26 | +public class SysJobServiceImpl implements ISysJobService | ||
| 27 | +{ | ||
| 28 | + @Autowired | ||
| 29 | + private Scheduler scheduler; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private SysJobMapper jobMapper; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) | ||
| 36 | + */ | ||
| 37 | + @PostConstruct | ||
| 38 | + public void init() throws SchedulerException, TaskException | ||
| 39 | + { | ||
| 40 | + scheduler.clear(); | ||
| 41 | + List<SysJob> jobList = jobMapper.selectJobAll(); | ||
| 42 | + for (SysJob job : jobList) | ||
| 43 | + { | ||
| 44 | + ScheduleUtils.createScheduleJob(scheduler, job); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 获取quartz调度器的计划任务列表 | ||
| 50 | + * | ||
| 51 | + * @param job 调度信息 | ||
| 52 | + * @return | ||
| 53 | + */ | ||
| 54 | + @Override | ||
| 55 | + public List<SysJob> selectJobList(SysJob job) | ||
| 56 | + { | ||
| 57 | + return jobMapper.selectJobList(job); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 通过调度任务ID查询调度信息 | ||
| 62 | + * | ||
| 63 | + * @param jobId 调度任务ID | ||
| 64 | + * @return 调度任务对象信息 | ||
| 65 | + */ | ||
| 66 | + @Override | ||
| 67 | + public SysJob selectJobById(Long jobId) | ||
| 68 | + { | ||
| 69 | + return jobMapper.selectJobById(jobId); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * 暂停任务 | ||
| 74 | + * | ||
| 75 | + * @param job 调度信息 | ||
| 76 | + */ | ||
| 77 | + @Override | ||
| 78 | + @Transactional | ||
| 79 | + public int pauseJob(SysJob job) throws SchedulerException | ||
| 80 | + { | ||
| 81 | + Long jobId = job.getJobId(); | ||
| 82 | + String jobGroup = job.getJobGroup(); | ||
| 83 | + job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); | ||
| 84 | + int rows = jobMapper.updateJob(job); | ||
| 85 | + if (rows > 0) | ||
| 86 | + { | ||
| 87 | + scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | ||
| 88 | + } | ||
| 89 | + return rows; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * 恢复任务 | ||
| 94 | + * | ||
| 95 | + * @param job 调度信息 | ||
| 96 | + */ | ||
| 97 | + @Override | ||
| 98 | + @Transactional | ||
| 99 | + public int resumeJob(SysJob job) throws SchedulerException | ||
| 100 | + { | ||
| 101 | + Long jobId = job.getJobId(); | ||
| 102 | + String jobGroup = job.getJobGroup(); | ||
| 103 | + job.setStatus(ScheduleConstants.Status.NORMAL.getValue()); | ||
| 104 | + int rows = jobMapper.updateJob(job); | ||
| 105 | + if (rows > 0) | ||
| 106 | + { | ||
| 107 | + scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | ||
| 108 | + } | ||
| 109 | + return rows; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + /** | ||
| 113 | + * 删除任务后,所对应的trigger也将被删除 | ||
| 114 | + * | ||
| 115 | + * @param job 调度信息 | ||
| 116 | + */ | ||
| 117 | + @Override | ||
| 118 | + @Transactional | ||
| 119 | + public int deleteJob(SysJob job) throws SchedulerException | ||
| 120 | + { | ||
| 121 | + Long jobId = job.getJobId(); | ||
| 122 | + String jobGroup = job.getJobGroup(); | ||
| 123 | + int rows = jobMapper.deleteJobById(jobId); | ||
| 124 | + if (rows > 0) | ||
| 125 | + { | ||
| 126 | + scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); | ||
| 127 | + } | ||
| 128 | + return rows; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 批量删除调度信息 | ||
| 133 | + * | ||
| 134 | + * @param jobIds 需要删除的任务ID | ||
| 135 | + * @return 结果 | ||
| 136 | + */ | ||
| 137 | + @Override | ||
| 138 | + @Transactional | ||
| 139 | + public void deleteJobByIds(Long[] jobIds) throws SchedulerException | ||
| 140 | + { | ||
| 141 | + for (Long jobId : jobIds) | ||
| 142 | + { | ||
| 143 | + SysJob job = jobMapper.selectJobById(jobId); | ||
| 144 | + deleteJob(job); | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + /** | ||
| 149 | + * 任务调度状态修改 | ||
| 150 | + * | ||
| 151 | + * @param job 调度信息 | ||
| 152 | + */ | ||
| 153 | + @Override | ||
| 154 | + @Transactional | ||
| 155 | + public int changeStatus(SysJob job) throws SchedulerException | ||
| 156 | + { | ||
| 157 | + int rows = 0; | ||
| 158 | + String status = job.getStatus(); | ||
| 159 | + if (ScheduleConstants.Status.NORMAL.getValue().equals(status)) | ||
| 160 | + { | ||
| 161 | + rows = resumeJob(job); | ||
| 162 | + } | ||
| 163 | + else if (ScheduleConstants.Status.PAUSE.getValue().equals(status)) | ||
| 164 | + { | ||
| 165 | + rows = pauseJob(job); | ||
| 166 | + } | ||
| 167 | + return rows; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * 立即运行任务 | ||
| 172 | + * | ||
| 173 | + * @param job 调度信息 | ||
| 174 | + */ | ||
| 175 | + @Override | ||
| 176 | + @Transactional | ||
| 177 | + public void run(SysJob job) throws SchedulerException | ||
| 178 | + { | ||
| 179 | + Long jobId = job.getJobId(); | ||
| 180 | + String jobGroup = job.getJobGroup(); | ||
| 181 | + SysJob properties = selectJobById(job.getJobId()); | ||
| 182 | + // 参数 | ||
| 183 | + JobDataMap dataMap = new JobDataMap(); | ||
| 184 | + dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties); | ||
| 185 | + scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + /** | ||
| 189 | + * 新增任务 | ||
| 190 | + * | ||
| 191 | + * @param job 调度信息 调度信息 | ||
| 192 | + */ | ||
| 193 | + @Override | ||
| 194 | + @Transactional | ||
| 195 | + public int insertJob(SysJob job) throws SchedulerException, TaskException | ||
| 196 | + { | ||
| 197 | + job.setStatus(ScheduleConstants.Status.PAUSE.getValue()); | ||
| 198 | + int rows = jobMapper.insertJob(job); | ||
| 199 | + if (rows > 0) | ||
| 200 | + { | ||
| 201 | + ScheduleUtils.createScheduleJob(scheduler, job); | ||
| 202 | + } | ||
| 203 | + return rows; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + /** | ||
| 207 | + * 更新任务的时间表达式 | ||
| 208 | + * | ||
| 209 | + * @param job 调度信息 | ||
| 210 | + */ | ||
| 211 | + @Override | ||
| 212 | + @Transactional | ||
| 213 | + public int updateJob(SysJob job) throws SchedulerException, TaskException | ||
| 214 | + { | ||
| 215 | + SysJob properties = selectJobById(job.getJobId()); | ||
| 216 | + int rows = jobMapper.updateJob(job); | ||
| 217 | + if (rows > 0) | ||
| 218 | + { | ||
| 219 | + updateSchedulerJob(job, properties.getJobGroup()); | ||
| 220 | + } | ||
| 221 | + return rows; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + /** | ||
| 225 | + * 更新任务 | ||
| 226 | + * | ||
| 227 | + * @param job 任务对象 | ||
| 228 | + * @param jobGroup 任务组名 | ||
| 229 | + */ | ||
| 230 | + public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException | ||
| 231 | + { | ||
| 232 | + Long jobId = job.getJobId(); | ||
| 233 | + // 判断是否存在 | ||
| 234 | + JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); | ||
| 235 | + if (scheduler.checkExists(jobKey)) | ||
| 236 | + { | ||
| 237 | + // 防止创建时存在数据问题 先移除,然后在执行创建操作 | ||
| 238 | + scheduler.deleteJob(jobKey); | ||
| 239 | + } | ||
| 240 | + ScheduleUtils.createScheduleJob(scheduler, job); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + /** | ||
| 244 | + * 校验cron表达式是否有效 | ||
| 245 | + * | ||
| 246 | + * @param cronExpression 表达式 | ||
| 247 | + * @return 结果 | ||
| 248 | + */ | ||
| 249 | + @Override | ||
| 250 | + public boolean checkCronExpressionIsValid(String cronExpression) | ||
| 251 | + { | ||
| 252 | + return CronUtils.isValid(cronExpression); | ||
| 253 | + } | ||
| 254 | +} |
| @@ -3,7 +3,7 @@ ruoyi: | @@ -3,7 +3,7 @@ ruoyi: | ||
| 3 | # 名称 | 3 | # 名称 |
| 4 | name: RuoYi | 4 | name: RuoYi |
| 5 | # 版本 | 5 | # 版本 |
| 6 | - version: 2.1.0 | 6 | + version: 2.2.0 |
| 7 | # 版权年份 | 7 | # 版权年份 |
| 8 | copyrightYear: 2019 | 8 | copyrightYear: 2019 |
| 9 | # 实例演示开关 | 9 | # 实例演示开关 |
| @@ -28,7 +28,6 @@ server: | @@ -28,7 +28,6 @@ server: | ||
| 28 | # Tomcat启动初始化的线程数,默认值25 | 28 | # Tomcat启动初始化的线程数,默认值25 |
| 29 | min-spare-threads: 30 | 29 | min-spare-threads: 30 |
| 30 | 30 | ||
| 31 | - | ||
| 32 | # 日志配置 | 31 | # 日志配置 |
| 33 | logging: | 32 | logging: |
| 34 | level: | 33 | level: |
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | +<!DOCTYPE mapper | ||
| 3 | +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | +<mapper namespace="com.ruoyi.project.monitor.mapper.SysJobLogMapper"> | ||
| 6 | + | ||
| 7 | + <resultMap type="SysJobLog" id="SysJobLogResult"> | ||
| 8 | + <id property="jobLogId" column="job_log_id" /> | ||
| 9 | + <result property="jobName" column="job_name" /> | ||
| 10 | + <result property="jobGroup" column="job_group" /> | ||
| 11 | + <result property="invokeTarget" column="invoke_target" /> | ||
| 12 | + <result property="jobMessage" column="job_message" /> | ||
| 13 | + <result property="status" column="status" /> | ||
| 14 | + <result property="exceptionInfo" column="exception_info" /> | ||
| 15 | + <result property="createTime" column="create_time" /> | ||
| 16 | + </resultMap> | ||
| 17 | + | ||
| 18 | + <sql id="selectJobLogVo"> | ||
| 19 | + select job_log_id, job_name, job_group, invoke_target, job_message, status, exception_info, create_time | ||
| 20 | + from sys_job_log | ||
| 21 | + </sql> | ||
| 22 | + | ||
| 23 | + <select id="selectJobLogList" parameterType="SysJobLog" resultMap="SysJobLogResult"> | ||
| 24 | + <include refid="selectJobLogVo"/> | ||
| 25 | + <where> | ||
| 26 | + <if test="jobName != null and jobName != ''"> | ||
| 27 | + AND job_name like concat('%', #{jobName}, '%') | ||
| 28 | + </if> | ||
| 29 | + <if test="jobGroup != null and jobGroup != ''"> | ||
| 30 | + AND job_group = #{jobGroup} | ||
| 31 | + </if> | ||
| 32 | + <if test="status != null and status != ''"> | ||
| 33 | + AND status = #{status} | ||
| 34 | + </if> | ||
| 35 | + <if test="invokeTarget != null and invokeTarget != ''"> | ||
| 36 | + AND invoke_target like concat('%', #{invokeTarget}, '%') | ||
| 37 | + </if> | ||
| 38 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> | ||
| 39 | + and date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 40 | + </if> | ||
| 41 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> | ||
| 42 | + and date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 43 | + </if> | ||
| 44 | + </where> | ||
| 45 | + </select> | ||
| 46 | + | ||
| 47 | + <select id="selectJobLogAll" resultMap="SysJobLogResult"> | ||
| 48 | + <include refid="selectJobLogVo"/> | ||
| 49 | + </select> | ||
| 50 | + | ||
| 51 | + <select id="selectJobLogById" parameterType="Long" resultMap="SysJobLogResult"> | ||
| 52 | + <include refid="selectJobLogVo"/> | ||
| 53 | + where job_log_id = #{jobLogId} | ||
| 54 | + </select> | ||
| 55 | + | ||
| 56 | + <delete id="deleteJobLogById" parameterType="Long"> | ||
| 57 | + delete from sys_job_log where job_log_id = #{jobLogId} | ||
| 58 | + </delete> | ||
| 59 | + | ||
| 60 | + <delete id="deleteJobLogByIds" parameterType="Long"> | ||
| 61 | + delete from sys_job_log where job_log_id in | ||
| 62 | + <foreach collection="array" item="jobLogId" open="(" separator="," close=")"> | ||
| 63 | + #{jobLogId} | ||
| 64 | + </foreach> | ||
| 65 | + </delete> | ||
| 66 | + | ||
| 67 | + <update id="cleanJobLog"> | ||
| 68 | + truncate table sys_job_log | ||
| 69 | + </update> | ||
| 70 | + | ||
| 71 | + <insert id="insertJobLog" parameterType="SysJobLog"> | ||
| 72 | + insert into sys_job_log( | ||
| 73 | + <if test="jobLogId != null and jobLogId != 0">job_log_id,</if> | ||
| 74 | + <if test="jobName != null and jobName != ''">job_name,</if> | ||
| 75 | + <if test="jobGroup != null and jobGroup != ''">job_group,</if> | ||
| 76 | + <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if> | ||
| 77 | + <if test="jobMessage != null and jobMessage != ''">job_message,</if> | ||
| 78 | + <if test="status != null and status != ''">status,</if> | ||
| 79 | + <if test="exceptionInfo != null and exceptionInfo != ''">exception_info,</if> | ||
| 80 | + create_time | ||
| 81 | + )values( | ||
| 82 | + <if test="jobLogId != null and jobLogId != 0">#{jobLogId},</if> | ||
| 83 | + <if test="jobName != null and jobName != ''">#{jobName},</if> | ||
| 84 | + <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if> | ||
| 85 | + <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if> | ||
| 86 | + <if test="jobMessage != null and jobMessage != ''">#{jobMessage},</if> | ||
| 87 | + <if test="status != null and status != ''">#{status},</if> | ||
| 88 | + <if test="exceptionInfo != null and exceptionInfo != ''">#{exceptionInfo},</if> | ||
| 89 | + sysdate() | ||
| 90 | + ) | ||
| 91 | + </insert> | ||
| 92 | + | ||
| 93 | +</mapper> |
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | +<!DOCTYPE mapper | ||
| 3 | +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | +<mapper namespace="com.ruoyi.project.monitor.mapper.SysJobMapper"> | ||
| 6 | + | ||
| 7 | + <resultMap type="SysJob" id="SysJobResult"> | ||
| 8 | + <id property="jobId" column="job_id" /> | ||
| 9 | + <result property="jobName" column="job_name" /> | ||
| 10 | + <result property="jobGroup" column="job_group" /> | ||
| 11 | + <result property="invokeTarget" column="invoke_target" /> | ||
| 12 | + <result property="cronExpression" column="cron_expression" /> | ||
| 13 | + <result property="misfirePolicy" column="misfire_policy" /> | ||
| 14 | + <result property="concurrent" column="concurrent" /> | ||
| 15 | + <result property="status" column="status" /> | ||
| 16 | + <result property="createBy" column="create_by" /> | ||
| 17 | + <result property="createTime" column="create_time" /> | ||
| 18 | + <result property="updateBy" column="update_by" /> | ||
| 19 | + <result property="updateTime" column="update_time" /> | ||
| 20 | + <result property="remark" column="remark" /> | ||
| 21 | + </resultMap> | ||
| 22 | + | ||
| 23 | + <sql id="selectJobVo"> | ||
| 24 | + select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark | ||
| 25 | + from sys_job | ||
| 26 | + </sql> | ||
| 27 | + | ||
| 28 | + <select id="selectJobList" parameterType="SysJob" resultMap="SysJobResult"> | ||
| 29 | + <include refid="selectJobVo"/> | ||
| 30 | + <where> | ||
| 31 | + <if test="jobName != null and jobName != ''"> | ||
| 32 | + AND job_name like concat('%', #{jobName}, '%') | ||
| 33 | + </if> | ||
| 34 | + <if test="jobGroup != null and jobGroup != ''"> | ||
| 35 | + AND job_group = #{jobGroup} | ||
| 36 | + </if> | ||
| 37 | + <if test="status != null and status != ''"> | ||
| 38 | + AND status = #{status} | ||
| 39 | + </if> | ||
| 40 | + <if test="invokeTarget != null and invokeTarget != ''"> | ||
| 41 | + AND invoke_target like concat('%', #{invokeTarget}, '%') | ||
| 42 | + </if> | ||
| 43 | + </where> | ||
| 44 | + </select> | ||
| 45 | + | ||
| 46 | + <select id="selectJobAll" resultMap="SysJobResult"> | ||
| 47 | + <include refid="selectJobVo"/> | ||
| 48 | + </select> | ||
| 49 | + | ||
| 50 | + <select id="selectJobById" parameterType="Long" resultMap="SysJobResult"> | ||
| 51 | + <include refid="selectJobVo"/> | ||
| 52 | + where job_id = #{jobId} | ||
| 53 | + </select> | ||
| 54 | + | ||
| 55 | + <delete id="deleteJobById" parameterType="Long"> | ||
| 56 | + delete from sys_job where job_id = #{jobId} | ||
| 57 | + </delete> | ||
| 58 | + | ||
| 59 | + <delete id="deleteJobByIds" parameterType="Long"> | ||
| 60 | + delete from sys_job where job_id in | ||
| 61 | + <foreach collection="array" item="jobId" open="(" separator="," close=")"> | ||
| 62 | + #{jobId} | ||
| 63 | + </foreach> | ||
| 64 | + </delete> | ||
| 65 | + | ||
| 66 | + <update id="updateJob" parameterType="SysJob"> | ||
| 67 | + update sys_job | ||
| 68 | + <set> | ||
| 69 | + <if test="jobName != null and jobName != ''">job_name = #{jobName},</if> | ||
| 70 | + <if test="jobGroup != null and jobGroup != ''">job_group = #{jobGroup},</if> | ||
| 71 | + <if test="invokeTarget != null and invokeTarget != ''">invoke_target = #{invokeTarget},</if> | ||
| 72 | + <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if> | ||
| 73 | + <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy = #{misfirePolicy},</if> | ||
| 74 | + <if test="concurrent != null and concurrent != ''">concurrent = #{concurrent},</if> | ||
| 75 | + <if test="status !=null">status = #{status},</if> | ||
| 76 | + <if test="remark != null and remark != ''">remark = #{remark},</if> | ||
| 77 | + <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> | ||
| 78 | + update_time = sysdate() | ||
| 79 | + </set> | ||
| 80 | + where job_id = #{jobId} | ||
| 81 | + </update> | ||
| 82 | + | ||
| 83 | + <insert id="insertJob" parameterType="SysJob" useGeneratedKeys="true" keyProperty="jobId"> | ||
| 84 | + insert into sys_job( | ||
| 85 | + <if test="jobId != null and jobId != 0">job_id,</if> | ||
| 86 | + <if test="jobName != null and jobName != ''">job_name,</if> | ||
| 87 | + <if test="jobGroup != null and jobGroup != ''">job_group,</if> | ||
| 88 | + <if test="invokeTarget != null and invokeTarget != ''">invoke_target,</if> | ||
| 89 | + <if test="cronExpression != null and cronExpression != ''">cron_expression,</if> | ||
| 90 | + <if test="misfirePolicy != null and misfirePolicy != ''">misfire_policy,</if> | ||
| 91 | + <if test="concurrent != null and concurrent != ''">concurrent,</if> | ||
| 92 | + <if test="status != null and status != ''">status,</if> | ||
| 93 | + <if test="remark != null and remark != ''">remark,</if> | ||
| 94 | + <if test="createBy != null and createBy != ''">create_by,</if> | ||
| 95 | + create_time | ||
| 96 | + )values( | ||
| 97 | + <if test="jobId != null and jobId != 0">#{jobId},</if> | ||
| 98 | + <if test="jobName != null and jobName != ''">#{jobName},</if> | ||
| 99 | + <if test="jobGroup != null and jobGroup != ''">#{jobGroup},</if> | ||
| 100 | + <if test="invokeTarget != null and invokeTarget != ''">#{invokeTarget},</if> | ||
| 101 | + <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if> | ||
| 102 | + <if test="misfirePolicy != null and misfirePolicy != ''">#{misfirePolicy},</if> | ||
| 103 | + <if test="concurrent != null and concurrent != ''">#{concurrent},</if> | ||
| 104 | + <if test="status != null and status != ''">#{status},</if> | ||
| 105 | + <if test="remark != null and remark != ''">#{remark},</if> | ||
| 106 | + <if test="createBy != null and createBy != ''">#{createBy},</if> | ||
| 107 | + sysdate() | ||
| 108 | + ) | ||
| 109 | + </insert> | ||
| 110 | + | ||
| 111 | +</mapper> |
-
请 注册 或 登录 后发表评论