package com.sifang.modules.sys.extention.permission.handlers;

import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.setting.dao.MemberRoleDao;
import com.sifang.modules.sys.extention.permission.PermissionHandler;
import com.sifang.modules.sys.extention.permission.PermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 保留sys_menu_pro中属于对应角色的菜单
 */
@Component
public class KeepMenusByUserRoleHandler implements PermissionHandler{

    @Autowired
    MemberRoleDao memberRoleDao;

    @Override
    public void handler(PermissionVo vo) {
        List<Record> menus = memberRoleDao.getMenusByUserRole(vo.getSysRoleId());
        vo.getData().clear();
        for(Record rd : menus){
            vo.getData().put(rd.getStr("id"), "1");
        }
    }
}
