Java Code Examples for com.querydsl.jpa.impl.JPAQuery#fetchCount()

The following examples show how to use com.querydsl.jpa.impl.JPAQuery#fetchCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseService.java    From ZTuoExchange_framework with MIT License 7 votes vote down vote up
/**
 * @param expressions        查询列表
 * @param entityPaths        查询表
 * @param predicates         条件
 * @param orderSpecifierList 排序
 * @param pageNo             页码
 * @param pageSize           页面大小
 */
@Transactional(readOnly = true)
public PageListMapResult queryDslForPageListResult(
        List<Expression> expressions,
        List<EntityPath> entityPaths,
        List<Predicate> predicates,
        List<OrderSpecifier> orderSpecifierList,
        Integer pageNo,
        Integer pageSize) {
    JPAQuery<Tuple> jpaQuery = queryFactory.select(expressions.toArray(new Expression[expressions.size()]))
            .from(entityPaths.toArray(new EntityPath[entityPaths.size()]))
            .where(predicates.toArray(new Predicate[predicates.size()]));
    List<Tuple> tuples = jpaQuery.orderBy(orderSpecifierList.toArray(new OrderSpecifier[orderSpecifierList.size()]))
            .offset((pageNo - 1) * pageSize).limit(pageSize)
            .fetch();
    List<Map<String, Object>> list = new LinkedList<>();//返回结果
    //封装结果
    for (int i = 0; i < tuples.size(); i++) {
        //遍历tuples
        Map<String, Object> map = new LinkedHashMap<>();//一条信息
        for (Expression expression : expressions) {
            map.put(expression.toString().split(" as ")[1],//别名作为Key
                    tuples.get(i).get(expression));//获取结果
        }
        list.add(map);
    }
    PageListMapResult pageListMapResult = new PageListMapResult(list, pageNo, pageSize, jpaQuery.fetchCount());//分页封装
    return pageListMapResult;
}
 
Example 2
Source File: OrderService.java    From ZTuoExchange_framework with MIT License 7 votes vote down vote up
public Page<OtcOrderVO> outExcel(List<Predicate> predicates , PageModel pageModel){
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers();
    JPAQuery<OtcOrderVO> query = queryFactory.select(
            Projections.fields(OtcOrderVO.class,
                    QOrder.order.id.as("id"),
                    QOrder.order.orderSn.as("orderSn"),
                    QOrder.order.advertiseType.as("advertiseType"),
                    QOrder.order.createTime.as("createTime"),
                    QOrder.order.memberName.as("memberName"),
                    QOrder.order.customerName.as("customerName"),
                    QOrder.order.coin.unit,
                    QOrder.order.money,
                    QOrder.order.number,
                    QOrder.order.commission.as("fee"),
                    QOrder.order.payMode.as("payMode"),
                    QOrder.order.releaseTime.as("releaseTime"),
                    QOrder.order.cancelTime.as("cancelTime"),
                    QOrder.order.payTime.as("payTime"),
                    QOrder.order.status.as("status"))
    ).from(QOrder.order).where(predicates.toArray(new BooleanExpression[predicates.size()]));
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    List<OtcOrderVO> list = query.offset((pageModel.getPageNo()-1)*pageModel.getPageSize()).limit(pageModel.getPageSize()).fetch();
    long total = query.fetchCount() ;
    return new PageImpl<>(list,pageModel.getPageable(),total);
}
 
