package com.engine.kq.cmd.importlog;

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GetHistorySearchConditionCmd extends AbstractCommonCommand<Map<String, Object>> {

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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        List<Object> itemList = new ArrayList<Object>();
        try {
            ConditionFactory conditionFactory = new ConditionFactory(user);
            SearchConditionItem searchConditionItem = null;
            HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();

            HrmFieldBean hrmFieldBean = null;
            hrmFieldBean = new HrmFieldBean("operatorid", "17482", "3", "17");
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            searchConditionItem.setLabelcol(7);
            searchConditionItem.setFieldcol(17);
            itemList.add(searchConditionItem);

            searchConditionItem = conditionFactory.createCondition(ConditionType.DATE, 2061, "3", "2");
            searchConditionItem.setDomkey(new String[]{"dateSelect", "fromdate", "enddate"});
            List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
            options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(332, user.getLanguage()), true));
            options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(15537, user.getLanguage())));
            options.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(15539, user.getLanguage())));
            options.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(15541, user.getLanguage())));
            options.add(new SearchConditionOption("7", SystemEnv.getHtmlLabelName(27347, user.getLanguage())));
            options.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(21904, user.getLanguage())));
            options.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(15384, user.getLanguage())));
            options.add(new SearchConditionOption("8", SystemEnv.getHtmlLabelName(81716, user.getLanguage())));
            options.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(32530, user.getLanguage())));
            searchConditionItem.setOptions(options);
            searchConditionItem.setLabelcol(7);
            searchConditionItem.setFieldcol(17);
            itemList.add(searchConditionItem);

            hrmFieldBean = new HrmFieldBean("departmentid", "124", "3", "4");
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            searchConditionItem.setLabelcol(7);
            searchConditionItem.setFieldcol(17);
            itemList.add(searchConditionItem);

            hrmFieldBean = new HrmFieldBean("subcompanyid", "141", "3", "164");
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            searchConditionItem.setLabelcol(7);
            searchConditionItem.setFieldcol(17);
            itemList.add(searchConditionItem);

            hrmFieldBean = new HrmFieldBean("status", "602", "5", "1");
            options = new ArrayList<SearchConditionOption>();
            options.add(new SearchConditionOption("", SystemEnv.getHtmlLabelName(332, user.getLanguage()), true));
            options.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(15242, user.getLanguage())));
            options.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(498, user.getLanguage())));
            hrmFieldBean.setSelectOption(options);
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            searchConditionItem.setLabelcol(7);
            searchConditionItem.setFieldcol(17);
            itemList.add(searchConditionItem);

            List<Object> groupList = new ArrayList<Object>();
            Map<String, Object> groupItem = new HashMap<String, Object>();
            groupItem.put("title", "");
            groupItem.put("defaultshow", true);
            groupItem.put("items", itemList);
            groupList.add(groupItem);

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

    @Override
    public BizLogContext getLogContext() {
        // TODO Auto-generated method stub
        return null;
    }
}
