package com.engine.kq.biz;

import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.schedule.BaseCronJob;

/**
 * 只保留进10天的考勤打卡日志
 */
public class KQClearCardLogJob extends BaseCronJob{

  @Override
	public void execute() {
		BaseBean bb = new BaseBean();
		try{
			bb.writeLog("begin do KQClearCardLogJob invoke ...");
      RecordSet rs = new RecordSet();
      String curdate = DateUtil.getCurrentDate();
      String curdate_10 = DateUtil.addDate(curdate, -10);
			String sql = "delete from kq_card_log where createdatetime < ? ";
      if(rs.getDBType().equalsIgnoreCase("oracle")) {
        sql = "delete from kq_card_log where to_char(createdatetime, 'yyyy-mm-dd') < ? ";
      }

      boolean isok = rs.executeUpdate(sql,curdate_10);
      bb.writeLog("KQClearCardLogJob invoke ...curdate::"+curdate+":curdate_10:"+curdate_10+":isok:"+isok);
      //删除加班
      String curdate_30 = DateUtil.addDate(curdate, -30);
      sql = "delete from kq_overtime_log where createdatetime < ? ";
      if(rs.getDBType().equalsIgnoreCase("oracle")) {
        sql = "delete from kq_overtime_log where to_char(createdatetime, 'yyyy-mm-dd') < ? ";
      }
      isok = rs.executeUpdate(sql,curdate_30);
      bb.writeLog("KQClearCardLogJob invoke ...curdate::"+curdate+":curdate_30:"+curdate_30+":sql:"+sql+":isok:"+isok);

      sql = "delete from kq_overtime_log_detail where createdatetime < ? ";
      if(rs.getDBType().equalsIgnoreCase("oracle")) {
        sql = "delete from kq_overtime_log_detail where to_char(createdatetime, 'yyyy-mm-dd') < ? ";
      }
      isok = rs.executeUpdate(sql,curdate_30);
      bb.writeLog("KQClearCardLogJob invoke ...curdate::"+curdate+":curdate_30:"+curdate_30+":sql:"+sql+":isok:"+isok);

			bb.writeLog("end do KQClearCardLogJob invoke  ...");
		}catch (Exception e) {
			bb.writeLog(e);
		}
	}
}
