Merge branch 'refs/heads/gyj' into dev

This commit is contained in:
GYJ 2024-07-17 11:25:58 +08:00
commit cf1f5c8688
4 changed files with 62 additions and 17 deletions

View File

@ -16,6 +16,7 @@
package cn.ysk.cashier.controller.order; package cn.ysk.cashier.controller.order;
import cn.ysk.cashier.annotation.Log; 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.TbOrderInfoDto;
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria; import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria; import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
@ -55,6 +56,7 @@ public class TbOrderInfoController {
@PostMapping("/date") @PostMapping("/date")
@ApiOperation("查询订单") @ApiOperation("查询订单")
@AnonymousPostMapping
public ResponseEntity<Object> queryTbOrderInfo(@RequestBody TbOrderInfoQueryCriteria criteria){ public ResponseEntity<Object> queryTbOrderInfo(@RequestBody TbOrderInfoQueryCriteria criteria){
return new ResponseEntity<>(tbOrderInfoService.queryAllPage(criteria),HttpStatus.OK); return new ResponseEntity<>(tbOrderInfoService.queryAllPage(criteria),HttpStatus.OK);
} }
@ -90,4 +92,4 @@ public class TbOrderInfoController {
// tbOrderInfoService.deleteAll(ids); // tbOrderInfoService.deleteAll(ids);
// return new ResponseEntity<>(HttpStatus.OK); // return new ResponseEntity<>(HttpStatus.OK);
// } // }
} }

View File

@ -72,4 +72,6 @@ public class TbOrderInfoQueryCriteria{
@Query @Query
private String tableName; private String tableName;
}
private String productName;
}

View File

@ -136,4 +136,13 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
"\t) AS total ", nativeQuery = true) "\t) AS total ", nativeQuery = true)
Tuple searchCount(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime); 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);
}

View File

