diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java index 8476657a..0c64badf 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/CompanyOverviewServiceImpl.java @@ -139,7 +139,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { List brushOrders = brushOrderMapper.selectList(brushWrapper); // 获取退款状态ID - Long refundStatusId = getRefundStatusId(); + List refundStatusIds = getRefundStatusIds(); // 计算上月同期数据(用于增长百分比) LocalDate lastMonthStartDate = startDate.minusMonths(1); @@ -211,26 +211,26 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { // 8. 计算店铺效率象限(ROI vs 净利) List shopEfficiencyQuadrants = calculateShopEfficiencyQuadrants( - shops, orders, promotionFees, brushOrders, refundStatusId); + shops, orders, promotionFees, brushOrders, refundStatusIds); overviewVO.setShopEfficiencyQuadrants(shopEfficiencyQuadrants); // 9. 多店铺数据横向对比 CompanyOverviewVO.ShopOverview shopOverview = calculateShopComparisons( - shops, orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate); + shops, orders, promotionFees, brushOrders, refundStatusIds, companyId, startDate, endDate); overviewVO.setShopComparisons(shopOverview); // 10. 多品类数据横向对比 CompanyOverviewVO.CategoryOverview categoryOverview = calculateCategoryComparisons( - orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate); + orders, promotionFees, brushOrders, refundStatusIds, companyId, startDate, endDate); overviewVO.setCategoryComparisons(categoryOverview); // 11. 平台维度汇总 CompanyOverviewVO.PlatformOverview platformOverview = calculatePlatformSummary( - shops, orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate); + shops, orders, promotionFees, brushOrders, refundStatusIds, companyId, startDate, endDate); overviewVO.setPlatformSummary(platformOverview); // 12. 汇总ROI和总税后盈亏 - BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusId); + BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusIds); overviewVO.setTotalROI(totalROI); overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax); @@ -366,7 +366,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { */ private List calculateShopEfficiencyQuadrants( List shops, List orders, List promotionFees, - List brushOrders, Long refundStatusId) { + List brushOrders, List refundStatusIds) { List quadrants = new ArrayList<>(); // 按店铺分组数据 @@ -390,14 +390,14 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal shopRefund = shopOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal shopPromotionFee = shopPromotionFees.stream() .map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee); - BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId); + BigDecimal profit = calculateShopProfit(shopOrders, refundStatusIds); BigDecimal netProfit = calculateShopNetProfit(profit); allROIs.add(roi); @@ -421,14 +421,14 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal shopRefund = shopOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal shopPromotionFee = shopPromotionFees.stream() .map(fee -> fee.getFeeAmount() != null ? fee.getFeeAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal roi = calculateSalesROI(shopSales.subtract(shopRefund), shopPromotionFee); - BigDecimal profit = calculateShopProfit(shopOrders, refundStatusId); + BigDecimal profit = calculateShopProfit(shopOrders, refundStatusIds); BigDecimal netProfit = calculateShopNetProfit(profit); int quadrant; @@ -459,7 +459,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { */ private CompanyOverviewVO.ShopOverview calculateShopComparisons( List shops, List orders, List promotionFees, - List brushOrders, Long refundStatusId, Long companyId, LocalDate startDate, LocalDate endDate) { + List brushOrders, List refundStatusIds, Long companyId, LocalDate startDate, LocalDate endDate) { List comparisons = new ArrayList<>(); // 按店铺分组数据 @@ -502,7 +502,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { int orderCount = shopOrders.size(); BigDecimal refundAmount = shopOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -703,13 +703,13 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { /** * 计算店铺利润(扣除退款) */ - private BigDecimal calculateShopProfit(List orders, Long refundStatusId) { + private BigDecimal calculateShopProfit(List orders, List refundStatusIds) { BigDecimal totalSales = orders.stream() .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal refundAmount = orders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -779,12 +779,12 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { * 计算汇总ROI(新公式):(销售额 - 退款金额)/ 推广费用 */ private BigDecimal calculateTotalROI(List orders, List promotionFees, - List brushOrders, Long refundStatusId) { + List brushOrders, List refundStatusIds) { BigDecimal totalSales = orders.stream() .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal totalRefund = orders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal netSales = totalSales.subtract(totalRefund); @@ -797,14 +797,14 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { /** * 获取退款状态ID(通过 is_refund 字段查询) */ - private Long getRefundStatusId() { + private List getRefundStatusIds() { Long companyId = currentUserContext.getCurrentCompanyId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(OrderStatusPO::getCompanyId, companyId) .eq(OrderStatusPO::getIsRefund, 1) - .last("LIMIT 1"); - OrderStatusPO status = orderStatusService.getOne(wrapper); - return status != null ? status.getId() : null; + .select(OrderStatusPO::getId); + List statusList = orderStatusService.list(wrapper); + return statusList.stream().map(OrderStatusPO::getId).collect(Collectors.toList()); } @@ -813,7 +813,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { */ private CompanyOverviewVO.CategoryOverview calculateCategoryComparisons( List orders, List promotionFees, - List brushOrders, Long refundStatusId, Long companyId, + List brushOrders, List refundStatusIds, Long companyId, LocalDate startDate, LocalDate endDate) { // Query all categories to build categoryId -> categoryName map @@ -875,7 +875,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { int orderCount = categoryOrders.size(); BigDecimal refundAmount = categoryOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -1056,7 +1056,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { */ private CompanyOverviewVO.PlatformOverview calculatePlatformSummary( List shops, List orders, List promotionFees, - List brushOrders, Long refundStatusId, Long companyId, + List brushOrders, List refundStatusIds, Long companyId, LocalDate startDate, LocalDate endDate) { List platformSummaries = new ArrayList<>(); @@ -1140,7 +1140,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { // 退款金额 BigDecimal shopRefund = shopOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); totalRefundAmount = totalRefundAmount.add(shopRefund); @@ -1263,7 +1263,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { if (!shopsWithoutPlatform.isEmpty()) { CompanyOverviewVO.PlatformSummary otherSummary = calculateOtherPlatformSummary( shopsWithoutPlatform, ordersByShop, promotionFeesByShop, brushOrdersByShop, - targetsByShop, refundStatusId, taxRate); + targetsByShop, refundStatusIds, taxRate); if (otherSummary.getOrderCount() > 0) { platformSummaries.add(otherSummary); } @@ -1365,7 +1365,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { Map> promotionFeesByShop, Map> brushOrdersByShop, Map> targetsByShop, - Long refundStatusId, + List refundStatusIds, BigDecimal taxRate) { BigDecimal totalSalesAmount = BigDecimal.ZERO; @@ -1392,7 +1392,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService { totalOrderCount += shopOrders.size(); BigDecimal shopRefund = shopOrders.stream() - .filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId())) + .filter(o -> !refundStatusIds.isEmpty() && refundStatusIds.contains(o.getStatusId())) .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); totalRefundAmount = totalRefundAmount.add(shopRefund); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java index c52b5744..29b2ae37 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ExportServiceImpl.java @@ -104,7 +104,7 @@ public class ExportServiceImpl implements ExportService { } List autoStatusIds = getAutoStatusIds(companyId); - Long refundStatusId = getRefundStatusId(companyId); + List refundStatusIds = getRefundStatusIds(companyId); List> shopDataList = new ArrayList<>(); BigDecimal totalSales = BigDecimal.ZERO; @@ -117,7 +117,7 @@ public class ExportServiceImpl implements ExportService { BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE; for (ShopPO shop : shops) { - Map data = buildShopData(shop, dateRange[0], dateRange[1], autoStatusIds, refundStatusId, companyId, taxRate); + Map data = buildShopData(shop, dateRange[0], dateRange[1], autoStatusIds, refundStatusIds, companyId, taxRate); shopDataList.add(data); totalSales = totalSales.add((BigDecimal) data.get("salesAmount")); @@ -236,7 +236,7 @@ public class ExportServiceImpl implements ExportService { BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE; List autoStatusIds = getAutoStatusIds(companyId); - Long refundStatusId = getRefundStatusId(companyId); + List refundStatusIds = getRefundStatusIds(companyId); // 查询订单 LambdaQueryWrapper orderWrapper = new LambdaQueryWrapper<>(); @@ -317,7 +317,7 @@ public class ExportServiceImpl implements ExportService { .reduce(BigDecimal.ZERO, BigDecimal::add); int orderCount = categoryOrders.size(); BigDecimal refundAmount = categoryOrders.stream() - .filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId())) + .filter(o -> !refundStatusIds.isEmpty() && refundStatusIds.contains(o.getStatusId())) .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal productCost = categoryOrders.stream() @@ -674,7 +674,7 @@ public class ExportServiceImpl implements ExportService { BrushOrderMapper brushOrderMapper, Long companyId, Long shopId, LocalDate startDate, LocalDate endDate, - Long refundStatusId) { + List refundStatusIds) { CellStyle headerStyle = createHeaderStyle(sheet.getWorkbook()); CellStyle dataStyle = createDataStyle(sheet.getWorkbook()); @@ -707,7 +707,7 @@ public class ExportServiceImpl implements ExportService { .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal refundAmount = productOrders.stream() - .filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId())) + .filter(o -> !refundStatusIds.isEmpty() && refundStatusIds.contains(o.getStatusId())) .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -1041,7 +1041,7 @@ public class ExportServiceImpl implements ExportService { // ==================== 数据构建方法 ==================== private Map buildShopData(ShopPO shop, LocalDate startDate, LocalDate endDate, - List autoStatusIds, Long refundStatusId, Long companyId, + List autoStatusIds, List refundStatusIds, Long companyId, BigDecimal taxRate) { LocalDateTime startDateTime = startDate.atStartOfDay(); LocalDateTime endDateTime = endDate.atTime(23, 59, 59); @@ -1103,7 +1103,7 @@ public class ExportServiceImpl implements ExportService { ? salesAmount.divide(new BigDecimal(orderCount), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO; BigDecimal refundAmount = orders.stream() - .filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId())) + .filter(o -> !refundStatusIds.isEmpty() && refundStatusIds.contains(o.getStatusId())) .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -1200,13 +1200,13 @@ public class ExportServiceImpl implements ExportService { return statusList.stream().map(OrderStatusPO::getId).collect(Collectors.toList()); } - private Long getRefundStatusId(Long companyId) { - OrderStatusPO status = orderStatusService.getOne( - new LambdaQueryWrapper() - .eq(OrderStatusPO::getCompanyId, companyId) - .eq(OrderStatusPO::getIsRefund, 1) - .last("LIMIT 1")); - return status != null ? status.getId() : null; + private List getRefundStatusIds(Long companyId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(OrderStatusPO::getCompanyId, companyId) + .eq(OrderStatusPO::getIsRefund, 1) + .select(OrderStatusPO::getId); + List statusList = orderStatusService.list(wrapper); + return statusList.stream().map(OrderStatusPO::getId).collect(Collectors.toList()); } // ==================== Excel 样式工具 ==================== @@ -1297,7 +1297,7 @@ public class ExportServiceImpl implements ExportService { BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE; List autoStatusIds = getAutoStatusIds(companyId); - Long refundStatusId = getRefundStatusId(companyId); + List refundStatusIds = getRefundStatusIds(companyId); // 查询所有店铺并按平台分组 List allShops = shopService.list( @@ -1403,7 +1403,7 @@ public class ExportServiceImpl implements ExportService { totalOrderCount += shopOrders.size(); BigDecimal shopRefund = shopOrders.stream() - .filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId())) + .filter(o -> !refundStatusIds.isEmpty() && refundStatusIds.contains(o.getStatusId())) .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); totalRefundAmount = totalRefundAmount.add(shopRefund); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java index b85ca467..b82d414f 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/overview/service/impl/ShopOverviewStatisticsServiceImpl.java @@ -135,8 +135,8 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics .le(BrushOrderPO::getBrushTime, endDateTime); List brushOrders = brushOrderMapper.selectList(brushWrapper); - // 获取退款状态ID - Long refundStatusId = getRefundStatusId(); + // 获取所有退款状态ID列表 + List refundStatusIds = getRefundStatusIds(); // 计算上月同期数据(用于增长百分比) LocalDate lastMonthStartDate = startDate.minusMonths(1); @@ -191,9 +191,9 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics // 3.1 退款金额、客单价(概览页与导出汇总表共用) BigDecimal refundAmountAgg = BigDecimal.ZERO; - if (refundStatusId != null) { + if (!refundStatusIds.isEmpty()) { refundAmountAgg = orders.stream() - .filter(o -> refundStatusId.equals(o.getStatusId())) + .filter(o -> refundStatusIds.contains(o.getStatusId())) .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); } @@ -230,7 +230,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics calculateTargetData(overviewVO, companyId, queryDTO.getShopId(), startDate, endDate, totalSalesAmount, totalOrderCount); // 8. 汇总ROI和总税后盈亏 - BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusId); + BigDecimal totalROI = calculateTotalROI(orders, promotionFees, brushOrders, refundStatusIds); overviewVO.setTotalROI(totalROI); overviewVO.setTotalProfitAfterTax(totalNetProfitAfterTax); @@ -242,12 +242,12 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics // 10. 多商品数据横向对比 ShopOverviewStatisticsVO.ProductOverview productOverview = calculateProductComparisons( - orders, promotionFees, brushOrders, refundStatusId); + orders, promotionFees, brushOrders, refundStatusIds); overviewVO.setProductOverview(productOverview); // 11. 品类多维度数据对比 ShopOverviewStatisticsVO.CategoryOverview categoryOverview = calculateCategoryComparisons( - orders, promotionFees, brushOrders, refundStatusId); + orders, promotionFees, brushOrders, refundStatusIds); overviewVO.setCategoryOverview(categoryOverview); return overviewVO; @@ -329,12 +329,12 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics * 计算汇总ROI */ private BigDecimal calculateTotalROI(List orders, List promotionFees, - List brushOrders, Long refundStatusId) { + List brushOrders, List refundStatusIds) { BigDecimal totalSales = orders.stream() .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal totalRefund = orders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal totalPromotionFee = promotionFees.stream() @@ -368,7 +368,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics */ private ShopOverviewStatisticsVO.ProductOverview calculateProductComparisons( List orders, List promotionFees, - List brushOrders, Long refundStatusId) { + List brushOrders, List refundStatusIds) { List comparisons = new ArrayList<>(); // 按商品分组订单数据 @@ -406,7 +406,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics int orderCount = productOrders.size(); BigDecimal refundAmount = productOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); @@ -661,14 +661,16 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics /** * 获取退款状态ID(通过 is_refund 字段查询) */ - private Long getRefundStatusId() { + private List getRefundStatusIds() { Long companyId = currentUserContext.getCurrentCompanyId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(OrderStatusPO::getCompanyId, companyId) .eq(OrderStatusPO::getIsRefund, 1) - .last("LIMIT 1"); - OrderStatusPO status = orderStatusService.getOne(wrapper); - return status != null ? status.getId() : null; + .select(OrderStatusPO::getId); + List statusList = orderStatusService.list(wrapper); + return statusList.stream() + .map(OrderStatusPO::getId) + .collect(Collectors.toList()); } private List getAutoStatisticsStatusIds(Long companyId) { @@ -687,7 +689,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics */ private ShopOverviewStatisticsVO.CategoryOverview calculateCategoryComparisons( List orders, List promotionFees, - List brushOrders, Long refundStatusId) { + List brushOrders, List refundStatusIds) { // 构建商品ID->品类ID的映射 Map productCategoryMap = new HashMap<>(); @@ -738,7 +740,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics int orderCount = catOrders.size(); BigDecimal refundAmount = catOrders.stream() - .filter(o -> refundStatusId != null && refundStatusId.equals(o.getStatusId())) + .filter(o -> !refundStatusIds.isEmpty() && refundStatusIds.contains(o.getStatusId())) .map(o -> o.getReceivedAmount() != null ? o.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/overview/service/impl/ProductOverviewServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/overview/service/impl/ProductOverviewServiceImpl.java index 77bdf7e4..d17f4b9f 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/overview/service/impl/ProductOverviewServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/overview/service/impl/ProductOverviewServiceImpl.java @@ -96,7 +96,7 @@ public class ProductOverviewServiceImpl implements ProductOverviewService { } // 获取退款状态ID - Long refundStatusId = getRefundStatusId(); + List refundStatusIds = getRefundStatusIds(); // 按日期分组订单数据 Map> ordersByDate = orders.stream() @@ -141,7 +141,7 @@ public class ProductOverviewServiceImpl implements ProductOverviewService { // 计算退款金额统计 ProductOverviewVO.DailyStatistics refundAmountStats = calculateRefundAmountStatistics( - ordersByDate, dateList, orders, refundStatusId); + ordersByDate, dateList, orders, refundStatusIds); overviewVO.setRefundAmount(refundAmountStats); // 计算推广费统计(按商品关联的店铺分摊,这里简化处理:按店铺粒度的推广费均摊到各商品) @@ -307,11 +307,11 @@ public class ProductOverviewServiceImpl implements ProductOverviewService { */ private ProductOverviewVO.DailyStatistics calculateRefundAmountStatistics( Map> ordersByDate, List dateList, - List allOrders, Long refundStatusId) { + List allOrders, List refundStatusIds) { ProductOverviewVO.DailyStatistics stats = new ProductOverviewVO.DailyStatistics(); BigDecimal total = allOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); stats.setTotal(total); @@ -322,7 +322,7 @@ public class ProductOverviewServiceImpl implements ProductOverviewService { dailyData.setDate(date); List dayOrders = ordersByDate.getOrDefault(date, List.of()); BigDecimal dayRefund = dayOrders.stream() - .filter(order -> refundStatusId != null && refundStatusId.equals(order.getStatusId())) + .filter(order -> !refundStatusIds.isEmpty() && refundStatusIds.contains(order.getStatusId())) .map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO) .reduce(BigDecimal.ZERO, BigDecimal::add); dailyData.setValue(dayRefund); @@ -406,16 +406,15 @@ public class ProductOverviewServiceImpl implements ProductOverviewService { } /** - * 获取退款状态ID(根据 is_refund 字段查找) + * 获取退款状态ID列表(根据 is_refund 字段查找) */ - private Long getRefundStatusId() { + private List getRefundStatusIds() { Long companyId = currentUserContext.getCurrentCompanyId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(OrderStatusPO::getCompanyId, companyId) .eq(OrderStatusPO::getIsRefund, 1) - .select(OrderStatusPO::getId) - .last("LIMIT 1"); - OrderStatusPO refundStatus = orderStatusMapper.selectOne(wrapper); - return refundStatus != null ? refundStatus.getId() : null; + .select(OrderStatusPO::getId); + List statusList = orderStatusMapper.selectList(wrapper); + return statusList.stream().map(OrderStatusPO::getId).collect(Collectors.toList()); } }