package com.engine.kq.cmd.holidaySet;

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 weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.moduledetach.ManageDetachComInfo;
import weaver.systeminfo.SystemEnv;
import weaver.systeminfo.systemright.CheckSubCompanyRight;

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 groupId = Util.null2String(params.get("groupId"));//考勤组的ID
        if("".equals(groupId)||groupId.equals("0")){
            resultMap.put("btnMenu", rightMenuList);
            return resultMap;
        }
        boolean isList = Util.null2String(params.get("isList")).equals("true");//是日历还是清单
        boolean canAdd = HrmUserVarify.checkUserRight("KQHolidaySetAdd:Add", user);//是否具有新建权限
        boolean canDelete = HrmUserVarify.checkUserRight("KQHolidaySetDelete:Delete", user);//是否具有删除权限
        boolean canLog = HrmUserVarify.checkUserRight("KQHolidaySet:Log", user);//是否具有查看日志的权限
        if (canAdd) {
            rightMenu = new RightMenu(languageId, RightMenuType.BTN_Addnew, "new", true);//新建
            rightMenuList.add(rightMenu);
        }
        if (canAdd) {
            rightMenu = new RightMenu(languageId, RightMenuType.BTN_Import, "import", true);//导入
            rightMenuList.add(rightMenu);
        }
        if(canAdd && !isList){
            rightMenu = new RightMenu(languageId, RightMenuType.BTN_Init, "init", true);//初始化
            rightMenuList.add(rightMenu);
        }
        if (canDelete && isList) {
            List<Map<String, Object>> menuList = new ArrayList<Map<String, Object>>();
            if (canDelete) {
                Map<String, Object> menuMap = new HashMap<String, Object>();
                menuMap.put("key", "0");
                menuMap.put("show", SystemEnv.getHtmlLabelName(32136, user.getLanguage()));//批量删除
                menuMap.put("selected", true);
                menuList.add(menuMap);

                menuMap = new HashMap<String, Object>();
                menuMap.put("key", "1");
                menuMap.put("show", SystemEnv.getHtmlLabelName(19015, user.getLanguage()));//同步
                menuList.add(menuMap);
            }
            resultMap.put("buttonSelect", menuList);
        }
        if (canLog) {
            rightMenu = new RightMenu(languageId, RightMenuType.BTN_log, "log", false);//日志
            rightMenuList.add(rightMenu);
        }
        if (isList) {
            rightMenu = new RightMenu(languageId, RightMenuType.BTN_COLUMN, "custom", false); //显示列定制
            rightMenuList.add(rightMenu);
        }
        resultMap.put("btnMenu", rightMenuList);
        return resultMap;
    }
}
