package com.engine.kq.cmd.upgrade;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQFormatData;
import com.engine.kq.biz.KQFormatJob;
import com.engine.kq.biz.KQOneStopUp;
import com.engine.kq.log.KQLog;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 考勤报表数据升级
 * @author pzy
 *
 */
public class DoUpgrade12Cmd extends AbstractCommonCommand<Map<String, Object>>{

	public DoUpgrade12Cmd(Map<String, Object> params, User user) {
		this.user = user;
		this.params = params;
	}

	@Override
	public BizLogContext getLogContext() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
		Map<String,Object> retmap = new HashMap<String,Object>();
    KQLog kqLog = new KQLog();
    RecordSet rs = new RecordSet();
    RecordSet rs1 = new RecordSet();
		try {
      Calendar cal = DateUtil.getCalendar();
		  KQFormatData kqFormatData = new KQFormatData();
      String startdate = Util.null2String(params.get("startdate"));
      String enddate = Util.null2String(params.get("enddate"));
      if (DateUtil.timeInterval(enddate, startdate) > 0) {
        retmap.put("status", "-1");
        return retmap;
      }
      System.out.println("in");
      String sql = "select id from hrmresource where status in (0,1,2,3)";
      rs1.execute(sql);
      while (rs1.next()){
        String resourceid = Util.null2String(rs1.getString("id"));
        boolean isEnd = false;
        for (String date = startdate; !isEnd; ) {
          if (date.equals(enddate)) isEnd = true;
          kqLog.info("KQScheduleFormatJob:resourceid:"+resourceid+":date:"+date);
          new KQFormatData().formatKqDate(resourceid, date);
          kqFormatData.formatKqDate(resourceid, date);
          cal.setTime(DateUtil.parseToDate(date));
          date = DateUtil.getDate(cal.getTime(), 1);
        }
      }
      System.out.println("out");

			retmap.put("status", "1");
      retmap.put("message", SystemEnv.getHtmlLabelName(505759,user.getLanguage()));
		} catch (Exception e) {
			writeLog(e);
      retmap.put("status", "-1");
      retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
		}
		return retmap;
	}

}
