public Page<OrderInfo> searchOrderDetail(final OrderInfo orderInfo, final Date start, final Date end, final int page, final int size) {
return orderInfoRepository.findAll(new Specification<OrderInfo>() {
public Predicate toPredicate(Root<OrderInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<Predicate>();
if (null != orderInfo) {
try {
// /**
// * 去掉售卡订单数据
// */
// predicates.add(cb.notEqual(root.<String>get("orderType"), "TYP_CARD"));
if (!StringUtils.isEmpty(orderInfo.getOrderDetail().getProductName())) {// 这里也可以root.get("name").as(String.class)这种方式来强转泛型类型
predicates.add(cb.like(root.<OrderDetail>get("orderDetail").get("productName"), "%" + orderInfo.getOrderDetail().getProductName() + "%"));
}
if (!StringUtils.isEmpty(orderInfo.getOrderDetail().getShopInfo().getShopName())) {// 这里也可以root.get("name").as(String.class)这种方式来强转泛型类型
predicates.add(cb.like(root.<OrderDetail>get("orderDetail").<ShopInfo>get("shopInfo").get("shopName")
, "%" + orderInfo.getOrderDetail().getShopInfo().getShopName() + "%"));
}
if (!StringUtils.isEmpty(orderInfo.getOrderUid())) {
predicates.add(cb.like(root.get("orderUid"), "%" + orderInfo.getOrderUid() + "%"));
}
if (!StringUtils.isEmpty(orderInfo.getOrderState())) {
predicates.add(cb.equal(root.<String>get("orderState"), orderInfo.getOrderState()));
}
predicates.add(cb.equal(root.get("mallUid"), orderInfo.getMallUid()));
predicates.add(cb.equal(root.get("promotionUid"), orderInfo.getPromotionUid()));
//TODO 是否有用?待删除
if (!StringUtils.isEmpty(orderInfo.getOrderDetail().getSubPromotionUid())) {
predicates.add(cb.equal(root.<OrderDetail>get("orderDetail").get("subPromotionUid"), orderInfo.getOrderDetail().getSubPromotionUid()));
}
} catch (Exception e) {
logger.error("error in searchOrderDetail, 动态sql查询错误", e);
}
}
predicates.add(cb.between(root.get("orderAt"), start, end));
Predicate[] p = new Predicate[predicates.size()];
query.where(cb.and(predicates.toArray(p)));
return null;
}
}, new PageRequest(page, size));
}
网友评论