Jessei
12/29/2016 - 8:52 AM

定时任务dbtool

定时任务dbtool

package highsoft.gk.gkfxmx;

import highsoft.common.db.DBTool;
import highsoft.common.db.Record;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.transaction.UserTransaction;

public class TaskGkFxmxAction implements ServletContextListener {

	private Timer timer = null;
	
	private String time = "235959";//凌晨0点执行

	public void contextDestroyed(ServletContextEvent contextEvent) {
		timer.cancel();
	}

	public void contextInitialized(ServletContextEvent contextEvent) {

		timer = new java.util.Timer(true);
		System.out.println("定时任务");
		timer.schedule(new DpzsTask(time,contextEvent.getServletContext()),
				1000 * 60, 1000);// 每天执行一次
		System.out.println("定时任务开始");

	}
}

class DpzsTask extends TimerTask {
	
	private String timeY = "25959";
	private ServletContext sContext = null;

	public DpzsTask(String time,ServletContext sc) {
		
		timeY = time;
		sContext = sc;
	}

	@Override
	public void run() {

		// 执行定时任务,每天执行一次
		try {
			
			Calendar cal = Calendar.getInstance();
			String time = cal.get(Calendar.HOUR_OF_DAY)+""+ cal.get(Calendar.MINUTE)+""+cal.get(Calendar.SECOND);
			
			if(timeY.equals(time))
			{
			
				insertFxmxResult();
				
				searchDzda();
			}
			
			

			

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	/**
	 * 分析模型结果
	 */
	public void insertFxmxResult()
	{
		try{
			DBTool dbtool = new DBTool();
			String sql = "SELECT FXMX_CODE, FXMX_NAME, FXMX_ZDRYPZ, FXMX_ZYXZ, HDFSSJ_START, HDFSSJ_END, HDFSDDQH, FXMX_PCTJ, FXMX_PC, FXMX_BDZQ, FXMX_SD_START, FXMX_SD_END, FXMX_YXX,FXMX_DZ, CREATED_BY, CREATED_DATE, CREATED_DEPT,FXMX_DTTS FROM GK_FXMXPZ WHERE FXMX_YXX='Y' ";
	
			Record[] rds = dbtool.executeQuery(sql, null);
	
			List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
			for (Record rd : rds) {
	
				String fmmxCode = rd.getString("FXMX_CODE");// 模型代码
				String fmmxZdrypz = rd.getString("FXMX_ZDRYPZ");// 重点人指标
				String fmmxZyxz = rd.getString("FXMX_ZYXZ");// 资源
	
				String hdfssjStart = rd.getString("HDFSSJ_START");// 活动开始时间
				String hdfssjEnd = rd.getString("HDFSSJ_END");// 活动结束时间
				
				
				
				String hdfsDdqh = rd.getString("HDFSDDQH");// 活动发生地
				String fmmxPctj = rd.getString("FXMX_PCTJ");// 频次条件
				String fmmxPc = rd.getString("FXMX_PC");// 频次
				String fmmxBdzq = rd.getString("FXMX_BDZQ");// 周期 目不使用
				String fmmxSdStart = rd.getString("FXMX_SD_START");// 分析高频时段
				String fmmxSdEnd = rd.getString("FXMX_SD_END");// 分析高频时段止
				String fmmxDz = rd.getString("FXMX_DZ");// 动作
				
				String fmmxDtts = rd.getString("FXMX_DTTS");// 结束时间倒推天数
				
				Map<String, String> map = new HashMap<String, String>();
				map.put("fmmxCode", fmmxCode);
				map.put("fmmxZdrypz", fmmxZdrypz);
				map.put("fmmxZyxz", fmmxZyxz);
				map.put("hdfssjStart", hdfssjStart);
				map.put("hdfssjEnd", hdfssjEnd);
				map.put("hdfsDdqh", hdfsDdqh);
				map.put("fmmxPctj", fmmxPctj);
				map.put("fmmxPc", fmmxPc);
				map.put("fmmxBdzq", fmmxBdzq);
				map.put("fmmxSdStart", fmmxSdStart);
				map.put("fmmxSdEnd", fmmxSdEnd);
				map.put("fmmxDz", fmmxDz);
				map.put("fmmxDtts", fmmxDtts);
				list.add((HashMap<String, String>) map);
	
			}
			for (HashMap<String, String> map : list) {
				FxmxUtil.fxmxTj(map.get("fmmxCode"), map.get("fmmxZdrypz"), map
						.get("fmmxZyxz"), map.get("hdfssjStart"), map
						.get("hdfssjEnd"), map.get("hdfsDdqh"), map
						.get("fmmxPctj"), map.get("fmmxPc"), map
						.get("fmmxBdzq"), map.get("fmmxSdStart"), map
						.get("fmmxSdEnd"), map.get("fmmxDz"),map.get("fmmxDtts"));
	
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	/**
	 * 电子档案统计 liwang20161228
	 */
	public void searchDzda()
	{
		try{
			DBTool dbtool = new DBTool();

			dbtool.executeProcedure("P_GK_FX_TJ_GRGJXX_QL_HC", null);
			dbtool.executeProcedure("P_GK_FX_TJ_GRXXK_HC", null);
			dbtool.executeProcedure("P_GK_FX_TJ_NEWS_LAST_HC", null);
		
			
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	

}