提交 183e4872 authored 作者: hzh's avatar hzh

代码优化

上级 c1b02ad8
package org.dromara.common.mybatis.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ReflectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.dromara.common.core.utils.MapstructUtils;
......@@ -130,6 +132,18 @@ public abstract class AbstractBaseService<V, B, T> implements IBaseService<V, B,
return lqw;
}
@Override
public IPage<V> convertPage(IPage<T> page) {
List<T> list = page.getRecords();
// 创建一个新的VO对象分页列表,并设置分页信息
IPage<V> voPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
if (CollUtil.isEmpty(list)) {
return voPage;
}
voPage.setRecords(MapstructUtils.convert(list, (Class<V>) GenericsUtils.getSuperClassGenricType(this.getClass(), 0)));
return voPage;
}
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if (isValid) {
......
package org.dromara.common.mybatis.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.common.mybatis.core.page.OrderBy;
import org.dromara.common.mybatis.core.page.PageQuery;
......@@ -105,6 +106,13 @@ public interface IBaseService<V, B, T> {
*/
LambdaQueryWrapper<T> buildQueryWrapper(B bo);
/**
* 分页转化
* @param page page
* @return 分页
*/
IPage<V> convertPage(IPage<T> page);
/**
* 保存之前校验实体
*
......
......@@ -57,7 +57,20 @@ public class SysRoleServiceImpl implements ISysRoleService {
@Override
public TableDataInfo<SysRoleVo> selectPageRoleList(SysRoleBo role, PageQuery pageQuery) {
Page<SysRoleVo> page = baseMapper.selectPageRoleList(pageQuery.build(), this.buildQueryWrapper(role));
Object permission = role.getParams().getOrDefault("permission", true);
Page<SysRoleVo> page;
if (Boolean.TRUE.equals(Boolean.valueOf(permission.toString()))) {
page = baseMapper.selectPageRoleList(pageQuery.build(), this.buildQueryWrapper(role));
} else {
Page<SysRole> srPage = baseMapper.selectPage(pageQuery.build(), new LambdaQueryWrapper<SysRole>()
.eq(SysRole::getStatus, UserConstants.ROLE_NORMAL)
.eq(StringUtils.isNotBlank(role.getRoleKey()), SysRole::getRoleKey, role.getRoleKey())
.like(StringUtils.isNotBlank(role.getRoleName()), SysRole::getRoleName, role.getRoleName())
.orderByAsc(SysRole::getRoleSort)
.orderByAsc(SysRole::getCreateTime));
page = new Page<SysRoleVo>(srPage.getCurrent(), srPage.getSize(), srPage.getTotal())
.setRecords(BeanUtil.copyToList(srPage.getRecords(), SysRoleVo.class));
}
return TableDataInfo.build(page);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论