From 76f23e7d82d018e615713ca0b23835795772df7c Mon Sep 17 00:00:00 2001 From: Lemon Date: Mon, 15 Jun 2026 14:17:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=AF=A2=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E5=8F=B0=E9=A6=96=E9=A1=B5=E6=B1=87=E6=80=BB=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E3=80=81=E6=9F=A5=E8=AF=A2=E7=BB=93=E7=AE=97=E6=97=A5?= =?UTF-8?q?=E6=8A=A5=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/BusinessFinancialController.java | 57 +++ .../service/BusinessFinancialService.java | 20 + .../impl/BusinessFinancialServiceImpl.java | 390 ++++++++++++++++++ 3 files changed, 467 insertions(+) diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessFinancialController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessFinancialController.java index c3dbf5f90..746d2aa77 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessFinancialController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/business/BusinessFinancialController.java @@ -9,15 +9,19 @@ import com.jsowell.common.response.RestApiResponse; import com.google.common.collect.ImmutableMap; import com.jsowell.pile.dto.MerchantOrderReportDTO; import com.jsowell.pile.dto.ParkingCouponRecordQueryDTO; +import com.jsowell.pile.dto.business.BusinessDailySettlementQueryDTO; import com.jsowell.pile.dto.business.BusinessEfficiencyQueryDTO; import com.jsowell.pile.dto.business.BusinessOperationAnalysisQueryDTO; import com.jsowell.pile.dto.business.BusinessScaleQueryDTO; +import com.jsowell.pile.dto.business.BusinessWorkbenchSummaryQueryDTO; +import com.jsowell.pile.vo.uniapp.business.BusinessDailySettlementDetailVO; import com.jsowell.pile.service.BusinessFinancialService; import com.jsowell.pile.vo.uniapp.business.BusinessEfficiencyAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessEfficiencyVO; import com.jsowell.pile.vo.uniapp.business.BusinessGunEfficiencyAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessOperationAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessScaleVO; +import com.jsowell.pile.vo.uniapp.business.BusinessWorkbenchSummaryVO; import com.jsowell.pile.vo.web.MerchantOrderReportVO; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +42,59 @@ public class BusinessFinancialController extends BaseController { @Autowired private BusinessFinancialService businessFinancialService; + /** + * 查询工作台首页汇总 + * + * @param dto 查询参数。前端可选传stationIdList,运营商和日期范围由后端按登录账号解析。 + * @return 工作台首页汇总 + */ + @PostMapping("/workbenchSummary") + public RestApiResponse getWorkbenchSummary(@RequestBody(required = false) BusinessWorkbenchSummaryQueryDTO dto) { + logger.info("查询工作台首页汇总 params:{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + BusinessWorkbenchSummaryVO result = businessFinancialService.getWorkbenchSummary(dto); + response = new RestApiResponse<>(result); + logger.info("查询工作台首页汇总成功 today:{}, stationCount:{}", + result.getToday(), result.getStationCount()); + } catch (BusinessException e) { + logger.warn("查询工作台首页汇总业务异常 code:{}, message:{}", e.getCode(), e.getMessage(), e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("查询工作台首页汇总系统异常 params:{}", JSONObject.toJSONString(dto), e); + response = new RestApiResponse<>(e); + } + return response; + } + + /** + * 查询结算日报详情 + * + * @param dto 查询参数。前端传开始日期、结束日期,可选传stationIdList。 + * @return 结算日报详情 + */ + @PostMapping("/dailySettlementDetail") + public RestApiResponse getDailySettlementDetail(@RequestBody BusinessDailySettlementQueryDTO dto) { + logger.info("查询结算日报详情 params:{}", JSONObject.toJSONString(dto)); + RestApiResponse response; + try { + if (dto == null) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + BusinessDailySettlementDetailVO result = businessFinancialService.getDailySettlementDetail(dto); + response = new RestApiResponse<>(result); + logger.info("查询结算日报详情成功 startTime:{}, endTime:{}", + dto.getStartTime(), dto.getEndTime()); + } catch (BusinessException e) { + logger.warn("查询结算日报详情业务异常 code:{}, message:{}", e.getCode(), e.getMessage(), e); + response = new RestApiResponse<>(e.getCode(), e.getMessage()); + } catch (Exception e) { + logger.error("查询结算日报详情系统异常 params:{}", JSONObject.toJSONString(dto), e); + response = new RestApiResponse<>(e); + } + return response; + } + /** * 我的钱包界面查询接口 * diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/BusinessFinancialService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/BusinessFinancialService.java index 87fb249f6..683d24c6e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/BusinessFinancialService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/BusinessFinancialService.java @@ -3,20 +3,40 @@ package com.jsowell.pile.service; import com.jsowell.common.core.page.PageResponse; import com.jsowell.pile.dto.MerchantOrderReportDTO; import com.jsowell.pile.dto.ParkingCouponRecordQueryDTO; +import com.jsowell.pile.dto.business.BusinessDailySettlementQueryDTO; import com.jsowell.pile.dto.business.BusinessOperationAnalysisQueryDTO; import com.jsowell.pile.dto.business.BusinessEfficiencyQueryDTO; import com.jsowell.pile.dto.business.BusinessScaleQueryDTO; +import com.jsowell.pile.dto.business.BusinessWorkbenchSummaryQueryDTO; +import com.jsowell.pile.vo.uniapp.business.BusinessDailySettlementDetailVO; import com.jsowell.pile.vo.uniapp.business.BusinessEfficiencyAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessEfficiencyVO; import com.jsowell.pile.vo.uniapp.business.BusinessGunEfficiencyAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessOperationAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessScaleVO; +import com.jsowell.pile.vo.uniapp.business.BusinessWorkbenchSummaryVO; import com.jsowell.pile.vo.web.MerchantOrderReportVO; import com.jsowell.pile.vo.web.ParkingCouponRecordVO; public interface BusinessFinancialService { MerchantOrderReportVO getMyWallet(MerchantOrderReportDTO dto); + /** + * 查询工作台首页汇总 + * + * @param dto 查询条件 + * @return 工作台首页汇总 + */ + BusinessWorkbenchSummaryVO getWorkbenchSummary(BusinessWorkbenchSummaryQueryDTO dto); + + /** + * 查询结算日报详情 + * + * @param dto 查询条件 + * @return 结算日报详情 + */ + BusinessDailySettlementDetailVO getDailySettlementDetail(BusinessDailySettlementQueryDTO dto); + /** * 分页查询停车优免记录 * diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/BusinessFinancialServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/BusinessFinancialServiceImpl.java index a896626e2..6752dac78 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/BusinessFinancialServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/BusinessFinancialServiceImpl.java @@ -12,14 +12,18 @@ import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.exception.BusinessException; import com.jsowell.pile.dto.MerchantOrderReportDTO; import com.jsowell.pile.dto.ParkingCouponRecordQueryDTO; +import com.jsowell.pile.dto.QueryOrderDTO; +import com.jsowell.pile.dto.business.BusinessDailySettlementQueryDTO; import com.jsowell.pile.dto.business.BusinessEfficiencyQueryDTO; import com.jsowell.pile.dto.business.BusinessOperationAnalysisQueryDTO; import com.jsowell.pile.dto.business.BusinessOperationDateRangeDTO; import com.jsowell.pile.dto.business.BusinessOperationSummaryDTO; import com.jsowell.pile.dto.business.BusinessScaleQueryDTO; +import com.jsowell.pile.dto.business.BusinessWorkbenchSummaryQueryDTO; import com.jsowell.pile.domain.PileConnectorInfo; import com.jsowell.pile.domain.PileStationInfo; import com.jsowell.pile.domain.SettleOrderReport; +import com.jsowell.pile.mapper.OrderBasicInfoMapper; import com.jsowell.pile.service.BusinessFinancialService; import com.jsowell.pile.service.CarCouponRecordService; import com.jsowell.pile.service.ClearingWithdrawInfoService; @@ -28,6 +32,7 @@ import com.jsowell.pile.service.PileStationInfoService; import com.jsowell.pile.service.SettleOrderReportService; import com.jsowell.pile.util.UserUtils; import com.jsowell.pile.vo.base.ConnectorInfoVO; +import com.jsowell.pile.vo.uniapp.business.BusinessDailySettlementDetailVO; import com.jsowell.pile.vo.uniapp.business.BusinessEfficiencyAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessGunEfficiencyAnalysisVO; import com.jsowell.pile.vo.uniapp.business.BusinessEfficiencyVO; @@ -38,7 +43,9 @@ import com.jsowell.pile.vo.uniapp.business.BusinessScaleChartVO; import com.jsowell.pile.vo.uniapp.business.BusinessScaleMetricVO; import com.jsowell.pile.vo.uniapp.business.BusinessScaleVO; import com.jsowell.pile.vo.uniapp.business.BusinessStationRankVO; +import com.jsowell.pile.vo.uniapp.business.BusinessWorkbenchSummaryVO; import com.jsowell.pile.vo.web.MerchantOrderReportVO; +import com.jsowell.pile.vo.web.OrderStatisticsVO; import com.jsowell.pile.vo.web.ParkingCouponRecordVO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -52,6 +59,7 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -85,6 +93,18 @@ public class BusinessFinancialServiceImpl implements BusinessFinancialService { private static final String EFFICIENCY_METRIC_GUN_AVG_ELECTRICITY = "GUN_AVG_ELECTRICITY"; private static final String EFFICIENCY_METRIC_POWER_UTILIZATION = "POWER_UTILIZATION"; + private static final String SETTLEMENT_ITEM_SERVICE_FEE = "CHARGE_SERVICE_FEE"; + private static final String SETTLEMENT_ITEM_ELECTRICITY_FEE = "CHARGE_ELECTRICITY_FEE"; + private static final String SETTLEMENT_ITEM_PLATFORM_SUBSIDY = "PLATFORM_SERVICE_SUBSIDY"; + private static final String SETTLEMENT_ITEM_MERCHANT_PLATFORM_FEE = "MERCHANT_PLATFORM_SERVICE_FEE"; + private static final String WORKBENCH_CARD_ORDER_MANAGEMENT = "ORDER_MANAGEMENT"; + private static final String WORKBENCH_CARD_BUSINESS_ADVISER = "BUSINESS_ADVISER"; + private static final String WORKBENCH_CARD_MY_WALLET = "MY_WALLET"; + private static final String WORKBENCH_CARD_DAILY_SETTLEMENT = "DAILY_SETTLEMENT"; + private static final String WORKBENCH_CARD_PARKING_DISCOUNT = "PARKING_DISCOUNT"; + private static final int STATION_QUERY_BATCH_SIZE = 500; + private static final int DEFAULT_DECIMAL_SCALE = 2; + /** * 财务查询通用线程池(支持多方法并行查询) * 核心线程数4:覆盖经营规模(2路)、我的钱包(3路)、经营分析(2路)、枪均效率(2路)等场景 @@ -114,6 +134,114 @@ public class BusinessFinancialServiceImpl implements BusinessFinancialService { @Autowired private PileConnectorInfoService pileConnectorInfoService; + @Autowired + private OrderBasicInfoMapper orderBasicInfoMapper; + + /** + * 查询工作台首页汇总 + * + * @param dto 查询条件 + * @return 工作台首页汇总 + */ + @Override + public BusinessWorkbenchSummaryVO getWorkbenchSummary(BusinessWorkbenchSummaryQueryDTO dto) { + if (dto == null) { + dto = new BusinessWorkbenchSummaryQueryDTO(); + } + + LocalDate today = LocalDate.now(); + String todayDate = today.toString(); + String recentStartTime = today.minusDays(6).toString(); + String recentEndTime = todayDate; + + FinancialScope scope = resolveFinancialScope(dto.getStationIdList()); + + CompletableFuture todayOrderCountFuture = CompletableFuture.supplyAsync( + () -> countTodayOrderCount(scope.getStationIdList(), todayDate), FINANCIAL_THREAD_POOL); + CompletableFuture> recentReportsFuture = CompletableFuture.supplyAsync( + () -> queryRawReports(scope.getStationIdList(), recentStartTime, recentEndTime), FINANCIAL_THREAD_POOL); + + List recentReports = recentReportsFuture.join(); + ReportSummary recentSummary = buildReportSummary(recentReports); + ReportSummary todaySummary = buildReportSummary(recentReports, todayDate); + Long todayOrderCount = todayOrderCountFuture.join(); + Integer pendingParkingAppealCount = countPendingParkingAppeal(scope.getStationIdList()); + + List cardList = new ArrayList<>(); + cardList.add(buildWorkbenchCard(WORKBENCH_CARD_ORDER_MANAGEMENT, "订单管理", "今日订单量", + BigDecimal.valueOf(todayOrderCount), "单")); + cardList.add(buildWorkbenchCard(WORKBENCH_CARD_BUSINESS_ADVISER, "经营参谋", "近7天净现金流", + formatMoney(recentSummary.getOrderTotalAmount()), "元")); + cardList.add(buildWorkbenchCard(WORKBENCH_CARD_MY_WALLET, "我的钱包", "今日到账", + formatMoney(todaySummary.getArrivalAmount()), "元")); + cardList.add(buildWorkbenchCard(WORKBENCH_CARD_DAILY_SETTLEMENT, "结算日报", "近7天净现金流", + formatMoney(recentSummary.getSettlementAmount()), "元")); + cardList.add(buildWorkbenchCard(WORKBENCH_CARD_PARKING_DISCOUNT, "停车减免", "待处理申诉", + BigDecimal.valueOf(pendingParkingAppealCount), "条")); + + return BusinessWorkbenchSummaryVO.builder() + .today(todayDate) + .recentStartTime(recentStartTime) + .recentEndTime(recentEndTime) + .merchantIdList(scope.getMerchantIdList()) + .stationIdList(scope.getStationIdList()) + .stationCount(scope.getStationIdList() != null ? scope.getStationIdList().size() : null) + .todayOrderCount(todayOrderCount) + .recentNetCashFlow(formatMoney(recentSummary.getOrderTotalAmount())) + .todayArrivalAmount(formatMoney(todaySummary.getArrivalAmount())) + .recentSettlementNetCashFlow(formatMoney(recentSummary.getSettlementAmount())) + .pendingParkingAppealCount(pendingParkingAppealCount) + .cardList(cardList) + .build(); + } + + /** + * 查询结算日报详情 + * + * @param dto 查询条件 + * @return 结算日报详情 + */ + @Override + public BusinessDailySettlementDetailVO getDailySettlementDetail(BusinessDailySettlementQueryDTO dto) { + validateDailySettlementQuery(dto); + + FinancialScope scope = resolveFinancialScope(dto.getStationIdList()); + List reportList = queryRawReports(scope.getStationIdList(), dto.getStartTime(), dto.getEndTime()); + ReportSummary summary = buildReportSummary(reportList); + BigDecimal incomeTotalAmount = summary.getIncomeTotalAmount(); + BigDecimal merchantPlatformServiceFee = summary.getMerchantPlatformServiceFee(); + BigDecimal expenseTotalAmount = merchantPlatformServiceFee; + + List incomeItems = new ArrayList<>(); + incomeItems.add(buildSettlementItem(SETTLEMENT_ITEM_SERVICE_FEE, "充电服务费(元)", summary.getChargeServiceFee())); + incomeItems.add(buildSettlementItem(SETTLEMENT_ITEM_ELECTRICITY_FEE, "充电电费(元)", summary.getChargeElectricityFee())); + incomeItems.add(buildSettlementItem(SETTLEMENT_ITEM_PLATFORM_SUBSIDY, "平台给商户的服务费补贴(元)", summary.getPlatformServiceSubsidy())); + + List expenseItems = new ArrayList<>(); + expenseItems.add(buildSettlementItem(SETTLEMENT_ITEM_MERCHANT_PLATFORM_FEE, "商户给平台的服务费(元)", merchantPlatformServiceFee)); + + return BusinessDailySettlementDetailVO.builder() + .startTime(dto.getStartTime()) + .endTime(dto.getEndTime()) + .merchantIdList(scope.getMerchantIdList()) + .stationCount(scope.getStationIdList() != null ? scope.getStationIdList().size() : null) + .settlementAmount(formatMoney(summary.getSettlementAmount())) + .incomeTotalAmount(formatMoney(incomeTotalAmount)) + .expenseTotalAmount(formatMoney(expenseTotalAmount)) + .totalOrderCount(BigDecimalUtils.normalize(summary.getTotalOrderCount())) + .orderTotalAmount(formatMoney(summary.getOrderTotalAmount())) + .orderElectricity(formatQuantity(summary.getOrderElectricity())) + .chargeServiceFee(formatMoney(summary.getChargeServiceFee())) + .chargeElectricityFee(formatMoney(summary.getChargeElectricityFee())) + .platformServiceSubsidy(formatMoney(summary.getPlatformServiceSubsidy())) + .merchantPlatformServiceFee(formatMoney(merchantPlatformServiceFee)) + .tradeAmount(formatMoney(summary.getTradeAmount())) + .tradeFee(formatMoney(summary.getTradeFee())) + .incomeItems(incomeItems) + .expenseItems(expenseItems) + .build(); + } + /** * 我的钱包查询 * 优化:订单报表DB、汇付余额HTTP、提现金额DB 三个独立数据源并行查询 @@ -467,6 +595,268 @@ public class BusinessFinancialServiceImpl implements BusinessFinancialService { return authorizedStationIds; } + /** + * 校验结算日报详情查询条件 + * + * @param dto 查询条件 + */ + private void validateDailySettlementQuery(BusinessDailySettlementQueryDTO dto) { + if (dto == null + || StringUtils.isBlank(dto.getStartTime()) + || StringUtils.isBlank(dto.getEndTime())) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + try { + LocalDate startDate = LocalDate.parse(dto.getStartTime()); + LocalDate endDate = LocalDate.parse(dto.getEndTime()); + if (endDate.isBefore(startDate)) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + } catch (BusinessException e) { + throw e; + } catch (Exception e) { + throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR); + } + } + + /** + * 解析财务接口通用账号和站点范围 + */ + private FinancialScope resolveFinancialScope(List stationIdList) { + List merchantIdList = UserUtils.getFirstMerchantIdList(); + List queryStationIds = stationIdList; + if (CollectionUtils.isEmpty(queryStationIds)) { + if (CollectionUtils.isEmpty(merchantIdList)) { + return new FinancialScope(merchantIdList, Collections.emptyList()); + } + queryStationIds = pileStationInfoService.getStationIdsByMerchantIds(merchantIdList); + if (queryStationIds == null) { + queryStationIds = Collections.emptyList(); + } + } + return new FinancialScope(merchantIdList, resolveStationIds(queryStationIds)); + } + + /** + * 统计今日订单量 + */ + private Long countTodayOrderCount(List stationIdList, String today) { + if (stationIdList != null && stationIdList.isEmpty()) { + return 0L; + } + String startTime = today + " 00:00:00"; + String endTime = today + " 23:59:59"; + if (stationIdList == null || stationIdList.size() <= STATION_QUERY_BATCH_SIZE) { + QueryOrderDTO queryOrderDTO = QueryOrderDTO.builder() + .stationIdList(stationIdList) + .startTime(startTime) + .endTime(endTime) + .build(); + OrderStatisticsVO statistics = orderBasicInfoMapper.countBusinessOrderStatistics(queryOrderDTO); + return statistics != null && statistics.getOrderCount() != null ? statistics.getOrderCount() : 0L; + } + + long orderCount = 0L; + for (int i = 0; i < stationIdList.size(); i += STATION_QUERY_BATCH_SIZE) { + int endIndex = Math.min(i + STATION_QUERY_BATCH_SIZE, stationIdList.size()); + QueryOrderDTO queryOrderDTO = QueryOrderDTO.builder() + .stationIdList(stationIdList.subList(i, endIndex)) + .startTime(startTime) + .endTime(endTime) + .build(); + OrderStatisticsVO statistics = orderBasicInfoMapper.countBusinessOrderStatistics(queryOrderDTO); + if (statistics != null && statistics.getOrderCount() != null) { + orderCount += statistics.getOrderCount(); + } + } + return orderCount; + } + + /** + * 统计停车减免待处理申诉数 + */ + private Integer countPendingParkingAppeal(List stationIdList) { + if (stationIdList != null && stationIdList.isEmpty()) { + return 0; + } + // 当前停车减免模块暂无独立申诉状态数据源,预留工作台展示字段。 + return 0; + } + + /** + * 构建报表汇总数据 + */ + private ReportSummary buildReportSummary(List reportList) { + return buildReportSummary(reportList, null); + } + + /** + * 构建指定日期的报表汇总数据 + */ + private ReportSummary buildReportSummary(List reportList, String tradeDate) { + ReportSummary summary = new ReportSummary(); + if (CollectionUtils.isEmpty(reportList)) { + return summary; + } + for (SettleOrderReport report : reportList) { + if (StringUtils.isNotBlank(tradeDate) && !StringUtils.equals(tradeDate, report.getTradeDate())) { + continue; + } + summary.add(report); + } + return summary; + } + + /** + * 构建工作台卡片 + */ + private BusinessWorkbenchSummaryVO.WorkbenchCard buildWorkbenchCard(String cardCode, + String cardName, + String metricName, + BigDecimal metricValue, + String unit) { + return BusinessWorkbenchSummaryVO.WorkbenchCard.builder() + .cardCode(cardCode) + .cardName(cardName) + .metricName(metricName) + .metricValue(metricValue) + .unit(unit) + .build(); + } + + /** + * 构建结算项 + */ + private BusinessDailySettlementDetailVO.SettlementItem buildSettlementItem(String itemCode, + String itemName, + BigDecimal amount) { + return BusinessDailySettlementDetailVO.SettlementItem.builder() + .itemCode(itemCode) + .itemName(itemName) + .unit("元") + .amount(formatMoney(amount)) + .build(); + } + + /** + * 金额统一保留两位小数 + */ + private BigDecimal formatMoney(BigDecimal amount) { + return formatDecimal(amount); + } + + /** + * 数量统一保留两位小数 + */ + private BigDecimal formatQuantity(BigDecimal amount) { + return formatDecimal(amount); + } + + /** + * 数值统一保留两位小数 + */ + private BigDecimal formatDecimal(BigDecimal amount) { + return BigDecimalUtils.nullToZero(amount).setScale(DEFAULT_DECIMAL_SCALE, RoundingMode.HALF_UP); + } + + private static class FinancialScope { + private final List merchantIdList; + private final List stationIdList; + + private FinancialScope(List merchantIdList, List stationIdList) { + this.merchantIdList = merchantIdList; + this.stationIdList = stationIdList; + } + + private List getMerchantIdList() { + return merchantIdList; + } + + private List getStationIdList() { + return stationIdList; + } + } + + private static class ReportSummary { + private BigDecimal orderTotalAmount = BigDecimal.ZERO; + private BigDecimal totalOrderCount = BigDecimal.ZERO; + private BigDecimal orderElectricity = BigDecimal.ZERO; + private BigDecimal chargeServiceFee = BigDecimal.ZERO; + private BigDecimal chargeElectricityFee = BigDecimal.ZERO; + private BigDecimal platformServiceSubsidy = BigDecimal.ZERO; + private BigDecimal settlementAmount = BigDecimal.ZERO; + private BigDecimal tradeAmount = BigDecimal.ZERO; + private BigDecimal tradeFee = BigDecimal.ZERO; + private BigDecimal arrivalAmount = BigDecimal.ZERO; + + private void add(SettleOrderReport report) { + BigDecimal reportTotalAmount = BigDecimalUtils.nullToZero(report.getTotalAmount()); + BigDecimal reportSettleAmount = report.getSettleAmount() != null + ? report.getSettleAmount() : reportTotalAmount; + + orderTotalAmount = orderTotalAmount.add(reportTotalAmount); + totalOrderCount = totalOrderCount.add(BigDecimalUtils.parseOrZero(report.getChargeNum())); + orderElectricity = orderElectricity.add(BigDecimalUtils.nullToZero(report.getUseElectricity())); + chargeServiceFee = chargeServiceFee.add(BigDecimalUtils.nullToZero(report.getServiceAmount())); + chargeElectricityFee = chargeElectricityFee.add(BigDecimalUtils.nullToZero(report.getElectricityAmount())); + platformServiceSubsidy = platformServiceSubsidy.add(BigDecimalUtils.nullToZero(report.getVirtualAmount())); + settlementAmount = settlementAmount.add(reportSettleAmount); + tradeAmount = tradeAmount.add(BigDecimalUtils.nullToZero(report.getTradeAmount())); + tradeFee = tradeFee.add(BigDecimalUtils.nullToZero(report.getTradeFee())); + arrivalAmount = arrivalAmount.add(report.getTradeAmount() != null + ? report.getTradeAmount() : reportSettleAmount); + } + + private BigDecimal getIncomeTotalAmount() { + return chargeServiceFee.add(chargeElectricityFee).add(platformServiceSubsidy); + } + + private BigDecimal getMerchantPlatformServiceFee() { + BigDecimal fee = getIncomeTotalAmount().subtract(settlementAmount); + return fee.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : fee; + } + + private BigDecimal getOrderTotalAmount() { + return orderTotalAmount; + } + + private BigDecimal getTotalOrderCount() { + return totalOrderCount; + } + + private BigDecimal getOrderElectricity() { + return orderElectricity; + } + + private BigDecimal getChargeServiceFee() { + return chargeServiceFee; + } + + private BigDecimal getChargeElectricityFee() { + return chargeElectricityFee; + } + + private BigDecimal getPlatformServiceSubsidy() { + return platformServiceSubsidy; + } + + private BigDecimal getSettlementAmount() { + return settlementAmount; + } + + private BigDecimal getTradeAmount() { + return tradeAmount; + } + + private BigDecimal getTradeFee() { + return tradeFee; + } + + private BigDecimal getArrivalAmount() { + return arrivalAmount; + } + } + /** * 获取当前账号可访问的站点ID列表,平台账号返回null表示不限制 *