package com.app.admin.framework.system.permission.authorization.service.impl;

import com.app.admin.framework.system.module.model.SysModule;
import com.app.admin.framework.system.permission.authorization.dao.SysRoleModuleDao;
import com.app.admin.framework.system.permission.authorization.model.SysRoleModule;
import com.app.admin.framework.system.permission.authorization.service.SysRoleModuleService;
import com.app.framework.core.support.service.impl.CrudBaseServiceSupport;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 角色资源关联管理
 */
@Service
public class SysRoleModuleServiceImpl extends CrudBaseServiceSupport<SysRoleModuleDao, SysRoleModule> implements SysRoleModuleService {

    public boolean deleteByRoleId(Long roleId) {
        LambdaQueryWrapper<SysRoleModule> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysRoleModule::getRoleId, roleId);
        return this.remove(wrapper);
    }

    public List<SysRoleModule> listByRoleId(Long roleId) {
        LambdaQueryWrapper<SysRoleModule> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysRoleModule::getRoleId, roleId);
        return this.list(wrapper);
    }

    public List<SysModule> selectByRoleIds(Integer mtype, Set<Long> roleIds) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("mtype", mtype);
        map.put("roleIds", roleIds);
        return getBaseMapper().selectByRoleIds(map);
    }
}