JobController.java
3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.bootdo.common.controller;
import com.bootdo.common.config.Constant;
import com.bootdo.common.domain.TaskDO;
import com.bootdo.common.service.JobService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
*
* @author chglee
* @email 1992lcg@163.com
* @date 2017-09-26 20:53:48
*/
@Controller
@RequestMapping("/common/job")
public class JobController extends BaseController{
@Autowired
private JobService taskScheduleJobService;
@GetMapping()
String taskScheduleJob() {
return "common/job/job";
}
@ResponseBody
@GetMapping("/list")
public PageUtils list(@RequestParam Map<String, Object> params) {
// 查询列表数据
Query query = new Query(params);
List<TaskDO> taskScheduleJobList = taskScheduleJobService.list(query);
int total = taskScheduleJobService.count(query);
PageUtils pageUtils = new PageUtils(taskScheduleJobList, total);
return pageUtils;
}
@GetMapping("/add")
String add() {
return "common/job/add";
}
@GetMapping("/edit/{id}")
String edit(@PathVariable("id") Long id, Model model) {
TaskDO job = taskScheduleJobService.get(id);
model.addAttribute("job", job);
return "common/job/edit";
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id) {
TaskDO taskScheduleJob = taskScheduleJobService.get(id);
return R.ok().put("taskScheduleJob", taskScheduleJob);
}
/**
* 保存
*/
@ResponseBody
@PostMapping("/save")
public R save(TaskDO taskScheduleJob) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (taskScheduleJobService.save(taskScheduleJob) > 0) {
return R.ok();
}
return R.error();
}
/**
* 修改
*/
@ResponseBody
@PostMapping("/update")
public R update(TaskDO taskScheduleJob) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
taskScheduleJobService.update(taskScheduleJob);
return R.ok();
}
/**
* 删除
*/
@PostMapping("/remove")
@ResponseBody
public R remove(Long id) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
if (taskScheduleJobService.remove(id) > 0) {
return R.ok();
}
return R.error();
}
/**
* 删除
*/
@PostMapping("/batchRemove")
@ResponseBody
public R remove(@RequestParam("ids[]") Long[] ids) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
taskScheduleJobService.batchRemove(ids);
return R.ok();
}
@PostMapping(value = "/changeJobStatus")
@ResponseBody
public R changeJobStatus(Long id,String cmd ) {
if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
return R.error(1, "演示系统不允许修改,完整体验请部署程序");
}
String label = "停止";
if ("start".equals(cmd)) {
label = "启动";
} else {
label = "停止";
}
try {
taskScheduleJobService.changeStatus(id, cmd);
return R.ok("任务" + label + "成功");
} catch (Exception e) {
e.printStackTrace();
}
return R.ok("任务" + label + "失败");
}
}