From 74e4e58c0e6db6fc045e18fa21261a4ac1a99b67 Mon Sep 17 00:00:00 2001 From: "xueli.xue" Date: Thu, 19 May 2016 20:06:19 +0800 Subject: [PATCH] =?UTF-8?q?GLUE=E7=BC=96=E8=BE=91=E5=99=A8=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=90=8E=E7=AB=AF=E4=BA=A4=E4=BA=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xxl/job/controller/JobCodeController.java | 52 ++++++- .../xxl/job/controller/JobInfoController.java | 8 ++ .../com/xxl/job/core/model/XxlJobLogGlue.java | 69 ++++++++++ .../java/com/xxl/job/dao/IXxlJobLogDao.java | 2 + .../com/xxl/job/dao/IXxlJobLogGlueDao.java | 21 +++ .../xxl/job/dao/impl/XxlJobLogDaoImpl.java | 8 ++ .../job/dao/impl/XxlJobLogGlueDaoImpl.java | 54 ++++++++ .../mybatis-mapper/XxlJobLogGlueMapper.xml | 78 +++++++++++ .../mybatis-mapper/XxlJobLogMapper.xml | 6 + .../webapp/WEB-INF/template/jobcode/index.ftl | 130 ++++++++++-------- .../main/webapp/static/js/jobcode.index.1.js | 32 +++-- .../main/webapp/static/js/jobinfo.index.1.js | 2 +- 12 files changed, 393 insertions(+), 69 deletions(-) create mode 100644 xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobLogGlue.java create mode 100644 xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogGlueDao.java create mode 100644 xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogGlueDaoImpl.java create mode 100644 xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml diff --git a/xxl-job-admin/src/main/java/com/xxl/job/controller/JobCodeController.java b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobCodeController.java index 90590974..ffb23c27 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/controller/JobCodeController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobCodeController.java @@ -1,7 +1,10 @@ package com.xxl.job.controller; -import javax.servlet.http.HttpServletRequest; +import java.util.List; +import javax.annotation.Resource; + +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @@ -9,6 +12,9 @@ import org.springframework.web.bind.annotation.ResponseBody; import com.xxl.job.core.model.ReturnT; import com.xxl.job.core.model.XxlJobInfo; +import com.xxl.job.core.model.XxlJobLogGlue; +import com.xxl.job.dao.IXxlJobInfoDao; +import com.xxl.job.dao.IXxlJobLogGlueDao; /** * job code controller @@ -17,15 +23,55 @@ import com.xxl.job.core.model.XxlJobInfo; @Controller @RequestMapping("/jobcode") public class JobCodeController { + + @Resource + private IXxlJobInfoDao xxlJobInfoDao; + @Resource + private IXxlJobLogGlueDao xxlJobLogGlueDao; @RequestMapping - public String index(Model model, HttpServletRequest request) { + public String index(Model model, String jobGroup, String jobName) { + XxlJobInfo jobInfo = xxlJobInfoDao.load(jobGroup, jobName); + List jobLogGlues = xxlJobLogGlueDao.selectList(jobGroup, jobName); + model.addAttribute("jobInfo", jobInfo); + model.addAttribute("jobLogGlues", jobLogGlues); return "jobcode/index"; } @RequestMapping("/save") @ResponseBody - public ReturnT save(Model model, XxlJobInfo jobInfo, HttpServletRequest request) { + public ReturnT save(Model model, String jobGroup, String jobName, String glueSource, String glueRemark) { + // valid + if (glueRemark==null) { + return new ReturnT(500, "请输入备注"); + } + if (glueRemark.length()<6 || glueRemark.length()>100) { + return new ReturnT(500, "备注长度应该在6至100之间"); + } + XxlJobInfo jobInfoOld = xxlJobInfoDao.load(jobGroup, jobName); + if (jobInfoOld == null) { + return new ReturnT(500, "任务不存在"); + } + + // log old code + XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue(); + xxlJobLogGlue.setJobGroup(jobInfoOld.getJobGroup()); + xxlJobLogGlue.setJobName(jobInfoOld.getJobName()); + xxlJobLogGlue.setGlueSource(jobInfoOld.getGlueSource()); + xxlJobLogGlue.setGlueRemark(jobInfoOld.getGlueRemark()); + + // init new code + jobInfoOld.setGlueSource(glueSource); + jobInfoOld.setGlueRemark(glueRemark); + + // update new code ,and log old code + xxlJobInfoDao.update(jobInfoOld); + if (StringUtils.isNotBlank(xxlJobLogGlue.getGlueSource()) && StringUtils.isNotBlank(xxlJobLogGlue.getGlueRemark())) { + xxlJobLogGlueDao.save(xxlJobLogGlue); + // remove code backup more than 30 + xxlJobLogGlueDao.removeOld(xxlJobLogGlue.getJobGroup(), xxlJobLogGlue.getJobName(), 3); + } + return ReturnT.SUCCESS; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java index ab1568ee..8edca196 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/controller/JobInfoController.java @@ -22,6 +22,8 @@ import com.xxl.job.core.model.ReturnT; import com.xxl.job.core.model.XxlJobInfo; import com.xxl.job.core.util.DynamicSchedulerUtil; import com.xxl.job.dao.IXxlJobInfoDao; +import com.xxl.job.dao.IXxlJobLogDao; +import com.xxl.job.dao.IXxlJobLogGlueDao; import com.xxl.job.service.job.RemoteHttpJobBean; /** @@ -34,6 +36,10 @@ public class JobInfoController { @Resource private IXxlJobInfoDao xxlJobInfoDao; + @Resource + public IXxlJobLogDao xxlJobLogDao; + @Resource + private IXxlJobLogGlueDao xxlJobLogGlueDao; @RequestMapping public String index(Model model) { @@ -216,6 +222,8 @@ public class JobInfoController { try { DynamicSchedulerUtil.removeJob(jobName, jobGroup); xxlJobInfoDao.delete(jobGroup, jobName); + xxlJobLogDao.delete(jobGroup, jobName); + xxlJobLogGlueDao.delete(jobGroup, jobName); return ReturnT.SUCCESS; } catch (SchedulerException e) { e.printStackTrace(); diff --git a/xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobLogGlue.java b/xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobLogGlue.java new file mode 100644 index 00000000..8ea29970 --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/job/core/model/XxlJobLogGlue.java @@ -0,0 +1,69 @@ +package com.xxl.job.core.model; + +/** + * xxl-job log for glue, used to track job code process + * @author xuxueli 2016-5-19 17:57:46 + */ +public class XxlJobLogGlue { + + private int id; + + private String jobGroup; + private String jobName; + + private String glueSource; + private String glueRemark; + private String addTime; + private String updateTime; + + public int getId() { + return id; + } + public void setId(int id) { + this.id = id; + } + public String getJobGroup() { + return jobGroup; + } + public void setJobGroup(String jobGroup) { + this.jobGroup = jobGroup; + } + public String getJobName() { + return jobName; + } + public void setJobName(String jobName) { + this.jobName = jobName; + } + public String getGlueSource() { + return glueSource; + } + public void setGlueSource(String glueSource) { + this.glueSource = glueSource; + } + public String getGlueRemark() { + return glueRemark; + } + public void setGlueRemark(String glueRemark) { + this.glueRemark = glueRemark; + } + public String getAddTime() { + return addTime; + } + public void setAddTime(String addTime) { + this.addTime = addTime; + } + public String getUpdateTime() { + return updateTime; + } + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } + + @Override + public String toString() { + return "XxlJobLogGlue [id=" + id + ", jobGroup=" + jobGroup + ", jobName=" + jobName + ", glueSource=" + + glueSource + ", glueRemark=" + glueRemark + ", addTime=" + addTime + ", updateTime=" + updateTime + + "]"; + } + +} diff --git a/xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogDao.java b/xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogDao.java index 5f6b206c..0aeab408 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogDao.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogDao.java @@ -21,4 +21,6 @@ public interface IXxlJobLogDao { public int updateTriggerInfo(XxlJobLog xxlJobLog); public int updateHandleInfo(XxlJobLog xxlJobLog); + public int delete(String jobGroup, String jobName); + } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogGlueDao.java b/xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogGlueDao.java new file mode 100644 index 00000000..7051876d --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/job/dao/IXxlJobLogGlueDao.java @@ -0,0 +1,21 @@ +package com.xxl.job.dao; + +import java.util.List; + +import com.xxl.job.core.model.XxlJobLogGlue; + +/** + * job log for glue + * @author xuxueli 2016-5-19 18:04:56 + */ +public interface IXxlJobLogGlueDao { + + public int save(XxlJobLogGlue xxlJobLogGlue); + + public List selectList(String jobGroup, String jobName); + + public int removeOld(String jobGroup, String jobName, int limit); + + public int delete(String jobGroup, String jobName); + +} diff --git a/xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogDaoImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogDaoImpl.java index eee665a6..4fc7e5b0 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogDaoImpl.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogDaoImpl.java @@ -84,5 +84,13 @@ public class XxlJobLogDaoImpl implements IXxlJobLogDao { } return sqlSessionTemplate.update("XxlJobLogMapper.updateHandleInfo", xxlJobLog); } + + @Override + public int delete(String jobGroup, String jobName) { + HashMap params = new HashMap(); + params.put("jobGroup", jobGroup); + params.put("jobName", jobName); + return sqlSessionTemplate.delete("XxlJobLogMapper.delete", params); + } } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogGlueDaoImpl.java b/xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogGlueDaoImpl.java new file mode 100644 index 00000000..54bfde48 --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/job/dao/impl/XxlJobLogGlueDaoImpl.java @@ -0,0 +1,54 @@ +package com.xxl.job.dao.impl; + +import java.util.HashMap; +import java.util.List; + +import javax.annotation.Resource; + +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.stereotype.Repository; + +import com.xxl.job.core.model.XxlJobLogGlue; +import com.xxl.job.dao.IXxlJobLogGlueDao; + +/** + * job log for glue + * @author xuxueli 2016-5-19 18:17:52 + */ +@Repository +public class XxlJobLogGlueDaoImpl implements IXxlJobLogGlueDao { + + @Resource + public SqlSessionTemplate sqlSessionTemplate; + + @Override + public int save(XxlJobLogGlue xxlJobLogGlue) { + return sqlSessionTemplate.insert("XxlJobLogGlueMapper.save", xxlJobLogGlue); + } + + @Override + public List selectList(String jobGroup, String jobName) { + HashMap params = new HashMap(); + params.put("jobGroup", jobGroup); + params.put("jobName", jobName); + return sqlSessionTemplate.selectList("XxlJobLogGlueMapper.selectList", params); + } + + @Override + public int removeOld(String jobGroup, String jobName, int limit) { + HashMap params = new HashMap(); + params.put("jobGroup", jobGroup); + params.put("jobName", jobName); + params.put("limit", limit); + return sqlSessionTemplate.delete("XxlJobLogGlueMapper.removeOld", params); + } + + @Override + public int delete(String jobGroup, String jobName) { + HashMap params = new HashMap(); + params.put("jobGroup", jobGroup); + params.put("jobName", jobName); + return sqlSessionTemplate.delete("XxlJobLogGlueMapper.delete", params); + } + +} diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml new file mode 100644 index 00000000..446b7464 --- /dev/null +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogGlueMapper.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + t.id, + t.job_group, + t.job_name, + t.glue_source, + t.glue_remark, + t.add_time, + t.update_time + + + + INSERT INTO `xxl_job_qrtz_trigger_logglue` ( + `job_group`, + `job_name`, + `glue_source`, + `glue_remark`, + `add_time`, + `update_time` + ) VALUES ( + #{jobGroup}, + #{jobName}, + #{glueSource}, + #{glueRemark}, + now(), + now() + ); + + SELECT LAST_INSERT_ID() + + + + + + + DELETE FROM xxl_job_qrtz_trigger_logglue + WHERE id NOT in( + SELECT id FROM( + SELECT id FROM xxl_job_qrtz_trigger_logglue + WHERE `job_group` = #{jobGroup} and `job_name` = #{jobName} + ORDER BY update_time desc + LIMIT 0, #{limit} + ) t1 + ) + + + + DELETE FROM xxl_job_qrtz_trigger_logglue + WHERE job_group = #{jobGroup} and job_name = #{jobName} + + + \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml index c2dee0a7..5ec18856 100644 --- a/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml +++ b/xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml @@ -130,4 +130,10 @@ WHERE `id`= #{id} + + delete from `xxl_job_qrtz_trigger_log` + WHERE job_group = #{jobGroup} + AND job_name = #{jobName} + + \ No newline at end of file diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/index.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/index.ftl index d55e20b0..3b4ed51c 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/index.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/jobcode/index.ftl @@ -16,59 +16,80 @@ -
- -
- -
-

任务调度中心任务CODE管理

-
+<#if !jobInfo?exists> +
+
+
+

抱歉,任务不存在.

+
+
+
+<#else> +
- -
-
-
-
-
- -
- -
-
-
-
-
- -
- -
-
-
-
-
- -
-
-
-
- -
-
-
- +
+ +
+

任务调度中心任务GLUE管理

+
+ +
+
+
+
+
+ +
+ + + + <#if jobLogGlues?exists && jobLogGlues?size gt 0 > + <#list jobLogGlues as glue> + + + + +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+ +
-
-
+ +
+ + <@netCommon.commonFooter />
- - <@netCommon.commonFooter /> -