JobLogController.java 2.7 KB
Newer Older
X
xueli.xue 已提交
1 2
package com.xxl.job.controller;

X
xueli.xue 已提交
3
import java.text.ParseException;
X
xueli.xue 已提交
4
import java.util.Date;
X
xueli.xue 已提交
5 6 7
import java.util.HashMap;
import java.util.List;
import java.util.Map;
X
xueli.xue 已提交
8 9 10

import javax.annotation.Resource;

X
xueli.xue 已提交
11 12
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
X
xueli.xue 已提交
13
import org.springframework.stereotype.Controller;
X
xueli.xue 已提交
14
import org.springframework.ui.Model;
X
xueli.xue 已提交
15
import org.springframework.web.bind.annotation.RequestMapping;
X
xueli.xue 已提交
16
import org.springframework.web.bind.annotation.RequestParam;
X
xueli.xue 已提交
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
import org.springframework.web.bind.annotation.ResponseBody;

import com.xxl.job.core.model.ReturnT;
import com.xxl.job.core.model.XxlJobLog;
import com.xxl.job.dao.IXxlJobLogDao;

/**
 * index controller
 * @author xuxueli 2015-12-19 16:13:16
 */
@Controller
@RequestMapping("/joblog")
public class JobLogController {

	@Resource
	public IXxlJobLogDao xxlJobLogDao;
	
	@RequestMapping("/save")
	@ResponseBody
	public ReturnT<String> triggerLog(int triggerLogId, String status, String msg) {
		XxlJobLog log = xxlJobLogDao.load(triggerLogId);
		if (log!=null) {
			log.setHandleTime(new Date());
			log.setHandleStatus(status);
			log.setHandleMsg(msg);
			xxlJobLogDao.updateHandleInfo(log);
			return ReturnT.SUCCESS;
		}
		return ReturnT.FAIL;
	}
	
X
xueli.xue 已提交
48 49 50 51
	@RequestMapping
	public String index(Model model, String jobName, String filterTime) {
		model.addAttribute("jobName", jobName);
		model.addAttribute("filterTime", filterTime);
X
xueli.xue 已提交
52 53 54 55 56
		return "joblog/index";
	}
	
	@RequestMapping("/pageList")
	@ResponseBody
X
xueli.xue 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,  
			@RequestParam(required = false, defaultValue = "10") int length,
			String jobName, String filterTime) {
		// parse param
		Date triggerTimeStart = null;
		Date triggerTimeEnd = null;
		if (StringUtils.isNotBlank(filterTime)) {
			String[] temp = filterTime.split(" - ");
			if (temp!=null && temp.length == 2) {
				try {
					triggerTimeEnd = DateUtils.parseDate(temp[0], new String[]{"yyyy-MM-dd HH:mm:ss"});
					triggerTimeEnd = DateUtils.parseDate(temp[1], new String[]{"yyyy-MM-dd HH:mm:ss"});
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
		}
X
xueli.xue 已提交
74
		
X
xueli.xue 已提交
75 76 77
		// page query
		List<XxlJobLog> list = xxlJobLogDao.pageList(start, length, jobName, triggerTimeStart, triggerTimeEnd);
		int list_count = xxlJobLogDao.pageListCount(start, length, jobName, triggerTimeStart, triggerTimeEnd);
X
xueli.xue 已提交
78
		
X
xueli.xue 已提交
79
		// package result
X
xueli.xue 已提交
80 81 82 83 84 85 86
		Map<String, Object> maps = new HashMap<String, Object>();
	    maps.put("recordsTotal", list_count);	// 总记录数
	    maps.put("recordsFiltered", list_count);// 过滤后的总记录数
	    maps.put("data", list);  				// 分页列表
		return maps;
	}
	
X
xueli.xue 已提交
87
}