mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat(store-overview): 全店大盘新增销售额与单量趋势平滑曲线
- CompanyOverviewVO 新增 TrendData / TrendDataItem 结构及 salesAmountTrend / orderCountTrend 字段 - CompanyOverviewServiceImpl 新增按日汇总销售额和单量的趋势计算逻辑 - ShopCharts.vue 重构:左侧替换为趋势平滑曲线(双Y轴),右侧保留店铺销售贡献排行柱状图,移除店铺经营健康度散点图 - 前端类型定义同步更新
This commit is contained in:
+39
@@ -1,9 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.overview.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -67,6 +69,18 @@ public class CompanyOverviewVO {
|
||||
@Schema(description = "店铺效率象限")
|
||||
private List<ShopEfficiencyQuadrant> shopEfficiencyQuadrants;
|
||||
|
||||
/**
|
||||
* 销售额趋势分析
|
||||
*/
|
||||
@Schema(description = "销售额趋势分析")
|
||||
private TrendData salesAmountTrend;
|
||||
|
||||
/**
|
||||
* 单量趋势分析
|
||||
*/
|
||||
@Schema(description = "单量趋势分析")
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
/**
|
||||
* 多店铺数据横向汇总(包含合计行和店铺列表)
|
||||
*/
|
||||
@@ -160,6 +174,31 @@ public class CompanyOverviewVO {
|
||||
@Schema(description = "销售额目标达成率", example = "83.33")
|
||||
private BigDecimal salesAmountAchievementRate;
|
||||
|
||||
/**
|
||||
* 趋势数据
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "趋势数据")
|
||||
public static class TrendData {
|
||||
@Schema(description = "时间范围的总值")
|
||||
private BigDecimal total;
|
||||
@Schema(description = "每日数据列表")
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 趋势数据项
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "趋势数据项")
|
||||
public static class TrendDataItem {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Schema(description = "日期", example = "2024-01-01")
|
||||
private LocalDate date;
|
||||
@Schema(description = "对应的值")
|
||||
private BigDecimal value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺销售占比
|
||||
*/
|
||||
|
||||
+64
-1
@@ -209,7 +209,13 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
List<CompanyOverviewVO.ShopSalesRatio> shopSalesRatios = calculateShopSalesRatios(shops, orders, totalSalesAmount);
|
||||
overviewVO.setShopSalesRatios(shopSalesRatios);
|
||||
|
||||
// 8. 计算店铺效率象限(ROI vs 净利)
|
||||
// 8. 计算销售额与单量趋势
|
||||
CompanyOverviewVO.TrendData salesAmountTrend = calculateSalesAmountTrend(orders, startDate, endDate);
|
||||
CompanyOverviewVO.TrendData orderCountTrend = calculateOrderCountTrend(orders, startDate, endDate);
|
||||
overviewVO.setSalesAmountTrend(salesAmountTrend);
|
||||
overviewVO.setOrderCountTrend(orderCountTrend);
|
||||
|
||||
// 9. 计算店铺效率象限(ROI vs 净利)
|
||||
List<CompanyOverviewVO.ShopEfficiencyQuadrant> shopEfficiencyQuadrants = calculateShopEfficiencyQuadrants(
|
||||
shops, orders, promotionFees, brushOrders, refundStatusIds);
|
||||
overviewVO.setShopEfficiencyQuadrants(shopEfficiencyQuadrants);
|
||||
@@ -1496,5 +1502,62 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
PlatformPO platform = platformMapper.selectOne(wrapper);
|
||||
return platform != null ? platform.getPlatformName() : null;
|
||||
}
|
||||
|
||||
private CompanyOverviewVO.TrendData calculateSalesAmountTrend(List<OrderPO> orders, LocalDate startDate, LocalDate endDate) {
|
||||
CompanyOverviewVO.TrendData trendData = new CompanyOverviewVO.TrendData();
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> order.getOrderTime().toLocalDate()));
|
||||
BigDecimal total = orders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
trendData.setTotal(total);
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
LocalDate currentDate = startDate;
|
||||
while (!currentDate.isAfter(endDate)) {
|
||||
dateList.add(currentDate);
|
||||
currentDate = currentDate.plusDays(1);
|
||||
}
|
||||
List<CompanyOverviewVO.TrendDataItem> dailyDataList = dateList.stream()
|
||||
.map(date -> {
|
||||
CompanyOverviewVO.TrendDataItem item = new CompanyOverviewVO.TrendDataItem();
|
||||
item.setDate(date);
|
||||
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
|
||||
BigDecimal dayTotal = dayOrders.stream()
|
||||
.map(order -> order.getReceivedAmount() != null ? order.getReceivedAmount() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
item.setValue(dayTotal);
|
||||
return item;
|
||||
})
|
||||
.sorted(Comparator.comparing(CompanyOverviewVO.TrendDataItem::getDate))
|
||||
.collect(Collectors.toList());
|
||||
trendData.setDailyDataList(dailyDataList);
|
||||
return trendData;
|
||||
}
|
||||
|
||||
private CompanyOverviewVO.TrendData calculateOrderCountTrend(List<OrderPO> orders, LocalDate startDate, LocalDate endDate) {
|
||||
CompanyOverviewVO.TrendData trendData = new CompanyOverviewVO.TrendData();
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> order.getOrderTime().toLocalDate()));
|
||||
int total = orders.size();
|
||||
trendData.setTotal(new BigDecimal(total));
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
LocalDate currentDate = startDate;
|
||||
while (!currentDate.isAfter(endDate)) {
|
||||
dateList.add(currentDate);
|
||||
currentDate = currentDate.plusDays(1);
|
||||
}
|
||||
List<CompanyOverviewVO.TrendDataItem> dailyDataList = dateList.stream()
|
||||
.map(date -> {
|
||||
CompanyOverviewVO.TrendDataItem item = new CompanyOverviewVO.TrendDataItem();
|
||||
item.setDate(date);
|
||||
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
|
||||
item.setValue(new BigDecimal(dayOrders.size()));
|
||||
return item;
|
||||
})
|
||||
.sorted(Comparator.comparing(CompanyOverviewVO.TrendDataItem::getDate))
|
||||
.collect(Collectors.toList());
|
||||
trendData.setDailyDataList(dailyDataList);
|
||||
return trendData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user