From ba0f5c3079fedcea55e3d375f319743e5daa239e Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 22 七月 2026 14:37:34 +0800
Subject: [PATCH] 修改地图站点查询bug

---
 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java |   53 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
index 4e7cbe6..5827bf4 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
@@ -296,43 +296,50 @@
 		siteList.setPageCurr(1);
 		siteList.setPageSize(99999);
 		PageInfo<GetSiteListDTO> list = siteService.getSiteList(siteList);
-		for (GetSiteListDTO record : list.getRecords()) {
+        List<GetSiteListDTO> records = list.getRecords();
+        if(records.isEmpty()){
+            return R.ok(Collections.emptyList());
+        }
+        List<Integer> collect = records.stream().map(GetSiteListDTO::getId).collect(Collectors.toList());
+        List<TChargingGun> tChargingGuns = chargingGunService.lambdaQuery().in(TChargingGun::getSiteId, collect).list();
+        List<TChargingPile> tChargingPiles = chargingPileService.lambdaQuery().in(TChargingPile::getSiteId, collect).list();
+        Map<Integer, BigDecimal> map = chargingOrderClient.getSiteChargingCapacity(collect).getData();
+        if(null == map){
+            return R.ok(Collections.emptyList());
+        }
+        for (GetSiteListDTO record : list.getRecords()) {
 			List<Integer> c1 = new ArrayList<>();
 			c1.add(3);
 			c1.add(4);
 			c1.add(5);
 			c1.add(6);
-			Long count = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 1).eq(TChargingGun::getStatus, 2).count();
+			Long count = tChargingGuns.stream().filter(s->s.getSiteId().equals(record.getId()) && s.getChargeMode() == 1 && s.getStatus() == 2).count();
 			record.setC1(count);
-			Long count1 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 1).count();
+            Long count1 = tChargingGuns.stream().filter(s->s.getSiteId().equals(record.getId()) && s.getChargeMode() == 1).count();
 			record.setC2(count1);
-			Long count2 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 2).eq(TChargingGun::getStatus, 2).count();
+			Long count2 = tChargingGuns.stream().filter(s->s.getSiteId().equals(record.getId()) && s.getChargeMode() == 2 && s.getStatus() == 2).count();
 			record.setK1(count2);
-			Long count3 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 2).count();
+			Long count3 = tChargingGuns.stream().filter(s->s.getSiteId().equals(record.getId()) && s.getChargeMode() == 2).count();
 			record.setK2(count3);
-			Long count4 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 3).eq(TChargingGun::getStatus, 2).count();
+			Long count4 = tChargingGuns.stream().filter(s->s.getSiteId().equals(record.getId()) && s.getChargeMode() == 3 && s.getStatus() == 2).count();
 			record.setM1(count4);
-			Long count5 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 3).count();
+			Long count5 = tChargingGuns.stream().filter(s->s.getSiteId().equals(record.getId()) && s.getChargeMode() == 3).count();
 			record.setM2(count5);
 
 			//利用率
-			BigDecimal bigDecimal = new BigDecimal("0");
-			//获取该站点的总充电度数
-			List<TChargingOrder> chargingOrders = chargingOrderClient.getList(record.getId()).getData();
-			for (TChargingOrder chargingOrder : chargingOrders) {
-				bigDecimal = bigDecimal.add(chargingOrder.getChargingCapacity());
-			}
+			BigDecimal bigDecimal = map.get(record.getId());
+			if(null == bigDecimal){
+                bigDecimal = BigDecimal.ZERO;
+            }
 			//获取该站点的所有充电桩
-			List<TChargingPile> chargingPiles = chargingPileService.lambdaQuery().eq(TChargingPile::getSiteId, record.getId()).list();
-			BigDecimal bigDecimal1 = new BigDecimal("0");
-			for (TChargingPile chargingPile : chargingPiles) {
-				bigDecimal1 = bigDecimal1.add(chargingPile.getRatedPower());
-			}
-			BigDecimal multiply = bigDecimal1.multiply(new BigDecimal("24"));
-
-			BigDecimal divide = bigDecimal.divide(multiply, 4, BigDecimal.ROUND_HALF_EVEN).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
-			record.setP1(divide);
-
+			List<TChargingPile> chargingPiles = tChargingPiles.stream().filter(s->s.getSiteId().equals(record.getId())).collect(Collectors.toList());
+            BigDecimal bigDecimal1 = chargingPiles.stream().map(TChargingPile::getRatedPower).reduce(BigDecimal::add).orElse(new BigDecimal("0"));
+            BigDecimal multiply = bigDecimal1.multiply(new BigDecimal("24"));
+            BigDecimal divide = BigDecimal.ZERO;
+            if(multiply.compareTo(BigDecimal.ZERO) > 0){
+                divide = bigDecimal.divide(multiply, 4, BigDecimal.ROUND_HALF_EVEN).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+            }
+            record.setP1(divide);
 		}
 		return R.ok(list.getRecords());
 	}

--
Gitblit v1.7.1