package com.engine.kq.cmd.balanceofleave;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.kq.biz.KQLeaveRulesComInfo;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;

import java.util.*;

/**
 * 假期余额--获取页签
 */
public class GetTabCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetTabCmd(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>();
        Map<String, Object> valueMap = new LinkedHashMap<String, Object>();//假期规则集合
        Map<String, Object> tabMap = new HashMap<String, Object>();
        List<Map<String, Object>> tabList = new ArrayList<Map<String, Object>>();


        /**
         * 加载TAB页签：
         * 只加载已启用并且已经开启了假期余额的假期规则
         */
        KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
        kqLeaveRulesComInfo.setTofirstRow();
        while (kqLeaveRulesComInfo.next()) {
            if (!kqLeaveRulesComInfo.getBalanceEnable().equals("1") || kqLeaveRulesComInfo.getIsEnable().equals("0")) {
                continue;
            }
            valueMap.put(Util.formatMultiLang(kqLeaveRulesComInfo.getLeaveName(), "" + user.getLanguage()), kqLeaveRulesComInfo.getId());
        }

        /**
         * 拼装前端TAB页签需要的数据
         */
        int index = 0;
        for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
            tabMap = new HashMap<String, Object>();
            tabMap.put("key", index);
            tabMap.put("id", entry.getValue().toString());
            tabMap.put("title", entry.getKey());
            tabList.add(tabMap);
            index++;
        }
        resultMap.put("tab", tabList);
        return resultMap;
    }
}
