Search in sources :

Example 1 with PageResult

use of cn.hutool.db.PageResult in project Jpom by dromara.

the class BaseDbCommonService method listPage.

/**
 * 分页查询
 *
 * @param where 条件
 * @param page  分页
 * @return 结果
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public PageResultDto<T> listPage(Entity where, Page page) {
    if (!DbConfig.getInstance().isInit()) {
        // ignore
        log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
        return PageResultDto.EMPTY;
    }
    where.setTableName(getTableName());
    PageResult<Entity> pageResult;
    Db db = Db.use();
    db.setWrapper((Character) null);
    try {
        pageResult = db.page(where, page);
    } catch (Exception e) {
        throw warpException(e);
    }
    // 
    List<T> list = pageResult.stream().map(entity -> {
        T entityToBean = this.entityToBean(entity, this.tClass);
        this.fillSelectResult(entityToBean);
        return entityToBean;
    }).collect(Collectors.toList());
    PageResultDto<T> pageResultDto = new PageResultDto(pageResult);
    pageResultDto.setResult(list);
    if (pageResultDto.isEmpty() && pageResultDto.getPage() > 1) {
        Assert.state(pageResultDto.getTotal() <= 0, "筛选的分页有问题,当前页码查询不到任何数据");
    }
    return pageResultDto;
}
Also used : PageResultDto(io.jpom.model.PageResultDto) PageResult(cn.hutool.db.PageResult) ExceptionUtil(cn.hutool.core.exceptions.ExceptionUtil) JdbcSQLNonTransientException(org.h2.jdbc.JdbcSQLNonTransientException) BeanUtil(cn.hutool.core.bean.BeanUtil) Page(cn.hutool.db.Page) Order(cn.hutool.db.sql.Order) JpomRuntimeException(io.jpom.system.JpomRuntimeException) LinkedHashMap(java.util.LinkedHashMap) TypeUtil(cn.hutool.core.util.TypeUtil) Map(java.util.Map) PageUtil(cn.hutool.core.util.PageUtil) DbConfig(io.jpom.system.db.DbConfig) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Db(cn.hutool.db.Db) Consumer(java.util.function.Consumer) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Condition(cn.hutool.db.sql.Condition) CopyOptions(cn.hutool.core.bean.copier.CopyOptions) Entity(cn.hutool.db.Entity) Assert(org.springframework.util.Assert) Entity(cn.hutool.db.Entity) Db(cn.hutool.db.Db) JdbcSQLNonTransientException(org.h2.jdbc.JdbcSQLNonTransientException) JpomRuntimeException(io.jpom.system.JpomRuntimeException) PageResultDto(io.jpom.model.PageResultDto)

Aggregations

BeanUtil (cn.hutool.core.bean.BeanUtil)1 CopyOptions (cn.hutool.core.bean.copier.CopyOptions)1 CollUtil (cn.hutool.core.collection.CollUtil)1 ExceptionUtil (cn.hutool.core.exceptions.ExceptionUtil)1 PageUtil (cn.hutool.core.util.PageUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 TypeUtil (cn.hutool.core.util.TypeUtil)1 Db (cn.hutool.db.Db)1 Entity (cn.hutool.db.Entity)1 Page (cn.hutool.db.Page)1 PageResult (cn.hutool.db.PageResult)1 Condition (cn.hutool.db.sql.Condition)1 Order (cn.hutool.db.sql.Order)1 PageResultDto (io.jpom.model.PageResultDto)1 JpomRuntimeException (io.jpom.system.JpomRuntimeException)1 DbConfig (io.jpom.system.db.DbConfig)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1