潘志宝
8 天以前 f3de04db06bae67537d093017e28863ee685f8a3
提交 | 用户 | 时间
e7c126 1 package com.xxl.job.admin.controller;
H 2
3 import com.xxl.job.admin.core.model.XxlJobInfo;
4 import com.xxl.job.admin.core.model.XxlJobLogGlue;
5 import com.xxl.job.admin.core.util.I18nUtil;
6 import com.xxl.job.admin.dao.XxlJobInfoDao;
7 import com.xxl.job.admin.dao.XxlJobLogGlueDao;
8 import com.xxl.job.core.biz.model.ReturnT;
9 import com.xxl.job.core.glue.GlueTypeEnum;
10 import org.springframework.stereotype.Controller;
11 import org.springframework.ui.Model;
12 import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.bind.annotation.ResponseBody;
14
15 import javax.annotation.Resource;
16 import javax.servlet.http.HttpServletRequest;
17 import java.util.Date;
18 import java.util.List;
19
20 /**
21  * job code controller
22  * @author xuxueli 2015-12-19 16:13:16
23  */
24 @Controller
25 @RequestMapping("/jobcode")
26 public class JobCodeController {
27     
28     @Resource
29     private XxlJobInfoDao xxlJobInfoDao;
30     @Resource
31     private XxlJobLogGlueDao xxlJobLogGlueDao;
32
33     @RequestMapping
34     public String index(HttpServletRequest request, Model model, int jobId) {
35         XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
36         List<XxlJobLogGlue> jobLogGlues = xxlJobLogGlueDao.findByJobId(jobId);
37
38         if (jobInfo == null) {
39             throw new RuntimeException(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
40         }
41         if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType())) {
42             throw new RuntimeException(I18nUtil.getString("jobinfo_glue_gluetype_unvalid"));
43         }
44
45         // valid permission
46         JobInfoController.validPermission(request, jobInfo.getJobGroup());
47
48         // Glue类型-字典
49         model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());
50
51         model.addAttribute("jobInfo", jobInfo);
52         model.addAttribute("jobLogGlues", jobLogGlues);
53         return "jobcode/jobcode.index";
54     }
55     
56     @RequestMapping("/save")
57     @ResponseBody
58     public ReturnT<String> save(Model model, int id, String glueSource, String glueRemark) {
59         // valid
60         if (glueRemark==null) {
61             return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
62         }
63         if (glueRemark.length()<4 || glueRemark.length()>100) {
64             return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
65         }
66         XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(id);
67         if (exists_jobInfo == null) {
68             return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
69         }
70         
71         // update new code
72         exists_jobInfo.setGlueSource(glueSource);
73         exists_jobInfo.setGlueRemark(glueRemark);
74         exists_jobInfo.setGlueUpdatetime(new Date());
75
76         exists_jobInfo.setUpdateTime(new Date());
77         xxlJobInfoDao.update(exists_jobInfo);
78
79         // log old code
80         XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
81         xxlJobLogGlue.setJobId(exists_jobInfo.getId());
82         xxlJobLogGlue.setGlueType(exists_jobInfo.getGlueType());
83         xxlJobLogGlue.setGlueSource(glueSource);
84         xxlJobLogGlue.setGlueRemark(glueRemark);
85
86         xxlJobLogGlue.setAddTime(new Date());
87         xxlJobLogGlue.setUpdateTime(new Date());
88         xxlJobLogGlueDao.save(xxlJobLogGlue);
89
90         // remove code backup more than 30
91         xxlJobLogGlueDao.removeOld(exists_jobInfo.getId(), 30);
92
93         return ReturnT.SUCCESS;
94     }
95     
96 }