mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 06:29:20 +08:00
feat: 移除 BI Overview 旧趋势字段,统一使用 dealTrend
This commit is contained in:
-20
@@ -1,13 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.categoryoverview.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -53,11 +51,6 @@ public class CategoryOverviewVO {
|
||||
|
||||
private List<ProductSalesRankItem> productSalesTop10;
|
||||
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData salesAmountTrend;
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
private ProductOverview productOverview;
|
||||
|
||||
@Data
|
||||
@@ -101,17 +94,4 @@ public class CategoryOverviewVO {
|
||||
private BigDecimal profitAfterTax;
|
||||
private BigDecimal roi;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TrendData {
|
||||
private BigDecimal total;
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TrendDataItem {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate date;
|
||||
private BigDecimal value;
|
||||
}
|
||||
}
|
||||
|
||||
-31
@@ -121,7 +121,6 @@ public class BiCategoryOverviewServiceImpl implements BiCategoryOverviewService
|
||||
fillProductSalesTop10(vo);
|
||||
fillLegacyFlatFields(vo, curT, prevT);
|
||||
fillTargets(vo, companyId, cur.shopIds(), start, end, curT.totalSales(), curT.orderCount());
|
||||
fillLegacyTrends(vo, dealTrend);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -249,36 +248,6 @@ public class BiCategoryOverviewServiceImpl implements BiCategoryOverviewService
|
||||
vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales()));
|
||||
}
|
||||
|
||||
private void fillLegacyTrends(CategoryOverviewVO vo, List<WorkbenchTrendPointVO> dealTrend) {
|
||||
CategoryOverviewVO.TrendData sales = new CategoryOverviewVO.TrendData();
|
||||
CategoryOverviewVO.TrendData orders = new CategoryOverviewVO.TrendData();
|
||||
List<CategoryOverviewVO.TrendDataItem> salesItems = new ArrayList<>();
|
||||
List<CategoryOverviewVO.TrendDataItem> orderItems = new ArrayList<>();
|
||||
BigDecimal salesTotal = BigDecimal.ZERO;
|
||||
BigDecimal orderTotal = BigDecimal.ZERO;
|
||||
if (dealTrend != null) {
|
||||
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||
CategoryOverviewVO.TrendDataItem s = new CategoryOverviewVO.TrendDataItem();
|
||||
s.setDate(LocalDate.parse(p.getDate()));
|
||||
s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan()));
|
||||
salesItems.add(s);
|
||||
salesTotal = salesTotal.add(s.getValue());
|
||||
|
||||
CategoryOverviewVO.TrendDataItem o = new CategoryOverviewVO.TrendDataItem();
|
||||
o.setDate(s.getDate());
|
||||
o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||
orderItems.add(o);
|
||||
orderTotal = orderTotal.add(o.getValue());
|
||||
}
|
||||
}
|
||||
sales.setDailyDataList(salesItems);
|
||||
sales.setTotal(salesTotal);
|
||||
orders.setDailyDataList(orderItems);
|
||||
orders.setTotal(orderTotal);
|
||||
vo.setSalesAmountTrend(sales);
|
||||
vo.setOrderCountTrend(orders);
|
||||
}
|
||||
|
||||
private void fillTargets(CategoryOverviewVO vo, Long companyId, List<Long> shopIds,
|
||||
LocalDate startDate, LocalDate endDate,
|
||||
BigDecimal sales, int orderCount) {
|
||||
|
||||
-31
@@ -1,10 +1,8 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -58,16 +56,6 @@ public class CompanyOverviewVO {
|
||||
*/
|
||||
private List<ShopEfficiencyQuadrant> shopEfficiencyQuadrants;
|
||||
|
||||
/**
|
||||
* 销售额趋势分析
|
||||
*/
|
||||
private TrendData salesAmountTrend;
|
||||
|
||||
/**
|
||||
* 单量趋势分析
|
||||
*/
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
/**
|
||||
* 多店铺数据横向汇总(包含合计行和店铺列表)
|
||||
*/
|
||||
@@ -156,25 +144,6 @@ public class CompanyOverviewVO {
|
||||
*/
|
||||
private BigDecimal salesAmountAchievementRate;
|
||||
|
||||
/**
|
||||
* 趋势数据
|
||||
*/
|
||||
@Data
|
||||
public static class TrendData {
|
||||
private BigDecimal total;
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 趋势数据项
|
||||
*/
|
||||
@Data
|
||||
public static class TrendDataItem {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate date;
|
||||
private BigDecimal value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺销售占比
|
||||
*/
|
||||
|
||||
+29
-30
@@ -11,6 +11,7 @@ import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.service.BiShopOverviewS
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.dto.CategoryExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.model.vo.CompanyOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.service.CategoryExportExcelService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
@@ -18,7 +19,7 @@ import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -145,9 +146,7 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
Sheet sheet = workbook.createSheet("品类汇总");
|
||||
writeCategoryMultidimensionalSheet(sheet, shopTitle, dateRangeLabel, rows, totalRow, taxRate, "品类名称");
|
||||
if (vo.getSalesAmountTrend() != null
|
||||
&& vo.getSalesAmountTrend().getDailyDataList() != null
|
||||
&& !vo.getSalesAmountTrend().getDailyDataList().isEmpty()) {
|
||||
if (vo.getDealTrend() != null && !vo.getDealTrend().isEmpty()) {
|
||||
Sheet trendSheet = workbook.createSheet("销量趋势");
|
||||
writeShopSalesTrendSheet(trendSheet, shopTitle, dateRangeLabel, vo);
|
||||
}
|
||||
@@ -160,7 +159,7 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
||||
}
|
||||
}
|
||||
|
||||
/** 与店铺概览销量趋势同源({@link ShopOverviewStatisticsVO} 日销售额、日单量)。 */
|
||||
/** 与店铺概览销量趋势同源:从 {@link ShopOverviewStatisticsVO#getDealTrend()} 取日销售额/单量。 */
|
||||
private void writeShopSalesTrendSheet(
|
||||
Sheet sheet, String shopContextTitle, String dateRangeLabel, ShopOverviewStatisticsVO vo) {
|
||||
Workbook wb = sheet.getWorkbook();
|
||||
@@ -181,32 +180,32 @@ public class CategoryExportExcelServiceImpl implements CategoryExportExcelServic
|
||||
cell.setCellStyle(headerStyle);
|
||||
}
|
||||
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> dailySales = vo.getSalesAmountTrend().getDailyDataList();
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> dailyOrders = vo.getOrderCountTrend() != null
|
||||
? vo.getOrderCountTrend().getDailyDataList()
|
||||
: null;
|
||||
List<WorkbenchTrendPointVO> dealTrend = vo.getDealTrend();
|
||||
if (dealTrend == null || dealTrend.isEmpty()) {
|
||||
sheet.setColumnWidth(0, 3200);
|
||||
sheet.setColumnWidth(1, 3200);
|
||||
sheet.setColumnWidth(2, 3200);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<LocalDate, BigDecimal> salesMap = dailySales.stream()
|
||||
.collect(Collectors.toMap(
|
||||
ShopOverviewStatisticsVO.TrendDataItem::getDate,
|
||||
ShopOverviewStatisticsVO.TrendDataItem::getValue,
|
||||
(a, b) -> a));
|
||||
Map<LocalDate, BigDecimal> ordersMap = dailyOrders != null
|
||||
? dailyOrders.stream()
|
||||
.collect(Collectors.toMap(
|
||||
ShopOverviewStatisticsVO.TrendDataItem::getDate,
|
||||
ShopOverviewStatisticsVO.TrendDataItem::getValue,
|
||||
(a, b) -> a))
|
||||
: Collections.emptyMap();
|
||||
|
||||
LocalDate startDate = dailySales.stream()
|
||||
.map(ShopOverviewStatisticsVO.TrendDataItem::getDate)
|
||||
.min(LocalDate::compareTo)
|
||||
.orElse(null);
|
||||
LocalDate endDate = dailySales.stream()
|
||||
.map(ShopOverviewStatisticsVO.TrendDataItem::getDate)
|
||||
.max(LocalDate::compareTo)
|
||||
.orElse(null);
|
||||
Map<LocalDate, BigDecimal> salesMap = new HashMap<>();
|
||||
Map<LocalDate, BigDecimal> ordersMap = new HashMap<>();
|
||||
LocalDate startDate = null;
|
||||
LocalDate endDate = null;
|
||||
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||
if (p == null || p.getDate() == null || p.getDate().isBlank()) {
|
||||
continue;
|
||||
}
|
||||
LocalDate d = LocalDate.parse(p.getDate());
|
||||
salesMap.put(d, p.getSalesYuan() != null ? p.getSalesYuan() : BigDecimal.ZERO);
|
||||
ordersMap.put(d, BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||
if (startDate == null || d.isBefore(startDate)) {
|
||||
startDate = d;
|
||||
}
|
||||
if (endDate == null || d.isAfter(endDate)) {
|
||||
endDate = d;
|
||||
}
|
||||
}
|
||||
|
||||
int rowIdx = 2;
|
||||
if (startDate != null && endDate != null) {
|
||||
|
||||
-20
@@ -1,13 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.platformoverview.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -53,11 +51,6 @@ public class PlatformOverviewVO {
|
||||
|
||||
private List<ProductSalesRankItem> productSalesTop10;
|
||||
|
||||
/** @deprecated 使用 dealTrend;保留以免旧客户端空指针 */
|
||||
private TrendData salesAmountTrend;
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
private ProductOverview productOverview;
|
||||
|
||||
private CategoryOverview categoryOverview;
|
||||
@@ -135,17 +128,4 @@ public class PlatformOverviewVO {
|
||||
private BigDecimal profitAfterTax;
|
||||
private BigDecimal roi;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TrendData {
|
||||
private BigDecimal total;
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TrendDataItem {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate date;
|
||||
private BigDecimal value;
|
||||
}
|
||||
}
|
||||
|
||||
-32
@@ -123,7 +123,6 @@ public class BiPlatformOverviewServiceImpl implements BiPlatformOverviewService
|
||||
fillProductSalesTop10(vo);
|
||||
fillLegacyFlatFields(vo, curT, prevT);
|
||||
fillTargets(vo, companyId, shopIds, start, end, curT.totalSales(), curT.orderCount());
|
||||
fillLegacyTrends(vo, dealTrend);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -217,7 +216,6 @@ public class BiPlatformOverviewServiceImpl implements BiPlatformOverviewService
|
||||
co.setCategories(List.of());
|
||||
vo.setCategoryOverview(co);
|
||||
fillLegacyFlatFields(vo, empty, empty);
|
||||
fillLegacyTrends(vo, vo.getDealTrend());
|
||||
}
|
||||
|
||||
private void fillLegacyFlatFields(PlatformOverviewVO vo,
|
||||
@@ -241,36 +239,6 @@ public class BiPlatformOverviewServiceImpl implements BiPlatformOverviewService
|
||||
vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales()));
|
||||
}
|
||||
|
||||
private void fillLegacyTrends(PlatformOverviewVO vo, List<WorkbenchTrendPointVO> dealTrend) {
|
||||
PlatformOverviewVO.TrendData sales = new PlatformOverviewVO.TrendData();
|
||||
PlatformOverviewVO.TrendData orders = new PlatformOverviewVO.TrendData();
|
||||
List<PlatformOverviewVO.TrendDataItem> salesItems = new ArrayList<>();
|
||||
List<PlatformOverviewVO.TrendDataItem> orderItems = new ArrayList<>();
|
||||
BigDecimal salesTotal = BigDecimal.ZERO;
|
||||
BigDecimal orderTotal = BigDecimal.ZERO;
|
||||
if (dealTrend != null) {
|
||||
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||
PlatformOverviewVO.TrendDataItem s = new PlatformOverviewVO.TrendDataItem();
|
||||
s.setDate(LocalDate.parse(p.getDate()));
|
||||
s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan()));
|
||||
salesItems.add(s);
|
||||
salesTotal = salesTotal.add(s.getValue());
|
||||
|
||||
PlatformOverviewVO.TrendDataItem o = new PlatformOverviewVO.TrendDataItem();
|
||||
o.setDate(s.getDate());
|
||||
o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||
orderItems.add(o);
|
||||
orderTotal = orderTotal.add(o.getValue());
|
||||
}
|
||||
}
|
||||
sales.setDailyDataList(salesItems);
|
||||
sales.setTotal(salesTotal);
|
||||
orders.setDailyDataList(orderItems);
|
||||
orders.setTotal(orderTotal);
|
||||
vo.setSalesAmountTrend(sales);
|
||||
vo.setOrderCountTrend(orders);
|
||||
}
|
||||
|
||||
private void fillTargets(PlatformOverviewVO vo, Long companyId, List<Long> shopIds,
|
||||
LocalDate startDate, LocalDate endDate,
|
||||
BigDecimal sales, int orderCount) {
|
||||
|
||||
-20
@@ -1,13 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.productoverview.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -47,26 +45,8 @@ public class ProductOverviewVO {
|
||||
|
||||
private List<SpecSalesRankItem> specSalesTop10;
|
||||
|
||||
/** @deprecated 使用 dealTrend;保留以免旧客户端空指针 */
|
||||
private TrendData salesAmountTrend;
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
private SpecSummary specSummaries;
|
||||
|
||||
@Data
|
||||
public static class TrendData {
|
||||
private BigDecimal total;
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TrendDataItem {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate date;
|
||||
private BigDecimal value;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class SpecSummary {
|
||||
private List<SpecSummaryItem> list;
|
||||
|
||||
-31
@@ -132,7 +132,6 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
||||
vo.setSpecSalesTop10(buildSpecTop10(specSummaries));
|
||||
fillLegacyFlatFields(vo, curT, prevT);
|
||||
fillTargets(vo, companyId, cur.shopIds(), start, end, curT.totalSales(), curT.orderCount());
|
||||
fillLegacyTrends(vo, dealTrend);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -204,36 +203,6 @@ public class BiProductOverviewServiceImpl implements BiProductOverviewService {
|
||||
vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales()));
|
||||
}
|
||||
|
||||
private void fillLegacyTrends(ProductOverviewVO vo, List<WorkbenchTrendPointVO> dealTrend) {
|
||||
ProductOverviewVO.TrendData sales = new ProductOverviewVO.TrendData();
|
||||
ProductOverviewVO.TrendData orders = new ProductOverviewVO.TrendData();
|
||||
List<ProductOverviewVO.TrendDataItem> salesItems = new ArrayList<>();
|
||||
List<ProductOverviewVO.TrendDataItem> orderItems = new ArrayList<>();
|
||||
BigDecimal salesTotal = BigDecimal.ZERO;
|
||||
BigDecimal orderTotal = BigDecimal.ZERO;
|
||||
if (dealTrend != null) {
|
||||
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||
ProductOverviewVO.TrendDataItem s = new ProductOverviewVO.TrendDataItem();
|
||||
s.setDate(LocalDate.parse(p.getDate()));
|
||||
s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan()));
|
||||
salesItems.add(s);
|
||||
salesTotal = salesTotal.add(s.getValue());
|
||||
|
||||
ProductOverviewVO.TrendDataItem o = new ProductOverviewVO.TrendDataItem();
|
||||
o.setDate(s.getDate());
|
||||
o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||
orderItems.add(o);
|
||||
orderTotal = orderTotal.add(o.getValue());
|
||||
}
|
||||
}
|
||||
sales.setDailyDataList(salesItems);
|
||||
sales.setTotal(salesTotal);
|
||||
orders.setDailyDataList(orderItems);
|
||||
orders.setTotal(orderTotal);
|
||||
vo.setSalesAmountTrend(sales);
|
||||
vo.setOrderCountTrend(orders);
|
||||
}
|
||||
|
||||
private void fillTargets(ProductOverviewVO vo, Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end, BigDecimal sales, int orderCount) {
|
||||
if (shopIds == null || shopIds.isEmpty()) {
|
||||
|
||||
-40
@@ -1,13 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.shopoverview.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -52,11 +50,6 @@ public class ShopOverviewStatisticsVO {
|
||||
|
||||
private List<ProductSalesRankItem> productSalesTop10;
|
||||
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData salesAmountTrend;
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
private ProductOverview productOverview;
|
||||
private CategoryOverview categoryOverview;
|
||||
|
||||
@@ -207,38 +200,5 @@ public class ShopOverviewStatisticsVO {
|
||||
|
||||
private BigDecimal roi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 趋势数据
|
||||
*/
|
||||
@Data
|
||||
public static class TrendData {
|
||||
/**
|
||||
* 时间范围的总值
|
||||
*/
|
||||
private BigDecimal total;
|
||||
|
||||
/**
|
||||
* 每日数据列表
|
||||
*/
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 趋势数据项
|
||||
*/
|
||||
@Data
|
||||
public static class TrendDataItem {
|
||||
/**
|
||||
* 日期
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate date;
|
||||
|
||||
/**
|
||||
* 对应的值
|
||||
*/
|
||||
private BigDecimal value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-20
@@ -12,6 +12,7 @@ import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.model.vo.ShopOverviewSt
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.service.BiShopOverviewService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.overview.service.CategoryExportExcelService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.shopoverview.service.BiShopExportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
@@ -19,9 +20,9 @@ import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class BiShopExportServiceImpl implements BiShopExportService {
|
||||
@@ -81,9 +82,8 @@ public class BiShopExportServiceImpl implements BiShopExportService {
|
||||
}
|
||||
|
||||
if (("trend".equals(exportType) || "all".equals(exportType) || "summary".equals(exportType))
|
||||
&& vo.getSalesAmountTrend() != null
|
||||
&& vo.getSalesAmountTrend().getDailyDataList() != null
|
||||
&& !vo.getSalesAmountTrend().getDailyDataList().isEmpty()) {
|
||||
&& vo.getDealTrend() != null
|
||||
&& !vo.getDealTrend().isEmpty()) {
|
||||
Sheet trendSheet = workbook.createSheet("销量趋势");
|
||||
createTrendSheetFromVO(trendSheet, dateRangeLabel, vo);
|
||||
}
|
||||
@@ -194,6 +194,7 @@ public class BiShopExportServiceImpl implements BiShopExportService {
|
||||
setCell(row, 18, profitAfterTax.doubleValue(), style);
|
||||
}
|
||||
|
||||
/** 从 dealTrend 写日销售额/单量;date 为 String,需 LocalDate.parse。 */
|
||||
private void createTrendSheetFromVO(Sheet sheet, String dateRangeLabel, ShopOverviewStatisticsVO vo) {
|
||||
CellStyle headerStyle = createHeaderStyle(sheet.getWorkbook());
|
||||
CellStyle dataStyle = createDataStyle(sheet.getWorkbook());
|
||||
@@ -212,23 +213,32 @@ public class BiShopExportServiceImpl implements BiShopExportService {
|
||||
cell.setCellStyle(headerStyle);
|
||||
}
|
||||
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> dailySales = vo.getSalesAmountTrend().getDailyDataList();
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> dailyOrders = vo.getOrderCountTrend() != null
|
||||
? vo.getOrderCountTrend().getDailyDataList() : null;
|
||||
List<WorkbenchTrendPointVO> dealTrend = vo.getDealTrend();
|
||||
if (dealTrend == null || dealTrend.isEmpty()) {
|
||||
sheet.setColumnWidth(0, 3200);
|
||||
sheet.setColumnWidth(1, 3200);
|
||||
sheet.setColumnWidth(2, 3200);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<LocalDate, BigDecimal> salesMap = dailySales.stream()
|
||||
.collect(Collectors.toMap(ShopOverviewStatisticsVO.TrendDataItem::getDate,
|
||||
ShopOverviewStatisticsVO.TrendDataItem::getValue, (a, b) -> a));
|
||||
Map<LocalDate, BigDecimal> ordersMap = dailyOrders != null
|
||||
? dailyOrders.stream().collect(Collectors.toMap(
|
||||
ShopOverviewStatisticsVO.TrendDataItem::getDate,
|
||||
ShopOverviewStatisticsVO.TrendDataItem::getValue, (a, b) -> a))
|
||||
: Collections.emptyMap();
|
||||
|
||||
LocalDate startDate = vo.getSalesAmountTrend().getDailyDataList().stream()
|
||||
.map(ShopOverviewStatisticsVO.TrendDataItem::getDate).min(LocalDate::compareTo).orElse(null);
|
||||
LocalDate endDate = vo.getSalesAmountTrend().getDailyDataList().stream()
|
||||
.map(ShopOverviewStatisticsVO.TrendDataItem::getDate).max(LocalDate::compareTo).orElse(null);
|
||||
Map<LocalDate, BigDecimal> salesMap = new HashMap<>();
|
||||
Map<LocalDate, BigDecimal> ordersMap = new HashMap<>();
|
||||
LocalDate startDate = null;
|
||||
LocalDate endDate = null;
|
||||
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||
if (p == null || p.getDate() == null || p.getDate().isBlank()) {
|
||||
continue;
|
||||
}
|
||||
LocalDate d = LocalDate.parse(p.getDate());
|
||||
salesMap.put(d, p.getSalesYuan() != null ? p.getSalesYuan() : BigDecimal.ZERO);
|
||||
ordersMap.put(d, BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||
if (startDate == null || d.isBefore(startDate)) {
|
||||
startDate = d;
|
||||
}
|
||||
if (endDate == null || d.isAfter(endDate)) {
|
||||
endDate = d;
|
||||
}
|
||||
}
|
||||
|
||||
int rowIdx = 2;
|
||||
if (startDate != null && endDate != null) {
|
||||
|
||||
-47
@@ -129,7 +129,6 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService {
|
||||
fillProductSalesTop10(vo);
|
||||
fillLegacyFlatFields(vo, curT, prevT);
|
||||
fillTargets(vo, companyId, shop.getId(), startDate, endDate, curT.totalSales(), curT.orderCount());
|
||||
fillLegacyTrends(vo, dealTrend);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -195,36 +194,6 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService {
|
||||
vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales()));
|
||||
}
|
||||
|
||||
private void fillLegacyTrends(ShopOverviewStatisticsVO vo, List<WorkbenchTrendPointVO> dealTrend) {
|
||||
ShopOverviewStatisticsVO.TrendData sales = new ShopOverviewStatisticsVO.TrendData();
|
||||
ShopOverviewStatisticsVO.TrendData orders = new ShopOverviewStatisticsVO.TrendData();
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> salesItems = new ArrayList<>();
|
||||
List<ShopOverviewStatisticsVO.TrendDataItem> orderItems = new ArrayList<>();
|
||||
BigDecimal salesTotal = BigDecimal.ZERO;
|
||||
BigDecimal orderTotal = BigDecimal.ZERO;
|
||||
if (dealTrend != null) {
|
||||
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||
ShopOverviewStatisticsVO.TrendDataItem s = new ShopOverviewStatisticsVO.TrendDataItem();
|
||||
s.setDate(LocalDate.parse(p.getDate()));
|
||||
s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan()));
|
||||
salesItems.add(s);
|
||||
salesTotal = salesTotal.add(s.getValue());
|
||||
|
||||
ShopOverviewStatisticsVO.TrendDataItem o = new ShopOverviewStatisticsVO.TrendDataItem();
|
||||
o.setDate(s.getDate());
|
||||
o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||
orderItems.add(o);
|
||||
orderTotal = orderTotal.add(o.getValue());
|
||||
}
|
||||
}
|
||||
sales.setDailyDataList(salesItems);
|
||||
sales.setTotal(salesTotal);
|
||||
orders.setDailyDataList(orderItems);
|
||||
orders.setTotal(orderTotal);
|
||||
vo.setSalesAmountTrend(sales);
|
||||
vo.setOrderCountTrend(orders);
|
||||
}
|
||||
|
||||
private List<WorkbenchCostSliceVO> buildProductSalesShare(
|
||||
ShopOverviewStatisticsVO.ProductOverview overview, BigDecimal salesTotal) {
|
||||
if (overview == null || overview.getProducts() == null || overview.getProducts().isEmpty()) {
|
||||
@@ -439,22 +408,6 @@ public class BiShopOverviewServiceImpl implements BiShopOverviewService {
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/** 税额 = 净销售额 × 税率 */
|
||||
private static BigDecimal salesTaxOnNet(BigDecimal sales, BigDecimal taxRate) {
|
||||
BigDecimal base = nz(sales);
|
||||
if (base.compareTo(BigDecimal.ZERO) < 0) {
|
||||
base = BigDecimal.ZERO;
|
||||
}
|
||||
return base.multiply(taxRate != null ? taxRate : DEFAULT_TAX_RATE).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private static BigDecimal roi(BigDecimal netSales, BigDecimal promo) {
|
||||
if (promo == null || promo.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return nz(netSales).divide(promo, 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
-20
@@ -1,12 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.skuoverview.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -44,22 +42,4 @@ public class SkuOverviewVO {
|
||||
private BigDecimal refundAmount;
|
||||
private BigDecimal averageOrderValue;
|
||||
private BigDecimal totalProfitBeforeTax;
|
||||
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData salesAmountTrend;
|
||||
/** @deprecated 使用 dealTrend */
|
||||
private TrendData orderCountTrend;
|
||||
|
||||
@Data
|
||||
public static class TrendData {
|
||||
private BigDecimal total;
|
||||
private List<TrendDataItem> dailyDataList;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TrendDataItem {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate date;
|
||||
private BigDecimal value;
|
||||
}
|
||||
}
|
||||
|
||||
-32
@@ -25,7 +25,6 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -122,7 +121,6 @@ public class BiSkuOverviewServiceImpl implements BiSkuOverviewService {
|
||||
vo.setYoyCompareDateStart(yoy[0].toString());
|
||||
vo.setYoyCompareDateEnd(yoy[1].toString());
|
||||
fillLegacyFlatFields(vo, curT, prevT);
|
||||
fillLegacyTrends(vo, dealTrend);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -267,36 +265,6 @@ public class BiSkuOverviewServiceImpl implements BiSkuOverviewService {
|
||||
vo.setMonthOverMonthGrowth(BiFinanceKpiAssembler.pctChange(cur.totalSales(), prev.totalSales()));
|
||||
}
|
||||
|
||||
private void fillLegacyTrends(SkuOverviewVO vo, List<WorkbenchTrendPointVO> dealTrend) {
|
||||
SkuOverviewVO.TrendData sales = new SkuOverviewVO.TrendData();
|
||||
SkuOverviewVO.TrendData orders = new SkuOverviewVO.TrendData();
|
||||
List<SkuOverviewVO.TrendDataItem> salesItems = new ArrayList<>();
|
||||
List<SkuOverviewVO.TrendDataItem> orderItems = new ArrayList<>();
|
||||
BigDecimal salesTotal = BigDecimal.ZERO;
|
||||
BigDecimal orderTotal = BigDecimal.ZERO;
|
||||
if (dealTrend != null) {
|
||||
for (WorkbenchTrendPointVO p : dealTrend) {
|
||||
SkuOverviewVO.TrendDataItem s = new SkuOverviewVO.TrendDataItem();
|
||||
s.setDate(LocalDate.parse(p.getDate()));
|
||||
s.setValue(BiFinanceKpiAssembler.nz(p.getSalesYuan()));
|
||||
salesItems.add(s);
|
||||
salesTotal = salesTotal.add(s.getValue());
|
||||
|
||||
SkuOverviewVO.TrendDataItem o = new SkuOverviewVO.TrendDataItem();
|
||||
o.setDate(s.getDate());
|
||||
o.setValue(BigDecimal.valueOf(p.getSalesOrderCount() != null ? p.getSalesOrderCount() : 0));
|
||||
orderItems.add(o);
|
||||
orderTotal = orderTotal.add(o.getValue());
|
||||
}
|
||||
}
|
||||
sales.setDailyDataList(salesItems);
|
||||
sales.setTotal(salesTotal);
|
||||
orders.setDailyDataList(orderItems);
|
||||
orders.setTotal(orderTotal);
|
||||
vo.setSalesAmountTrend(sales);
|
||||
vo.setOrderCountTrend(orders);
|
||||
}
|
||||
|
||||
private record PeriodBundle(List<Long> shopIds,
|
||||
BiFinanceKpiAssembler.Totals totals,
|
||||
List<OverviewAggRows.DailyRow> dailyRows) {
|
||||
|
||||
+3
-4
@@ -83,7 +83,6 @@ public class ProductSpecServiceImpl implements ProductSpecService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<ProductSpecVO> replaceSpecs(Long productId, ReplaceProductSpecsDTO dto) {
|
||||
ProductPO product = requireProduct(productId);
|
||||
Long companyId = product.getCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
List<ReplaceProductSpecsDTO.SpecItem> items =
|
||||
dto.getSpecs() == null ? List.of() : dto.getSpecs();
|
||||
@@ -368,7 +367,7 @@ public class ProductSpecServiceImpl implements ProductSpecService {
|
||||
if (valueIds.isEmpty()) {
|
||||
throw new BusinessException("请至少选择一个规格值");
|
||||
}
|
||||
List<ProductSpecValuePO> values = valueMapper.selectBatchIds(valueIds);
|
||||
List<ProductSpecValuePO> values = valueMapper.selectByIds(valueIds);
|
||||
if (values.size() != valueIds.size()) {
|
||||
throw new BusinessException("存在无效的规格值");
|
||||
}
|
||||
@@ -383,7 +382,7 @@ public class ProductSpecServiceImpl implements ProductSpecService {
|
||||
throw new BusinessException("同一规格维只能选择一个规格值");
|
||||
}
|
||||
}
|
||||
Map<Long, ProductSpecPO> specById = specMapper.selectBatchIds(specIds).stream()
|
||||
Map<Long, ProductSpecPO> specById = specMapper.selectByIds(specIds).stream()
|
||||
.collect(Collectors.toMap(ProductSpecPO::getId, s -> s, (a, b) -> a));
|
||||
return new ResolvedSpecValues(values, specById);
|
||||
}
|
||||
@@ -432,7 +431,7 @@ public class ProductSpecServiceImpl implements ProductSpecService {
|
||||
return Map.of();
|
||||
}
|
||||
Set<Long> valueIds = rels.stream().map(ProductSkuSpecValuePO::getSpecValueId).collect(Collectors.toSet());
|
||||
Map<Long, ProductSpecValuePO> valueMap = valueMapper.selectBatchIds(valueIds).stream()
|
||||
Map<Long, ProductSpecValuePO> valueMap = valueMapper.selectByIds(valueIds).stream()
|
||||
.collect(Collectors.toMap(ProductSpecValuePO::getId, v -> v, (a, b) -> a));
|
||||
Map<Long, List<ProductSpecValueVO>> result = new HashMap<>();
|
||||
for (ProductSkuSpecValuePO rel : rels) {
|
||||
|
||||
Reference in New Issue
Block a user