7668d9bc by 赵千

定时任务前端编写

1 parent 3b051109
...@@ -6,15 +6,19 @@ class sjsbTask { ...@@ -6,15 +6,19 @@ class sjsbTask {
6 // 定时任务查询接口 6 // 定时任务查询接口
7 async getTaskListByName (data) { 7 async getTaskListByName (data) {
8 return request({ 8 return request({
9 url: SERVER.SERVERAPI + '/sjsbTask/getTaskListByName', 9 url: SERVER.SERVERAPI + '/rest/schedule/getScheduleList',
10 method: 'post', 10 method: 'get',
11 data 11 params: {
12 jobName: data.jobName,
13 pageNo: data.currentPage,
14 pageSize: data.pageSize
15 }
12 }) 16 })
13 } 17 }
14 // 定时任务新增接口 18 // 定时任务新增接口
15 async sjsbTaskSave (data) { 19 async sjsbTaskSave (data) {
16 return request({ 20 return request({
17 url: SERVER.SERVERAPI + '/sjsbTask/save', 21 url: SERVER.SERVERAPI + '/rest/schedule/add',
18 method: 'post', 22 method: 'post',
19 data 23 data
20 }) 24 })
...@@ -22,7 +26,7 @@ class sjsbTask { ...@@ -22,7 +26,7 @@ class sjsbTask {
22 // 修改定时任务执行时间接口 26 // 修改定时任务执行时间接口
23 async updateCron (data) { 27 async updateCron (data) {
24 return request({ 28 return request({
25 url: SERVER.SERVERAPI + '/sjsbTask/updateCron', 29 url: SERVER.SERVERAPI + '/rest/schedule/update',
26 method: 'post', 30 method: 'post',
27 data 31 data
28 }) 32 })
...@@ -30,50 +34,30 @@ class sjsbTask { ...@@ -30,50 +34,30 @@ class sjsbTask {
30 // 定时任务删除接口 34 // 定时任务删除接口
31 async sjsbTaskRemove (id) { 35 async sjsbTaskRemove (id) {
32 return request({ 36 return request({
33 url: SERVER.SERVERAPI + '/sjsbTask/remove', 37 url: SERVER.SERVERAPI + '/rest/schedule/delete',
34 method: 'get', 38 method: 'get',
35 params: { 39 params: {
36 id: id 40 jobId: id
37 }
38 })
39 }
40 // 暂停任务接口
41 async pauseJob (id) {
42 return request({
43 url: SERVER.SERVERAPI + '/sjsbTask/pauseJob',
44 method: 'get',
45 params: {
46 id: id
47 } 41 }
48 }) 42 })
49 } 43 }
50 // 恢复任务接口 44 // 恢复任务接口
51 async resumeJob (id) { 45 async recover (id) {
52 return request({ 46 return request({
53 url: SERVER.SERVERAPI + '/sjsbTask/resumeJob', 47 url: SERVER.SERVERAPI + '/rest/schedule/recover',
54 method: 'get', 48 method: 'get',
55 params: { 49 params: {
56 id: id 50 jobId: id
57 } 51 }
58 }) 52 })
59 } 53 }
60 // 激活任务接口 54 // 激活任务接口
61 async activateJob (id) { 55 async active (id) {
62 return request({
63 url: SERVER.SERVERAPI + '/sjsbTask/activateJob',
64 method: 'get',
65 params: {
66 id: id
67 }
68 })
69 }
70 // 手动测试
71 async sjsbTaskRun (id) {
72 return request({ 56 return request({
73 url: SERVER.SERVERAPI + '/sjsbTask/run', 57 url: SERVER.SERVERAPI + '/rest/schedule/active',
74 method: 'get', 58 method: 'get',
75 params: { 59 params: {
76 id: id 60 jobId: id
77 } 61 }
78 }) 62 })
79 } 63 }
......
...@@ -25,4 +25,10 @@ export default class filter { ...@@ -25,4 +25,10 @@ export default class filter {
25 return name 25 return name
26 } 26 }
27 } 27 }
28 stateStatus(val) {
29 let index = val + 1;
30 // -1 : 不存在 ,0 : 待激活,1:正常,2:暂停,3 : 出错, 4:阻塞
31 let status = { 0: '不存在', 1: '待激活', 2: '正常', 3: '暂停', 4: '出错', 5: '阻塞' }
32 return status[index]
33 }
28 } 34 }
......
1 <template> 1 <template>
2 <!-- 编辑 --> 2 <!-- 编辑 -->
3 <dialogBox ref="addTask" width="60%" @submitForm="handleSubmit" :closed="true" @closeDialog="handleClose" 3 <dialogBox ref="addTask" width="60%" @submitForm="handleSubmit" @closeDialog="handleClose" v-model="myValue"
4 customClass="editValidRule" multiple title="新增定时任务"> 4 customClass="editValidRule" title="新增定时任务">
5 <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px"> 5 <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
6 <el-row :gutter="20"> 6 <el-row :gutter="20">
7 <el-col :span="12"> 7 <el-col :span="12">
8 <el-form-item label="任务名" prop="job_name"> 8 <el-form-item label="任务名" prop="jobName">
9 <el-input v-model="ruleForm.job_name" placeholder="任务名"></el-input> 9 <el-input v-model="ruleForm.jobName" placeholder="任务名"></el-input>
10 </el-form-item> 10 </el-form-item>
11 </el-col> 11 </el-col>
12 <el-col :span="12"> 12 <el-col :span="12">
13 <el-form-item label="任务分组" prop="job_group"> 13 <el-form-item label="类名" prop="beanName">
14 <el-input v-model="ruleForm.job_group" placeholder="任务分组"></el-input> 14 <el-input v-model="ruleForm.beanName" placeholder="类名"></el-input>
15 </el-form-item> 15 </el-form-item>
16 </el-col> 16 </el-col>
17 </el-row> 17 </el-row>
18 <el-row :gutter="20"> 18 <el-row :gutter="20">
19 <el-col :span="12"> 19 <el-col :span="12">
20 <el-form-item label="cron表达式" prop="cron_expression"> 20 <el-form-item label="cron表达式" prop="cronExpression">
21 <el-input v-model="ruleForm.cron_expression" placeholder="cron表达式"></el-input> 21 <el-input v-model="ruleForm.cronExpression" placeholder="cron表达式"></el-input>
22 </el-form-item> 22 </el-form-item>
23 </el-col> 23 </el-col>
24 <el-col :span="12"> 24 <el-col :span="12">
25 <el-form-item label="任务类名" prop="bean_class"> 25 <el-form-item label="方法名" prop="methodName">
26 <el-input v-model="ruleForm.bean_class" placeholder="任务执行时调用哪个类的方法 包名+类名"></el-input> 26 <el-input v-model="ruleForm.methodName" placeholder="方法名"></el-input>
27 </el-form-item> 27 </el-form-item>
28 </el-col> 28 </el-col>
29 </el-row> 29 </el-row>
30 <el-row :gutter="20"> 30 <el-row :gutter="20">
31 <el-col :span="24"> 31 <el-col :span="24">
32 <el-form-item label="任务描述" prop="description"> 32 <el-form-item label="任务描述" prop="remark">
33 <el-input v-model="ruleForm.description" placeholder="任务描述"></el-input> 33 <el-input v-model="ruleForm.remark" placeholder="任务描述"></el-input>
34 </el-form-item> 34 </el-form-item>
35 </el-col> 35 </el-col>
36 </el-row> 36 </el-row>
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
43 import sjsbTask from '@/api/sjsbTask.js' 43 import sjsbTask from '@/api/sjsbTask.js'
44 export default { 44 export default {
45 props: { 45 props: {
46 value: { type: Boolean, default: false },
46 taskData: { 47 taskData: {
47 type: Object, 48 type: Object,
48 default: null 49 default: null
...@@ -50,42 +51,33 @@ export default { ...@@ -50,42 +51,33 @@ export default {
50 }, 51 },
51 data () { 52 data () {
52 return { 53 return {
54 myValue: this.value,
53 ruleForm: { 55 ruleForm: {
54 job_name: '', 56 jobName: '',
55 job_group: '', 57 cronExpression: '',
56 cron_expression: '', 58 beanName: '',
57 bean_class: '', 59 methodName: '',
58 description: '' 60 methodParams: '',
61 remark: ''
59 }, 62 },
60 rules: { 63 rules: {
61 job_name: [ 64 jobName: [
62 { required: true, message: '任务名', trigger: 'blur' } 65 { required: true, message: '任务名', trigger: 'blur' }
63 ], 66 ],
64 job_group: [ 67 cronExpression: [
65 { required: true, message: '分组', trigger: 'blur' }
66 ],
67 cron_expression: [
68 { required: true, message: 'cron表达式', trigger: 'blur' } 68 { required: true, message: 'cron表达式', trigger: 'blur' }
69 ], 69 ],
70 bean_class: [ 70 beanName: [
71 { required: true, message: '任务类名', trigger: 'blur' } 71 { required: true, message: '任务类名', trigger: 'blur' }
72 ], 72 ],
73 description: [ 73 methodName: [
74 { required: true, message: '任务描述', trigger: 'blur' } 74 { required: true, message: '任务方法名', trigger: 'blur' }
75 ], 75 ]
76 }, 76 },
77 message: '' 77 message: ''
78 } 78 }
79 }, 79 },
80 methods: { 80 methods: {
81 isShow () {
82 this.$refs.addTask.isShow()
83 setTimeout(() => {
84 if (this.taskData) {
85 this.ruleForm = _.cloneDeep(this.taskData)
86 }
87 }, 0)
88 },
89 handleSubmit () { 81 handleSubmit () {
90 let _this = this 82 let _this = this
91 this.$refs['ruleForm'].validate(async (valid) => { 83 this.$refs['ruleForm'].validate(async (valid) => {
...@@ -129,13 +121,49 @@ export default { ...@@ -129,13 +121,49 @@ export default {
129 }) 121 })
130 }, 122 },
131 handleClose () { 123 handleClose () {
132 this.$refs.addTask.isHide() 124 this.$emit("input", false);
133 this.$refs['ruleForm'].resetFields() 125 }
126 },
127 watch: {
128 value(val) {
129 this.myValue = val
130 },
131 taskData(val) {
132 if (val != null) {
133 this.ruleForm = val
134 } else {
135 this.ruleForm = {
136 jobName: '',
137 cronExpression: '',
138 beanName: '',
139 methodName: '',
140 methodParams: '',
141 remark: ''
142 }
143 }
134 } 144 }
135 } 145 }
136 } 146 }
137 </script> 147 </script>
138 <style rel="stylesheet/less" lang="less" scoped> 148 <style rel="stylesheet/scss" lang="scss" scoped>
149 @import "~@/styles/public.scss";
150
151 .editDialogBox-box {
152 margin: 14px 18px 30px 18px !important
153 }
154
155 /deep/.el-form-item__label {
156 color: #fff;
157 }
158
159 /deep/.el-form-item {
160 color: #fff;
161 margin-bottom: 10px;
162 }
139 163
164 /deep/ .el-input__inner {
165 background-color: transparent;
166 border: 1px solid #458ACF;
167 }
140 </style> 168 </style>
141 169
......
...@@ -6,34 +6,35 @@ class data extends filter { ...@@ -6,34 +6,35 @@ class data extends filter {
6 columns () { 6 columns () {
7 return [ 7 return [
8 { 8 {
9 prop: "job_name", 9 prop: "jobName",
10 label: "任务名称", 10 label: "任务名称",
11 width: 130 11 width: 130
12 }, 12 },
13 { 13 {
14 prop: "description", 14 prop: "remark",
15 label: "任务描述", 15 label: "任务描述",
16 width: 300 16 width: 300
17 }, 17 },
18 { 18 {
19 prop: "cron_expression", 19 prop: "cronExpression",
20 label: "cron表达式" 20 label: "cron表达式"
21 }, 21 },
22 { 22 {
23 prop: "bean_class", 23 prop: "beanName",
24 width: 260, 24 width: 260,
25 label: "任务类" 25 label: "任务类"
26 }, 26 },
27 { 27 {
28 prop: "job_group", 28 prop: "methodName",
29 label: "任务分组" 29 label: "方法名称"
30 }, 30 },
31 { 31 {
32 label: "状态", 32 label: "状态",
33 prop: "jobStatus",
33 render: (h, scope) => { 34 render: (h, scope) => {
34 return ( 35 return (
35 <div> 36 <div>
36 { this.stateStatus(scope.row.job_status) } 37 { this.stateStatus(scope.row.jobStatus) }
37 </div> 38 </div>
38 ) 39 )
39 }, 40 },
......
...@@ -8,11 +8,12 @@ ...@@ -8,11 +8,12 @@
8 <el-row> 8 <el-row>
9 <el-col :span="6"> 9 <el-col :span="6">
10 <el-form-item label="搜索标题"> 10 <el-form-item label="搜索标题">
11 <el-input v-model="form.job_name" placeholder="标题"></el-input> 11 <el-input v-model="form.jobName" placeholder="标题"></el-input>
12 </el-form-item> 12 </el-form-item>
13 </el-col> 13 </el-col>
14 <el-col :span="18" class="btnColRight"> 14 <el-col :span="18" class="btnColRight">
15 <btn nativeType="cx" @click="handleSearch">查询</btn> 15 <btn nativeType="cx" @click="handleSubmit">搜索</btn>
16 <btn nativeType="cx" @click="resetSe">重置</btn>
16 <btn nativeType="cx" @click="handleAdd">新增</btn> 17 <btn nativeType="cx" @click="handleAdd">新增</btn>
17 </el-col> 18 </el-col>
18 </el-row> 19 </el-row>
...@@ -23,7 +24,7 @@ ...@@ -23,7 +24,7 @@
23 @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns" 24 @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns"
24 :data="tableData.data"> 25 :data="tableData.data">
25 </lb-table> 26 </lb-table>
26 <add-task ref="task" :taskData="taskData" /> 27 <add-task ref="task" :taskData="taskData" v-model="isDialog"/>
27 </div> 28 </div>
28 </div> 29 </div>
29 </template> 30 </template>
...@@ -42,8 +43,9 @@ export default { ...@@ -42,8 +43,9 @@ export default {
42 data () { 43 data () {
43 return { 44 return {
44 taskData: null, 45 taskData: null,
46 isDialog: false,
45 form: { 47 form: {
46 job_name: '', 48 jobName: '',
47 currentPage: 1 49 currentPage: 1
48 }, 50 },
49 selectionList: [], 51 selectionList: [],
...@@ -60,37 +62,23 @@ export default { ...@@ -60,37 +62,23 @@ export default {
60 render: (h, scope) => { 62 render: (h, scope) => {
61 return ( 63 return (
62 <div> 64 <div>
63 <el-button type="text" size="mini" style="color: #67C23A"
64 v-show={scope.row.job_status !== '1' && scope.row.job_status !== '2'}
65 icon="el-icon-magic-stick"
66 onClick={() => { this.handleRecovery(scope.row) }}>激活
67 </el-button>
68
69 <el-button type="text" size="mini"
70 style="color: #67C23A;margin-left:0"
71 icon="el-icon-refresh-right"
72 v-show={scope.row.job_status === '2'}
73 onClick={() => { this.handleActivation(scope.row) }}>恢复
74 </el-button>
75
76 <el-button type="text" size="mini" 65 <el-button type="text" size="mini"
77 v-show={scope.row.job_status !== '1'} 66 v-show={scope.row.jobStatus === 0}
78 icon="el-icon-stopwatch" 67 icon="el-icon-video-pause"
79 onClick={() => { this.handletest(scope.row) }}>手动测试 68 onClick={() => { this.handleActive(scope.row) }}>激活
80 </el-button> 69 </el-button>
81 <el-button type="text" size="mini" 70 <el-button type="text" size="mini"
82 v-show={scope.row.job_status === '1'} 71 v-show={scope.row.jobStatus === -1}
83 icon="el-icon-video-pause" 72 icon="el-icon-video-pause"
84 onClick={() => { this.handleSuspend(scope.row) }}>暂停 73 onClick={() => { this.recover(scope.row) }}>恢复
85 </el-button> 74 </el-button>
86 <el-button type="text" size="mini" 75 <el-button type="text" size="mini"
87 icon="el-icon-edit" 76 icon="el-icon-edit"
88 v-show={scope.row.job_status === '2' || scope.row.job_status === '-1' || scope.row.job_status === '0'}
89 onClick={() => { this.handleEdit(scope.row) }}>编辑 77 onClick={() => { this.handleEdit(scope.row) }}>编辑
90 </el-button> 78 </el-button>
91 <el-button type="text" size="mini" 79 <el-button type="text" size="mini"
92 icon="el-icon-delete" style="color:#F56C6C" 80 icon="el-icon-delete" style="color:#F56C6C"
93 v-show={scope.row.job_status !== '1'} 81 v-show={scope.row.jobStatus !== -1}
94 onClick={() => { this.handleDel(scope.row) }}>删除 82 onClick={() => { this.handleDel(scope.row) }}>删除
95 </el-button> 83 </el-button>
96 </div> 84 </div>
...@@ -110,37 +98,30 @@ export default { ...@@ -110,37 +98,30 @@ export default {
110 methods: { 98 methods: {
111 handleAdd () { 99 handleAdd () {
112 this.taskData = null 100 this.taskData = null
113 this.$refs.task.isShow() 101 this.isDialog = true
114 }, 102 },
115 handleSearch () { 103 resetSe() {
116 this.form.currentPage = 1 104 this.form.jobName = ''
117 this.tableData.data = [] 105 this.featchData()
118 this.queryClick()
119 }, 106 },
120 async featchData () { 107 async featchData () {
121 try { 108 try {
122 this.form = Object.assign(this.form, this.formData) 109 this.form = Object.assign(this.form, this.formData)
123 let { result: { list, total, pages: pageSize, pageNum: current } 110 let { result } = await sjsbTask.getTaskListByName(this.form)
124 } = await sjsbTask.getTaskListByName(this.form) 111 this.tableData.data = result.list
125 this.tableData.data = list 112 console.log(this.tableData.data, 'fffffffffffffffffff')
126 this.pageData = {
127 pageSize,
128 current,
129 total
130 }
131 } catch (error) { 113 } catch (error) {
132 this.message = error 114 this.message = error
133 } 115 }
134 }, 116 },
135 // 暂停 117 recover(row) {
136 handleSuspend (row) { 118 this.$confirm('此操将进行恢复操作, 是否继续?', '提示', {
137 this.$confirm('此操将进行暂停操作, 是否继续?', '提示', {
138 confirmButtonText: '确定', 119 confirmButtonText: '确定',
139 cancelButtonText: '取消', 120 cancelButtonText: '取消',
140 type: 'warning', 121 type: 'warning',
141 }) 122 })
142 .then(() => { 123 .then(() => {
143 sjsbTask.pauseJob(row.id) 124 sjsbTask.recover(row.jobId)
144 .then((res) => { 125 .then((res) => {
145 if ((res.code = 200)) { 126 if ((res.code = 200)) {
146 this.$message({ 127 this.$message({
...@@ -164,15 +145,15 @@ export default { ...@@ -164,15 +145,15 @@ export default {
164 }) 145 })
165 }) 146 })
166 }, 147 },
167 // 激活 148
168 handleRecovery (row) { 149 handleActive(row) {
169 this.$confirm('此操将进行激活操作, 是否继续?', '提示', { 150 this.$confirm('此操将进行激活操作, 是否继续?', '提示', {
170 confirmButtonText: '确定', 151 confirmButtonText: '确定',
171 cancelButtonText: '取消', 152 cancelButtonText: '取消',
172 type: 'warning', 153 type: 'warning',
173 }) 154 })
174 .then(() => { 155 .then(() => {
175 sjsbTask.activateJob(row.id) 156 sjsbTask.active(row.jobId)
176 .then((res) => { 157 .then((res) => {
177 if ((res.code = 200)) { 158 if ((res.code = 200)) {
178 this.$message({ 159 this.$message({
...@@ -196,15 +177,15 @@ export default { ...@@ -196,15 +177,15 @@ export default {
196 }) 177 })
197 }) 178 })
198 }, 179 },
199 // 恢复 180 // 暂停
200 handleActivation (row) { 181 handleSuspend (row) {
201 this.$confirm('此操将进行恢复操作, 是否继续?', '提示', { 182 this.$confirm('此操将进行暂停操作, 是否继续?', '提示', {
202 confirmButtonText: '确定', 183 confirmButtonText: '确定',
203 cancelButtonText: '取消', 184 cancelButtonText: '取消',
204 type: 'warning', 185 type: 'warning',
205 }) 186 })
206 .then(() => { 187 .then(() => {
207 sjsbTask.resumeJob(row.id) 188 sjsbTask.pauseJob(row.id)
208 .then((res) => { 189 .then((res) => {
209 if ((res.code = 200)) { 190 if ((res.code = 200)) {
210 this.$message({ 191 this.$message({
...@@ -228,41 +209,9 @@ export default { ...@@ -228,41 +209,9 @@ export default {
228 }) 209 })
229 }) 210 })
230 }, 211 },
231 // 手动测试
232 handletest (row) {
233 this.$confirm('此操将进行手动测试, 是否继续?', '提示', {
234 confirmButtonText: '确定',
235 cancelButtonText: '取消',
236 type: 'warning',
237 })
238 .then(() => {
239 sjsbTask.sjsbTaskRun(row.id)
240 .then((res) => {
241 if ((res.code = 200)) {
242 this.$alert(res.message, '提示', {
243 confirmButtonText: '确定',
244 type: 'success'
245 });
246 this.featchData()
247 }
248 })
249 .catch((error) => {
250 this.$alert(error, '提示', {
251 confirmButtonText: '确定',
252 type: 'error'
253 })
254 })
255 })
256 .catch(() => {
257 this.$message({
258 type: 'info',
259 message: '已取消',
260 })
261 })
262 },
263 handleEdit (row) { 212 handleEdit (row) {
264 this.taskData = row 213 this.taskData = row
265 this.$refs.task.isShow() 214 this.isDialog = true
266 }, 215 },
267 handleDel (row) { 216 handleDel (row) {
268 this.$confirm('此操将进行删除操作, 是否继续?', '提示', { 217 this.$confirm('此操将进行删除操作, 是否继续?', '提示', {
...@@ -271,7 +220,7 @@ export default { ...@@ -271,7 +220,7 @@ export default {
271 type: 'warning', 220 type: 'warning',
272 }) 221 })
273 .then(() => { 222 .then(() => {
274 sjsbTask.sjsbTaskRemove(row.id) 223 sjsbTask.sjsbTaskRemove(row.jobId)
275 .then((res) => { 224 .then((res) => {
276 if ((res.code = 200)) { 225 if ((res.code = 200)) {
277 this.$message({ 226 this.$message({
......