package com.engine.kq.cmd.hrmAttProcSet;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.enums.KqSplitFlowTypeEnum;
import com.engine.kq.wfset.attendance.domain.HrmAttProcSet;
import com.engine.kq.wfset.attendance.manager.HrmAttProcSetManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.common.StringUtil;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

/**
 * 获取考勤流程设置的 tab页签数据
 * @author pzy
 *
 */
public class GetStateProcSetTabInfoCmd extends AbstractCommonCommand<Map<String, Object>>{
	
	public GetStateProcSetTabInfoCmd(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 {
			if(!HrmUserVarify.checkUserRight("HrmAttendanceProcess:setting",user)) {
				retmap.put("status", "-1");
				retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
				return retmap;
		  }

			String url = "";
			String title = "";
			StringUtil strUtil = new StringUtil();
			String id = Util.null2String(params.get("id"));
			int field006 = Util.getIntValue(Util.null2String(params.get("field006")));
			String subcompanyid = Util.null2String(params.get("subcompanyid"));
			
			HrmAttProcSetManager attProcSetManager = new HrmAttProcSetManager();
			HrmAttProcSet bean = attProcSetManager.get(id);
			bean = bean == null ? new HrmAttProcSet() : bean;
			
			List<Map<String,Object>> tabs = new ArrayList<Map<String,Object>>();
			Map<String,Object> tab = null;

			tab = new HashMap<String, Object>();
			title = SystemEnv.getHtmlLabelName(500272,weaver.general.Util.getIntValue(user.getLanguage()));
			url = "/hrm/attendance/hrmAttProcSet/content.jsp?id="+id+"&subcompanyid="+subcompanyid;
			tab.put("key", "1");
			tab.put("url", url);
			tab.put("title", title);
			tabs.add(tab);
			if(strUtil.isNotNull(id)) {
				tab = new HashMap<String, Object>();
				title = SystemEnv.getHtmlLabelName(10000609,weaver.general.Util.getIntValue(user.getLanguage()));
				url = "/hrm/attendance/hrmAttProcSet/wfFields.jsp?id="+id;
				tab.put("key", "2");
				tab.put("url", url);
				tab.put("title", title);
				tabs.add(tab);
        tab = new HashMap<String, Object>();
        title = SystemEnv.getHtmlLabelName(33085,weaver.general.Util.getIntValue(user.getLanguage()));
        url = "/hrm/attendance/hrmAttProcSet/wfSet.jsp?id="+id;
        tab.put("key", "3");
        tab.put("url", url);
        tab.put("title", title);
        tabs.add(tab);
			}
			if(field006 == KqSplitFlowTypeEnum.LEAVE.getFlowtype()
          || field006 == KqSplitFlowTypeEnum.EVECTION.getFlowtype()
          || field006 == KqSplitFlowTypeEnum.OUT.getFlowtype()
          || field006 == KqSplitFlowTypeEnum.OVERTIME.getFlowtype()
          || field006 == KqSplitFlowTypeEnum.CARD.getFlowtype()
          || field006 == KqSplitFlowTypeEnum.PROCESSCHANGE.getFlowtype()){
        tab = new HashMap<String, Object>();
        title = SystemEnv.getHtmlLabelName(83194,weaver.general.Util.getIntValue(user.getLanguage()));
        tab.put("key", "4");
        tab.put("url", url);
        tab.put("title", title);
        tabs.add(tab);
      }

			retmap.put("status", "1");
			retmap.put("tabs", tabs);
		} catch (Exception e) {
			retmap.put("status", "-1");
			retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
			writeLog(e);
		}
		return retmap;
	}
	
	@Override
	public BizLogContext getLogContext() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
