SaveJobInfoController.java 1.81 KB
/**
 * 
 */
package com.yoho.jobs.server.controller;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yoho.jobs.common.domain.ProcessResult;
import com.yoho.jobs.dal.IJobResultMapper;
import com.yoho.jobs.dal.domain.ProcessResultVO;

/**
 * @author yanzhang.fu
 *
 */
@Controller
@RequestMapping("/jobmanager")
public class SaveJobInfoController {

	@Resource
	private IJobResultMapper jobResultMapper;

	@RequestMapping("/saveJobResult.do")
	public void saveJobResult(@RequestBody ProcessResult jobInfo) {
		ProcessResultVO result = new ProcessResultVO();
		convert(result, jobInfo);
		//TODO 若执行失败,则上报告警并入库
		
		jobResultMapper.insertJob(result);
	}

	private void convert(ProcessResultVO result, ProcessResult jobInfo) {
		result.setActiveMode(jobInfo.getJobInfo().getActiveMode());
		result.setBeginTime(jobInfo.getBeginTime());
		result.setCode(jobInfo.getCode());
		result.setContext(jobInfo.getJobInfo().getContext());
		result.setCronExpression(jobInfo.getJobInfo().getCronExpression());
		result.setDesc(jobInfo.getJobInfo().getDesc());
		result.setEndTime(jobInfo.getEndTime());
		result.setJobGroup(jobInfo.getJobInfo().getJobGroup());
		result.setJobName(jobInfo.getJobInfo().getJobName());
		result.setJobType(jobInfo.getJobInfo().getJobType());
		result.setMessage(jobInfo.getMessage());
		result.setModule(jobInfo.getJobInfo().getModule());
		result.setOperator(jobInfo.getJobInfo().getOperator());
		result.setProcessIp(jobInfo.getJobInfo().getProcessIp());
		result.setProcessor(jobInfo.getJobInfo().getProcessor());
		result.setStatus(jobInfo.getJobInfo().getStatus());
		result.setRecordDate(new Date());
	}
}