@Override public Page<Order> findAll(String outTradeNo, String tradeNo, String mchAppid, String status, String payType, String startData, String endData, Pageable pageable) { Page<Order> pageList = orderDao.findAll((root,query,cb) -> { List<Predicate> list = new ArrayList<Predicate>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdfmat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); if (StringUtils.isNotEmpty(startData) && StringUtils.isNotEmpty(endData)) { try { list.add(cb.between(root.get("payTime"), LocalDateTime.parse(sdfmat.format(sdf.parse(startData)),df), LocalDateTime.parse(sdfmat.format(sdf.parse(endData).getTime()+86400000), df))); } catch (ParseException e) { e.printStackTrace(); } } if(outTradeNo!=null && outTradeNo!="") { list.add(cb.like(root.get("outTradeNo"), "%"+outTradeNo+"%")); } if(tradeNo!=null && tradeNo!="") { list.add(cb.like(root.get("tradeNo"), "%"+tradeNo+"%")); } if(mchAppid!=null && mchAppid!="") { list.add(cb.like(root.get("mchAppid"), "%"+mchAppid+"%")); } if(status!=null && status!="") { list.add(cb.equal(root.get("state"), status)); } if(payType!=null && payType!="") { list.add(cb.equal(root.get("payType"), payType)); } Predicate[] array = new Predicate[list.size()]; return cb.and(list.toArray(array)); }, pageable); return pageList; }
更多精彩文章欢迎关注公众号“Java之康庄大道”