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.bean.RightMenu;
import com.engine.kq.bean.RightMenuType;
import com.engine.kq.biz.KQLeaveRulesBiz;
import com.engine.kq.biz.KQLeaveRulesComInfo;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
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 GetRightMenuCmd extends AbstractCommonCommand<Map<String, Object>> {

    public GetRightMenuCmd(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<Object> rightMenuList = new ArrayList<Object>();//表示有权限可以看见的菜单List集合
        int languageId = user.getLanguage();//用户选择的语言
        RightMenu rightMenu = null;

        String ruleId = Util.null2String(params.get("ruleId"));//假期类型的ID
        //判断是否是调休
        boolean isTiaoXiu = KQLeaveRulesBiz.isTiaoXiu(ruleId);
        /**
         * 具有【假期规则维护权限】
         */
        boolean canAdd = HrmUserVarify.checkUserRight("KQLeaveRulesAdd:Add", user);//是否具有新建权限
        if (canAdd) {
            if(!isTiaoXiu){
                rightMenu = new RightMenu(languageId, RightMenuType.BTN_Save, "save", true);//保存
                rightMenuList.add(rightMenu);
            }

            rightMenu = new RightMenu(languageId, RightMenuType.BTN_Import, "importExcel", true);//导入
            rightMenuList.add(rightMenu);

            if(!isTiaoXiu){
                rightMenu = new RightMenu(languageId, RightMenuType.BTN_BatchEditing, "batchEditing", true);//批处理
                rightMenuList.add(rightMenu);
            }

            rightMenu = new RightMenu(languageId, RightMenuType.BTN_EXPORTEXCEL, "exportExcel", true);//导出Excel
            rightMenuList.add(rightMenu);

            rightMenu = new RightMenu(languageId, RightMenuType.BTN_log, "log", false);//日志
            rightMenuList.add(rightMenu);
        }
        resultMap.put("btnMenu", rightMenuList);
        return resultMap;
    }
}