Example 3
Source File: MemberApplicationService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param predicateList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<MemberApplication> query(List<Predicate> predicateList, Integer pageNo, Integer pageSize) {
    List<MemberApplication> list;
    JPAQuery<MemberApplication> jpaQuery = queryFactory.selectFrom(memberApplication);
    if (predicateList != null) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    jpaQuery.orderBy(memberApplication.createTime.desc());
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 4
Source File: AdminAccessLogService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
public Page<AdminAccessLog> page(List<BooleanExpression> predicates, PageModel pageModel){
    JPAQuery<AdminAccessLog>  query = queryFactory.select(
            Projections.fields(AdminAccessLog.class,
                    QAdminAccessLog.adminAccessLog.id.as("id"),
                    QAdminAccessLog.adminAccessLog.accessIp.as("accessIp"),
                    QAdminAccessLog.adminAccessLog.accessMethod.as("accessMethod"),
                    QAdminAccessLog.adminAccessLog.accessTime.as("accessTime"),
                    QAdminAccessLog.adminAccessLog.adminId.as("adminId"),
                    QAdminAccessLog.adminAccessLog.uri.as("uri"),
                    QAdminAccessLog.adminAccessLog.module.as("module"),
                    QAdminAccessLog.adminAccessLog.operation.as("operation"),
                    QAdmin.admin.username.as("adminName"))
    ).from(QAdminAccessLog.adminAccessLog,QAdmin.admin).where(predicates.toArray(new BooleanExpression[predicates.size()])) ;
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers() ;
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    long total = query.fetchCount() ;
    query.offset(pageModel.getPageSize()*(pageModel.getPageNo()-1)).limit(pageModel.getPageSize());
    List<AdminAccessLog> list = query.fetch() ;
    return new PageImpl<AdminAccessLog>(list,pageModel.getPageable(),total);
}
 
Example 5
Source File: BaseService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 查询列表
 *
 * @param pageNo             分页参数
 * @param pageSize           分页大小
 * @param predicateList      查询条件
 * @param entityPathBase     查询表
 * @param orderSpecifierList 排序条件
 * @return
 */
@Transactional(readOnly = true)
public PageResult<T> queryDsl(Integer pageNo, Integer pageSize, List<Predicate> predicateList, EntityPathBase<T> entityPathBase, List<OrderSpecifier> orderSpecifierList) {
    List<T> list;
    //查询表
    JPAQuery<T> jpaQuery = queryFactory.selectFrom(entityPathBase);
    //查询条件
    if (predicateList != null && predicateList.size() > 0) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    //排序方式
    if (orderSpecifierList != null && orderSpecifierList.size() > 0) {
        jpaQuery.orderBy(orderSpecifierList.toArray(new OrderSpecifier[orderSpecifierList.size()]));
    }
    //分页查询
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, pageNo, pageSize, jpaQuery.fetchCount());
}
 
