From b880058e6ded5169ed38bb214d2da3b841d51bdd Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 14 三月 2025 16:27:36 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java |   73 +++++++++++++++++++++++++-----------
 1 files changed, 50 insertions(+), 23 deletions(-)

diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
index 46f6c7d..b9c35e2 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java
@@ -400,15 +400,37 @@
     @GetMapping(value = "/pay/order/charging/details")
     @ApiOperation(value = "充电明细", tags = {"管理后台-支付订单-订单信息"})
     public R<List<TChargingOrderAccountingStrategy>> chargingDetail(Long orderId) {
-        List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.lambdaQuery().eq(TChargingOrderAccountingStrategy::getChargingOrderId, orderId).orderByDesc(TChargingOrderAccountingStrategy::getStartTime).list();
+        List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.lambdaQuery().eq(TChargingOrderAccountingStrategy::getChargingOrderId, orderId)
+                .orderByDesc(TChargingOrderAccountingStrategy::getStartTime).list();
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         for (TChargingOrderAccountingStrategy tChargingOrderAccountingStrategy : list) {
-            String format = tChargingOrderAccountingStrategy.getCreateTime().format(formatter);
+            LocalDateTime createTime = tChargingOrderAccountingStrategy.getCreateTime();
+            String format = createTime.format(formatter);
+            String startTime = tChargingOrderAccountingStrategy.getStartTime();
+            if("00:00".equals(startTime)){
+                createTime = createTime.plusDays(1);
+                format = createTime.format(formatter);
+            }
             tChargingOrderAccountingStrategy.setStartTime(format+" "+tChargingOrderAccountingStrategy.getStartTime());
             tChargingOrderAccountingStrategy.setEndTime(format+" "+tChargingOrderAccountingStrategy.getEndTime());
         }
-
-
+        //从新排序
+        list.sort(new Comparator<TChargingOrderAccountingStrategy>() {
+            @Override
+            public int compare(TChargingOrderAccountingStrategy o1, TChargingOrderAccountingStrategy o2) {
+                String startTime = o1.getStartTime();
+                String startTime1 = o2.getStartTime();
+                LocalDateTime localDateTime = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
+                LocalDateTime localDateTime1 = LocalDateTime.parse(startTime1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
+                if(localDateTime.isBefore(localDateTime1)){
+                    return -1;
+                }
+                if(localDateTime.isAfter(localDateTime1)){
+                    return 1;
+                }
+                return 0;
+            }
+        });
         return R.ok(list);
     }
     
@@ -548,27 +570,15 @@
         List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.lambdaQuery().eq(TChargingOrderAccountingStrategy::getChargingOrderId, strategyId).orderByDesc(TChargingOrderAccountingStrategy::getStartTime).list();
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         for (TChargingOrderAccountingStrategy tChargingOrderAccountingStrategy : list) {
-            String format = "";
-            String format1 = "";
-            String temp1=list.get(0).getStartTime().split(":")[0];
-            System.err.println("订单详情时间第一条"+list.get(0).getStartTime());
-            System.err.println("订单详情时间开始"+tChargingOrderAccountingStrategy.getStartTime());
-            System.err.println("订单详情时间结束"+tChargingOrderAccountingStrategy.getEndTime());
-//            String temp1=list.get(0).getStartTime().split(":")[0];
-            String[] split = tChargingOrderAccountingStrategy.getStartTime().split(":");
-            if (Integer.parseInt(split[0])>=Integer.parseInt(temp1)){
-                format = byId.getCreateTime().format(formatter);
-            }else {
-                format = byId.getEndTime().format(formatter);
-            }
-            String[] split1 = tChargingOrderAccountingStrategy.getEndTime().split(":");
-            if (Integer.parseInt(split1[0])<Integer.parseInt(temp1)){
-                format1 = byId.getCreateTime().format(formatter);
-            }else {
-                format1 = byId.getEndTime().format(formatter);
+            LocalDateTime createTime = tChargingOrderAccountingStrategy.getCreateTime();
+            String format = createTime.format(formatter);
+            String startTime = tChargingOrderAccountingStrategy.getStartTime();
+            if("00:00".equals(startTime)){
+                createTime = createTime.plusDays(1);
+                format = createTime.format(formatter);
             }
             tChargingOrderAccountingStrategy.setStartTime(format+" "+tChargingOrderAccountingStrategy.getStartTime());
-            tChargingOrderAccountingStrategy.setEndTime(format1+" "+tChargingOrderAccountingStrategy.getEndTime());
+            tChargingOrderAccountingStrategy.setEndTime(format+" "+tChargingOrderAccountingStrategy.getEndTime());
             if (byId.getVipDiscountAmount()!=null && byId.getServiceCharge().compareTo(BigDecimal.ZERO) != 0){
                 BigDecimal multiply = byId.getVipDiscountAmount().divide(byId.getServiceCharge(), 2)
                         .multiply(tChargingOrderAccountingStrategy.getPeriodOriginalServicePrice());
@@ -580,6 +590,23 @@
                 tChargingOrderAccountingStrategy.setCouponDiscount(multiply);
             }
         }
+        //从新排序
+        list.sort(new Comparator<TChargingOrderAccountingStrategy>() {
+            @Override
+            public int compare(TChargingOrderAccountingStrategy o1, TChargingOrderAccountingStrategy o2) {
+                String startTime = o1.getStartTime();
+                String startTime1 = o2.getStartTime();
+                LocalDateTime localDateTime = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
+                LocalDateTime localDateTime1 = LocalDateTime.parse(startTime1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
+                if(localDateTime.isBefore(localDateTime1)){
+                    return -1;
+                }
+                if(localDateTime.isAfter(localDateTime1)){
+                    return 1;
+                }
+                return 0;
+            }
+        });
         chargingOrderInfoVO.setList(list);
         return AjaxResult.success(chargingOrderInfoVO);
     }

--
Gitblit v1.7.1