package com.engine.kq.cmd.leaverules;

import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
import com.engine.kq.biz.KQLeaveRulesComInfo;
import weaver.general.Util;
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 GetSearchConditionCmd extends AbstractCommonCommand<Map<String, Object>> {

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

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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> resultMap = new HashMap<String, Object>();

        List<Map<String, Object>> groupList = new ArrayList<Map<String, Object>>();
        Map<String, Object> groupItem = new HashMap<String, Object>();
        List<Object> itemList = new ArrayList<Object>();
        HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
        SearchConditionItem searchConditionItem = null;
        HrmFieldBean hrmFieldBean = null;

        hrmFieldBean = new HrmFieldBean();
        hrmFieldBean.setFieldname("ruleName");//规则名称
        hrmFieldBean.setFieldlabel("19829");
        hrmFieldBean.setFieldhtmltype("1");
        hrmFieldBean.setType("1");
        searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
        itemList.add(searchConditionItem);

        hrmFieldBean = new HrmFieldBean();
        hrmFieldBean.setFieldname("typeId");//假期类型
        hrmFieldBean.setFieldlabel("129811");
        hrmFieldBean.setFieldhtmltype("5");
        hrmFieldBean.setType("1");
        hrmFieldBean.setIsFormField(true);
        searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
        List<SearchConditionOption> optionsList = new ArrayList<SearchConditionOption>();
        KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo();
        rulesComInfo.setTofirstRow();
        while (rulesComInfo.next()) {
            optionsList.add(new SearchConditionOption(rulesComInfo.getId(), Util.formatMultiLang(rulesComInfo.getLeaveName())));
        }
        searchConditionItem.setOptions(optionsList);
        itemList.add(searchConditionItem);

        groupItem.put("title", SystemEnv.getHtmlLabelName(347,weaver.general.Util.getIntValue(user.getLanguage())));
        groupItem.put("defaultshow", true);

        groupItem.put("items", itemList);
        groupList.add(groupItem);
        resultMap.put("condition", groupList);
        return resultMap;
    }
}
