package com.engine.kq.cmd.hrmAttProcSet;

import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import weaver.common.StringUtil;
import weaver.hrm.User;
import weaver.hrm.moduledetach.ManageDetachComInfo;
import weaver.systeminfo.SystemEnv;

/**
 * 获取考勤流程设置的查询条件
 * @author pzy
 *
 */
public class GetStateProcSetListSearchConditionCmd extends AbstractCommonCommand<Map<String, Object>> {

	public GetStateProcSetListSearchConditionCmd(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>();
		List<Map<String,Object>> grouplist = new ArrayList<Map<String,Object>>();
		Map<String,Object> groupitem = null;
		List<Object> itemlist = null;
		try{

			int subcompanyid = StringUtil.parseToInt(StringUtil.vString(params.get("subcompanyid")), 0);
			//流程路径 对应表单 表单类型 状态 最后修改日期 变更流程类型
			String[] fields = new String[]{"field001,34067,1,1","field002,15600,3,wfFormBrowser","field003,18411,5,1"
											,"subcompanyid,19799,3,169","field005,602,5,1","createdateselect,19521,3,2"
											,"field006,84791,5,1"};

			ManageDetachComInfo ManageDetachComInfo = new ManageDetachComInfo();
			HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
			SearchConditionItem searchConditionItem = null;
			HrmFieldBean hrmFieldBean = null;
			itemlist = new ArrayList<Object>();
			groupitem = new HashMap<String,Object>();
			groupitem.put("title", SystemEnv.getHtmlLabelName(20331, user.getLanguage()));
			groupitem.put("defaultshow", true);
			for(int i=0;i<fields.length;i++){
				String[] fieldinfo = fields[i].split(",");
				hrmFieldBean = new HrmFieldBean();
				hrmFieldBean.setFieldname(fieldinfo[0]);
				hrmFieldBean.setFieldlabel(fieldinfo[1]);
				hrmFieldBean.setFieldhtmltype(fieldinfo[2]);
				hrmFieldBean.setType(fieldinfo[3]);
				
				if("subcompanyid".equals(hrmFieldBean.getFieldname())){
					if(!StringUtil.vString(ManageDetachComInfo.getDetachable()).equals("1")) {
						continue;
					}
					//表示左侧分部树选择了
					if(subcompanyid > 0){
						hrmFieldBean.setFieldvalue(subcompanyid);
					}
				}
				if("field003".equals(hrmFieldBean.getFieldname())){
					List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
					options.add(new SearchConditionOption("",SystemEnv.getHtmlLabelName(332, user.getLanguage())));
					options.add(new SearchConditionOption("0",SystemEnv.getHtmlLabelName(125026,weaver.general.Util.getIntValue(user.getLanguage()))));
					options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(125027,weaver.general.Util.getIntValue(user.getLanguage()))));
					hrmFieldBean.setSelectOption(options);
				}else if("field005".equals(hrmFieldBean.getFieldname())){
					List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
					options.add(new SearchConditionOption("",SystemEnv.getHtmlLabelName(332, user.getLanguage())));
					options.add(new SearchConditionOption("0",SystemEnv.getHtmlLabelName(18096,user.getLanguage())));
					options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(18095,user.getLanguage())));
					hrmFieldBean.setSelectOption(options);
				}else if("field006".equals(hrmFieldBean.getFieldname())){
					hrmFieldBean.setFieldlabel("15880,18015,63");
					List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
					options.add(new SearchConditionOption("",SystemEnv.getHtmlLabelName(332, user.getLanguage())));
					options.add(new SearchConditionOption("0",SystemEnv.getHtmlLabelName(83393,weaver.general.Util.getIntValue(user.getLanguage()))));
					options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(83394,weaver.general.Util.getIntValue(user.getLanguage()))));
					options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(83395,weaver.general.Util.getIntValue(user.getLanguage()))));
					options.add(new SearchConditionOption("3",SystemEnv.getHtmlLabelName(83396,weaver.general.Util.getIntValue(user.getLanguage()))));
					options.add(new SearchConditionOption("5",SystemEnv.getHtmlLabelName(390737,weaver.general.Util.getIntValue(user.getLanguage()))));
          options.add(new SearchConditionOption("6",SystemEnv.getHtmlLabelName(389117,weaver.general.Util.getIntValue(user.getLanguage()))));
          options.add(new SearchConditionOption("7",SystemEnv.getHtmlLabelName(390274,weaver.general.Util.getIntValue(user.getLanguage()))));
          options.add(new SearchConditionOption("8",SystemEnv.getHtmlLabelName(513400,weaver.general.Util.getIntValue(user.getLanguage()))));
					hrmFieldBean.setSelectOption(options);
				}
				
				searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
				if("subcompanyid".equals(hrmFieldBean.getFieldname())){
					//表示左侧分部树选择了
					if(subcompanyid > 0){
						searchConditionItem.setValue(subcompanyid);
					}
          searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "HrmAttendanceProcess:setting");
          searchConditionItem.getBrowserConditionParam().getCompleteParams().put("rightStr", "HrmAttendanceProcess:setting");
				}
				if(searchConditionItem.getBrowserConditionParam()!=null){
					searchConditionItem.getBrowserConditionParam().setViewAttr(2);
				}
				searchConditionItem.setViewAttr(2);
				itemlist.add(searchConditionItem);
			}
			groupitem.put("items", itemlist);
			grouplist.add(groupitem);
			retmap.put("status", "1");
			retmap.put("conditions", grouplist);
		}catch (Exception e) {
			retmap.put("status", "-1");
			retmap.put("message",  SystemEnv.getHtmlLabelName(382661,user.getLanguage()));
			writeLog(e);
		}
		return retmap;
	}

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