From 7ea47db47d3e039e25531cd511d8d7b1342ccfc0 Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期三, 23 十月 2024 20:04:54 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TChargingOrderController.java |  104 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 86 insertions(+), 18 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 16d93c1..6dc6368 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
@@ -248,7 +248,7 @@
     @ResponseBody
     @GetMapping(value = "/pay/order/charging")
     @ApiOperation(value = "充电信息", tags = {"管理后台-支付订单-订单信息"})
-    public R refundDetail(Long orderId) {
+    public R<PayOrderChargingInfo> refundDetail(Long orderId) {
         PayOrderChargingInfo payOrderChargingInfo = new PayOrderChargingInfo();
         TChargingOrder byId = chargingOrderService.getById(orderId);
         List<Site> data = siteClient.getSiteByIds(Collections.singletonList(byId.getSiteId())).getData();
@@ -261,7 +261,20 @@
             List<TAppUserCar> data3 = appUserCarClient.getCarByIds(Collections.singletonList(byId.getAppUserCarId())).getData();
             payOrderChargingInfo.setCarNum(data3.get(0).getLicensePlate());
         }
-        return R.ok();
+        payOrderChargingInfo.setTChargingOrder(byId);
+
+        Long count = chargingOrderAccountingStrategyService.lambdaQuery().eq(TChargingOrderAccountingStrategy::getChargingOrderId, orderId).count();
+        payOrderChargingInfo.setPeriodCount(count);
+        if (byId.getAppUserCarId()!=null) {
+            List<Long> carid = new ArrayList<>();
+            carid.add(byId.getAppUserCarId());
+            R<List<TAppUserCar>> carByIds = appUserCarClient.getCarByIds(carid);
+            payOrderChargingInfo.setCarNum(carByIds.getData().get(0).getLicensePlate());
+        }
+        payOrderChargingInfo.setStartTime(byId.getStartTime());
+        payOrderChargingInfo.setEndTime(byId.getEndTime());
+        payOrderChargingInfo.setTimeCount(payOrderChargingInfo.calculateDuration());
+        return R.ok(payOrderChargingInfo);
     }
 
     @ResponseBody
@@ -315,10 +328,10 @@
         TChargingOrder byId = chargingOrderService.getById(strategyId);
         ChargingOrderInfoVO chargingOrderInfoVO = new ChargingOrderInfoVO();
 
