From dba67c50a297d73ad032c129f7fdae0a9aac3a8e Mon Sep 17 00:00:00 2001 From: zhangli <123879394@qq.com> Date: Thu, 31 Jul 2025 23:27:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BF=A1=E6=81=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sczx/order/dto/OrderDTO.java | 6 +++++ .../java/com/sczx/order/po/OrderMainPO.java | 6 +++++ .../order/service/impl/OrderServiceImpl.java | 23 +++++++++++++++---- src/main/resources/mapper/OrderMainMapper.xml | 10 ++++---- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/sczx/order/dto/OrderDTO.java b/src/main/java/com/sczx/order/dto/OrderDTO.java index 72a00e4..a71bf8f 100644 --- a/src/main/java/com/sczx/order/dto/OrderDTO.java +++ b/src/main/java/com/sczx/order/dto/OrderDTO.java @@ -119,6 +119,12 @@ public class OrderDTO { @ApiModelProperty("租电套餐id") private Long rentBatteyRuleId; + @ApiModelProperty("订单结束时间") + private LocalDateTime endOrderTime; + + @ApiModelProperty("订单总金额") + private BigDecimal orderAmount; + @ApiModelProperty("租电套餐信息") private RentBatteyRuleDTO rentBatteyRule; diff --git a/src/main/java/com/sczx/order/po/OrderMainPO.java b/src/main/java/com/sczx/order/po/OrderMainPO.java index e9280d9..650ed0a 100644 --- a/src/main/java/com/sczx/order/po/OrderMainPO.java +++ b/src/main/java/com/sczx/order/po/OrderMainPO.java @@ -126,6 +126,12 @@ public class OrderMainPO implements Serializable { @ApiModelProperty("租电套餐id") private Long rentBatteyRuleId; + @ApiModelProperty("订单结束时间") + private LocalDateTime endOrderTime; + + @ApiModelProperty("订单总金额") + private BigDecimal orderAmount; + @ApiModelProperty("删除标志(0代表存在 2代表删除)") private String delFlag; diff --git a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java index 6bf1723..8125d5d 100644 --- a/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/sczx/order/service/impl/OrderServiceImpl.java @@ -31,8 +31,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; @Slf4j @@ -62,6 +64,14 @@ public class OrderServiceImpl implements OrderService { public RentCarOrderResultDTO submitRentCarOrder(RentCarOrderReq rentCarOrderReq) { SimpleUserInfoDTO userInfoDTO = jwtUtil.getUserInfoFromToken(); + LambdaQueryWrapper currentOrderWrapper = new LambdaQueryWrapper<>(); + currentOrderWrapper.eq(OrderMainPO::getCustomerId, userInfoDTO.getUserId()) + .notIn(OrderMainPO::getOrderStatus, Arrays.asList(OrderStatusEnum.AUTO_END.getCode(), OrderStatusEnum.MANUAL_END.getCode())) + .eq(OrderMainPO::getDelFlag, "0"); + List currentOrderList = orderMainRepo.list(currentOrderWrapper); + if(currentOrderList.size()>0){ + throw new BizException("您有未完成的订单,请先完成订单"); + } //获取门店信息 CompanyStoreDTO companyStoreDTO = storeInteg.getStoreById(Integer.valueOf(rentCarOrderReq.getStoreId().toString())); @@ -87,7 +97,7 @@ public class OrderServiceImpl implements OrderService { //TODO 默认应该是待支付状态,这里先默认支付完成待取车 // orderMainPO.setOrderStatus(OrderStatusEnum.WAIT_PAY.getCode()); orderMainPO.setOrderStatus(OrderStatusEnum.WAIT_PICK.getCode()); - orderMainRepo.save(orderMainPO); + //生成子表订单 String paymentType; @@ -110,7 +120,6 @@ public class OrderServiceImpl implements OrderService { if(!rentCarOrderReq.getIsDepositFree()){ OrderSubPO depositOrder = new OrderSubPO(); depositOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.YJ_PREFIX)); - depositOrder.setOrderId(orderMainPO.getOrderId()); depositOrder.setSuborderType(SubOrderTypeEnum.DEPOSIT.getCode()); depositOrder.setAmount(orderMainPO.getDepositPrice()); depositOrder.setCreatedAt(LocalDateTime.now()); @@ -122,7 +131,6 @@ public class OrderServiceImpl implements OrderService { rentBatteyRuleDTO = carInteg.getRentBatteyRuleByBatteyRuleId(rentCarOrderReq.getRentBatteyRuleId()); OrderSubPO depositOrder = new OrderSubPO(); depositOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.ZD_PREFIX)); - depositOrder.setOrderId(orderMainPO.getOrderId()); depositOrder.setSuborderType(SubOrderTypeEnum.RENTBATTEY.getCode()); depositOrder.setAmount(rentBatteyRuleDTO.getRentPrice()); depositOrder.setCreatedAt(LocalDateTime.now()); @@ -132,12 +140,19 @@ public class OrderServiceImpl implements OrderService { //生成租车订单 OrderSubPO rentOrder = new OrderSubPO(); rentOrder.setSuborderNo(OrderUtil.generateSubOrderNo(OrderUtil.ZC_PREFIX)); - rentOrder.setOrderId(orderMainPO.getOrderId()); rentOrder.setSuborderType(SubOrderTypeEnum.RENTCAR.getCode()); rentOrder.setAmount(orderMainPO.getRentalPrice()); rentOrder.setCreatedAt(LocalDateTime.now()); rentOrder.setPaymentMethod(paymentType); orderSubPOList.add(rentOrder); + + BigDecimal orderAmount = orderSubPOList.stream().map(OrderSubPO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + orderMainPO.setOrderAmount(orderAmount); + orderMainRepo.save(orderMainPO); + + orderSubPOList.forEach(orderSubPO -> { + orderSubPO.setOrderId(orderMainPO.getOrderId()); + }); orderSubRepo.saveBatch(orderSubPOList); // TODO 发起支付返回预支付信息 UnifiedPaymentInfoDTO unifiedPaymentInfoDTO = new UnifiedPaymentInfoDTO(); diff --git a/src/main/resources/mapper/OrderMainMapper.xml b/src/main/resources/mapper/OrderMainMapper.xml index afd290d..a2b6550 100644 --- a/src/main/resources/mapper/OrderMainMapper.xml +++ b/src/main/resources/mapper/OrderMainMapper.xml @@ -6,11 +6,11 @@ SELECT store_id, COUNT(*) as total_orders, - SUM(CASE WHEN (status = 'AUTO_END' OR status = 'MANUAL_END') AND DATE_FORMAT(end_order_time, '%Y-%m') = DATE_FORMAT(NOW(), '%Y-%m') THEN 1 ELSE 0 END) as monthly_completed_orders, - SUM(CASE WHEN (status = 'AUTO_END' OR status = 'MANUAL_END') AND DATE_FORMAT(end_order_time, '%Y-%m') = DATE_FORMAT(NOW(), '%Y-%m') THEN order_amount ELSE 0 END) as monthly_order_amount, - COUNT(CASE WHEN status = 'WAIT_RETURN' THEN 1 END) as pending_pickup_count, - COUNT(CASE WHEN status = 'WAIT_RETURN' THEN 1 END) as pending_return_count, - COUNT(CASE WHEN status = 'RENT_OVERDUE' THEN 1 END) as overdue_count + SUM(CASE WHEN (order_status = 'AUTO_END' OR order_status = 'MANUAL_END') AND DATE_FORMAT(end_order_time, '%Y-%m') = DATE_FORMAT(NOW(), '%Y-%m') THEN 1 ELSE 0 END) as monthly_completed_orders, + SUM(CASE WHEN (order_status = 'AUTO_END' OR order_status = 'MANUAL_END') AND DATE_FORMAT(end_order_time, '%Y-%m') = DATE_FORMAT(NOW(), '%Y-%m') THEN order_amount ELSE 0 END) as monthly_order_amount, + COUNT(CASE WHEN order_status = 'WAIT_RETURN' THEN 1 END) as pending_pickup_count, + COUNT(CASE WHEN order_status = 'WAIT_RETURN' THEN 1 END) as pending_return_count, + COUNT(CASE WHEN order_status = 'RENT_OVERDUE' THEN 1 END) as overdue_count FROM zc_order_main WHERE store_id = #{storeId} GROUP BY store_id