update ServicePlusImpl 功能 下沉到 BaseMapperPlus
This commit is contained in:
parent
5e38e054a7
commit
bd89cc0287
@ -1,9 +1,16 @@
|
|||||||
package com.ruoyi.common.core.mybatisplus.core;
|
package com.ruoyi.common.core.mybatisplus.core;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.ruoyi.common.utils.BeanCopyUtils;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义 Mapper 接口, 实现 自定义扩展
|
* 自定义 Mapper 接口, 实现 自定义扩展
|
||||||
@ -18,4 +25,63 @@ public interface BaseMapperPlus<T> extends BaseMapper<T> {
|
|||||||
*/
|
*/
|
||||||
int insertAll(@Param("list") Collection<T> batchList);
|
int insertAll(@Param("list") Collection<T> batchList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 ID 查询
|
||||||
|
*/
|
||||||
|
default <V> V selectVoById(Serializable id, Class<V> voClass){
|
||||||
|
T obj = this.selectById(id);
|
||||||
|
return BeanCopyUtils.copy(obj, voClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询(根据ID 批量查询)
|
||||||
|
*/
|
||||||
|
default <V> List<V> selectVoBatchIds(Collection<? extends Serializable> idList, Class<V> voClass){
|
||||||
|
List<T> list = this.selectBatchIds(idList);
|
||||||
|
if (list == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return BeanCopyUtils.copyList(list, voClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询(根据 columnMap 条件)
|
||||||
|
*/
|
||||||
|
default <V> List<V> selectVoByMap(Map<String, Object> map, Class<V> voClass){
|
||||||
|
List<T> list = this.selectByMap(map);
|
||||||
|
if (list == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return BeanCopyUtils.copyList(list, voClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 entity 条件,查询一条记录
|
||||||
|
*/
|
||||||
|
default <V> V selectVoOne(Wrapper<T> wrapper, Class<V> voClass) {
|
||||||
|
T obj = this.selectOne(wrapper);
|
||||||
|
return BeanCopyUtils.copy(obj, voClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 entity 条件,查询全部记录
|
||||||
|
*/
|
||||||
|
default <V> List<V> selectVoList(Wrapper<T> wrapper, Class<V> voClass) {
|
||||||
|
List<T> list = this.selectList(wrapper);
|
||||||
|
if (list == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return BeanCopyUtils.copyList(list, voClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询VO
|
||||||
|
*/
|
||||||
|
default <V> IPage<V> selectVoPage(IPage<T> page, Wrapper<T> wrapper, Class<V> voClass) {
|
||||||
|
IPage<T> pageData = this.selectPage(page, wrapper);
|
||||||
|
IPage<V> voPage = new Page<>(pageData.getCurrent(), pageData.getSize(), pageData.getTotal());
|
||||||
|
voPage.setRecords(BeanCopyUtils.copyList(pageData.getRecords(), voClass));
|
||||||
|
return voPage;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.ruoyi.common.core.mybatisplus.core;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||||
@ -160,74 +161,47 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T, V> extends ServiceI
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 ID 查询
|
* 根据 ID 查询
|
||||||
*
|
|
||||||
* @param id 主键ID
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public V getVoById(Serializable id) {
|
public V getVoById(Serializable id) {
|
||||||
T t = getBaseMapper().selectById(id);
|
return getBaseMapper().selectVoById(id, voClass);
|
||||||
return BeanCopyUtils.copy(t, voClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询(根据ID 批量查询)
|
* 查询(根据ID 批量查询)
|
||||||
*
|
|
||||||
* @param idList 主键ID列表
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<V> listVoByIds(Collection<? extends Serializable> idList) {
|
public List<V> listVoByIds(Collection<? extends Serializable> idList) {
|
||||||
List<T> list = getBaseMapper().selectBatchIds(idList);
|
return getBaseMapper().selectVoBatchIds(idList, voClass);
|
||||||
if (list == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return BeanCopyUtils.copyList(list, voClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询(根据 columnMap 条件)
|
* 查询(根据 columnMap 条件)
|
||||||
*
|
|
||||||
* @param columnMap 表字段 map 对象
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<V> listVoByMap(Map<String, Object> columnMap) {
|
public List<V> listVoByMap(Map<String, Object> columnMap) {
|
||||||
List<T> list = getBaseMapper().selectByMap(columnMap);
|
return getBaseMapper().selectVoByMap(columnMap, voClass);
|
||||||
if (list == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return BeanCopyUtils.copyList(list, voClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据 Wrapper,查询一条记录 <br/>
|
* 根据 Wrapper,查询一条记录 <br/>
|
||||||
* <p>结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")</p>
|
* <p>结果集,如果是多个会抛出异常,随机取一条加上限制条件 wrapper.last("LIMIT 1")</p>
|
||||||
*
|
|
||||||
* @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public V getVoOne(Wrapper<T> queryWrapper) {
|
public V getVoOne(Wrapper<T> queryWrapper) {
|
||||||
T t = getOne(queryWrapper, true);
|
return getBaseMapper().selectVoOne(queryWrapper, voClass);
|
||||||
return BeanCopyUtils.copy(t, voClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询列表
|
* 查询列表
|
||||||
*
|
|
||||||
* @param queryWrapper 实体对象封装操作类 {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<V> listVo(Wrapper<T> queryWrapper) {
|
public List<V> listVo(Wrapper<T> queryWrapper) {
|
||||||
List<T> list = getBaseMapper().selectList(queryWrapper);
|
return getBaseMapper().selectVoList(queryWrapper, voClass);
|
||||||
if (list == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return BeanCopyUtils.copyList(list, voClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 翻页查询
|
* 翻页查询
|
||||||
*
|
|
||||||
* @param page 翻页对象
|
|
||||||
* @param queryWrapper 实体对象封装操作类
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PagePlus<T, V> pageVo(PagePlus<T, V> page, Wrapper<T> queryWrapper) {
|
public PagePlus<T, V> pageVo(PagePlus<T, V> page, Wrapper<T> queryWrapper) {
|
||||||
@ -237,4 +211,14 @@ public class ServicePlusImpl<M extends BaseMapperPlus<T>, T, V> extends ServiceI
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 翻页查询
|
||||||
|
*
|
||||||
|
* @param page 翻页对象
|
||||||
|
* @param queryWrapper 实体对象封装操作类
|
||||||
|
*/
|
||||||
|
public IPage<V> pageVo(IPage<T> page, Wrapper<T> queryWrapper) {
|
||||||
|
return getBaseMapper().selectVoPage(page, queryWrapper, voClass);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user