mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-05-11 22:32:11 +08:00
[重大更新] 集成 mybatis-plus-join 重构项目代码(实验性功能不稳定)
This commit is contained in:
@@ -4,22 +4,21 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
||||
import com.baomidou.mybatisplus.core.toolkit.reflect.GenericTypeUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 自定义 Mapper 接口, 实现 自定义扩展
|
||||
@@ -30,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
* @since 2021-05-13
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
||||
public interface BaseMapperPlus<T, V> extends MPJBaseMapper<T> {
|
||||
|
||||
Log log = LogFactory.getLog(BaseMapperPlus.class);
|
||||
|
||||
@@ -42,7 +41,7 @@ public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
||||
* @return 当前类的泛型类型 V 的 Class 对象
|
||||
*/
|
||||
default Class<V> currentVoClass() {
|
||||
return (Class<V>) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 1);
|
||||
return (Class<V>) GenericTypeUtils.resolveTypeArguments(this.getClass(), BaseMapperPlus.class)[1];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +52,7 @@ public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
||||
* @return 当前类的泛型类型 T 的 Class 对象
|
||||
*/
|
||||
default Class<T> currentModelClass() {
|
||||
return (Class<T>) ReflectionKit.getSuperClassGenericType(this.getClass(), BaseMapperPlus.class, 0);
|
||||
return (Class<T>) GenericTypeUtils.resolveTypeArguments(this.getClass(), BaseMapperPlus.class)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,11 +235,7 @@ public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
||||
* @return 查询到的单个VO对象,经过类型转换为指定的VO类后返回
|
||||
*/
|
||||
default <C> C selectVoOne(Wrapper<T> wrapper, Class<C> voClass) {
|
||||
T obj = this.selectOne(wrapper);
|
||||
if (ObjectUtil.isNull(obj)) {
|
||||
return null;
|
||||
}
|
||||
return MapstructUtils.convert(obj, voClass);
|
||||
return selectVoOne(wrapper, voClass, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,7 +332,7 @@ public interface BaseMapperPlus<T, V> extends BaseMapper<T> {
|
||||
* @return 查询到的符合条件的对象列表,经过转换为指定类型的对象后返回
|
||||
*/
|
||||
default <C> List<C> selectObjs(Wrapper<T> wrapper, Function<? super Object, C> mapper) {
|
||||
return this.selectObjs(wrapper).stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toList());
|
||||
return StreamUtils.toList(this.selectObjs(wrapper), mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -225,13 +225,22 @@ public class PlusDataPermissionHandler {
|
||||
if (!access.constrained()) {
|
||||
return roles;
|
||||
}
|
||||
Map<Long, RoleDTO> allRoleMap = new LinkedHashMap<>();
|
||||
if (CollUtil.isNotEmpty(roles)) {
|
||||
roles.forEach(role -> allRoleMap.put(role.getRoleId(), role));
|
||||
}
|
||||
Map<Long, RoleDTO> roleMap = new LinkedHashMap<>();
|
||||
Map<String, List<RoleDTO>> dataScopeRoleMap = user.getDataScopeRoleMap();
|
||||
Map<String, List<Long>> dataScopeRoleMap = user.getDataScopeRoleMap();
|
||||
if (CollUtil.isNotEmpty(dataScopeRoleMap)) {
|
||||
access.perms().forEach(perm -> {
|
||||
List<RoleDTO> roleList = dataScopeRoleMap.get(perm);
|
||||
if (CollUtil.isNotEmpty(roleList)) {
|
||||
roleList.forEach(role -> roleMap.putIfAbsent(role.getRoleId(), role));
|
||||
List<Long> roleIds = dataScopeRoleMap.get(perm);
|
||||
if (CollUtil.isNotEmpty(roleIds)) {
|
||||
roleIds.forEach(roleId -> {
|
||||
RoleDTO role = allRoleMap.get(roleId);
|
||||
if (role != null) {
|
||||
roleMap.putIfAbsent(role.getRoleId(), role);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user