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 java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.attendance.domain.HrmPaidLeaveTime;
import weaver.hrm.attendance.manager.HrmPaidLeaveTimeManager;
import weaver.systeminfo.SystemEnv;

/**
 * 调休数据升级 准备
 * @author pzy
 *
 */
public class GetUpgrade7Cmd extends AbstractCommonCommand<Map<String, Object>>{

	public GetUpgrade7Cmd(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>();
    String type = Util.null2String((String)params.get("type"));
    RecordSet rs = new RecordSet();
    String paidCnt  = "0";
    KQUpgradeTabEnum kqUpgradeTabEnum = KQUpgradeTabEnum.Upgrade7;
    try {
      if(type.equalsIgnoreCase(kqUpgradeTabEnum.getTabtype())){
        String firstdate = DateUtil.getFirstDayOfYear(DateUtil.getCurrentDate());
        String enddate = DateUtil.getLastDayOfYear(DateUtil.getCurrentDate());
        HrmPaidLeaveTimeManager paidLeaveTimeManager = new HrmPaidLeaveTimeManager();
        Map<String,String> otherparams = new HashMap<>();
        otherparams.put("fromdate", firstdate);
        otherparams.put("enddate", enddate);
        otherparams.put("sql_field001", " and field001 >0 ");
        Map<String,Comparable> paramMap = new HashMap<String,Comparable>();
        Iterator it = otherparams.entrySet().iterator();
        while(it.hasNext()){
          Map.Entry entry = (Map.Entry) it.next();
          paramMap.put((String)entry.getKey(), (String)entry.getValue());
        }
        List<HrmPaidLeaveTime> tList = paidLeaveTimeManager.find(paramMap);

        String paidSql = " select count(1) from hrm_paid_leave ";
        rs.executeQuery(paidSql);
        if(rs.next()){
          paidCnt = ""+rs.getInt(1);
        }
        paidCnt = tList != null && !tList.isEmpty() ? ""+tList.size() : "0";
      }
    } catch (Exception e) {
      writeLog(e);
    }
    retmap.put("count", UpgradeUtil.formatMsg(kqUpgradeTabEnum, user.getLanguage(), paidCnt) );
    retmap.put("title", SystemEnv.getHtmlLabelName(17530,user.getLanguage()));
    retmap.put("status", "1");
    return retmap;
	}

}
