From c5dbd04c9c99fc187ef526c0fda188dc30e51825 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期二, 14 十二月 2021 10:11:16 +0800 Subject: [PATCH] fix 修复数据权限 仅自己 相关问题 --- ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java | 54 +++++++++++++++++++++++++++--------------------------- 1 files changed, 27 insertions(+), 27 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java index 6f73c43..4de5b32 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java @@ -1,19 +1,18 @@ package com.ruoyi.common.core.mybatisplus.core; -import cn.hutool.core.bean.copier.CopyOptions; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.core.toolkit.Assert; -import com.baomidou.mybatisplus.core.toolkit.ClassUtils; +import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.page.PagePlus; import com.ruoyi.common.utils.BeanCopyUtils; import com.ruoyi.common.utils.reflect.ReflectUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ResolvableType; import java.io.Serializable; import java.util.ArrayList; @@ -49,7 +48,7 @@ return entityClass; } - protected Class<T> mapperClass = currentMapperClass(); + protected Class<M> mapperClass = currentMapperClass(); protected Class<V> voClass = currentVoClass(); @@ -58,22 +57,17 @@ } @Override - protected Class<T> currentMapperClass() { - return (Class<T>) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(0).getType(); + protected Class<M> currentMapperClass() { + return (Class<M>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 0); } @Override protected Class<T> currentModelClass() { - return (Class<T>) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(1).getType(); + return (Class<T>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 1); } protected Class<V> currentVoClass() { - return (Class<V>) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(2).getType(); - } - - @Override - protected ResolvableType getResolvableType() { - return ResolvableType.forClass(ClassUtils.getUserClass(getClass())); + return (Class<V>) ReflectionKit.getSuperClassGenericType(this.getClass(), ServicePlusImpl.class, 2); } /** @@ -126,6 +120,9 @@ */ @Override public boolean saveAll(Collection<T> entityList) { + if (CollUtil.isEmpty(entityList)) { + return false; + } return baseMapper.insertAll(entityList) == entityList.size(); } @@ -134,6 +131,9 @@ */ @Override public boolean saveOrUpdateAll(Collection<T> entityList) { + if (CollUtil.isEmpty(entityList)) { + return false; + } TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); String keyProperty = tableInfo.getKeyProperty(); @@ -149,10 +149,10 @@ updateList.add(entity); } } - if (updateList.size()>0 && updateBatchById(updateList)) { + if (CollUtil.isNotEmpty(updateList) && updateBatchById(updateList)) { row += updateList.size(); } - if (addList.size() > 0) { + if (CollUtil.isNotEmpty(addList)) { row += baseMapper.insertAll(addList); } return row == entityList.size(); @@ -164,9 +164,9 @@ * @param id 涓婚敭ID */ @Override - public V getVoById(Serializable id, CopyOptions copyOptions) { + public V getVoById(Serializable id) { T t = getBaseMapper().selectById(id); - return BeanCopyUtils.oneCopy(t, copyOptions, voClass); + return BeanCopyUtils.copy(t, voClass); } /** @@ -175,12 +175,12 @@ * @param idList 涓婚敭ID鍒楄〃 */ @Override - public List<V> listVoByIds(Collection<? extends Serializable> idList, CopyOptions copyOptions) { + public List<V> listVoByIds(Collection<? extends Serializable> idList) { List<T> list = getBaseMapper().selectBatchIds(idList); if (list == null) { return null; } - return BeanCopyUtils.listCopy(list, copyOptions, voClass); + return BeanCopyUtils.copyList(list, voClass); } /** @@ -189,12 +189,12 @@ * @param columnMap 琛ㄥ瓧娈� map 瀵硅薄 */ @Override - public List<V> listVoByMap(Map<String, Object> columnMap, CopyOptions copyOptions) { + public List<V> listVoByMap(Map<String, Object> columnMap) { List<T> list = getBaseMapper().selectByMap(columnMap); if (list == null) { return null; } - return BeanCopyUtils.listCopy(list, copyOptions, voClass); + return BeanCopyUtils.copyList(list, voClass); } /** @@ -204,9 +204,9 @@ * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper} */ @Override - public V getVoOne(Wrapper<T> queryWrapper, CopyOptions copyOptions) { + public V getVoOne(Wrapper<T> queryWrapper) { T t = getOne(queryWrapper, true); - return BeanCopyUtils.oneCopy(t, copyOptions, voClass); + return BeanCopyUtils.copy(t, voClass); } /** @@ -215,12 +215,12 @@ * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper} */ @Override - public List<V> listVo(Wrapper<T> queryWrapper, CopyOptions copyOptions) { + public List<V> listVo(Wrapper<T> queryWrapper) { List<T> list = getBaseMapper().selectList(queryWrapper); if (list == null) { return null; } - return BeanCopyUtils.listCopy(list, copyOptions, voClass); + return BeanCopyUtils.copyList(list, voClass); } /** @@ -230,9 +230,9 @@ * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� */ @Override - public PagePlus<T, V> pageVo(PagePlus<T, V> page, Wrapper<T> queryWrapper, CopyOptions copyOptions) { + public PagePlus<T, V> pageVo(PagePlus<T, V> page, Wrapper<T> queryWrapper) { PagePlus<T, V> result = getBaseMapper().selectPage(page, queryWrapper); - List<V> volist = BeanCopyUtils.listCopy(result.getRecords(), copyOptions, voClass); + List<V> volist = BeanCopyUtils.copyList(result.getRecords(), voClass); result.setRecordsVo(volist); return result; } -- Gitblit v1.9.3