package com.cool.store.dao;

import com.cool.store.entity.SysRoleMenuDO;
import com.cool.store.mapper.SysRoleMenuMapper;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangchenbiao
 * @date 2023-05-19 03:01
 */
@Repository
public class SysRoleMenuDAO {

    @Resource
    private SysRoleMenuMapper sysRoleMenuMapper;

    /**
     * 获取菜单
     * @param roleId
     * @param platform
     * @return
     */
    public List<SysRoleMenuDO> getRoleMenuByRoleId(String roleId){
        if(Objects.isNull(roleId)){
            return Lists.newArrayList();
        }
        return sysRoleMenuMapper.getRoleMenuByRoleId(roleId);
    }

    public Integer updateRoleAuth(String roleId, List<Long> menuIds){
        //先删后增
        sysRoleMenuMapper.deleteRoleAuth(roleId);
        List<SysRoleMenuDO> insertList = new ArrayList<>();
        for (Long menuId : menuIds) {
            SysRoleMenuDO insert = new SysRoleMenuDO();
            insert.setMenuId(menuId);
            insert.setRoleId(roleId);
            insertList.add(insert);
        }
        return sysRoleMenuMapper.batchInsert(insertList);
    }

}