@ -1,10 +1,12 @@
package cn.ysk.cashier.service.impl.order; package cn.ysk.cashier.service.impl.order;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.ysk.cashier.cons.rabbit.RabbitConstants; import cn.ysk.cashier.cons.rabbit.RabbitConstants;
import cn.ysk.cashier.dto.order.TbOrderInfoDto; import cn.ysk.cashier.dto.order.TbOrderInfoDto;
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria; import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria; 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.order.TbOrderInfoMapper;
import cn.ysk.cashier.mapper.product.TbProductMapper; import cn.ysk.cashier.mapper.product.TbProductMapper;
import cn.ysk.cashier.mapper.product.TbProductSkuMapper; 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())) { if (StringUtils.isBlank(criteria.getStatus()) && StringUtils.isBlank(criteria.getSource())) {
predicate = criteriaBuilder.and(predicate, criteriaBuilder.notEqual(root.get("orderType"), "return")); 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; return predicate;
}, pageable); }, pageable);
@ -121,7 +153,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
detail.setRefundNumber(refundNumber); detail.setRefundNumber(refundNumber);
} }
}); });
}else { } else {
details.parallelStream().forEach(detail -> { details.parallelStream().forEach(detail -> {
detail.setRefundNumber(detail.getNum()); detail.setRefundNumber(detail.getNum());
}); });
@ -151,10 +183,10 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
end = createdAt.get(1); end = createdAt.get(1);
} }
} }
if(ObjectUtil.isEmpty(criteria.getTableName())){ if (ObjectUtil.isEmpty(criteria.getTableName())) {
criteria.setTableName(null); criteria.setTableName(null);
} }
List<TbOrderPayCountVo> payCountVoList = tbOrderInfoRepository.queryTbOrderPayCount(criteria.getShopId(),criteria.getTableName(), start, end); List<TbOrderPayCountVo> payCountVoList = tbOrderInfoRepository.queryTbOrderPayCount(criteria.getShopId(), criteria.getTableName(), start, end);
BigDecimal totalPayAmount = BigDecimal.ZERO; BigDecimal totalPayAmount = BigDecimal.ZERO;
for (TbOrderPayCountVo payCount : payCountVoList) { for (TbOrderPayCountVo payCount : payCountVoList) {
totalPayAmount = totalPayAmount.add(new BigDecimal(payCount.getPayAmount().toString())); totalPayAmount = totalPayAmount.add(new BigDecimal(payCount.getPayAmount().toString()));
@ -171,7 +203,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
result.add(payCount); result.add(payCount);
} }
} }
TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(criteria.getShopId(),criteria.getTableName(), start, end); TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(criteria.getShopId(), criteria.getTableName(), start, end);
if (payRufund != null) { if (payRufund != null) {
totalPayAmount = totalPayAmount.subtract(new BigDecimal(payRufund.getPayAmount().toString())); totalPayAmount = totalPayAmount.subtract(new BigDecimal(payRufund.getPayAmount().toString()));
payRufund.setPayType("退单"); payRufund.setPayType("退单");
@ -231,7 +263,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
dto.setIsRefund(0); dto.setIsRefund(0);
dto.setRefundAmount(BigDecimal.ZERO); dto.setRefundAmount(BigDecimal.ZERO);
List<TbOrderInfo> tbOrderInfos = tbOrderInfoRepository.selTbOrdersBysource(tbOrderInfo.getId(), tbOrderInfo.getShopId()); List<TbOrderInfo> tbOrderInfos = tbOrderInfoRepository.selTbOrdersBysource(tbOrderInfo.getId(), tbOrderInfo.getShopId());
if(!CollectionUtils.isEmpty(tbOrderInfos)){ if (!CollectionUtils.isEmpty(tbOrderInfos)) {
dto.setIsRefund(1); dto.setIsRefund(1);
dto.setRefundAmount(tbOrderInfos.stream().map(TbOrderInfo::getOrderAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); dto.setRefundAmount(tbOrderInfos.stream().map(TbOrderInfo::getOrderAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
} }
@ -250,15 +282,15 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void expired(String orderId) { public void expired(String orderId) {
//修改耗材数据 //修改耗材数据
JSONObject jsonObject1=new JSONObject(); JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("type","delete"); jsonObject1.put("type", "delete");
Optional<TbOrderInfo> byId = tbOrderInfoRepository.findById(Integer.valueOf(orderId)); Optional<TbOrderInfo> byId = tbOrderInfoRepository.findById(Integer.valueOf(orderId));
if (byId != null && byId.isPresent()) { if (byId != null && byId.isPresent()) {
TbOrderInfo tbOrderInfo = byId.get(); TbOrderInfo tbOrderInfo = byId.get();
if (tbOrderInfo.getStatus().equals("unpaid")) { if (tbOrderInfo.getStatus().equals("unpaid")) {
upOrderStatus(tbOrderInfo); upOrderStatus(tbOrderInfo);
jsonObject1.put("orderId",tbOrderInfo.getId()); jsonObject1.put("orderId", tbOrderInfo.getId());
// 发送取消订单mq消息 // 发送取消订单mq消息
rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT, rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT,
jsonObject1.toJSONString(), new CorrelationData(UUID.randomUUID().toString())); jsonObject1.toJSONString(), new CorrelationData(UUID.randomUUID().toString()));
@ -274,7 +306,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
redisUtils.set(CacheKey.ORDER_EXPIRED + tbOrderInfo.getId(), tbOrderInfo.getId(), 60 * 2); redisUtils.set(CacheKey.ORDER_EXPIRED + tbOrderInfo.getId(), tbOrderInfo.getId(), 60 * 2);
} else { } else {
upOrderStatus(tbOrderInfo); upOrderStatus(tbOrderInfo);
jsonObject1.put("orderId",tbOrderInfo.getId()); jsonObject1.put("orderId", tbOrderInfo.getId());
// 发送取消订单mq消息 // 发送取消订单mq消息
rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT, rabbitTemplate.convertAndSend(RabbitConstants.CONS_COLLECT_PUT, RabbitConstants.CONS_COLLECT_ROUTINGKEY_PUT,
@ -360,7 +392,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
public void download(List<TbOrderInfoDto> all, HttpServletResponse response) throws IOException { public void download(List<TbOrderInfoDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
all=all.stream().sorted(Comparator.comparing(TbOrderInfoDto::getId).reversed()).collect(Collectors.toList()); all = all.stream().sorted(Comparator.comparing(TbOrderInfoDto::getId).reversed()).collect(Collectors.toList());
for (TbOrderInfoDto tbOrderInfo : all) { for (TbOrderInfoDto tbOrderInfo : all) {
Map<String, Object> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
map.put("订单编号", tbOrderInfo.getOrderNo()); map.put("订单编号", tbOrderInfo.getOrderNo());
@ -408,8 +440,8 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
map.put("商品信息", productNames); map.put("商品信息", productNames);
// //
if(ObjectUtil.isNotEmpty(tbOrderInfo.getPayType())&&ObjectUtil.isNotNull(tbOrderInfo.getPayType())){ if (ObjectUtil.isNotEmpty(tbOrderInfo.getPayType()) && ObjectUtil.isNotNull(tbOrderInfo.getPayType())) {
switch (tbOrderInfo.getPayType()){ switch (tbOrderInfo.getPayType()) {
case "scanCode": case "scanCode":
tbOrderInfo.setPayType("收款码支付"); tbOrderInfo.setPayType("收款码支付");
break; break;
@ -424,7 +456,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
break; break;
} }
}else { } else {
tbOrderInfo.setPayType(""); tbOrderInfo.setPayType("");
} }
@ -471,7 +503,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
map.put("状态", tbOrderInfo.getStatus()); map.put("状态", tbOrderInfo.getStatus());
map.put("创建日期", DateUtil.timeStampFormatyMdHms(tbOrderInfo.getCreatedAt())); map.put("创建日期", DateUtil.timeStampFormatyMdHms(tbOrderInfo.getCreatedAt()));
map.put("备注", tbOrderInfo.getRemark()); map.put("备注", tbOrderInfo.getRemark());
map.put("台桌",tbOrderInfo.getTableName()); map.put("台桌", tbOrderInfo.getTableName());
list.add(map); list.add(map);
} }
FileUtil.downloadExcel(list, response); FileUtil.downloadExcel(list, response);