package com.engine.kq.biz;

import com.engine.kq.log.KQLog;
import java.util.List;
import org.apache.commons.compress.utils.Lists;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.tools.HrmDateCheck;
import weaver.interfaces.schedule.BaseCronJob;

/**
 * 格式化入职日期、离职日期发生变化的考勤数据
 */
public class KQFormatDateChangeJob extends BaseCronJob{
  private KQLog kqLog = new KQLog();


	@Override
  public void execute() {
		RecordSet rs = new RecordSet();
		try{
			kqLog.info("begin do KQFormatDateChangeJob invoke ...");

			List<String> upSqls = Lists.newArrayList();
      RecordSet rs1 = new RecordSet();
      String sql = "select * from kq_date_change_log where status ='0'";
      kqLog.info("begin do KQFormatDateChangeJob invoke ...sql::"+sql);
      rs1.execute(sql);
      while (rs1.next()){
        String id = Util.null2String(rs1.getString("id"));
        String resourceid = Util.null2String(rs1.getString("resourceid"));
        String changefromdate = Util.null2String(rs1.getString("changefromdate"));
        String changetodate = Util.null2String(rs1.getString("changetodate"));
        kqLog.info("KQScheduleFormatJob:id:"+id+":resourceid:"+resourceid+":changefromdate:"+changefromdate+":changetodate:"+changetodate);
        new HrmDateCheck().calKqData(changefromdate,changetodate,resourceid);
        String upsql = "update kq_date_change_log set status='1' where id = "+id;
        upSqls.add(upsql);
      }

      for (String upsql :upSqls) {
        rs1.executeUpdate(upsql);
      }
			kqLog.info("end do KQFormatDateChangeJob invoke  ...");
		}catch (Exception e) {
			kqLog.info(e) ;
		}
	}
}
