mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 04:29:21 +08:00
refactor(ecom-dmb): 店铺/品类/平台概览统一改为对象结构(含后端计算的合计行)
This commit is contained in:
+30
-4
@@ -68,16 +68,16 @@ public class CompanyOverviewVO {
|
||||
private List<ShopEfficiencyQuadrant> shopEfficiencyQuadrants;
|
||||
|
||||
/**
|
||||
* 多店铺数据横向对比(16维度)
|
||||
* 多店铺数据横向对比(包含合计行和店铺列表)
|
||||
*/
|
||||
@Schema(description = "多店铺数据横向对比")
|
||||
private List<ShopComparison> shopComparisons;
|
||||
private ShopOverview shopComparisons;
|
||||
|
||||
/**
|
||||
* 多品类数据横向对比
|
||||
* 多品类数据横向对比(包含合计行和品类列表)
|
||||
*/
|
||||
@Schema(description = "多品类数据横向对比")
|
||||
private List<CategoryComparison> categoryComparisons;
|
||||
private CategoryOverview categoryComparisons;
|
||||
|
||||
/**
|
||||
* 平台维度概览(包含合计行和平台列表)
|
||||
@@ -92,6 +92,32 @@ public class CompanyOverviewVO {
|
||||
private List<PlatformSummary> platforms;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多店铺概览(包含合计行和店铺列表)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "多店铺概览")
|
||||
public static class ShopOverview {
|
||||
@Schema(description = "合计行")
|
||||
private ShopComparison total;
|
||||
|
||||
@Schema(description = "各店铺对比列表")
|
||||
private List<ShopComparison> shops;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多品类概览(包含合计行和品类列表)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "多品类概览")
|
||||
public static class CategoryOverview {
|
||||
@Schema(description = "合计行")
|
||||
private CategoryComparison total;
|
||||
|
||||
@Schema(description = "各品类对比列表")
|
||||
private List<CategoryComparison> categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台维度汇总
|
||||
*/
|
||||
|
||||
+156
-8
@@ -215,14 +215,14 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
overviewVO.setShopEfficiencyQuadrants(shopEfficiencyQuadrants);
|
||||
|
||||
// 9. 多店铺数据横向对比
|
||||
List<CompanyOverviewVO.ShopComparison> shopComparisons = calculateShopComparisons(
|
||||
CompanyOverviewVO.ShopOverview shopOverview = calculateShopComparisons(
|
||||
shops, orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate);
|
||||
overviewVO.setShopComparisons(shopComparisons);
|
||||
overviewVO.setShopComparisons(shopOverview);
|
||||
|
||||
// 10. 多品类数据横向对比
|
||||
List<CompanyOverviewVO.CategoryComparison> categoryComparisons = calculateCategoryComparisons(
|
||||
CompanyOverviewVO.CategoryOverview categoryOverview = calculateCategoryComparisons(
|
||||
orders, promotionFees, brushOrders, refundStatusId, companyId, startDate, endDate);
|
||||
overviewVO.setCategoryComparisons(categoryComparisons);
|
||||
overviewVO.setCategoryComparisons(categoryOverview);
|
||||
|
||||
// 11. 平台维度汇总
|
||||
CompanyOverviewVO.PlatformOverview platformOverview = calculatePlatformSummary(
|
||||
@@ -457,7 +457,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
/**
|
||||
* 计算多店铺数据横向对比
|
||||
*/
|
||||
private List<CompanyOverviewVO.ShopComparison> calculateShopComparisons(
|
||||
private CompanyOverviewVO.ShopOverview calculateShopComparisons(
|
||||
List<ShopPO> shops, List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders, Long refundStatusId, Long companyId, LocalDate startDate, LocalDate endDate) {
|
||||
List<CompanyOverviewVO.ShopComparison> comparisons = new ArrayList<>();
|
||||
@@ -616,7 +616,88 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
// 按销售额降序排序
|
||||
comparisons.sort(Comparator.comparing(CompanyOverviewVO.ShopComparison::getSalesAmount).reversed());
|
||||
return comparisons;
|
||||
|
||||
// 计算合计行
|
||||
CompanyOverviewVO.ShopComparison total = computeShopTotal(comparisons);
|
||||
|
||||
// 封装为 ShopOverview
|
||||
CompanyOverviewVO.ShopOverview overview = new CompanyOverviewVO.ShopOverview();
|
||||
overview.setTotal(total);
|
||||
overview.setShops(comparisons);
|
||||
return overview;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算店铺对比的合计行
|
||||
*/
|
||||
private CompanyOverviewVO.ShopComparison computeShopTotal(List<CompanyOverviewVO.ShopComparison> shops) {
|
||||
BigDecimal totalSales = BigDecimal.ZERO;
|
||||
int totalOrders = 0;
|
||||
BigDecimal totalTargetAmount = BigDecimal.ZERO;
|
||||
int totalTargetOrders = 0;
|
||||
BigDecimal totalProductCost = BigDecimal.ZERO;
|
||||
BigDecimal totalShippingCost = BigDecimal.ZERO;
|
||||
BigDecimal totalOtherCost = BigDecimal.ZERO;
|
||||
BigDecimal totalRefund = BigDecimal.ZERO;
|
||||
BigDecimal totalPromoFee = BigDecimal.ZERO;
|
||||
BigDecimal totalBrushFee = BigDecimal.ZERO;
|
||||
|
||||
for (CompanyOverviewVO.ShopComparison s : shops) {
|
||||
totalSales = totalSales.add(s.getSalesAmount() != null ? s.getSalesAmount() : BigDecimal.ZERO);
|
||||
totalOrders += s.getOrderCount() != null ? s.getOrderCount() : 0;
|
||||
totalTargetAmount = totalTargetAmount.add(s.getTargetAmount() != null ? s.getTargetAmount() : BigDecimal.ZERO);
|
||||
totalTargetOrders += s.getTargetOrderCount() != null ? s.getTargetOrderCount() : 0;
|
||||
totalProductCost = totalProductCost.add(s.getProductCost() != null ? s.getProductCost() : BigDecimal.ZERO);
|
||||
totalShippingCost = totalShippingCost.add(s.getShippingCost() != null ? s.getShippingCost() : BigDecimal.ZERO);
|
||||
totalOtherCost = totalOtherCost.add(s.getOtherCost() != null ? s.getOtherCost() : BigDecimal.ZERO);
|
||||
totalRefund = totalRefund.add(s.getRefundAmount() != null ? s.getRefundAmount() : BigDecimal.ZERO);
|
||||
totalPromoFee = totalPromoFee.add(s.getTotalPromotionFee() != null ? s.getTotalPromotionFee() : BigDecimal.ZERO);
|
||||
totalBrushFee = totalBrushFee.add(s.getBrushFee() != null ? s.getBrushFee() : BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
BigDecimal avgOrderValue = totalOrders > 0
|
||||
? totalSales.divide(new BigDecimal(totalOrders), 2, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund);
|
||||
BigDecimal salesTax = totalSales.multiply(new BigDecimal("0.04"));
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal feeRatio = totalSales.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalPromoFee.add(totalBrushFee).divide(totalSales, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal salesAchievementRate = totalTargetAmount.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSales.divide(totalTargetAmount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
||||
: totalSales.compareTo(BigDecimal.ZERO) > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
BigDecimal orderAchievementRate = totalTargetOrders > 0
|
||||
? new BigDecimal(totalOrders).divide(new BigDecimal(totalTargetOrders), 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"))
|
||||
: totalOrders > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
|
||||
CompanyOverviewVO.ShopComparison total = new CompanyOverviewVO.ShopComparison();
|
||||
total.setShopId(0L);
|
||||
total.setShopName("合计");
|
||||
total.setSalesAmount(totalSales);
|
||||
total.setOrderCount(totalOrders);
|
||||
total.setAverageOrderValue(avgOrderValue);
|
||||
total.setTargetAmount(totalTargetAmount);
|
||||
total.setTargetOrderCount(totalTargetOrders);
|
||||
total.setSalesAmountAchievementRate(salesAchievementRate);
|
||||
total.setOrderCountAchievementRate(orderAchievementRate);
|
||||
total.setProductCost(totalProductCost);
|
||||
total.setShippingCost(totalShippingCost);
|
||||
total.setOtherCost(totalOtherCost);
|
||||
total.setRefundAmount(totalRefund);
|
||||
total.setTotalPromotionFee(totalPromoFee);
|
||||
total.setBrushFee(totalBrushFee);
|
||||
total.setFeeRatio(feeRatio);
|
||||
total.setTotalProfitBeforeTax(profitBeforeTax);
|
||||
total.setSalesTaxAmount(salesTax);
|
||||
total.setRoi(roi);
|
||||
total.setProfitAfterTax(profitAfterTax);
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -730,7 +811,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
/**
|
||||
* Calculate category comparison data
|
||||
*/
|
||||
private List<CompanyOverviewVO.CategoryComparison> calculateCategoryComparisons(
|
||||
private CompanyOverviewVO.CategoryOverview calculateCategoryComparisons(
|
||||
List<OrderPO> orders, List<PromotionFeePO> promotionFees,
|
||||
List<BrushOrderPO> brushOrders, Long refundStatusId, Long companyId,
|
||||
LocalDate startDate, LocalDate endDate) {
|
||||
@@ -890,8 +971,75 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
}
|
||||
|
||||
comparisons.sort(Comparator.comparing(CompanyOverviewVO.CategoryComparison::getSalesAmount).reversed());
|
||||
return comparisons;
|
||||
|
||||
// 计算合计行
|
||||
CompanyOverviewVO.CategoryComparison total = computeCategoryTotal(comparisons);
|
||||
|
||||
// 封装为 CategoryOverview
|
||||
CompanyOverviewVO.CategoryOverview overview = new CompanyOverviewVO.CategoryOverview();
|
||||
overview.setTotal(total);
|
||||
overview.setCategories(comparisons);
|
||||
return overview;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算品类对比的合计行
|
||||
*/
|
||||
private CompanyOverviewVO.CategoryComparison computeCategoryTotal(List<CompanyOverviewVO.CategoryComparison> categories) {
|
||||
BigDecimal totalSales = BigDecimal.ZERO;
|
||||
int totalOrders = 0;
|
||||
BigDecimal totalProductCost = BigDecimal.ZERO;
|
||||
BigDecimal totalShippingCost = BigDecimal.ZERO;
|
||||
BigDecimal totalOtherCost = BigDecimal.ZERO;
|
||||
BigDecimal totalRefund = BigDecimal.ZERO;
|
||||
BigDecimal totalPromoFee = BigDecimal.ZERO;
|
||||
BigDecimal totalBrushFee = BigDecimal.ZERO;
|
||||
|
||||
for (CompanyOverviewVO.CategoryComparison c : categories) {
|
||||
totalSales = totalSales.add(c.getSalesAmount() != null ? c.getSalesAmount() : BigDecimal.ZERO);
|
||||
totalOrders += c.getOrderCount() != null ? c.getOrderCount() : 0;
|
||||
totalProductCost = totalProductCost.add(c.getProductCost() != null ? c.getProductCost() : BigDecimal.ZERO);
|
||||
totalShippingCost = totalShippingCost.add(c.getShippingCost() != null ? c.getShippingCost() : BigDecimal.ZERO);
|
||||
totalOtherCost = totalOtherCost.add(c.getOtherCost() != null ? c.getOtherCost() : BigDecimal.ZERO);
|
||||
totalRefund = totalRefund.add(c.getRefundAmount() != null ? c.getRefundAmount() : BigDecimal.ZERO);
|
||||
totalPromoFee = totalPromoFee.add(c.getTotalPromotionFee() != null ? c.getTotalPromotionFee() : BigDecimal.ZERO);
|
||||
totalBrushFee = totalBrushFee.add(c.getBrushFee() != null ? c.getBrushFee() : BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
BigDecimal avgOrderValue = totalOrders > 0
|
||||
? totalSales.divide(new BigDecimal(totalOrders), 2, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal totalCost = totalProductCost.add(totalShippingCost).add(totalOtherCost);
|
||||
BigDecimal profitBeforeTax = totalSales.subtract(totalCost).subtract(totalRefund);
|
||||
BigDecimal salesTax = totalSales.multiply(new BigDecimal("0.04"));
|
||||
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTax);
|
||||
BigDecimal roi = totalPromoFee.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalSales.subtract(totalRefund).divide(totalPromoFee, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
BigDecimal feeRatio = totalSales.compareTo(BigDecimal.ZERO) > 0
|
||||
? totalPromoFee.add(totalBrushFee).divide(totalSales, 4, RoundingMode.HALF_UP)
|
||||
: BigDecimal.ZERO;
|
||||
|
||||
CompanyOverviewVO.CategoryComparison total = new CompanyOverviewVO.CategoryComparison();
|
||||
total.setCategoryId(0L);
|
||||
total.setCategoryName("合计");
|
||||
total.setSalesAmount(totalSales);
|
||||
total.setOrderCount(totalOrders);
|
||||
total.setAverageOrderValue(avgOrderValue);
|
||||
total.setProductCost(totalProductCost);
|
||||
total.setShippingCost(totalShippingCost);
|
||||
total.setOtherCost(totalOtherCost);
|
||||
total.setRefundAmount(totalRefund);
|
||||
total.setTotalPromotionFee(totalPromoFee);
|
||||
total.setBrushFee(totalBrushFee);
|
||||
total.setFeeRatio(feeRatio);
|
||||
total.setTotalProfitBeforeTax(profitBeforeTax);
|
||||
total.setSalesTaxAmount(salesTax);
|
||||
total.setRoi(roi);
|
||||
total.setProfitAfterTax(profitAfterTax);
|
||||
return total;
|
||||
}
|
||||
|
||||
private List<Long> getAutoStatisticsStatusIds(Long companyId) {
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
|
||||
Reference in New Issue
Block a user