package com.engine.kq.cmd.reportdetial;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQOvertimeRulesBiz;
import com.engine.kq.enums.OverTimeComputingModeEnum;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 考勤报表明细tabs
 * @author pzy
 *
 */
public class GetTabsCmd extends AbstractCommonCommand<Map<String, Object>>{

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

	@Override
	public Map<String, Object> execute(CommandContext commandContext) {
		Map<String,Object> retmap = new HashMap<String,Object>();
		try {
			List<Map<String,Object>> tabs = new ArrayList<Map<String,Object>>();
			Map<String,Object> tab = null;

			//必要的权限判断
//			if(!HrmUserVarify.checkUserRight("BohaiInsuranceScheduleReport:View",user)) {
//				retmap.put("status", "-1");
//				retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
//				return retmap;
//			}

			String type = Util.null2String(params.get("type"));

			if(type.equals("beLate")||type.equals("beLateMins")||
				 type.equals("graveBeLate")||type.equals("graveBeLateMins")){
				tab = new HashMap<String, Object>();
				tab.put("key", "1");
				tab.put("selected",type.equals("beLate")||type.equals("beLateMins"));
				tab.put("title", SystemEnv.getHtmlLabelName(20088,user.getLanguage()));
				tabs.add(tab);

				tab = new HashMap<String, Object>();
				tab.put("key", "2");
				tab.put("selected",type.equals("graveBeLate")||type.equals("graveBeLateMins"));
				tab.put("title", SystemEnv.getHtmlLabelName(390520,user.getLanguage()));
				tabs.add(tab);
			}else if(type.equals("leaveEearly")||type.equals("leaveEarlyMins")||
							type.equals("graveLeaveEarly")||type.equals("graveLeaveEarlyMins")){
				tab = new HashMap<String, Object>();
				tab.put("key", "1");
				tab.put("selected",type.equals("leaveEearly")||type.equals("leaveEarlyMins"));
				tab.put("title", SystemEnv.getHtmlLabelName(20089,user.getLanguage()));
				tabs.add(tab);

				tab = new HashMap<String, Object>();
				tab.put("key", "2");
				tab.put("selected",type.equals("graveLeaveEarly")||type.equals("graveLeaveEarlyMins"));
				tab.put("title", SystemEnv.getHtmlLabelName(391415,user.getLanguage()));
				tabs.add(tab);
			}else if(type.startsWith("leaveType_")||
							type.equals("businessLeave")||type.equals("officialBusiness")||type.equals("leave")){
				tab = new HashMap<String, Object>();
				tab.put("key", "1");
				tab.put("title", SystemEnv.getHtmlLabelName(18800,user.getLanguage()));
				tabs.add(tab);

				tab = new HashMap<String, Object>();
				tab.put("key", "2");
				tab.put("title", SystemEnv.getHtmlLabelName(17999,user.getLanguage()));
				tabs.add(tab);
			}else if("overtimeTotal".equalsIgnoreCase(type)){
        OverTimeComputingModeEnum[] enums = OverTimeComputingModeEnum.values();
        for(int i = 0 ; enums != null && i < enums.length; i++){
          OverTimeComputingModeEnum overTimeComputingModeEnums = enums[i];
          tab = new HashMap<String, Object>();
          tab.put("key", overTimeComputingModeEnums.getComputingMode());
          tab.put("title", SystemEnv.getHtmlLabelNames(overTimeComputingModeEnums.getLabel(),user.getLanguage()));
          tabs.add(tab);
        }
      }

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

	@Override
	public BizLogContext getLogContext() {
		return null;
	}

}
