Merge branch 'refs/heads/gyj' into dev
This commit is contained in:
commit
cf1f5c8688
|
|
@ -16,6 +16,7 @@
|
|||
package cn.ysk.cashier.controller.order;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
|
||||
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
|
||||
|
|
@ -55,6 +56,7 @@ public class TbOrderInfoController {
|
|||
|
||||
@PostMapping("/date")
|
||||
@ApiOperation("查询订单")
|
||||
@AnonymousPostMapping
|
||||
public ResponseEntity<Object> queryTbOrderInfo(@RequestBody TbOrderInfoQueryCriteria criteria){
|
||||
return new ResponseEntity<>(tbOrderInfoService.queryAllPage(criteria),HttpStatus.OK);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,4 +72,6 @@ public class TbOrderInfoQueryCriteria{
|
|||
|
||||
@Query
|
||||
private String tableName;
|
||||
|
||||
private String productName;
|
||||
}
|
||||
|
|
@ -136,4 +136,13 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
|
|||
"\t) AS total ", nativeQuery = true)
|
||||
Tuple searchCount(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query(value = "SELECT d.order_id \n" +
|
||||
" FROM tb_order_detail d \n" +
|
||||
" WHERE d.product_name LIKE %:productName% \n" +
|
||||
" AND d.shop_id = :shopId \n" +
|
||||
" AND d.create_time BETWEEN :startTime AND :endTime \n" +
|
||||
" GROUP BY d.order_id", nativeQuery = true)
|
||||
List<Integer> findOrderIdsByProductNameLike(@Param("productName") String productName, @Param("shop_id") String shopId,
|
||||
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
package cn.ysk.cashier.service.impl.order;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
|
||||
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mapper.order.TbOrderInfoMapper;
|
||||
import cn.ysk.cashier.mapper.product.TbProductMapper;
|
||||
import cn.ysk.cashier.mapper.product.TbProductSkuMapper;
|
||||
|
|
@ -96,6 +98,36 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
if (StringUtils.isBlank(criteria.getStatus()) && StringUtils.isBlank(criteria.getSource())) {
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.notEqual(root.get("orderType"), "return"));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(criteria.getProductName())) {
|
||||
Date startTime, endTime;
|
||||
DateTime offsetMonth = cn.hutool.core.date.DateUtil.offsetMonth(new Date(), 3);
|
||||
if (criteria.getCreatedAt() != null && criteria.getCreatedAt().size() == 2) {
|
||||
Long startLong = criteria.getCreatedAt().get(0);
|
||||
Long endLong = criteria.getCreatedAt().get(1);
|
||||
|
||||
startTime = new Date(startLong);
|
||||
endTime = new Date(endLong);
|
||||
|
||||
// 如果开始时间小于三个月前,不查询
|
||||
if (startTime.before(offsetMonth)) {
|
||||
throw new BadRequestException("查询时间范围不能超过三个月");
|
||||
}
|
||||
} else {
|
||||
startTime = offsetMonth;
|
||||
endTime = new Date();
|
||||
}
|
||||
|
||||
List<Integer> productIds = tbOrderDetailRepository.findOrderIdsByProductNameLike(criteria.getProductName(),
|
||||
criteria.getShopId(), startTime, endTime);
|
||||
|
||||
if (productIds.isEmpty()) {
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.equal(root.get("id"), 0));
|
||||
} else {
|
||||
predicate = criteriaBuilder.and(predicate, root.get("id").in(productIds));
|
||||
}
|
||||
}
|
||||
|
||||
return predicate;
|
||||
}, pageable);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue