package com.engine.kq.cmd.schedulecode;

import java.util.*;

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 weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
 

public class GetScheduleCodeConditionCmd extends AbstractCommonCommand<Map<String, Object>>{
	
	public GetScheduleCodeConditionCmd(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{
			//必要的权限判断
			if(!HrmUserVarify.checkUserRight("ScheduleCode:Edit",user)) {
				retmap.put("status", "-1");
				retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
				return retmap;
			}

			Map<String, List<HrmFieldBean>> fieldGroups= new LinkedHashMap<String, List<HrmFieldBean>>();
			List<HrmFieldBean> lsField = new ArrayList<HrmFieldBean>();
			HrmFieldBean hrmFieldBean = null;
			List<SearchConditionOption> options = null;

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("lastname");
			hrmFieldBean.setFieldlabel("413");
			hrmFieldBean.setFieldhtmltype("1");
			hrmFieldBean.setType("1");
			lsField.add(hrmFieldBean);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("schedulecode");
			hrmFieldBean.setFieldlabel("27960");
			hrmFieldBean.setFieldhtmltype("1");
			hrmFieldBean.setType("1");
			lsField.add(hrmFieldBean);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("subcompanyid");
			hrmFieldBean.setFieldlabel("141");
			hrmFieldBean.setFieldhtmltype("3");
			hrmFieldBean.setType("194");
			lsField.add(hrmFieldBean);
			fieldGroups.put("1361", lsField);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("departmentid");
			hrmFieldBean.setFieldlabel("124");
			hrmFieldBean.setFieldhtmltype("3");
			hrmFieldBean.setType("57");
			lsField.add(hrmFieldBean);
			fieldGroups.put("1361", lsField);

			hrmFieldBean = new HrmFieldBean();
			hrmFieldBean.setFieldname("jobtitle");
			hrmFieldBean.setFieldlabel("6086");
			hrmFieldBean.setFieldhtmltype("3");
			hrmFieldBean.setType("278");
			lsField.add(hrmFieldBean);
			fieldGroups.put("1361", lsField);

			HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
			SearchConditionItem searchConditionItem = null;
			Iterator<Map.Entry<String, List<HrmFieldBean>>> iter = fieldGroups.entrySet().iterator();
			while (iter.hasNext()) {
				Map.Entry<String, List<HrmFieldBean>> entry = iter.next();
				String grouplabel = entry.getKey();
				List<HrmFieldBean> fields = entry.getValue();
				groupitem = new HashMap<String, Object>();
				groupitem.put("title", SystemEnv.getHtmlLabelNames(grouplabel, user.getLanguage()));
				groupitem.put("defaultshow", true);

				itemlist = new ArrayList<Object>();
				for (int j = 0; j < fields.size(); j++) {
					hrmFieldBean = fields.get(j);
					searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
					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() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
