package com.engine.kq.cmd.schedulesignimport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;
 

public class GetImportFormCmd extends AbstractCommonCommand<Map<String, Object>>{
	
	public GetImportFormCmd(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<Object> lsGroup = new ArrayList<Object>();
		Map<String,Object> groupitem = null;
		List<Object> itemlist = null;
		SearchConditionItem searchConditionItem = null;

		try {
			if (!HrmUserVarify.checkUserRight("HrmResourceEdit:Edit", user)) {
				retmap.put("status", "-1");
				retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage()));
				return retmap;
			}
			
			ConditionFactory conditionFactory = new ConditionFactory(user);
			
			String excelpath = "/hrm/schedule/inputexcellfile/inputE9.xls";
			itemlist = new ArrayList<Object>();
			groupitem = new HashMap<String,Object>();
			groupitem.put("title", SystemEnv.getHtmlLabelName(1361, user.getLanguage()));
			groupitem.put("defaultshow", true);
			
			//重复验证字段
			List<SearchConditionOption> statusOptions = new ArrayList<SearchConditionOption>();
			statusOptions.add(new SearchConditionOption("loginid",SystemEnv.getHtmlLabelName(	412, user.getLanguage())));
			statusOptions.add(new SearchConditionOption("workcode",SystemEnv.getHtmlLabelName(714, user.getLanguage()),true));
			statusOptions.add(new SearchConditionOption("lastname",SystemEnv.getHtmlLabelName(413, user.getLanguage())));
			searchConditionItem = conditionFactory.createCondition(ConditionType.SELECT, 33582,"keyField",statusOptions);
			searchConditionItem.setValue("workcode");
			itemlist.add(searchConditionItem);
			
			//模板文件
			searchConditionItem = conditionFactory.createCondition(ConditionType.INPUT,28576,"templet");
			searchConditionItem.setValue(excelpath);
			itemlist.add(searchConditionItem);
			
			//Excel文件
			searchConditionItem = conditionFactory.createCondition(ConditionType.RESOURCEIMG, 16630, "excelfile");
			itemlist.add(searchConditionItem);
			
			groupitem.put("items", itemlist);
			lsGroup.add(groupitem);
		
			
			itemlist = new ArrayList<Object>();
			groupitem = new HashMap<String,Object>();
			groupitem.put("title", SystemEnv.getHtmlLabelName(33803,weaver.general.Util.getIntValue(user.getLanguage())));
			groupitem.put("defaultshow", true);
			List<String> lsPromptLabel = new ArrayList<String>(); //提示信息
			lsPromptLabel.add("124999");
			lsPromptLabel.add("125000");
			lsPromptLabel.add("125001");
			lsPromptLabel.add("125002");
			lsPromptLabel.add("503604");
			lsPromptLabel.add("390316");
			lsPromptLabel.add("390317");
			lsPromptLabel.add("33456,125006");
			lsPromptLabel.add("27961,125007");
			lsPromptLabel.add("33586,125008");
			
			for(int i=0;i<lsPromptLabel.size();i++){
				Map<String,Object> item = new HashMap<String,Object>();
				item.put("index", (i+1));
				String value = "";
				String[] label = Util.splitString(lsPromptLabel.get(i), ",");
				value = Util.toScreen(SystemEnv.getHtmlLabelNames(label[0], user.getLanguage()), user.getLanguage());
				if(label.length>1){
					value = Util.toScreen(SystemEnv.getHtmlLabelNames(label[1], user.getLanguage()), user.getLanguage());
				}
				if(i==0){
					value += SystemEnv.getHtmlLabelName(28576, user.getLanguage());
					item.put("link",excelpath);
				}
				item.put("value",value);
				itemlist.add(item);
			}
			groupitem.put("items", itemlist);
			lsGroup.add(groupitem);
			
			retmap.put("status", "1");
			retmap.put("condition", lsGroup);
		} 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;
	}
	
	
}
