JobLogController.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.xxl.job.controller;
  2. import java.text.ParseException;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.annotation.Resource;
  9. import org.apache.commons.lang.StringUtils;
  10. import org.apache.commons.lang.time.DateUtils;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.Model;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  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("/save")
  29. @ResponseBody
  30. public ReturnT<String> triggerLog(int triggerLogId, String status, String msg) {
  31. XxlJobLog log = xxlJobLogDao.load(triggerLogId);
  32. if (log!=null) {
  33. log.setHandleTime(new Date());
  34. log.setHandleStatus(status);
  35. log.setHandleMsg(msg);
  36. xxlJobLogDao.updateHandleInfo(log);
  37. return ReturnT.SUCCESS;
  38. }
  39. return ReturnT.FAIL;
  40. }
  41. @RequestMapping
  42. public String index(Model model, String jobName, String filterTime) {
  43. // 默认filterTime
  44. Calendar todayz = Calendar.getInstance();
  45. todayz.set(Calendar.HOUR_OF_DAY, 0);
  46. todayz.set(Calendar.MINUTE, 0);
  47. todayz.set(Calendar.SECOND, 0);
  48. model.addAttribute("triggerTimeStart", todayz.getTime());
  49. model.addAttribute("triggerTimeEnd", Calendar.getInstance().getTime());
  50. model.addAttribute("jobName", jobName);
  51. model.addAttribute("filterTime", filterTime);
  52. return "joblog/index";
  53. }
  54. @RequestMapping("/pageList")
  55. @ResponseBody
  56. public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
  57. @RequestParam(required = false, defaultValue = "10") int length,
  58. String jobName, String filterTime) {
  59. // parse param
  60. Date triggerTimeStart = null;
  61. Date triggerTimeEnd = null;
  62. if (StringUtils.isNotBlank(filterTime)) {
  63. String[] temp = filterTime.split(" - ");
  64. if (temp!=null && temp.length == 2) {
  65. try {
  66. triggerTimeEnd = DateUtils.parseDate(temp[0], new String[]{"yyyy-MM-dd HH:mm:ss"});
  67. triggerTimeEnd = DateUtils.parseDate(temp[1], new String[]{"yyyy-MM-dd HH:mm:ss"});
  68. } catch (ParseException e) {
  69. e.printStackTrace();
  70. }
  71. }
  72. }
  73. // page query
  74. List<XxlJobLog> list = xxlJobLogDao.pageList(start, length, jobName, triggerTimeStart, triggerTimeEnd);
  75. int list_count = xxlJobLogDao.pageListCount(start, length, jobName, triggerTimeStart, triggerTimeEnd);
  76. // package result
  77. Map<String, Object> maps = new HashMap<String, Object>();
  78. maps.put("recordsTotal", list_count); // 总记录数
  79. maps.put("recordsFiltered", list_count);// 过滤后的总记录数
  80. maps.put("data", list); // 分页列表
  81. return maps;
  82. }
  83. }