JobLogController.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.xxl.job.controller;
  2. import java.text.ParseException;
  3. import java.util.Date;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.annotation.Resource;
  8. import org.apache.commons.lang.StringUtils;
  9. import org.apache.commons.lang.time.DateUtils;
  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.RequestParam;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import com.xxl.job.core.constant.Constants.JobGroupEnum;
  16. import com.xxl.job.core.model.ReturnT;
  17. import com.xxl.job.core.model.XxlJobLog;
  18. import com.xxl.job.dao.IXxlJobLogDao;
  19. /**
  20. * index controller
  21. * @author xuxueli 2015-12-19 16:13:16
  22. */
  23. @Controller
  24. @RequestMapping("/joblog")
  25. public class JobLogController {
  26. @Resource
  27. public IXxlJobLogDao xxlJobLogDao;
  28. @RequestMapping
  29. public String index(Model model, String jobGroup, String jobName) {
  30. model.addAttribute("jobGroup", jobGroup);
  31. model.addAttribute("jobName", jobName);
  32. model.addAttribute("JobGroupList", JobGroupEnum.values());
  33. return "joblog/index";
  34. }
  35. @RequestMapping("/pageList")
  36. @ResponseBody
  37. public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
  38. @RequestParam(required = false, defaultValue = "10") int length,
  39. String jobGroup, String jobName, String filterTime) {
  40. // parse param
  41. Date triggerTimeStart = null;
  42. Date triggerTimeEnd = null;
  43. if (StringUtils.isNotBlank(filterTime)) {
  44. String[] temp = filterTime.split(" - ");
  45. if (temp!=null && temp.length == 2) {
  46. try {
  47. triggerTimeStart = DateUtils.parseDate(temp[0], new String[]{"yyyy-MM-dd HH:mm:ss"});
  48. triggerTimeEnd = DateUtils.parseDate(temp[1], new String[]{"yyyy-MM-dd HH:mm:ss"});
  49. } catch (ParseException e) { }
  50. }
  51. }
  52. // page query
  53. List<XxlJobLog> list = xxlJobLogDao.pageList(start, length, jobGroup, jobName, triggerTimeStart, triggerTimeEnd);
  54. int list_count = xxlJobLogDao.pageListCount(start, length, jobGroup, jobName, triggerTimeStart, triggerTimeEnd);
  55. // package result
  56. Map<String, Object> maps = new HashMap<String, Object>();
  57. maps.put("recordsTotal", list_count); // 总记录数
  58. maps.put("recordsFiltered", list_count); // 过滤后的总记录数
  59. maps.put("data", list); // 分页列表
  60. return maps;
  61. }
  62. @RequestMapping("/save")
  63. @ResponseBody
  64. public ReturnT<String> triggerLog(int trigger_log_id, String status, String msg) {
  65. XxlJobLog log = xxlJobLogDao.load(trigger_log_id);
  66. if (log!=null) {
  67. log.setHandleTime(new Date());
  68. log.setHandleStatus(status);
  69. log.setHandleMsg(msg);
  70. xxlJobLogDao.updateHandleInfo(log);
  71. return ReturnT.SUCCESS;
  72. }
  73. return ReturnT.FAIL;
  74. }
  75. }