com.querydsl.core.types.Predicate Java Examples
The following examples show how to use
com.querydsl.core.types.Predicate.
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: ExchangeOrderService.java From ZTuoExchange_framework with MIT License | 6 votes |
@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 #2
Source File: QuerydslKeyValueRepository.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
@Override public Page<T> findAll(Predicate predicate, Pageable pageable) { AbstractCollQuery<T, ?> query = prepareQuery(predicate); if (pageable.isPaged() || pageable.getSort().isSorted()) { query.offset(pageable.getOffset()); query.limit(pageable.getPageSize()); if (pageable.getSort().isSorted()) { query.orderBy(toOrderSpecifier(pageable.getSort(), builder)); } } return new PageImpl<>(query.fetchResults().getResults(), pageable, count(predicate)); }
Example #3
Source File: MemberApplicationController.java From ZTuoExchange_framework with MIT License | 6 votes |
@RequiresPermissions("member:member-application:page-query") @PostMapping("page-query") @AccessLog(module = AdminModule.MEMBER, operation = "分页查找会员MemberApplication认证信息") public MessageResult queryPage(PageModel pageModel, MemberApplicationScreen screen) { List<BooleanExpression> booleanExpressions = new ArrayList<>(); if (screen.getAuditStatus() != null) { booleanExpressions.add(memberApplication.auditStatus.eq(screen.getAuditStatus())); } if (!StringUtils.isEmpty(screen.getAccount())) { booleanExpressions.add(memberApplication.member.username.like("%" + screen.getAccount() + "%") //.or(memberApplication.member.mobilePhone.like(screen.getAccount() + "%")) // .or(memberApplication.member.email.like(screen.getAccount() + "%")) .or(memberApplication.member.realName.like("%" + screen.getAccount() + "%"))); } if(!StringUtils.isEmpty(screen.getCardNo())) { booleanExpressions.add(memberApplication.member.idNumber.like("%" + screen.getCardNo() + "%")); } Predicate predicate = PredicateUtils.getPredicate(booleanExpressions); Page<MemberApplication> all = memberApplicationService.findAll(predicate, pageModel.getPageable()); return success(all); }
Example #4
Source File: MemberApplicationService.java From ZTuoExchange_framework with MIT License | 6 votes |
/** * 条件查询对象 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 #5
Source File: AnnouncementController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("system:announcement:page-query") @GetMapping("page-query") public MessageResult page( PageModel pageModel, @RequestParam(required = false) Boolean isShow) { //条件 ArrayList<BooleanExpression> booleanExpressions = new ArrayList<>(); if (isShow != null) { booleanExpressions.add(QAnnouncement.announcement.isShow.eq(isShow)); } Predicate predicate = PredicateUtils.getPredicate(booleanExpressions); Page<Announcement> all = announcementService.findAll(predicate, pageModel.getPageable()); return success(all); }
Example #6
Source File: AdvertiseController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("cms:system-advertise:out-excel") @GetMapping("/out-excel") @AccessLog(module = AdminModule.CMS, operation = "导出系统广告Excel") public MessageResult outExcel( @RequestParam(value = "serialNumber", required = false) String serialNumber, @RequestParam(value = "sysAdvertiseLocation", required = false) SysAdvertiseLocation sysAdvertiseLocation, @RequestParam(value = "status", required = false) CommonStatus status, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Predicate> predicateList = getPredicateList(serialNumber, sysAdvertiseLocation, status); List list = sysAdvertiseService.query(predicateList, null, null).getContent(); return new FileUtil().exportExcel(request, response, list, "sysAdvertise"); }
Example #7
Source File: AdminAdvertiseController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("otc:advertise:page-query") @PostMapping("page-query") @AccessLog(module = AdminModule.OTC, operation = "分页查找后台广告Advertise") public MessageResult page(PageModel pageModel, AdvertiseScreen screen) { Predicate predicate = getPredicate(screen); Page<Advertise> all = advertiseService.findAll(predicate, pageModel.getPageable()); return success(all); }
Example #8
Source File: SysHelpService.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 根据分类分页查询 * @param pageNo * @param pageSize * @param cate * @return */ public Page<SysHelp> findByCondition(int pageNo,int pageSize,SysHelpClassification cate){ Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "sort")); Pageable pageable = new PageRequest(pageNo - 1, pageSize, sort); Specification specification = new Specification() { List<javax.persistence.criteria.Predicate> predicates = new ArrayList<>(); @Override public javax.persistence.criteria.Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { predicates.add(criteriaBuilder.equal(root.get("sysHelpClassification"),cate)); return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[predicates.size()])); } }; return sysHelpDao.findAll(specification,pageable); }
Example #9
Source File: SysGroupController.java From SuperBoot with MIT License | 5 votes |
@ApiOperation(value = "获取组织信息", notes = "获取组织基本信息,系统管理员默认可以访问") @RequestMapping(value = "/", method = RequestMethod.GET) public BaseResponse<List<ResGroup>> getGroupList(@RequestParam(value = "page", defaultValue = "0") Integer page, @RequestParam(value = "size", defaultValue = "15") Integer size, @QuerydslPredicate(root = SuperbootGroup.class) Predicate predicate) throws BaseException { Pageable pageable = new PageRequest(page, size); return groupService.getGroupList(pageable, predicate); }
Example #10
Source File: AuthorRepository.java From library with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * @param filter * @return */ @Override default Predicate getQPredicate(String filter) { final QAuthor author = QAuthor.author; return author.name.likeIgnoreCase(this.likeAny(filter)) .or(author.email.likeIgnoreCase(this.likeAny(filter))); }
Example #11
Source File: BaseService.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 查询列表 * * @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: SystemUserService.java From radman with MIT License | 5 votes |
private Predicate buildSystemUserSearchPredicate(@Nullable String searchText) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(searchText)) { booleanBuilder.or(QSystemUser.systemUser.username.contains(searchText)); booleanBuilder.or(QSystemUser.systemUser.role.stringValue().contains(searchText)); } return booleanBuilder; }
Example #13
Source File: LegalWalletWithdrawController.java From ZTuoExchange_framework with MIT License | 5 votes |
private Predicate getPredicate(LegalWalletWithdrawScreen screen) { ArrayList<BooleanExpression> booleanExpressions = new ArrayList<>(); if (StringUtils.isNotBlank(screen.getUsername())) { booleanExpressions.add(QLegalWalletWithdraw.legalWalletWithdraw.member.username.eq(screen.getUsername())); } if (screen.getStatus() != null) { booleanExpressions.add(QLegalWalletWithdraw.legalWalletWithdraw.status.eq(screen.getStatus())); } if (StringUtils.isNotBlank(screen.getCoinName())) { booleanExpressions.add(QLegalWalletWithdraw.legalWalletWithdraw.coin.name.eq(screen.getCoinName())); } return PredicateUtils.getPredicate(booleanExpressions); }
Example #14
Source File: SysHelpService.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 根据分类分页查询 * @param pageNo * @param pageSize * @param cate * @return */ public Page<SysHelp> findByCondition(int pageNo,int pageSize,SysHelpClassification cate){ Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "sort")); Pageable pageable = new PageRequest(pageNo - 1, pageSize, sort); Specification specification = new Specification() { List<javax.persistence.criteria.Predicate> predicates = new ArrayList<>(); @Override public javax.persistence.criteria.Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { predicates.add(criteriaBuilder.equal(root.get("sysHelpClassification"),cate)); return criteriaBuilder.and(predicates.toArray(new javax.persistence.criteria.Predicate[predicates.size()])); } }; return sysHelpDao.findAll(specification,pageable); }
Example #15
Source File: UserRepository.java From SMSC with Apache License 2.0 | 5 votes |
@Override @EntityGraph(attributePaths = {"dashboards", "roles", "authorities", "groups", "salutation"}) @PreAuthorize("hasRole('POWER_ADMIN_USER') or (hasRole('ADMIN_USER') and hasAuthority('ADMIN_USER_READ'))") Iterable<User> findAll(Predicate predicate, Sort sort);
Example #16
Source File: MemberController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("member:page-query") @PostMapping("page-query") @ResponseBody @AccessLog(module = AdminModule.MEMBER, operation = "分页查找会员Member") public MessageResult page( PageModel pageModel, MemberScreen screen) { Predicate predicate = getPredicate(screen); Page<Member> all = memberService.findAll(predicate, pageModel.getPageable()); return success(all); }
Example #17
Source File: BusinessAuthController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("business:auth:deposit:page") @GetMapping("page") public MessageResult getAll(PageModel pageModel, CommonStatus status) { ArrayList<BooleanExpression> booleanExpressions = new ArrayList<>(); QBusinessAuthDeposit businessAuthDeposit = QBusinessAuthDeposit.businessAuthDeposit; if (status != null) { booleanExpressions.add(businessAuthDeposit.status.eq(status)); } Predicate predicate = PredicateUtils.getPredicate(booleanExpressions); Page<BusinessAuthDeposit> depositPage = businessAuthDepositService.findAll(predicate, pageModel); MessageResult result = MessageResult.success(); result.setData(depositPage); return result; }
Example #18
Source File: MenuServiceImpl.java From SuperBoot with MIT License | 5 votes |
@Override public BaseResponse getCount(long pkGroup, Predicate predicate) throws BaseException { QSuperbootMenu qSuperbootMenu = QSuperbootMenu.superbootMenu; long count; if (-1 == pkGroup) { count = getQueryFactory().select(qSuperbootMenu.pkMenu.count()).from(qSuperbootMenu) .where(qSuperbootMenu.menuType.in(0, 1).and(qSuperbootMenu.dr.eq(BaseConstants.DATA_STATUS_OK)).and(predicate)).fetchOne(); } else { //校验操作的组织是否是自己的组织 checkGroupIsMy(pkGroup); count = getQueryFactory().select(qSuperbootMenu.pkMenu.count()).from(qSuperbootMenu) .where(qSuperbootMenu.menuType.eq(1).and(qSuperbootMenu.dr.eq(BaseConstants.DATA_STATUS_OK)).and(predicate)).fetchOne(); } return new BaseResponse(new ResCount(count)); }
Example #19
Source File: BusinessAuthController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("business:auth:deposit:page") @GetMapping("page") public MessageResult getAll(PageModel pageModel, CommonStatus status) { ArrayList<BooleanExpression> booleanExpressions = new ArrayList<>(); QBusinessAuthDeposit businessAuthDeposit = QBusinessAuthDeposit.businessAuthDeposit; if (status != null) { booleanExpressions.add(businessAuthDeposit.status.eq(status)); } Predicate predicate = PredicateUtils.getPredicate(booleanExpressions); Page<BusinessAuthDeposit> depositPage = businessAuthDepositService.findAll(predicate, pageModel); MessageResult result = MessageResult.success(); result.setData(depositPage); return result; }
Example #20
Source File: QuerydslQueryBackend.java From katharsis-framework with Apache License 2.0 | 5 votes |
@Override public Predicate and(List<Predicate> predicates) { if (predicates.size() == 1) { return predicates.get(0); } else { // only two elements for each operation supported, needs querydsl fix? Predicate result = predicates.get(0); for (int i = 1; i < predicates.size(); i++) { result = new BooleanPredicateOperation(Ops.AND, (ImmutableList) ImmutableList.of(result, predicates.get(i))); } return result; } }
Example #21
Source File: QueryDslPredicates.java From spring4-sandbox with Apache License 2.0 | 5 votes |
public static Predicate inProgressConferences() { QConference conf = QConference.conference; final Date now = new Date(); BooleanBuilder builder = new BooleanBuilder(); return builder.and(conf.startedDate.before(now)) .and(conf.endedDate.after(now)).getValue(); }
Example #22
Source File: UserController.java From spring-data-examples with Apache License 2.0 | 5 votes |
@RequestMapping(value = "/", method = RequestMethod.GET) String index(Model model, // @QuerydslPredicate(root = User.class) Predicate predicate, // @PageableDefault(sort = { "lastname", "firstname" }) Pageable pageable, // @RequestParam MultiValueMap<String, String> parameters) { ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest(); builder.replaceQueryParam("page", new Object[0]); model.addAttribute("baseUri", builder.build().toUri()); model.addAttribute("users", repository.findAll(predicate, pageable)); return "index"; }
Example #23
Source File: ScreenAbility.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 获取条件(添加外部筛选) * * @param booleanExpressions 条件断言 * @return */ default Predicate getPredicate(BooleanExpression... booleanExpressions) { ArrayList<BooleanExpression> booleanExpressionsList = getBooleanExpressions(); for (BooleanExpression b : booleanExpressions) { booleanExpressionsList.add(b); } return PredicateUtils.getPredicate(booleanExpressionsList); }
Example #24
Source File: SysMenuController.java From SuperBoot with MIT License | 5 votes |
@ApiOperation(value = "获取全部菜单", notes = "获取全部菜单,系统管理员默认可以访问") @RequestMapping(value = "/", method = RequestMethod.GET) public BaseResponse<List<ResMenu>> getItems(@RequestParam(value = "page", defaultValue = "0") Integer page, @RequestParam(value = "size", defaultValue = "15") Integer size, @QuerydslPredicate(root = SuperbootMenu.class) Predicate predicate) throws BaseException { Pageable pageable = new PageRequest(page, size); return menuService.getMenus(-1, pageable, predicate); }
Example #25
Source File: LogServiceImpl.java From SuperBoot with MIT License | 5 votes |
@Override public BaseResponse getLogList(Pageable pageable, Predicate predicate) throws BaseException { Page<DataInfo> page = dataInfoDAO.findAll(predicate, pageable); List list = new ArrayList(); for (DataInfo dataInfo : page.getContent()) { ResLog resLog = new ResLog(); BeanUtils.copyProperties(dataInfo, resLog); //MongoDB主键为组合主键,此处需要进行处理 resLog.setId(dataInfo.getId().toString()); list.add(resLog); } return new BaseResponse(list); }
Example #26
Source File: DutiesServiceImpl.java From SuperBoot with MIT License | 5 votes |
@Override public BaseResponse<ResCount> getDutiesCount(long pkGroup, Predicate predicate) { QSuperbootDuties impDuties = QSuperbootDuties.superbootDuties; long count = getQueryFactory().select( impDuties.pkDuties.count() ).from(impDuties) .where( impDuties.dr.eq(BaseConstants.DATA_STATUS_OK) .and(impDuties.pkGroup.eq(pkGroup).and(predicate) ) ).fetchOne(); return new BaseResponse(new ResCount(count)); }
Example #27
Source File: SysUserController.java From SuperBoot with MIT License | 5 votes |
@ApiOperation(value = "获取用户信息", notes = "获取系统用户信息,系统管理员默认可以访问") @RequestMapping(value = "/", method = RequestMethod.GET) public BaseResponse<List<ResUser>> getUser(@RequestParam(value = "page", defaultValue = "0") Integer page, @RequestParam(value = "size", defaultValue = "15") Integer size, @QuerydslPredicate(root = SuperbootUser.class) Predicate user, @QuerydslPredicate(root = SuperbootRole.class) Predicate role, @QuerydslPredicate(root = SuperbootGroup.class) Predicate group) throws BaseException { Pageable pageable = new PageRequest(page, size); return userService.getUserList(pageable, false, user, role, group); }
Example #28
Source File: DashboardRepository.java From SMSC with Apache License 2.0 | 5 votes |
@Override @EntityGraph(attributePaths = {"dashboardBoxes"}) @PostAuthorize("hasRole('POWER_ADMIN_USER') or hasAuthority('DASHBOARD_READ')") Dashboard findOne(Predicate predicate);
Example #29
Source File: DividendController.java From ZTuoExchange_framework with MIT License | 5 votes |
@RequiresPermissions("system:dividend:page-query") @PostMapping("page-query") public MessageResult pageQuery( PageModel pageModel, @RequestParam(value = "unit", required = false) String unit) { Predicate predicate = null; if (!StringUtils.isEmpty(unit)) { predicate = QDividendStartRecord.dividendStartRecord.unit.eq(unit); } Page<DividendStartRecord> all = dividendStartRecordService.findAll(predicate, pageModel); return success(all); }
Example #30
Source File: OrderService.java From ZTuoExchange_framework with MIT License | 5 votes |
/** * 条件查询对象 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()); }