From 88f8a06039ddb14cb1c8ac0c012b6d1ee8bd933a Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 18 七月 2025 16:55:03 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java |   61 ++++++++++++++++--------------
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/task/TaskUtil.java                     |   44 +++++++++++++---------
 ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml                  |    2 -
 3 files changed, 58 insertions(+), 49 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
index 2eb375b..01740da 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -2323,6 +2323,10 @@
 			return R.ok();
 		}
 		try {
+			Object cacheObject = redisService.getCacheObject("chargingOrderStatus:" + vo.getTransaction_serial_number());
+			if(null != cacheObject && 5 == (int)cacheObject){
+				return R.ok();
+			}
 			TChargingOrder chargingOrder = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getCode, vo.getTransaction_serial_number()));
 			if (null == chargingOrder) {
 				return R.ok();
@@ -2533,31 +2537,28 @@
 			//退款金额=充值金额-实际支付金额
 			BigDecimal refundAmount = rechargeAmount.subtract(payAmount);
 			
-			TChargingOrder order = new TChargingOrder();
-			order.setId(chargingOrder.getId());
-			order.setAppUserId(chargingOrder.getAppUserId());
 			UploadRealTimeMonitoringData uploadRealTimeMonitoringData = uploadRealTimeMonitoringDataService.getLastDataById(chargingOrder.getCode());
 			if (null != uploadRealTimeMonitoringData && null == chargingOrder.getEndMode()) {
 				Integer soc = uploadRealTimeMonitoringData.getSoc();
 				if (soc >= 98) {
-					order.setEndMode(2);
+					chargingOrder.setEndMode(2);
 				} else if (chargingOrder.getResidualAmount().compareTo(new BigDecimal(1)) <= 0) {
-					order.setEndMode(3);
+					chargingOrder.setEndMode(3);
 				} else {
-					order.setEndMode(0);
+					chargingOrder.setEndMode(0);
 				}
 			}
-			order.setResidualAmount(rechargeAmount.subtract(total).setScale(2, RoundingMode.HALF_EVEN));
-			order.setStartTime(LocalDateTime.parse(vo.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
-			order.setEndTime(LocalDateTime.parse(vo.getEnd_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
-			order.setStatus(5);
-			order.setOrderAmount(orderAmount.setScale(2, RoundingMode.HALF_EVEN));
-			order.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.HALF_EVEN));
-			order.setChargingCapacity(vo.getTotal_electricity());
-			order.setElectricity(vo.getTotal_electricity());
-			order.setVipDiscountAmount(vipDiscountAmount_total);
+			chargingOrder.setResidualAmount(rechargeAmount.subtract(total).setScale(2, RoundingMode.HALF_EVEN));
+			chargingOrder.setStartTime(LocalDateTime.parse(vo.getStart_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
+			chargingOrder.setEndTime(LocalDateTime.parse(vo.getEnd_time(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS")));
+			chargingOrder.setStatus(5);
+			chargingOrder.setOrderAmount(orderAmount.setScale(2, RoundingMode.HALF_EVEN));
+			chargingOrder.setElectrovalence(periodElectricPrice_total.setScale(2, RoundingMode.HALF_EVEN));
+			chargingOrder.setChargingCapacity(vo.getTotal_electricity());
+			chargingOrder.setElectricity(vo.getTotal_electricity());
+			chargingOrder.setVipDiscountAmount(vipDiscountAmount_total);
 			if (vipDiscountAmount_total.compareTo(BigDecimal.ZERO) == 0) {
-				order.setVipDiscount(BigDecimal.valueOf(1));
+				chargingOrder.setVipDiscount(BigDecimal.valueOf(1));
 			}
 			
 			//计算优惠券
@@ -2582,9 +2583,9 @@
 						appCoupon.setStatus(2);
 						appCouponClient.updateAppCoupon(appCoupon);
 					} else {
-						order.setAppCouponId(null);
-						order.setCouponDiscountAmount(BigDecimal.ZERO);
 						appCouponClient.refund(chargingOrder.getAppCouponId().toString());
+						chargingOrder.setAppCouponId(null);
+						chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO);
 					}
 				}
 				if (2 == preferentialMode) {
@@ -2604,8 +2605,8 @@
 						appCoupon.setStatus(2);
 						appCouponClient.updateAppCoupon(appCoupon);
 					} else {
-						order.setAppCouponId(null);
-						order.setCouponDiscountAmount(BigDecimal.ZERO);
+						chargingOrder.setAppCouponId(null);
+						chargingOrder.setCouponDiscountAmount(BigDecimal.ZERO);
 						appCouponClient.refund(chargingOrder.getAppCouponId().toString());
 					}
 				}
@@ -2619,13 +2620,15 @@
 			if (serviceCharge_total.compareTo(BigDecimal.ZERO) > 0) {
 				serviceCharge_total = serviceCharge_total.subtract(couponDiscount);
 			}
-			order.setCouponDiscountAmount(couponDiscount.setScale(2, RoundingMode.HALF_EVEN));
-			order.setServiceCharge(serviceCharge_total.setScale(2, RoundingMode.HALF_EVEN));
-			order.setPaymentAmount(payAmount.setScale(2, RoundingMode.HALF_EVEN));
-			order.setRefundAmount(refundAmount.setScale(2, RoundingMode.HALF_EVEN));
-			order.setRefundStatus(1);
-			this.updateById(order);
-			chargingOrder = this.getById(order.getId());
+			chargingOrder.setCouponDiscountAmount(couponDiscount.setScale(2, RoundingMode.HALF_EVEN));
+			chargingOrder.setServiceCharge(serviceCharge_total.setScale(2, RoundingMode.HALF_EVEN));
+			chargingOrder.setPaymentAmount(payAmount.setScale(2, RoundingMode.HALF_EVEN));
+			chargingOrder.setRefundAmount(refundAmount.setScale(2, RoundingMode.HALF_EVEN));
+			chargingOrder.setRefundStatus(1);
+			this.updateById(chargingOrder);
+			redisService.setCacheObject("chargingOrderStatus:" + vo.getTransaction_serial_number(), 5, 100L, TimeUnit.SECONDS);
+			
+			chargingOrder = this.getById(chargingOrder.getId());
 			
 			//推送三方平台
 			if (2 == chargingOrder.getOrderSource()) {
@@ -2642,9 +2645,9 @@
 			}
 			
 			//开始将优惠券优惠的金额添加到明细中
-			BigDecimal couponDiscountAmount = order.getCouponDiscountAmount();
+			BigDecimal couponDiscountAmount = chargingOrder.getCouponDiscountAmount();
 			if (null != couponDiscountAmount && couponDiscountAmount.compareTo(BigDecimal.ZERO) > 0) {
-				List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, order.getId()));
+				List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.list(new LambdaQueryWrapper<TChargingOrderAccountingStrategy>().eq(TChargingOrderAccountingStrategy::getChargingOrderId, chargingOrder.getId()));
 				BigDecimal reduce = list.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 				for (TChargingOrderAccountingStrategy chargingOrderAccountingStrategy : list) {
 					BigDecimal periodServicePrice = chargingOrderAccountingStrategy.getPeriodServicePrice();
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/task/TaskUtil.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/task/TaskUtil.java
index c9c2c85..8db8d05 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/task/TaskUtil.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/util/task/TaskUtil.java
@@ -80,30 +80,36 @@
             List<TChargingOrder> failedStartupOrder = chargingOrderService.findFailedStartupOrder();
             log.info("定时任务执行,查询到启动失败的订单数量:{}", failedStartupOrder.size());
             for (TChargingOrder order : failedStartupOrder) {
+                log.info("定时任务执行,查询到启动失败的订单:{}", order.getCode());
                 //查询是否有充电信息
                 List<UploadRealTimeMonitoringData> dataByOrderCode = uploadRealTimeMonitoringDataService.getDataByOrderCode(order.getCode());
-                log.info("充电实时数据:{}", JSON.toJSONString(dataByOrderCode));
+                log.info("充电实时数据:{}", dataByOrderCode.size());
                 //没有充电数据,则执行退款
                 if(null == dataByOrderCode || dataByOrderCode.isEmpty()){
                     log.info("定时任务执行,查询到启动失败的订单,执行退款:{}", order.getCode());
-                    chargingOrderService.refund(order.getCode());
-                    int num = 0;
-                    while (true){
-                        TChargingOrderRefund one = chargingOrderRefundService.getOne(new LambdaQueryWrapper<TChargingOrderRefund>().eq(TChargingOrderRefund::getChargingOrderId, order.getId()));
-                        if(null != one && 2 == one.getRefundStatus()){
-                            order.setStatus(-1);
-                            chargingOrderService.updateById(order);
-                            break;
+                    if(1 == order.getOrderSource()){
+                        chargingOrderService.refund(order.getCode());
+                        int num = 0;
+                        while (true){
+                            TChargingOrderRefund one = chargingOrderRefundService.getOne(new LambdaQueryWrapper<TChargingOrderRefund>().eq(TChargingOrderRefund::getChargingOrderId, order.getId()));
+                            if(null != one && 2 == one.getRefundStatus()){
+                                order.setStatus(-1);
+                                chargingOrderService.updateById(order);
+                                break;
+                            }
+                            try {
+                                Thread.sleep(5000);
+                            } catch (InterruptedException e) {
+                                throw new RuntimeException(e);
+                            }
+                            num++;
+                            if(num > 10){
+                                break;
+                            }
                         }
-                        try {
-                            Thread.sleep(5000);
-                        } catch (InterruptedException e) {
-                            throw new RuntimeException(e);
-                        }
-                        num++;
-                        if(num > 10){
-                            break;
-                        }
+                    }else{
+                        order.setStatus(-1);
+                        chargingOrderService.updateById(order);
                     }
                 }
             }
@@ -111,6 +117,7 @@
             List<TChargingOrder> stoppedOrder = chargingOrderService.findStoppedOrder();
             log.info("定时任务执行,查询到停止中的订单数量:{}", stoppedOrder.size());
             for (TChargingOrder order : stoppedOrder) {
+                log.info("定时任务执行,查询到停止中的订单:{}", order.getCode());
                 TransactionRecord one = transactionRecordService.findOne(order.getCode());
                 if(null != one){
                     log.info("定时任务执行,查询到停止中的订单账单数据:{}", JSON.toJSONString(one));
@@ -124,6 +131,7 @@
             List<TChargingOrder> chargingOrder = chargingOrderService.findChargingOrder();
             log.info("定时任务执行,查询到充电中的订单数量:{}", chargingOrder.size());
             for (TChargingOrder order : chargingOrder) {
+                log.info("定时任务执行,查询到充电中的订单:{}", order.getCode());
                 TransactionRecord one = transactionRecordService.findOne(order.getCode());
                 if(null != one && StringUtils.isNotEmpty(one.getResult())){
                     log.info("定时任务执行,查询到充电中的订单账单数据:{}", JSON.toJSONString(one));
diff --git a/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml b/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
index 1f434b9..bf5ff24 100644
--- a/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
+++ b/ruoyi-service/ruoyi-order/src/main/resources/mapper/order/TChargingOrderMapper.xml
@@ -1783,10 +1783,8 @@
         WHERE
             `status` = 2
           AND recharge_payment_status = 2
-          AND recharge_serial_number IS NOT NULL
           AND NOW() >= ADDDATE(pay_time, INTERVAL 15 MINUTE )
           AND del_flag = 0
-          AND order_source = 1
           AND id NOT IN (
             SELECT
                 charging_order_id

--
Gitblit v1.7.1