优化分页的实现,与 MyBatis Plus 解耦

pull/2/head
YunaiV 2021-01-23 18:35:41 +08:00
parent 1ecbe5aa61
commit aa38c0f9d1
18 changed files with 59 additions and 114 deletions

View File

@ -3,9 +3,7 @@ package cn.iocoder.dashboard.modules.system.convert.dept;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.*;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@ -21,9 +19,6 @@ public interface SysPostConvert {
SysPostRespVO convert(SysPostDO id);
@Mapping(source = "records", target = "list")
PageResult<SysPostDO> convertPage02(IPage<SysPostDO> page);
SysPostDO convert(SysPostCreateReqVO bean);
SysPostDO convert(SysPostUpdateReqVO reqVO);

View File

@ -3,9 +3,7 @@ package cn.iocoder.dashboard.modules.system.convert.dict;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.*;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@ -25,9 +23,6 @@ public interface SysDictDataConvert {
SysDictDataDO convert(SysDictDataCreateReqVO bean);
@Mapping(source = "records", target = "list")
PageResult<SysDictDataDO> convertPage02(IPage<SysDictDataDO> page);
List<SysDictDataExcelVO> convertList02(List<SysDictDataDO> bean);
}

View File

@ -3,9 +3,7 @@ package cn.iocoder.dashboard.modules.system.convert.dict;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.*;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@ -19,9 +17,6 @@ public interface SysDictTypeConvert {
SysDictTypeRespVO convert(SysDictTypeDO bean);
@Mapping(source = "records", target = "list")
PageResult<SysDictTypeDO> convertPage02(IPage<SysDictTypeDO> page);
SysDictTypeDO convert(SysDictTypeCreateReqVO bean);
SysDictTypeDO convert(SysDictTypeUpdateReqVO bean);

View File

@ -5,9 +5,7 @@ import cn.iocoder.dashboard.modules.system.controller.notice.vo.SysNoticeCreateR
import cn.iocoder.dashboard.modules.system.controller.notice.vo.SysNoticeRespVO;
import cn.iocoder.dashboard.modules.system.controller.notice.vo.SysNoticeUpdateReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.notice.SysNoticeDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
@ -23,7 +21,4 @@ public interface SysNoticeConvert {
SysNoticeDO convert(SysNoticeCreateReqVO bean);
@Mapping(source = "records", target = "list")
PageResult<SysNoticeDO> convertPage02(IPage<SysNoticeDO> page);
}

View File

@ -1,11 +1,8 @@
package cn.iocoder.dashboard.modules.system.convert.permission;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.*;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@ -19,9 +16,6 @@ public interface SysRoleConvert {
SysRoleRespVO convert(SysRoleDO bean);
@Mapping(source = "records", target = "list")
PageResult<SysRoleDO> convertPage(IPage<SysRoleDO> page);
SysRoleDO convert(SysRoleCreateReqVO bean);
List<SysRoleSimpleRespVO> convertList02(List<SysRoleDO> list);

View File

@ -1,12 +1,9 @@
package cn.iocoder.dashboard.modules.system.convert.user;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.*;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysDeptDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
@ -18,9 +15,6 @@ public interface SysUserConvert {
SysUserPageItemRespVO.Dept convert(SysDeptDO bean);
@Mapping(source = "records", target = "list")
PageResult<SysUserDO> convertPage(IPage<SysUserDO> page);
SysUserDO convert(SysUserCreateReqVO bean);
SysUserDO convert(SysUserUpdateReqVO bean);

View File

@ -1,30 +1,29 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dept;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.dept.vo.post.SysPostPageReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dept.SysPostDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
@Mapper
public interface SysPostMapper extends BaseMapper<SysPostDO> {
public interface SysPostMapper extends BaseMapperX<SysPostDO> {
default List<SysPostDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
return selectList(new QueryWrapperX<SysPostDO>().inIfPresent("id", ids)
.inIfPresent("status", statuses));
}
default IPage<SysPostDO> selectList(SysPostPageReqVO reqVO) {
return selectPage(MyBatisUtils.buildPage(reqVO),
new QueryWrapperX<SysPostDO>().likeIfPresent("name", reqVO.getName())
.eqIfPresent("status", reqVO.getStatus()));
default PageResult<SysPostDO> selectPage(SysPostPageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<SysPostDO>()
.likeIfPresent("name", reqVO.getName())
.eqIfPresent("status", reqVO.getStatus()));
}
default List<SysPostDO> selectList(SysPostExportReqVO reqVO) {

View File

@ -1,22 +1,19 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import java.util.Date;
import java.util.List;
import static com.baomidou.mybatisplus.core.metadata.OrderItem.asc;
@Mapper
public interface SysDictDataMapper extends BaseMapper<SysDictDataDO> {
public interface SysDictDataMapper extends BaseMapperX<SysDictDataDO> {
default SysDictDataDO selectByLabel(String label) {
return selectOne(new QueryWrapper<SysDictDataDO>().eq("label", label));
@ -26,12 +23,12 @@ public interface SysDictDataMapper extends BaseMapper<SysDictDataDO> {
return selectCount(new QueryWrapper<SysDictDataDO>().eq("dict_type", dictType));
}
default IPage<SysDictDataDO> selectList(SysDictDataPageReqVO reqVO) {
return selectPage(MyBatisUtils.buildPage(reqVO),
new QueryWrapperX<SysDictDataDO>().likeIfPresent("label", reqVO.getLabel())
.likeIfPresent("dict_type", reqVO.getDictType())
.eqIfPresent("status", reqVO.getStatus()))
.addOrder(asc("dict_type"), asc("sort"));
default PageResult<SysDictDataDO> selectPage(SysDictDataPageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<SysDictDataDO>()
.likeIfPresent("label", reqVO.getLabel())
.likeIfPresent("dict_type", reqVO.getDictType())
.eqIfPresent("status", reqVO.getStatus())
.orderByAsc("dict_type", "sort"));
}
default List<SysDictDataDO> selectList() {

View File

@ -1,26 +1,25 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.dict;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypeExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.dict.vo.type.SysDictTypePageReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SysDictTypeMapper extends BaseMapper<SysDictTypeDO> {
public interface SysDictTypeMapper extends BaseMapperX<SysDictTypeDO> {
default IPage<SysDictTypeDO> selectList(SysDictTypePageReqVO reqVO) {
return selectPage(MyBatisUtils.buildPage(reqVO),
new QueryWrapperX<SysDictTypeDO>().likeIfPresent("name", reqVO.getName())
.likeIfPresent("dict_type", reqVO.getType())
.eqIfPresent("status", reqVO.getStatus())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
default PageResult<SysDictTypeDO> selectPage(SysDictTypePageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<SysDictTypeDO>()
.likeIfPresent("name", reqVO.getName())
.likeIfPresent("dict_type", reqVO.getType())
.eqIfPresent("status", reqVO.getStatus())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
}
default List<SysDictTypeDO> selectList(SysDictTypeExportReqVO reqVO) {

View File

@ -1,20 +1,19 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.notice;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.dashboard.modules.system.controller.notice.vo.SysNoticePageReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.notice.SysNoticeDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SysNoticeMapper extends BaseMapper<SysNoticeDO> {
public interface SysNoticeMapper extends BaseMapperX<SysNoticeDO> {
default IPage<SysNoticeDO> selectList(SysNoticePageReqVO reqVO) {
return selectPage(MyBatisUtils.buildPage(reqVO),
new QueryWrapperX<SysNoticeDO>().likeIfPresent("title", reqVO.getTitle())
.eqIfPresent("status", reqVO.getStatus()));
default PageResult<SysNoticeDO> selectPage(SysNoticePageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<SysNoticeDO>()
.likeIfPresent("title", reqVO.getTitle())
.eqIfPresent("status", reqVO.getStatus()));
}
}

View File

@ -1,13 +1,12 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRoleExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.role.SysRolePageReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;
@ -18,12 +17,11 @@ import java.util.List;
@Mapper
public interface SysRoleMapper extends BaseMapperX<SysRoleDO> {
default IPage<SysRoleDO> selectPage(SysRolePageReqVO reqVO) {
return selectPage(MyBatisUtils.buildPage(reqVO),
new QueryWrapperX<SysRoleDO>().likeIfPresent("name", reqVO.getName())
.likeIfPresent("code", reqVO.getCode())
.eqIfPresent("status", reqVO.getStatus())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
default PageResult<SysRoleDO> selectPage(SysRolePageReqVO reqVO) {
return selectPage(reqVO, new QueryWrapperX<SysRoleDO>().likeIfPresent("name", reqVO.getName())
.likeIfPresent("code", reqVO.getCode())
.eqIfPresent("status", reqVO.getStatus())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
}
default List<SysRoleDO> listRoles(SysRoleExportReqVO reqVO) {

View File

@ -1,20 +1,19 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.user;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserPageReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
@Mapper
public interface SysUserMapper extends BaseMapper<SysUserDO> {
public interface SysUserMapper extends BaseMapperX<SysUserDO> {
default SysUserDO selectByUsername(String username) {
return selectOne(new QueryWrapper<SysUserDO>().eq("username", username));
@ -28,13 +27,13 @@ public interface SysUserMapper extends BaseMapper<SysUserDO> {
return selectOne(new QueryWrapper<SysUserDO>().eq("email", email));
}
default IPage<SysUserDO> selectList(SysUserPageReqVO reqVO, Collection<Long> deptIds) {
return selectPage(MyBatisUtils.buildPage(reqVO),
new QueryWrapperX<SysUserDO>().likeIfPresent("username", reqVO.getUsername())
.likeIfPresent("mobile", reqVO.getMobile())
.eqIfPresent("status", reqVO.getStatus())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())
.inIfPresent("dept_id", deptIds));
default PageResult<SysUserDO> selectPage(SysUserPageReqVO reqVO, Collection<Long> deptIds) {
return selectPage(reqVO, new QueryWrapperX<SysUserDO>()
.likeIfPresent("username", reqVO.getUsername())
.likeIfPresent("mobile", reqVO.getMobile())
.eqIfPresent("status", reqVO.getStatus())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime())
.inIfPresent("dept_id", deptIds));
}
default List<SysUserDO> selectList(SysUserExportReqVO reqVO, Collection<Long> deptIds) {

View File

@ -36,7 +36,7 @@ public class SysPostServiceImpl implements SysPostService {
@Override
public PageResult<SysPostDO> pagePosts(SysPostPageReqVO reqVO) {
return SysPostConvert.INSTANCE.convertPage02(postMapper.selectList(reqVO));
return postMapper.selectPage(reqVO);
}
@Override

View File

@ -138,7 +138,7 @@ public class SysDictDataServiceImpl implements SysDictDataService {
@Override
public PageResult<SysDictDataDO> pageDictDatas(SysDictDataPageReqVO reqVO) {
return SysDictDataConvert.INSTANCE.convertPage02(dictDataMapper.selectList(reqVO));
return dictDataMapper.selectPage(reqVO);
}
@Override

View File

@ -12,10 +12,8 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictType
import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService;
import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
@ -28,8 +26,6 @@ import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
@Service
public class SysDictTypeServiceImpl implements SysDictTypeService {
@Resource
private SysDictTypeServiceImpl self;
@Resource
private SysDictDataService dictDataService;
@ -38,7 +34,7 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
@Override
public PageResult<SysDictTypeDO> pageDictTypes(SysDictTypePageReqVO reqVO) {
return SysDictTypeConvert.INSTANCE.convertPage02(dictTypeMapper.selectList(reqVO));
return dictTypeMapper.selectPage(reqVO);
}
@Override
@ -77,18 +73,6 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
@Override
public void deleteDictType(Long id) {
// 执行删除
self.deleteDictType0(id);
// TODO 发送 MQ 消息
}
@Override
public List<SysDictTypeDO> listDictTypes() {
return dictTypeMapper.selectList();
}
@Transactional
public void deleteDictType0(Long id) {
// 校验是否存在
SysDictTypeDO dictType = this.checkDictTypeExists(id);
// 校验是否有字典数据
@ -99,6 +83,11 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
dictTypeMapper.deleteById(id);
}
@Override
public List<SysDictTypeDO> listDictTypes() {
return dictTypeMapper.selectList();
}
private void checkCreateOrUpdate(Long id, String name, String type) {
// 校验自己存在
checkDictTypeExists(id);

View File

@ -28,7 +28,7 @@ public class SysNoticeServiceImpl implements SysNoticeService {
@Override
public PageResult<SysNoticeDO> pageNotices(SysNoticePageReqVO reqVO) {
return SysNoticeConvert.INSTANCE.convertPage02(noticeMapper.selectList(reqVO));
return noticeMapper.selectPage(reqVO);
}
@Override

View File

@ -18,7 +18,6 @@ import cn.iocoder.dashboard.modules.system.enums.permission.SysRoleTypeEnum;
import cn.iocoder.dashboard.modules.system.mq.producer.permission.SysRoleProducer;
import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService;
import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
@ -201,8 +200,7 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public PageResult<SysRoleDO> pageRole(SysRolePageReqVO reqVO) {
IPage<SysRoleDO> roleDOPage = roleMapper.selectPage(reqVO);
return SysRoleConvert.INSTANCE.convertPage(roleDOPage);
return roleMapper.selectPage(reqVO);
}
@Override

View File

@ -74,8 +74,7 @@ public class SysUserServiceImpl implements SysUserService {
@Override
public PageResult<SysUserDO> pageUsers(SysUserPageReqVO reqVO) {
return SysUserConvert.INSTANCE.convertPage(userMapper.selectList(reqVO,
this.getDeptCondition(reqVO.getDeptId())));
return userMapper.selectPage(reqVO, this.getDeptCondition(reqVO.getDeptId()));
}
@Override