-        chargingOrderInfoVO.setCdElectronic(byId.getCurrent()!=null?byId.getCurrent()+"":"");
-        chargingOrderInfoVO.setCdVoltage(byId.getVoltage()!=null?byId.getVoltage()+"":"");
-        chargingOrderInfoVO.setSurplus(byId.getTotalElectricity()!=null?byId.getTotalElectricity()+"":"");
-        chargingOrderInfoVO.setTotalPower(byId.getPower()!=null?byId.getPower()+"":"");
+        chargingOrderInfoVO.setCdElectronic(byId.getCurrent()!=null?byId.getCurrent().setScale(2, BigDecimal.ROUND_HALF_DOWN)+"":"");
+        chargingOrderInfoVO.setCdVoltage(byId.getVoltage()!=null?byId.getVoltage().setScale(2, BigDecimal.ROUND_HALF_DOWN)+"":"");
+        chargingOrderInfoVO.setSurplus(byId.getTotalElectricity()!=null?byId.getTotalElectricity().setScale(2, BigDecimal.ROUND_HALF_DOWN)+"":"");
+        chargingOrderInfoVO.setTotalPower(byId.getPower()!=null?byId.getPower().setScale(2, BigDecimal.ROUND_HALF_DOWN)+"":"");
         if (byId.getAppUserCarId()!=null){
             List<TAppUserCar> data = appUserCarClient.getCarByIds(Collections.singletonList(byId.getAppUserCarId())).getData();
             if (!data.isEmpty()){
@@ -331,16 +344,20 @@
         // 时段总服务费
         BigDecimal bigDecimal = new BigDecimal("0");
         List<TChargingOrderAccountingStrategy> list = chargingOrderAccountingStrategyService.lambdaQuery().eq(TChargingOrderAccountingStrategy::getChargingOrderId, strategyId).orderByDesc(TChargingOrderAccountingStrategy::getStartTime).list();
+
         for (TChargingOrderAccountingStrategy tChargingOrderAccountingStrategy : list) {
+            if (byId.getVipDiscountAmount()!=null){
+                BigDecimal multiply = byId.getVipDiscountAmount().divide(byId.getServiceCharge(), 2)
+                        .multiply(tChargingOrderAccountingStrategy.getPeriodOriginalServicePrice());
+                tChargingOrderAccountingStrategy.setVipDiscount(multiply);
+            }
             bigDecimal = bigDecimal.add(tChargingOrderAccountingStrategy.getPeriodOriginalServicePrice());
-            tChargingOrderAccountingStrategy.setVipDiscount(
-                    tChargingOrderAccountingStrategy.getPeriodOriginalServicePrice()
-                            .subtract(tChargingOrderAccountingStrategy.getPeriodServicePrice())
-            );
-            tChargingOrderAccountingStrategy.setCouponDiscount(
-                    tChargingOrderAccountingStrategy.getPeriodOriginalServicePrice()
-                            .subtract(tChargingOrderAccountingStrategy.getPeriodServicePrice())
-            );
+
+            if (byId.getCouponDiscountAmount()!=null){
+                BigDecimal multiply = byId.getCouponDiscountAmount().divide(byId.getServiceCharge(), 2)
+                        .multiply(tChargingOrderAccountingStrategy.getPeriodOriginalServicePrice());
+                tChargingOrderAccountingStrategy.setCouponDiscount(multiply);
+            }
         }
         chargingOrderInfoVO.setList(list);
         return AjaxResult.success(chargingOrderInfoVO);
@@ -618,10 +635,36 @@
         }
         LocalDate sixBefore = PreviousSixMonths.get();
         //通过siteIds进行sql查询统计
+        List<SixChargingDto> sixChargingDtos = generateLastSixMonths();
         List<SixChargingDto> chargingDtos = chargingOrderService.charge(sixBefore, siteIds);
+        for (SixChargingDto sixChargingDto : sixChargingDtos) {
+            for (SixChargingDto chargingDto : chargingDtos) {
+                if (sixChargingDto.getMonth().equals(chargingDto.getMonth())){
+                    BeanUtils.copyProperties(chargingDto,sixChargingDto);
+                }
+            }
 
-        return R.ok(chargingDtos);
+        }
 
+        return R.ok(sixChargingDtos);
+
+    }
+
+
+    public static List<SixChargingDto> generateLastSixMonths() {
+        LocalDate today = LocalDate.now();
+        List<SixChargingDto> months = new ArrayList<>();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM");
+
+        for (int i = 5; i >= 0; i--) {
+            LocalDate date = today.minusMonths(i);
+            String month = date.format(formatter);
+            SixChargingDto sixChargingDto = new SixChargingDto();
+            sixChargingDto.setMonth(month);
+            months.add(sixChargingDto);
+        }
+
+        return months;
     }
 
     @ResponseBody
@@ -655,7 +698,33 @@
         //count近6个月的数据
         LocalDate sixBefore = PreviousSixMonths.get();
         List<SixShopDto> sixShopDtos =  shoppingOrderService.sixBefore(sixBefore,status);
-        return R.ok(sixShopDtos);
+        List<SixShopDto> sixChargingDtos = generateLastSixMonths1();
+        for (SixShopDto sixChargingDto : sixChargingDtos) {
+            for (SixShopDto chargingDto : sixShopDtos) {
+                if (sixChargingDto.getMonth().equals(chargingDto.getMonth())){
+                    BeanUtils.copyProperties(chargingDto,sixChargingDto);
+                }
+            }
+
+        }
+
+        return R.ok(sixChargingDtos);
+    }
+
+    public static List<SixShopDto> generateLastSixMonths1() {
+        LocalDate today = LocalDate.now();
+        List<SixShopDto> months = new ArrayList<>();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM");
+
+        for (int i = 5; i >= 0; i--) {
+            LocalDate date = today.minusMonths(i);
+            String month = date.format(formatter);
+            SixShopDto sixChargingDto = new SixShopDto();
+            sixChargingDto.setMonth(month);
+            months.add(sixChargingDto);
+        }
+
+        return months;
     }
 
     @ResponseBody
@@ -785,7 +854,7 @@
         LocalDate end = null;
         if (statisticsQueryDto.getDayType()==1){
             start = LocalDate.now();
-            end = LocalDate.now();
+            end = LocalDate.now().plusDays(1);
 
         }else if (statisticsQueryDto.getDayType()==2){
             LocalDate today = LocalDate.now();
@@ -794,7 +863,6 @@
             LocalDate mondayThisWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
             start = statisticsQueryDto.getStartTime();
             end = statisticsQueryDto.getEndTime();
-
             System.out.println("本周一是: " + mondayThisWeek);
         }
         else if (statisticsQueryDto.getDayType()==3){

--
Gitblit v1.7.1