From 05699d56867ee2e6a946219dc267189e0443dab1 Mon Sep 17 00:00:00 2001 From: Lemon Date: Tue, 26 May 2026 16:19:19 +0800 Subject: [PATCH] =?UTF-8?q?update=20=20=E9=A6=96=E9=A1=B5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A4=A7=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/index/indexController.java | 249 +++++++++++++++--- .../jsowell/common/core/redis/RedisCache.java | 2 + .../com/jsowell/pile/dto/IndexQueryDTO.java | 5 + .../pile/mapper/MemberBasicInfoMapper.java | 4 +- .../pile/mapper/OrderBasicInfoMapper.java | 10 + .../pile/mapper/PileBasicInfoMapper.java | 40 +-- .../pile/service/MemberBasicInfoService.java | 4 +- .../pile/service/OrderBasicInfoService.java | 14 + .../pile/service/PileBasicInfoService.java | 38 +-- .../impl/MemberBasicInfoServiceImpl.java | 4 +- .../impl/OrderBasicInfoServiceImpl.java | 28 ++ .../impl/PileBasicInfoServiceImpl.java | 72 ++++- .../mapper/pile/MemberBasicInfoMapper.xml | 4 +- .../mapper/pile/OrderBasicInfoMapper.xml | 21 ++ .../mapper/pile/PileBasicInfoMapper.xml | 94 +++++-- 15 files changed, 483 insertions(+), 106 deletions(-) diff --git a/jsowell-admin/src/main/java/com/jsowell/web/controller/index/indexController.java b/jsowell-admin/src/main/java/com/jsowell/web/controller/index/indexController.java index e84b0a1e3..ab3e1621e 100644 --- a/jsowell-admin/src/main/java/com/jsowell/web/controller/index/indexController.java +++ b/jsowell-admin/src/main/java/com/jsowell/web/controller/index/indexController.java @@ -10,14 +10,28 @@ import com.jsowell.pile.service.OrderBasicInfoService; import com.jsowell.pile.service.PileBasicInfoService; import com.jsowell.pile.service.PileConnectorInfoService; import com.jsowell.pile.service.PileStationInfoService; +import com.jsowell.pile.service.PileMerchantInfoService; +import com.jsowell.pile.service.BusinessFinancialService; +import com.jsowell.pile.dto.business.BusinessOperationAnalysisQueryDTO; +import com.jsowell.pile.util.UserUtils; import com.jsowell.pile.vo.web.*; +import com.jsowell.common.core.domain.vo.AuthorizedDeptVO; +import com.jsowell.common.util.SecurityUtils; +import com.jsowell.common.constant.Constants; +import com.jsowell.pile.domain.PileMerchantInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.util.CollectionUtils; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; /** * 首页数据展示Controller @@ -43,6 +57,15 @@ public class indexController extends BaseController { @Autowired private PileConnectorInfoService pileConnectorInfoService; + @Autowired + private PileMerchantInfoService pileMerchantInfoService; + + @Autowired + private BusinessFinancialService businessFinancialService; + + @Autowired + private Executor threadPoolTaskExecutor; + @PostMapping("/getGeneralSituation") public RestApiResponse getGeneralSituation(@RequestBody IndexQueryDTO dto) { logger.info("首页基础数据查询 param:{}", JSON.toJSONString(dto)); @@ -117,7 +140,8 @@ public class indexController extends BaseController { } /** - * 大数据平台-总览数据 + * 大数据平台-总览数据(性能优化版) + * 权限解析在主线程完成,按merchantId或stationId维度查询,不用SQL SUM,Java汇总 */ @PostMapping("/getBigDataOverview") public RestApiResponse getBigDataOverview(@RequestBody(required = false) IndexQueryDTO dto) { @@ -126,47 +150,145 @@ public class indexController extends BaseController { RestApiResponse response; try { BigDataOverviewVO overviewVO = new BigDataOverviewVO(); - overviewVO.setTotalUsers(memberBasicInfoService.countTotalMembers()); - overviewVO.setTotalOrders(orderBasicInfoService.countTotalOrders()); - IndexGeneralSituationVO generalSituation = pileBasicInfoService.getGeneralSituation(dto); - overviewVO.setTotalTransactionAmount(generalSituation.getTotalChargingAmount()); - overviewVO.setTotalElectricity(generalSituation.getTotalChargingDegree()); - overviewVO.setTotalPiles(Long.valueOf(generalSituation.getTotalPileQuantity())); - overviewVO.setTotalStations(pileStationInfoService.countTotalStations()); - // 新增字段 - overviewVO.setDailyNewUsers(memberBasicInfoService.countTodayNewMembers()); - java.math.BigDecimal todayAmount = pileBasicInfoService.getTodayTransactionAmount(); + + // === 第一步:主线程做权限解析(依赖SecurityContext,不可异步) === + // 平台管理员:merchantIdList为空,直接查全量(不加任何过滤) + // 运营商管理员:使用merchantId维度 + // 站点管理员:使用stationId维度 + AuthParams authParams = resolveAuthParams(); + + // demo账号标记 + boolean isDemo = false; + try { + isDemo = "demo".equals(SecurityUtils.getUsername()); + } catch (Exception ignored) {} + + // === 第二步:所有DB查询并行执行 === + final List finalMerchantIdList = authParams.merchantIdList; + final List finalStationIdList = authParams.stationIdList; + final boolean isPlatformAdmin = authParams.isPlatformAdmin; + + // 带权限过滤的查询:根据账号级别选择维度 + CompletableFuture situationFuture; + CompletableFuture totalPilesFuture; + + if (isPlatformAdmin) { + // 平台管理员:直接查全量,不加merchant_id/station_id过滤 + situationFuture = CompletableFuture.supplyAsync( + () -> pileBasicInfoService.aggregateReportByMerchantIds(null), threadPoolTaskExecutor); + totalPilesFuture = CompletableFuture.supplyAsync( + () -> pileBasicInfoService.countTotalPilesByMerchantIds(null), threadPoolTaskExecutor); + } else if (!CollectionUtils.isEmpty(finalMerchantIdList)) { + // 运营商管理员:按merchantId查 + final List midList = finalMerchantIdList; + situationFuture = CompletableFuture.supplyAsync( + () -> pileBasicInfoService.aggregateReportByMerchantIds(midList), threadPoolTaskExecutor); + totalPilesFuture = CompletableFuture.supplyAsync( + () -> pileBasicInfoService.countTotalPilesByMerchantIds(midList), threadPoolTaskExecutor); + } else { + // 站点管理员:按stationId查 + final List sidList = finalStationIdList; + situationFuture = CompletableFuture.supplyAsync( + () -> pileBasicInfoService.aggregateReportByStationIds(sidList), threadPoolTaskExecutor); + totalPilesFuture = CompletableFuture.supplyAsync( + () -> pileBasicInfoService.countTotalPilesByStationIds(sidList), threadPoolTaskExecutor); + } + + // 不需要权限过滤的全局查询(日期在代码中生成,不在数据库中运算) + java.time.LocalDate today = java.time.LocalDate.now(); + String todayStart = today.format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00"; + String todayEnd = today.plusDays(1).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " 00:00:00"; + String monthStart = today.withDayOfMonth(1).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")); + String monthEnd = today.plusDays(1).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")); + final String fTodayStart = todayStart; + final String fTodayEnd = todayEnd; + final String fMonthStart = monthStart; + final String fMonthEnd = monthEnd; + + CompletableFuture totalUsersFuture = CompletableFuture.supplyAsync( + () -> memberBasicInfoService.countTotalMembers(), threadPoolTaskExecutor); + CompletableFuture totalStationsFuture = CompletableFuture.supplyAsync( + () -> pileStationInfoService.countTotalStations(), threadPoolTaskExecutor); + CompletableFuture dailyNewUsersFuture = CompletableFuture.supplyAsync( + () -> memberBasicInfoService.countTodayNewMembers(fTodayStart, fTodayEnd), threadPoolTaskExecutor); + CompletableFuture todayAmountFuture = CompletableFuture.supplyAsync( + () -> orderBasicInfoService.getTodayTransactionAmount(fTodayStart, fTodayEnd), threadPoolTaskExecutor); + CompletableFuture todayElecFuture = CompletableFuture.supplyAsync( + () -> orderBasicInfoService.getTodayElectricity(fTodayStart, fTodayEnd), threadPoolTaskExecutor); + CompletableFuture monthlyAvgFuture = CompletableFuture.supplyAsync( + () -> pileBasicInfoService.getMonthlyAvgElectricity(fMonthStart, fMonthEnd), threadPoolTaskExecutor); + CompletableFuture totalGunsFuture = CompletableFuture.supplyAsync( + () -> pileConnectorInfoService.countTotalConnectors(), threadPoolTaskExecutor); + CompletableFuture onlinePilesFuture = CompletableFuture.supplyAsync( + () -> pileConnectorInfoService.countOnlinePiles(), threadPoolTaskExecutor); + CompletableFuture dcPilesFuture = CompletableFuture.supplyAsync( + () -> pileConnectorInfoService.countDcPiles(), threadPoolTaskExecutor); + CompletableFuture acPilesFuture = CompletableFuture.supplyAsync( + () -> pileConnectorInfoService.countAcPiles(), threadPoolTaskExecutor); + + // 等待所有异步查询完成 + CompletableFuture.allOf( + situationFuture, totalPilesFuture, + totalUsersFuture, totalStationsFuture, dailyNewUsersFuture, + todayAmountFuture, todayElecFuture, monthlyAvgFuture, + totalGunsFuture, onlinePilesFuture, dcPilesFuture, acPilesFuture + ).join(); + + // === 第三步:组装结果 === + IndexGeneralSituationVO situation = situationFuture.get(); + String totalChargingAmount = situation.getTotalChargingAmount(); + String totalChargingDegree = situation.getTotalChargingDegree(); + Long totalPileCount = totalPilesFuture.get(); + // 总订单数从settle_order_report的GROUP BY结果中获取(charge_num汇总) + String totalOrderCountStr = situation.getTotalChargingQuantity(); + Long totalOrderCount = (totalOrderCountStr != null && !totalOrderCountStr.isEmpty()) + ? Long.parseLong(totalOrderCountStr.replaceAll("[.](.*)", "")) : 0L; + + // demo账号数据放大3倍 + if (isDemo) { + BigDecimal multiplier = new BigDecimal(Constants.THREE); + totalChargingAmount = new BigDecimal(situation.getTotalSettleAmount()).multiply(multiplier).toString(); + totalChargingDegree = new BigDecimal(totalChargingDegree).multiply(multiplier).toString(); + totalPileCount = totalPileCount != null ? totalPileCount * 3 : 0L; + totalOrderCount = totalOrderCount * 3; + } + + overviewVO.setTotalUsers(totalUsersFuture.get()); + overviewVO.setTotalOrders(totalOrderCount); + overviewVO.setTotalTransactionAmount(totalChargingAmount); + overviewVO.setTotalElectricity(totalChargingDegree); + overviewVO.setTotalPiles(totalPileCount != null ? totalPileCount : 0L); + overviewVO.setTotalStations(totalStationsFuture.get()); + overviewVO.setDailyNewUsers(dailyNewUsersFuture.get()); + BigDecimal todayAmount = todayAmountFuture.get(); overviewVO.setTodayTransactionAmount(todayAmount != null ? todayAmount.toPlainString() : "0"); - java.math.BigDecimal todayElec = pileBasicInfoService.getTodayElectricity(); + BigDecimal todayElec = todayElecFuture.get(); overviewVO.setTodayElectricity(todayElec != null ? todayElec.toPlainString() : "0"); - java.math.BigDecimal monthlyAvg = pileBasicInfoService.getMonthlyAvgElectricity(); + BigDecimal monthlyAvg = monthlyAvgFuture.get(); overviewVO.setMonthlyAvgElectricity(monthlyAvg != null ? monthlyAvg.toPlainString() : "0"); - overviewVO.setTotalGuns(pileConnectorInfoService.countTotalConnectors()); - overviewVO.setOnlinePiles(pileConnectorInfoService.countOnlinePiles()); - overviewVO.setOnlineStations(pileConnectorInfoService.countDcPiles()); - overviewVO.setOnlineGuns(pileConnectorInfoService.countAcPiles()); + overviewVO.setTotalGuns(totalGunsFuture.get()); + overviewVO.setOnlinePiles(onlinePilesFuture.get()); + overviewVO.setOnlineStations(dcPilesFuture.get()); + overviewVO.setOnlineGuns(acPilesFuture.get()); + // 节能减排计算 - java.math.BigDecimal totalElecKwh = new java.math.BigDecimal(generalSituation.getTotalChargingDegree()); - // 累计碳减排 (吨) = 累计充电量(kWh) × 0.5306 / 1000 - java.math.BigDecimal carbonKg = totalElecKwh.multiply(new java.math.BigDecimal("0.5306")); - java.math.BigDecimal carbonTon = carbonKg.divide(new java.math.BigDecimal("1000"), 2, java.math.RoundingMode.HALF_UP); + BigDecimal totalElecKwh = new BigDecimal(totalChargingDegree); + BigDecimal carbonKg = totalElecKwh.multiply(new BigDecimal("0.5306")); + BigDecimal carbonTon = carbonKg.divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP); overviewVO.setCarbonReduction(carbonTon.toPlainString()); - // 单次充电平均减碳量 (kg) = 累计碳减排量(kg) / 总订单数 - Long totalOrderCount = overviewVO.getTotalOrders(); if (totalOrderCount != null && totalOrderCount > 0) { - java.math.BigDecimal avgCarbon = carbonKg.divide(new java.math.BigDecimal(totalOrderCount), 2, java.math.RoundingMode.HALF_UP); + BigDecimal avgCarbon = carbonKg.divide(new BigDecimal(totalOrderCount), 2, RoundingMode.HALF_UP); overviewVO.setAvgCarbonPerOrder(avgCarbon.toPlainString()); } else { overviewVO.setAvgCarbonPerOrder("0"); } - // 节约燃油 (升) = 累计充电量(kWh) × 8 / 15 - java.math.BigDecimal fuelSaved = totalElecKwh.multiply(new java.math.BigDecimal("8")) - .divide(new java.math.BigDecimal("15"), 2, java.math.RoundingMode.HALF_UP); + BigDecimal fuelSaved = totalElecKwh.multiply(new BigDecimal("8")) + .divide(new BigDecimal("15"), 2, RoundingMode.HALF_UP); overviewVO.setFuelSaved(fuelSaved.toPlainString()); - // 相当于替代标准煤 (吨) = 累计充电量(kWh) × 0.000404 - java.math.BigDecimal coalSaved = totalElecKwh.multiply(new java.math.BigDecimal("0.000404")) - .setScale(2, java.math.RoundingMode.HALF_UP); + BigDecimal coalSaved = totalElecKwh.multiply(new BigDecimal("0.000404")) + .setScale(2, RoundingMode.HALF_UP); overviewVO.setStandardCoalSaved(coalSaved.toPlainString()); + response = new RestApiResponse<>(overviewVO); } catch (Exception e) { logger.error("大数据平台总览数据查询错误", e); @@ -176,6 +298,51 @@ public class indexController extends BaseController { return response; } + /** + * 权限参数内部类 + */ + private static class AuthParams { + boolean isPlatformAdmin = false; + List merchantIdList = new ArrayList<>(); + List stationIdList = new ArrayList<>(); + } + + /** + * 解析当前用户权限参数 + * - 平台管理员:标记isPlatformAdmin=true,不需要任何过滤条件 + * - 运营商管理员:根据deptId获取merchantId + * - 站点管理员:使用stationId + */ + private AuthParams resolveAuthParams() { + AuthParams params = new AuthParams(); + AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap(); + if (authorizedMap == null) { + return params; + } + List stationDeptIds = authorizedMap.getStationDeptIds(); + List merchantDeptIds = authorizedMap.getMerchantDeptIds(); + + if (!CollectionUtils.isEmpty(stationDeptIds)) { + // 站点管理员:使用站点维度 + List list = pileStationInfoService.queryByStationDeptIds(stationDeptIds); + if (!CollectionUtils.isEmpty(list)) { + params.stationIdList.addAll(list); + } + } else if (!CollectionUtils.isEmpty(merchantDeptIds)) { + // 运营商管理员:根据deptId获取merchantId + for (String deptId : merchantDeptIds) { + PileMerchantInfo merchant = pileMerchantInfoService.queryInfoByDeptId(deptId); + if (merchant != null && merchant.getId() != null) { + params.merchantIdList.add(String.valueOf(merchant.getId())); + } + } + } else { + // 平台管理员:直接查全量,不需要任何过滤 + params.isPlatformAdmin = true; + } + return params; + } + /** * 大数据平台-充电站地图数据 */ @@ -190,7 +357,7 @@ public class indexController extends BaseController { logger.error("大数据平台充电站地图数据查询错误", e); response = new RestApiResponse<>("00200006", "大数据平台充电站地图数据查询错误"); } - logger.info("大数据平台充电站地图数据查询 result:{}", JSON.toJSONString(response)); + // logger.info("大数据平台充电站地图数据查询 result:{}", JSON.toJSONString(response)); return response; } @@ -255,4 +422,24 @@ public class indexController extends BaseController { return response; } + /** + * 大数据平台-站点订单排行(前10条) + */ + @PostMapping("/getStationOrderRank") + public RestApiResponse getStationOrderRank() { + logger.info("大数据平台站点订单排行查询"); + RestApiResponse response; + try { + BusinessOperationAnalysisQueryDTO dto = new BusinessOperationAnalysisQueryDTO(); + dto.setPageNum(1); + dto.setPageSize(10); + com.jsowell.common.core.page.PageResponse pageResponse = businessFinancialService.getStationOrderRank(dto); + response = new RestApiResponse<>(pageResponse); + } catch (Exception e) { + logger.error("大数据平台站点订单排行查询错误", e); + response = new RestApiResponse<>("00200010", "站点订单排行查询错误"); + } + return response; + } + } diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java index 700a511b3..251740cc9 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java +++ b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java @@ -226,6 +226,8 @@ public class RedisCache { List dataList = entry.getValue(); if (dataList != null && !dataList.isEmpty()) { + // 先删除旧数据,避免rightPushAll追加导致重复 + redisTemplate.delete(key); Long count = redisTemplate.opsForList().rightPushAll(key, dataList); totalCount += (count != null ? count : 0); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/IndexQueryDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/IndexQueryDTO.java index 4381368df..c624f2820 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/dto/IndexQueryDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/IndexQueryDTO.java @@ -20,6 +20,11 @@ public class IndexQueryDTO extends BaseEntity { private List stationIdList; + /** + * 商户id列表(用于大数据平台按商户维度查询,避免展开为大量stationId) + */ + private List merchantIdList; + private String startTime; private String endTime; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberBasicInfoMapper.java index 662b5794e..c3612ad16 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberBasicInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/MemberBasicInfoMapper.java @@ -149,9 +149,9 @@ public interface MemberBasicInfoMapper { Long countTotalMembers(); /** - * 统计今日新增会员数 + * 统计今日新增会员数,日期由代码传入 * * @return 今日新增会员数 */ - Long countTodayNewMembers(); + Long countTodayNewMembers(@Param("startTime") String startTime, @Param("endTime") String endTime); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java index 12922ca11..ab44805da 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/OrderBasicInfoMapper.java @@ -490,4 +490,14 @@ public interface OrderBasicInfoMapper { * @return 时段分布数据 */ List getTimeDistribution(@Param("dto") IndexQueryDTO dto); + + /** + * 大数据平台-今日订单金额明细(Java汇总),日期由代码传入 + */ + List getTodayOrderAmountRows(@Param("startTime") String startTime, @Param("endTime") String endTime); + + /** + * 大数据平台-今日充电电量明细(Java汇总),日期由代码传入 + */ + List getTodayElectricityRows(@Param("startTime") String startTime, @Param("endTime") String endTime); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java index e22bfbca4..474d7fae0 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java @@ -142,7 +142,7 @@ public interface PileBasicInfoMapper { * @param dto 站点Id * @return 首页基本信息 */ - public IndexGeneralSituationVO getGeneralSituationInfo(@Param("IndexQueryDTO")IndexQueryDTO dto); + public List getGeneralSituationInfo(@Param("IndexQueryDTO")IndexQueryDTO dto); /** * 通过会员id查询个人桩列表 @@ -181,23 +181,29 @@ public interface PileBasicInfoMapper { int movePile2AnotherStation(ReplaceMerchantStationDTO dto); /** - * 查询当日累计交易金额 - * - * @return 当日交易金额 - */ - java.math.BigDecimal getTodayTransactionAmount(); - - /** - * 查询当日充电电量 - * - * @return 当日充电电量 - */ - java.math.BigDecimal getTodayElectricity(); - - /** - * 查询本月日均充电电量 + * 查询本月日均充电电量,日期由代码传入 * * @return 月均充电电量 */ - java.math.BigDecimal getMonthlyAvgElectricity(); + List getMonthlyAvgElectricity(@Param("monthStartDate") String monthStartDate, @Param("monthEndDate") String monthEndDate); + + /** + * 根据站点ID列表统计充电桩总数 + */ + Long countTotalPilesByStationIds(@Param("stationIdList") List stationIdList); + + /** + * 根据商户ID列表统计充电桩总数 + */ + Long countTotalPilesByMerchantIds(@Param("merchantIdList") List merchantIdList); + + /** + * 按merchantId分组汇总settle_order_report(每个商户一行,Java再汇总) + */ + List getSettleReportGroupByMerchant(@Param("merchantIdList") List merchantIdList); + + /** + * 按stationId分组汇总settle_order_report(每个站点一行,Java再汇总) + */ + List getSettleReportGroupByStation(@Param("stationIdList") List stationIdList); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/MemberBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/MemberBasicInfoService.java index baad42865..b6ed5203e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/MemberBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/MemberBasicInfoService.java @@ -191,9 +191,9 @@ public interface MemberBasicInfoService { Long countTotalMembers(); /** - * 统计今日新增会员数 + * 统计今日新增会员数,日期由代码传入 * * @return 今日新增会员数 */ - Long countTodayNewMembers(); + Long countTodayNewMembers(String startTime, String endTime); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java index ffc852f28..5e1e18238 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/OrderBasicInfoService.java @@ -704,4 +704,18 @@ public interface OrderBasicInfoService{ * 大数据平台-充电时段分布 */ List getTimeDistribution(IndexQueryDTO dto); + + /** + * 大数据平台-今日交易金额(Java汇总) + * + * @return 今日已完成订单的交易金额合计 + */ + java.math.BigDecimal getTodayTransactionAmount(String startTime, String endTime); + + /** + * 大数据平台-今日充电电量(Java汇总) + * + * @return 今日已完成订单的充电电量合计(kWh) + */ + java.math.BigDecimal getTodayElectricity(String startTime, String endTime); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java index a994fcaec..5f069c91a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/PileBasicInfoService.java @@ -260,23 +260,29 @@ public interface PileBasicInfoService { int movePile2AnotherStation(ReplaceMerchantStationDTO dto); /** - * 查询当日累计交易金额 - * - * @return 当日交易金额 - */ - java.math.BigDecimal getTodayTransactionAmount(); - - /** - * 查询当日充电电量 - * - * @return 当日充电电量 - */ - java.math.BigDecimal getTodayElectricity(); - - /** - * 查询本月日均充电电量 + * 查询本月日均充电电量,日期由代码传入 * * @return 月均充电电量 */ - java.math.BigDecimal getMonthlyAvgElectricity(); + java.math.BigDecimal getMonthlyAvgElectricity(String monthStartDate, String monthEndDate); + + /** + * 根据站点ID列表统计充电桩总数 + */ + Long countTotalPilesByStationIds(List stationIdList); + + /** + * 根据商户ID列表统计充电桩总数 + */ + Long countTotalPilesByMerchantIds(List merchantIdList); + + /** + * 大数据平台专用:根据商户ID查settle_order_report GROUP BY merchant_id,Java汇总返回 + */ + IndexGeneralSituationVO aggregateReportByMerchantIds(List merchantIdList); + + /** + * 大数据平台专用:根据站点ID查settle_order_report GROUP BY station_id,Java汇总返回 + */ + IndexGeneralSituationVO aggregateReportByStationIds(List stationIdList); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberBasicInfoServiceImpl.java index fd0457aa5..058d4dbd3 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/MemberBasicInfoServiceImpl.java @@ -921,8 +921,8 @@ public class MemberBasicInfoServiceImpl implements MemberBasicInfoService { } @Override - public Long countTodayNewMembers() { - return memberBasicInfoMapper.countTodayNewMembers(); + public Long countTodayNewMembers(String startTime, String endTime) { + return memberBasicInfoMapper.countTodayNewMembers(startTime, endTime); } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java index 63bc66d93..7f520642e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/OrderBasicInfoServiceImpl.java @@ -6706,5 +6706,33 @@ public class OrderBasicInfoServiceImpl implements OrderBasicInfoService { public List getTimeDistribution(IndexQueryDTO dto) { return orderBasicInfoMapper.getTimeDistribution(dto); } + + @Override + public java.math.BigDecimal getTodayTransactionAmount(String startTime, String endTime) { + List rows = orderBasicInfoMapper.getTodayOrderAmountRows(startTime, endTime); + java.math.BigDecimal total = java.math.BigDecimal.ZERO; + if (rows != null) { + for (java.math.BigDecimal amount : rows) { + if (amount != null) { + total = total.add(amount); + } + } + } + return total; + } + + @Override + public java.math.BigDecimal getTodayElectricity(String startTime, String endTime) { + List rows = orderBasicInfoMapper.getTodayElectricityRows(startTime, endTime); + java.math.BigDecimal total = java.math.BigDecimal.ZERO; + if (rows != null) { + for (java.math.BigDecimal elec : rows) { + if (elec != null) { + total = total.add(elec); + } + } + } + return total; + } } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java index ed169e10c..0b276b0fe 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -985,8 +985,9 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { } log.info("后管首页基本信息查询 authorizedMap:{}, dto:{}", JSON.toJSONString(authorizedMap), JSON.toJSONString(dto)); dto.setStationIdList(stationIdList); - // IndexGeneralSituationVO generalInfo = pileBasicInfoMapper.getGeneralSituation(dto); - IndexGeneralSituationVO generalInfo = pileBasicInfoMapper.getGeneralSituationInfo(dto); + // 查询settle_order_report原始行记录,Java汇总(不用SQL的SUM) + List reportRows = pileBasicInfoMapper.getGeneralSituationInfo(dto); + IndexGeneralSituationVO generalInfo = aggregateSituationRows(reportRows); List pileInfoVOS = queryPileDetailList(stationIdList); // 对集合根据pileSn进行去重 @@ -1635,17 +1636,72 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService { } @Override - public java.math.BigDecimal getTodayTransactionAmount() { - return pileBasicInfoMapper.getTodayTransactionAmount(); + public java.math.BigDecimal getMonthlyAvgElectricity(String monthStartDate, String monthEndDate) { + List rows = pileBasicInfoMapper.getMonthlyAvgElectricity(monthStartDate, monthEndDate); + if (rows == null || rows.isEmpty()) { + return java.math.BigDecimal.ZERO; + } + java.math.BigDecimal total = java.math.BigDecimal.ZERO; + for (java.math.BigDecimal val : rows) { + if (val != null) { + total = total.add(val); + } + } + return total.divide(new java.math.BigDecimal(rows.size()), 2, java.math.RoundingMode.HALF_UP); } @Override - public java.math.BigDecimal getTodayElectricity() { - return pileBasicInfoMapper.getTodayElectricity(); + public Long countTotalPilesByStationIds(List stationIdList) { + return pileBasicInfoMapper.countTotalPilesByStationIds(stationIdList); } @Override - public java.math.BigDecimal getMonthlyAvgElectricity() { - return pileBasicInfoMapper.getMonthlyAvgElectricity(); + public Long countTotalPilesByMerchantIds(List merchantIdList) { + return pileBasicInfoMapper.countTotalPilesByMerchantIds(merchantIdList); + } + + @Override + public IndexGeneralSituationVO aggregateReportByMerchantIds(List merchantIdList) { + List rows = pileBasicInfoMapper.getSettleReportGroupByMerchant(merchantIdList); + return aggregateSituationRows(rows); + } + + @Override + public IndexGeneralSituationVO aggregateReportByStationIds(List stationIdList) { + List rows = pileBasicInfoMapper.getSettleReportGroupByStation(stationIdList); + return aggregateSituationRows(rows); + } + + /** + * Java层汇总settle_order_report GROUP BY结果(每行是一个商户/站点的汇总) + */ + private IndexGeneralSituationVO aggregateSituationRows(List rows) { + IndexGeneralSituationVO result = new IndexGeneralSituationVO(); + BigDecimal totalAmount = BigDecimal.ZERO; + BigDecimal settleAmount = BigDecimal.ZERO; + BigDecimal totalDegree = BigDecimal.ZERO; + long totalQuantity = 0L; + if (rows != null) { + for (IndexGeneralSituationVO row : rows) { + if (row.getTotalChargingAmount() != null) { + totalAmount = totalAmount.add(new BigDecimal(row.getTotalChargingAmount())); + } + if (row.getTotalSettleAmount() != null) { + settleAmount = settleAmount.add(new BigDecimal(row.getTotalSettleAmount())); + } + if (row.getTotalChargingDegree() != null) { + totalDegree = totalDegree.add(new BigDecimal(row.getTotalChargingDegree())); + } + if (row.getTotalChargingQuantity() != null && !row.getTotalChargingQuantity().isEmpty()) { + String qty = row.getTotalChargingQuantity().replaceAll("[.](.*)", ""); + totalQuantity += Long.parseLong(qty); + } + } + } + result.setTotalChargingAmount(totalAmount.toPlainString()); + result.setTotalSettleAmount(settleAmount.toPlainString()); + result.setTotalChargingDegree(totalDegree.toPlainString()); + result.setTotalChargingQuantity(String.valueOf(totalQuantity)); + return result; } } diff --git a/jsowell-pile/src/main/resources/mapper/pile/MemberBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/MemberBasicInfoMapper.xml index 412058dfe..b0d68baf0 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/MemberBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/MemberBasicInfoMapper.xml @@ -344,6 +344,8 @@ diff --git a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml index 1ba533337..86f269137 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/OrderBasicInfoMapper.xml @@ -3703,4 +3703,25 @@ GROUP BY HOUR(t1.create_time) ORDER BY hour ASC + + + + + + diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml index 3cf8d28c3..8d9c6c348 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml @@ -400,10 +400,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select ifnull(sum(t1.total_amount), 0) - from settle_order_report t1 - where t1.del_flag = '0' - and t1.trade_date = DATE_FORMAT(CURDATE(), '%Y-%m-%d') - - - - + + + + + + + + + +