Example 6
Source File: SysAdvertiseService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param predicateList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<SysAdvertise> query(List<Predicate> predicateList, Integer pageNo, Integer pageSize) {
    List<SysAdvertise> list;
    JPAQuery<SysAdvertise> jpaQuery = queryFactory.selectFrom(sysAdvertise);
    if (predicateList != null) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.orderBy(new OrderSpecifier<>(Order.DESC, sysAdvertise.createTime))
                .offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.orderBy(new OrderSpecifier<>(Order.DESC, sysAdvertise.createTime)).fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 7
Source File: ExchangeOrderService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@Transactional(readOnly = true)
public PageResult<ExchangeOrder> queryWhereOrPage(List<Predicate> predicates, Integer pageNo, Integer pageSize) {
    List<ExchangeOrder> list;
    JPAQuery<ExchangeOrder> jpaQuery = queryFactory.selectFrom(QExchangeOrder.exchangeOrder);
    if (predicates != null) {
        jpaQuery.where(predicates.toArray(new BooleanExpression[predicates.size()]));
    }
    jpaQuery.orderBy(QExchangeOrder.exchangeOrder.time.desc());
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    PageResult<ExchangeOrder> result = new PageResult<>(list, jpaQuery.fetchCount());
    result.setNumber(pageNo);
    result.setSize(pageSize);
    return result;
}
 
Example 8
Source File: MemberWalletService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<MemberWalletDTO> joinFind(List<Predicate> predicates,QMember qMember ,QMemberWallet qMemberWallet,PageModel pageModel) {
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers();
    predicates.add(qMember.id.eq(qMemberWallet.memberId));
    JPAQuery<MemberWalletDTO> query = queryFactory.select(
                    Projections.fields(MemberWalletDTO.class, qMemberWallet.id.as("id"),qMemberWallet.memberId.as("memberId") ,qMember.username,qMember.realName.as("realName"),
                    qMember.email,qMember.mobilePhone.as("mobilePhone"),qMemberWallet.balance,qMemberWallet.address,qMemberWallet.coin.unit
                    ,qMemberWallet.frozenBalance.as("frozenBalance"),qMemberWallet.balance.add(qMemberWallet.frozenBalance).as("allBalance"))).from(QMember.member,QMemberWallet.memberWallet).where(predicates.toArray(new Predicate[predicates.size()]))
                    .orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    List<MemberWalletDTO> content = query.offset((pageModel.getPageNo()-1)*pageModel.getPageSize()).limit(pageModel.getPageSize()).fetch();
    long total = query.fetchCount();
    return new PageImpl<>(content, pageModel.getPageable(), total);
}
 
Example 9
Source File: CoinService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<Coin> query(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    List<Coin> list;
    JPAQuery<Coin> jpaQuery = queryFactory.selectFrom(QCoin.coin);
    if (booleanExpressionList != null) {
        jpaQuery.where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());//添加总条数
}
 
Example 10
Source File: CoinService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<Coin> query(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    List<Coin> list;
    JPAQuery<Coin> jpaQuery = queryFactory.selectFrom(QCoin.coin);
    if (booleanExpressionList != null) {
        jpaQuery.where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());//添加总条数
}
 
Example 11
Source File: BaseService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 查询列表
 *
 * @param pageNo             分页参数
 * @param pageSize           分页大小
 * @param predicateList      查询条件
 * @param entityPathBase     查询表
 * @param orderSpecifierList 排序条件
 * @return
 */
@Transactional(readOnly = true)
public PageResult<T> queryDsl(Integer pageNo, Integer pageSize, List<Predicate> predicateList, EntityPathBase<T> entityPathBase, List<OrderSpecifier> orderSpecifierList) {
    List<T> list;
    //查询表
    JPAQuery<T> jpaQuery = queryFactory.selectFrom(entityPathBase);
    //查询条件
    if (predicateList != null && predicateList.size() > 0) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    //排序方式
    if (orderSpecifierList != null && orderSpecifierList.size() > 0) {
        jpaQuery.orderBy(orderSpecifierList.toArray(new OrderSpecifier[orderSpecifierList.size()]));
    }
    //分页查询
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, pageNo, pageSize, jpaQuery.fetchCount());
}
 
