完成用户的角色分配,妥妥的。睡觉~
This commit is contained in:
@@ -8,6 +8,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMapper extends BaseMapper<SysRoleDO> {
|
||||
|
||||
@@ -27,5 +31,7 @@ public interface SysRoleMapper extends BaseMapper<SysRoleDO> {
|
||||
return selectOne(new QueryWrapperX<SysRoleDO>().eq("code", code));
|
||||
}
|
||||
|
||||
|
||||
default List<SysRoleDO> selectListByStatus(@Nullable Collection<Integer> statuses) {
|
||||
return selectList(new QueryWrapperX<SysRoleDO>().in("status", statuses));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRoleDO> {
|
||||
@@ -14,4 +16,20 @@ public interface SysUserRoleMapper extends BaseMapper<SysUserRoleDO> {
|
||||
return selectList(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId));
|
||||
}
|
||||
|
||||
default void insertList(Long userId, Collection<Long> roleIds) {
|
||||
List<SysUserRoleDO> list = roleIds.stream().map(roleId -> {
|
||||
SysUserRoleDO entity = new SysUserRoleDO();
|
||||
entity.setUserId(userId);
|
||||
entity.setRoleId(roleId);
|
||||
return entity;
|
||||
}).collect(Collectors.toList());
|
||||
// TODO 芋艿,mybatis plus 增加批量插入的功能
|
||||
list.forEach(this::insert);
|
||||
}
|
||||
|
||||
default void deleteListByUserIdAndRoleIdIds(Long userId, Collection<Long> roleIds) {
|
||||
delete(new QueryWrapper<SysUserRoleDO>().eq("user_id", userId)
|
||||
.in("role_id", roleIds));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user