package com.engine.kq.cmd.myattendance;

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 com.engine.portal.util.DateUtil;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.systeminfo.SystemEnv;

import java.util.*;

/**
 * 获取【我的考勤】各明细的高级搜索条件
 */
public class GetDetailCondition4MobileCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetDetailCondition4MobileCmd(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;

            String kqtype = Util.null2String(params.get("kqtype"));//类型，不同明细下的高级搜索可能不同
            if ("overtime".equalsIgnoreCase(kqtype)) {
                hrmFieldBean = new HrmFieldBean();
                hrmFieldBean.setFieldname("paidLeaveEnable");//关联调休
                hrmFieldBean.setFieldlabel("125804");
                hrmFieldBean.setFieldhtmltype("5");
                hrmFieldBean.setType("1");
                searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
                List<SearchConditionOption> optionsList = new ArrayList<SearchConditionOption>();
                optionsList.add(new SearchConditionOption("-1", SystemEnv.getHtmlLabelName(332, user.getLanguage()), true));//全部
                optionsList.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(163, user.getLanguage())));//是
                optionsList.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(161, user.getLanguage())));//否
                searchConditionItem.setOptions(optionsList);
                itemList.add(searchConditionItem);

                hrmFieldBean = new HrmFieldBean();
                hrmFieldBean.setFieldname("computingMode");//加班方式
                hrmFieldBean.setFieldlabel("513203");
                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(500382, user.getLanguage())));//需审批，以加班流程为准
                optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(500383, user.getLanguage())));//需审批，以打卡为准，但是不能超过加班流程时长
                optionsList.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(390837, user.getLanguage())));//无需审批，根据打卡时间计算加班时长
                searchConditionItem.setOptions(optionsList);
                itemList.add(searchConditionItem);
            } else {
                hrmFieldBean = new HrmFieldBean();
                hrmFieldBean.setFieldname("signType");//打卡类型
                hrmFieldBean.setFieldlabel("500502,63");
                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(512504, user.getLanguage())));
                optionsList.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(512505, 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) {
            writeLog(e);
        }
        return resultMap;
    }
}
