package com.engine.kq.cmd.leavetypes;

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

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

/**
 * @Auther: Administrator
 * @Date: 2019-03-12 22:09
 * @Description:
 */
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>();
        try{
            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("leaveName");//假期类型名称
            hrmFieldBean.setFieldlabel("388883");
            hrmFieldBean.setFieldhtmltype("1");
            hrmFieldBean.setType("1");
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            itemList.add(searchConditionItem);

            hrmFieldBean = new HrmFieldBean();
            hrmFieldBean.setFieldname("minimumUnit");//请假单位
            hrmFieldBean.setFieldlabel("388884");
            hrmFieldBean.setFieldhtmltype("5");
            hrmFieldBean.setType("1");
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            List<SearchConditionOption> optionsList = new ArrayList<SearchConditionOption>();
            optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(332, user.getLanguage()),true));
            optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(388885, user.getLanguage())));
            optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(388886, user.getLanguage())));
            optionsList.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(388887, user.getLanguage())));
            optionsList.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(389680, user.getLanguage())));
            optionsList.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(514712, user.getLanguage())));
            optionsList.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(514786, user.getLanguage())));
            searchConditionItem.setOptions(optionsList);
            itemList.add(searchConditionItem);

            hrmFieldBean = new HrmFieldBean();
            hrmFieldBean.setFieldname("computingMode");//计算请假时长方式
            hrmFieldBean.setFieldlabel("388888");
            hrmFieldBean.setFieldhtmltype("5");
            hrmFieldBean.setType("1");
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            optionsList = new ArrayList<SearchConditionOption>();
            optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(332, user.getLanguage()),true));
            optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(388889, user.getLanguage())));
            optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(388890, user.getLanguage())));
            searchConditionItem.setOptions(optionsList);
            itemList.add(searchConditionItem);

            hrmFieldBean = new HrmFieldBean();
            hrmFieldBean.setFieldname("balanceEnable");//是否启用假期余额
            hrmFieldBean.setFieldlabel("388945");
            hrmFieldBean.setFieldhtmltype("5");
            hrmFieldBean.setType("1");
            searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
            optionsList = new ArrayList<SearchConditionOption>();
            optionsList.add(new SearchConditionOption("-1", SystemEnv.getHtmlLabelName(332, user.getLanguage()),true));
            optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(32386, user.getLanguage())));
            optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(18095, user.getLanguage())));
            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);
        }catch (Exception e){
            e.printStackTrace();
        }
        return resultMap;
    }
}