Example 12
Source File: OrderService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param predicateList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<Order> query(List<Predicate> predicateList, Integer pageNo, Integer pageSize) {
    List<Order> list;
    JPAQuery<Order> jpaQuery = queryFactory.selectFrom(QOrder.order);
    if (predicateList != null) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 13
Source File: WithdrawRecordService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象
 *
 * @param predicateList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<WithdrawRecord> query(List<Predicate> predicateList, Integer pageNo, Integer pageSize) {
    List<WithdrawRecord> list;
    JPAQuery<WithdrawRecord> jpaQuery = queryFactory.selectFrom(withdrawRecord);
    if (predicateList != null) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 14
Source File: AdminAccessLogService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<AdminAccessLog> page(List<BooleanExpression> predicates, PageModel pageModel){
    JPAQuery<AdminAccessLog>  query = queryFactory.select(
            Projections.fields(AdminAccessLog.class,
                    QAdminAccessLog.adminAccessLog.id.as("id"),
                    QAdminAccessLog.adminAccessLog.accessIp.as("accessIp"),
                    QAdminAccessLog.adminAccessLog.accessMethod.as("accessMethod"),
                    QAdminAccessLog.adminAccessLog.accessTime.as("accessTime"),
                    QAdminAccessLog.adminAccessLog.adminId.as("adminId"),
                    QAdminAccessLog.adminAccessLog.uri.as("uri"),
                    QAdminAccessLog.adminAccessLog.module.as("module"),
                    QAdminAccessLog.adminAccessLog.operation.as("operation"),
                    QAdmin.admin.username.as("adminName"))
    ).from(QAdminAccessLog.adminAccessLog,QAdmin.admin).where(predicates.toArray(new BooleanExpression[predicates.size()])) ;
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers() ;
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    long total = query.fetchCount() ;
    query.offset(pageModel.getPageSize()*(pageModel.getPageNo()-1)).limit(pageModel.getPageSize());
    List<AdminAccessLog> list = query.fetch() ;
    return new PageImpl<AdminAccessLog>(list,pageModel.getPageable(),total);
}
 
Example 15
Source File: AdminAccessLogService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
@Transactional(readOnly = true)
public PageResult<AdminAccessLog> query(List<Predicate> predicateList, Integer pageNo, Integer pageSize) {
    List<AdminAccessLog> list;
    JPAQuery<AdminAccessLog> jpaQuery = queryFactory.selectFrom(QAdminAccessLog.adminAccessLog);
    if (predicateList != null && predicateList.size() > 0) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());//添加总条数
}
 
Example 16
Source File: AdvertiseService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<Advertise> queryWhereOrPage(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    List<Advertise> list;
    JPAQuery<Advertise> jpaQuery = queryFactory.selectFrom(advertise);
    if (booleanExpressionList != null) {
        jpaQuery.where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 17
Source File: AdminAccessLogService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
@Transactional(readOnly = true)
public PageResult<AdminAccessLog> query(List<Predicate> predicateList, Integer pageNo, Integer pageSize) {
    List<AdminAccessLog> list;
    JPAQuery<AdminAccessLog> jpaQuery = queryFactory.selectFrom(QAdminAccessLog.adminAccessLog);
    if (predicateList != null && predicateList.size() > 0) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());//添加总条数
}
 
Example 18
Source File: MemberTransactionService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<MemberTransactionVO> joinFind(List<Predicate> predicates, PageModel pageModel){
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers() ;
    JPAQuery<MemberTransactionVO> query = queryFactory.select(Projections.fields(MemberTransactionVO.class,
            QMemberTransaction.memberTransaction.address,
            QMemberTransaction.memberTransaction.amount,
            QMemberTransaction.memberTransaction.createTime.as("createTime"),
            QMemberTransaction.memberTransaction.fee,
            QMemberTransaction.memberTransaction.flag,
            QMemberTransaction.memberTransaction.id.as("id"),
            QMemberTransaction.memberTransaction.symbol,
            QMemberTransaction.memberTransaction.type,
            QMember.member.username.as("memberUsername"),
            QMember.member.mobilePhone.as("phone"),
            QMember.member.email,
            QMember.member.realName.as("memberRealName"),
            QMember.member.id.as("memberId")))
            .from(QMemberTransaction.memberTransaction, QMember.member);
    predicates.add(QMemberTransaction.memberTransaction.memberId.eq(QMember.member.id));
            query.where(predicates.toArray(new BooleanExpression[predicates.size()]));
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    List<MemberTransactionVO> list = query.offset((pageModel.getPageNo()-1)*pageModel.getPageSize()).limit(pageModel.getPageSize()).fetch();
    long total = query.fetchCount();
    return new PageImpl<>(list, pageModel.getPageable(), total);
}
 
Example 19
Source File: MemberTransactionService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<MemberTransaction> queryWhereOrPage(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    List<MemberTransaction> list;
    JPAQuery<MemberTransaction> jpaQuery = queryFactory.selectFrom(QMemberTransaction.memberTransaction);
    if (booleanExpressionList != null) {
        jpaQuery.where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    }
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 20
Source File: OrderFinder.java    From jeeshop with Apache License 2.0 4 votes vote down vote up
public Long countAll(String searchCriteria, OrderStatus status, Long skuId) {
    JPAQuery<Order> query = new JPAQueryFactory(entityManager).selectFrom(order)
            .where(matchesSearchAndStatusAndItemsSkuId(searchCriteria, status, skuId));
    return query.fetchCount();
}