mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
refactor: 把工作台接口迁移到bi层
This commit is contained in:
@@ -26,11 +26,22 @@
|
||||
### 1.2 边界(本版不做)
|
||||
|
||||
- 不做月 / 年 rollup(旧 `ec_order_stat_monthly_*` / `yearly_*` 不迁移到本管线)
|
||||
- 不做推广费 / 刷单日表进 Mongo(仍走现有小表逻辑,读路径改造另期)
|
||||
- **不定义**工作台 / 概览等分析查看接口在 `bi` 下的目录命名(迁入与命名另期设计)
|
||||
- **切读 Mongo 另期**;现有读接口暂仍留在 `modules/ec`
|
||||
- 不做推广费 / 刷单日表进 Mongo(仍走现有小表逻辑;工作台读路径拼 MySQL)
|
||||
- 工作台分析接口已落 `modules/bi/workbench`(`/api/bi/workbench`,DTO/VO 同包);旧 `/api/ec/workbench` 仅兼容壳,可整目录删除
|
||||
- 不做非 PDD 渠道实现(契约预留 `platform`)
|
||||
|
||||
### 1.2.1 工作台 Mongo 缺口(可选后续)
|
||||
|
||||
当前 **不必** 新增集合即可跑通工作台:订单侧用 shop/product 日文档,推广/刷单/目标仍 MySQL。
|
||||
|
||||
若后续要减负或加速,可考虑:
|
||||
|
||||
| 建议 | 说明 |
|
||||
|------|------|
|
||||
| `bi_fee_stat_daily_shop` | 按店+日预聚合推广费、刷单费(仍可由 MySQL 触发回写) |
|
||||
| shop 日文档补 `platformCode` 已有 | 平台维 rollup 无需新集合 |
|
||||
| **不建议** 把税率/净利润写入 Mongo | 税率是查询参数,净利依赖费用分摊,适合读时计算 |
|
||||
|
||||
### 1.3 现状锚点
|
||||
|
||||
- PDD day / incremental / repair 已落 `channel_pdd_*`;扩展点 `PddOrderAfterSyncListener` 尚无业务实现
|
||||
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.orderstat.query;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyProductDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.model.document.BiOrderStatDailyShopDoc;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.repository.BiOrderStatDailyRepository;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.agg.OverviewAggRows;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* BI 订单日汇聚读查询:Mongo → 工作台/概览沿用的 {@link OverviewAggRows} 行形态。
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BiOrderStatQueryService {
|
||||
|
||||
private final BiOrderStatDailyRepository repository;
|
||||
|
||||
public List<BiOrderStatDailyShopDoc> listShopDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
return repository.listShopDocs(companyId, shopIds, start, end);
|
||||
}
|
||||
|
||||
public List<BiOrderStatDailyProductDoc> listProductDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
return repository.listProductDocs(companyId, shopIds, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品日文档按 (shopId, productId, categoryId) 合并区间后,转为工作台多维/四表所需行。
|
||||
* platformCode 由店铺主数据补齐(商品日文档无平台字段)。
|
||||
*/
|
||||
public List<OverviewAggRows.ShopProductRow> toShopProductRows(
|
||||
List<BiOrderStatDailyProductDoc> docs, Map<Long, String> platformByShopId) {
|
||||
Map<String, OverviewAggRows.ShopProductRow> merged = new HashMap<>();
|
||||
for (BiOrderStatDailyProductDoc doc : docs) {
|
||||
if (doc == null || doc.getShopId() == null) {
|
||||
continue;
|
||||
}
|
||||
long productId = doc.getProductId() != null ? doc.getProductId() : 0L;
|
||||
long categoryId = doc.getCategoryId() != null ? doc.getCategoryId() : 0L;
|
||||
String key = doc.getShopId() + ":" + productId + ":" + categoryId;
|
||||
OverviewAggRows.ShopProductRow row = merged.computeIfAbsent(key, k -> {
|
||||
OverviewAggRows.ShopProductRow r = new OverviewAggRows.ShopProductRow();
|
||||
r.setShopId(doc.getShopId());
|
||||
r.setPlatformCode(platformByShopId != null ? platformByShopId.get(doc.getShopId()) : null);
|
||||
r.setProductId(productId);
|
||||
r.setCategoryId(categoryId);
|
||||
r.setSalesAmount(BigDecimal.ZERO);
|
||||
r.setOrderCount(0L);
|
||||
r.setSalesQuantitySum(0L);
|
||||
r.setRefundAmount(BigDecimal.ZERO);
|
||||
r.setProductCost(BigDecimal.ZERO);
|
||||
r.setFreightCost(BigDecimal.ZERO);
|
||||
r.setOtherCost(BigDecimal.ZERO);
|
||||
r.setGmvAllStatus(BigDecimal.ZERO);
|
||||
r.setGmvOrderCount(0L);
|
||||
r.setGmvQuantitySum(0L);
|
||||
return r;
|
||||
});
|
||||
row.setSalesAmount(nz(row.getSalesAmount()).add(nz(doc.getSalesAmount())));
|
||||
row.setOrderCount(nzLong(row.getOrderCount()) + nzInt(doc.getSalesOrderCount()));
|
||||
row.setSalesQuantitySum(nzLong(row.getSalesQuantitySum()) + nzInt(doc.getSalesQuantitySum()));
|
||||
row.setRefundAmount(nz(row.getRefundAmount()).add(nz(doc.getRefundAmount())));
|
||||
row.setProductCost(nz(row.getProductCost()).add(nz(doc.getProductCost())));
|
||||
row.setFreightCost(nz(row.getFreightCost()).add(nz(doc.getFreightCost())));
|
||||
row.setOtherCost(nz(row.getOtherCost()).add(nz(doc.getOtherCost())));
|
||||
row.setGmvAllStatus(nz(row.getGmvAllStatus()).add(nz(doc.getGmvAmount())));
|
||||
row.setGmvOrderCount(nzLong(row.getGmvOrderCount()) + nzInt(doc.getGmvOrderCount()));
|
||||
row.setGmvQuantitySum(nzLong(row.getGmvQuantitySum()) + nzInt(doc.getGmvQuantitySum()));
|
||||
}
|
||||
return new ArrayList<>(merged.values());
|
||||
}
|
||||
|
||||
/** 店铺日文档按日历日跨店求和,供趋势图。 */
|
||||
public List<OverviewAggRows.DailyRow> toDailyRows(List<BiOrderStatDailyShopDoc> shopDocs) {
|
||||
Map<LocalDate, OverviewAggRows.DailyRow> byDay = new HashMap<>();
|
||||
for (BiOrderStatDailyShopDoc doc : shopDocs) {
|
||||
if (doc == null || doc.getStatDate() == null) {
|
||||
continue;
|
||||
}
|
||||
OverviewAggRows.DailyRow row = byDay.computeIfAbsent(doc.getStatDate(), d -> {
|
||||
OverviewAggRows.DailyRow r = new OverviewAggRows.DailyRow();
|
||||
r.setStatDate(d);
|
||||
r.setSalesAmount(BigDecimal.ZERO);
|
||||
r.setRefundAmount(BigDecimal.ZERO);
|
||||
r.setProductCost(BigDecimal.ZERO);
|
||||
r.setFreightCost(BigDecimal.ZERO);
|
||||
r.setOtherCost(BigDecimal.ZERO);
|
||||
return r;
|
||||
});
|
||||
row.setSalesAmount(nz(row.getSalesAmount()).add(nz(doc.getSalesAmount())));
|
||||
row.setRefundAmount(nz(row.getRefundAmount()).add(nz(doc.getRefundAmount())));
|
||||
row.setProductCost(nz(row.getProductCost()).add(nz(doc.getProductCost())));
|
||||
row.setFreightCost(nz(row.getFreightCost()).add(nz(doc.getFreightCost())));
|
||||
row.setOtherCost(nz(row.getOtherCost()).add(nz(doc.getOtherCost())));
|
||||
}
|
||||
return new ArrayList<>(byDay.values());
|
||||
}
|
||||
|
||||
/** 店铺日文档区间合计(KPI 用:单量不跨商品重复计)。 */
|
||||
public ShopPeriodMetrics sumShopDocs(List<BiOrderStatDailyShopDoc> shopDocs) {
|
||||
BigDecimal sales = BigDecimal.ZERO;
|
||||
BigDecimal refund = BigDecimal.ZERO;
|
||||
BigDecimal pc = BigDecimal.ZERO;
|
||||
BigDecimal fc = BigDecimal.ZERO;
|
||||
BigDecimal oc = BigDecimal.ZERO;
|
||||
BigDecimal gmv = BigDecimal.ZERO;
|
||||
int salesOrderCount = 0;
|
||||
int salesQuantitySum = 0;
|
||||
int gmvOrderCount = 0;
|
||||
int gmvQuantitySum = 0;
|
||||
for (BiOrderStatDailyShopDoc doc : shopDocs) {
|
||||
if (doc == null) {
|
||||
continue;
|
||||
}
|
||||
sales = sales.add(nz(doc.getSalesAmount()));
|
||||
refund = refund.add(nz(doc.getRefundAmount()));
|
||||
pc = pc.add(nz(doc.getProductCost()));
|
||||
fc = fc.add(nz(doc.getFreightCost()));
|
||||
oc = oc.add(nz(doc.getOtherCost()));
|
||||
gmv = gmv.add(nz(doc.getGmvAmount()));
|
||||
salesOrderCount += nzInt(doc.getSalesOrderCount());
|
||||
salesQuantitySum += nzInt(doc.getSalesQuantitySum());
|
||||
gmvOrderCount += nzInt(doc.getGmvOrderCount());
|
||||
gmvQuantitySum += nzInt(doc.getGmvQuantitySum());
|
||||
}
|
||||
return new ShopPeriodMetrics(sales, refund, pc, fc, oc, gmv,
|
||||
salesOrderCount, salesQuantitySum, gmvOrderCount, gmvQuantitySum);
|
||||
}
|
||||
|
||||
public record ShopPeriodMetrics(
|
||||
BigDecimal salesAmount,
|
||||
BigDecimal refundAmount,
|
||||
BigDecimal productCost,
|
||||
BigDecimal freightCost,
|
||||
BigDecimal otherCost,
|
||||
BigDecimal gmvAmount,
|
||||
int salesOrderCount,
|
||||
int salesQuantitySum,
|
||||
int gmvOrderCount,
|
||||
int gmvQuantitySum
|
||||
) {
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private static long nzLong(Number v) {
|
||||
return v != null ? v.longValue() : 0L;
|
||||
}
|
||||
|
||||
private static int nzInt(Integer v) {
|
||||
return v != null ? v : 0;
|
||||
}
|
||||
}
|
||||
+24
@@ -33,6 +33,30 @@ public class BiOrderStatDailyRepository {
|
||||
return Optional.ofNullable(mongoTemplate.findOne(q, BiOrderStatDailyShopDoc.class));
|
||||
}
|
||||
|
||||
/** 区间内店铺日文档(闭区间 [start, end])。shopIds 为空返回空列表。 */
|
||||
public List<BiOrderStatDailyShopDoc> listShopDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
if (companyId == null || shopIds == null || shopIds.isEmpty() || start == null || end == null) {
|
||||
return List.of();
|
||||
}
|
||||
Query q = Query.query(Criteria.where("companyId").is(companyId)
|
||||
.and("shopId").in(shopIds)
|
||||
.and("statDate").gte(start).lte(end));
|
||||
return mongoTemplate.find(q, BiOrderStatDailyShopDoc.class);
|
||||
}
|
||||
|
||||
/** 区间内商品日文档(闭区间)。shopIds 为空返回空列表。 */
|
||||
public List<BiOrderStatDailyProductDoc> listProductDocs(Long companyId, List<Long> shopIds,
|
||||
LocalDate start, LocalDate end) {
|
||||
if (companyId == null || shopIds == null || shopIds.isEmpty() || start == null || end == null) {
|
||||
return List.of();
|
||||
}
|
||||
Query q = Query.query(Criteria.where("companyId").is(companyId)
|
||||
.and("shopId").in(shopIds)
|
||||
.and("statDate").gte(start).lte(end));
|
||||
return mongoTemplate.find(q, BiOrderStatDailyProductDoc.class);
|
||||
}
|
||||
|
||||
public void replaceShopDay(BiOrderStatDailyShopDoc shopDoc,
|
||||
List<BiOrderStatDailyProductDoc> products,
|
||||
List<BiOrderStatDailySkuDoc> skus) {
|
||||
|
||||
+18
-18
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.controller;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -9,52 +9,52 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto.WorkbenchQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchFinanceSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchMultiAnalysisPanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchPeriodCompareSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.service.WorkbenchService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.service.BiWorkbenchService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchFinanceSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchMultiAnalysisPanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchPeriodCompareSliceVO;
|
||||
|
||||
/**
|
||||
* 电商运营工作台:经营概览、多维分析、排行等分 Tab 聚合数据。
|
||||
* BI 工作台查询:订单指标来自 Mongo 日汇聚,推广/刷单来自 MySQL。
|
||||
*/
|
||||
@Tag(name = "电商-工作台", description = "工作台聚合统计")
|
||||
@Tag(name = "BI-工作台", description = "工作台聚合统计(Mongo 订单日汇聚)")
|
||||
@RestController
|
||||
@RequestMapping("/api/ec/workbench")
|
||||
public class WorkbenchController {
|
||||
@RequestMapping("/api/bi/workbench")
|
||||
public class BiWorkbenchController {
|
||||
|
||||
private final WorkbenchService workbenchService;
|
||||
private final BiWorkbenchService biWorkbenchService;
|
||||
|
||||
public WorkbenchController(WorkbenchService workbenchService) {
|
||||
this.workbenchService = workbenchService;
|
||||
public BiWorkbenchController(BiWorkbenchService biWorkbenchService) {
|
||||
this.biWorkbenchService = biWorkbenchService;
|
||||
}
|
||||
|
||||
@Operation(summary = "经营概览 Tab", description = "KPI、趋势、平台占比及底部四张汇总表")
|
||||
@PostMapping("/finance")
|
||||
@RequirePermission(value = "ecom:shop:read", description = "查询工作台经营概览", allowSuper = true)
|
||||
public ApiResponse<WorkbenchFinanceSliceVO> finance(@Valid @RequestBody WorkbenchQueryDTO queryDTO) {
|
||||
return ApiResponse.success("获取经营概览成功", workbenchService.financeSlice(queryDTO));
|
||||
return ApiResponse.success("获取经营概览成功", biWorkbenchService.financeSlice(queryDTO));
|
||||
}
|
||||
|
||||
@Operation(summary = "多维分析 Tab", description = "平台/店铺/品类/商品四维损益")
|
||||
@PostMapping("/multi-analysis")
|
||||
@RequirePermission(value = "ecom:shop:read", description = "查询工作台多维分析", allowSuper = true)
|
||||
public ApiResponse<WorkbenchMultiAnalysisPanelVO> multiAnalysis(@Valid @RequestBody WorkbenchQueryDTO queryDTO) {
|
||||
return ApiResponse.success("获取多维分析成功", workbenchService.multiAnalysis(queryDTO));
|
||||
return ApiResponse.success("获取多维分析成功", biWorkbenchService.multiAnalysis(queryDTO));
|
||||
}
|
||||
|
||||
@Operation(summary = "销售额排行 Tab", description = "与多维分析同源,按销售额降序")
|
||||
@PostMapping("/sales-rank")
|
||||
@RequirePermission(value = "ecom:shop:read", description = "查询工作台销售额排行", allowSuper = true)
|
||||
public ApiResponse<WorkbenchMultiAnalysisPanelVO> salesRank(@Valid @RequestBody WorkbenchQueryDTO queryDTO) {
|
||||
return ApiResponse.success("获取销售额排行成功", workbenchService.salesRank(queryDTO));
|
||||
return ApiResponse.success("获取销售额排行成功", biWorkbenchService.salesRank(queryDTO));
|
||||
}
|
||||
|
||||
@Operation(summary = "区间对比切片", description = "按单段日期范围返回店铺汇总「合计」行,供区间对比 Tab 双请求对比")
|
||||
@Operation(summary = "区间对比切片", description = "按单段日期范围返回店铺汇总「合计」行")
|
||||
@PostMapping("/period-compare/slice")
|
||||
@RequirePermission(value = "ecom:shop:read", description = "查询工作台区间对比", allowSuper = true)
|
||||
public ApiResponse<WorkbenchPeriodCompareSliceVO> periodCompareSlice(
|
||||
@Valid @RequestBody WorkbenchQueryDTO queryDTO) {
|
||||
return ApiResponse.success("获取区间对比数据成功", workbenchService.periodCompareSlice(queryDTO));
|
||||
return ApiResponse.success("获取区间对比数据成功", biWorkbenchService.periodCompareSlice(queryDTO));
|
||||
}
|
||||
}
|
||||
+17
-24
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.controller;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -11,58 +11,51 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.service.BiWorkbenchExportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.util.ExportFilenameUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto.WorkbenchExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.service.WorkbenchExportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchExportDTO;
|
||||
|
||||
/**
|
||||
* 多维度经营明细 Excel 导出:{@code POST /ec/workbench/export/...}
|
||||
*/
|
||||
@Tag(name = "电商-工作台导出", description = "多维度经营明细:按店铺/平台/品类/商品汇总导出 Excel")
|
||||
@Tag(name = "BI-工作台导出", description = "多维度经营明细 Excel 导出(Mongo 订单日汇聚)")
|
||||
@RestController
|
||||
@RequestMapping("/api/ec/workbench/export")
|
||||
public class WorkbenchExportController {
|
||||
@RequestMapping("/api/bi/workbench/export")
|
||||
public class BiWorkbenchExportController {
|
||||
|
||||
private final WorkbenchExportService workbenchExportService;
|
||||
private final BiWorkbenchExportService exportService;
|
||||
|
||||
public WorkbenchExportController(WorkbenchExportService workbenchExportService) {
|
||||
this.workbenchExportService = workbenchExportService;
|
||||
public BiWorkbenchExportController(BiWorkbenchExportService exportService) {
|
||||
this.exportService = exportService;
|
||||
}
|
||||
|
||||
@Operation(summary = "多维度经营明细-按店铺汇总导出")
|
||||
@PostMapping("/by-shop")
|
||||
@RequirePermission(value = "data:export", description = "导出多维度经营明细(按店铺)", allowSuper = true)
|
||||
public void exportByShop(@Valid @RequestBody WorkbenchExportDTO dto, HttpServletResponse response) {
|
||||
byte[] data = workbenchExportService.exportByShop(dto);
|
||||
String filename = ExportFilenameUtils.buildWorkbenchXlsxName("按店铺汇总", dto.getDateRange());
|
||||
writeExcel(response, filename, data);
|
||||
writeExcel(response, ExportFilenameUtils.buildWorkbenchXlsxName("按店铺汇总", dto.getDateRange()),
|
||||
exportService.exportByShop(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "多维度经营明细-按平台汇总导出")
|
||||
@PostMapping("/by-platform")
|
||||
@RequirePermission(value = "data:export", description = "导出多维度经营明细(按平台)", allowSuper = true)
|
||||
public void exportByPlatform(@Valid @RequestBody WorkbenchExportDTO dto, HttpServletResponse response) {
|
||||
byte[] data = workbenchExportService.exportByPlatform(dto);
|
||||
String filename = ExportFilenameUtils.buildWorkbenchXlsxName("按平台汇总", dto.getDateRange());
|
||||
writeExcel(response, filename, data);
|
||||
writeExcel(response, ExportFilenameUtils.buildWorkbenchXlsxName("按平台汇总", dto.getDateRange()),
|
||||
exportService.exportByPlatform(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "多维度经营明细-按品类汇总导出")
|
||||
@PostMapping("/by-category")
|
||||
@RequirePermission(value = "data:export", description = "导出多维度经营明细(按品类)", allowSuper = true)
|
||||
public void exportByCategory(@Valid @RequestBody WorkbenchExportDTO dto, HttpServletResponse response) {
|
||||
byte[] data = workbenchExportService.exportByCategory(dto);
|
||||
String filename = ExportFilenameUtils.buildWorkbenchXlsxName("按品类汇总", dto.getDateRange());
|
||||
writeExcel(response, filename, data);
|
||||
writeExcel(response, ExportFilenameUtils.buildWorkbenchXlsxName("按品类汇总", dto.getDateRange()),
|
||||
exportService.exportByCategory(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "多维度经营明细-按商品汇总导出")
|
||||
@PostMapping("/by-product")
|
||||
@RequirePermission(value = "data:export", description = "导出多维度经营明细(按商品)", allowSuper = true)
|
||||
public void exportByProduct(@Valid @RequestBody WorkbenchExportDTO dto, HttpServletResponse response) {
|
||||
byte[] data = workbenchExportService.exportByProduct(dto);
|
||||
String filename = ExportFilenameUtils.buildWorkbenchXlsxName("按商品汇总", dto.getDateRange());
|
||||
writeExcel(response, filename, data);
|
||||
writeExcel(response, ExportFilenameUtils.buildWorkbenchXlsxName("按商品汇总", dto.getDateRange()),
|
||||
exportService.exportByProduct(dto));
|
||||
}
|
||||
|
||||
private void writeExcel(HttpServletResponse response, String filename, byte[] data) {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchExportDTO;
|
||||
|
||||
public interface BiWorkbenchExportService {
|
||||
|
||||
byte[] exportByShop(WorkbenchExportDTO dto);
|
||||
|
||||
byte[] exportByPlatform(WorkbenchExportDTO dto);
|
||||
|
||||
byte[] exportByCategory(WorkbenchExportDTO dto);
|
||||
|
||||
byte[] exportByProduct(WorkbenchExportDTO dto);
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.vo.CompanyOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchFinanceSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchMultiAnalysisPanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchPeriodCompareSliceVO;
|
||||
|
||||
/**
|
||||
* BI 工作台:读 Mongo 订单日汇聚 + MySQL 推广/刷单。
|
||||
*/
|
||||
public interface BiWorkbenchService {
|
||||
|
||||
WorkbenchFinanceSliceVO financeSlice(WorkbenchQueryDTO queryDTO);
|
||||
|
||||
WorkbenchMultiAnalysisPanelVO multiAnalysis(WorkbenchQueryDTO queryDTO);
|
||||
|
||||
WorkbenchMultiAnalysisPanelVO salesRank(WorkbenchQueryDTO queryDTO);
|
||||
|
||||
WorkbenchPeriodCompareSliceVO periodCompareSlice(WorkbenchQueryDTO queryDTO);
|
||||
|
||||
/** 与 finance 四表同口径,供导出使用 */
|
||||
CompanyOverviewVO.WorkbenchTableBundle loadSummaryTables(WorkbenchExportDTO dto);
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.service.BiWorkbenchExportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.service.BiWorkbenchService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.dto.CategoryExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.dto.CompanyExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.dto.PlatformExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.vo.CompanyOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.service.CategoryExportExcelService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.service.ExportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchExportDTO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
public class BiWorkbenchExportServiceImpl implements BiWorkbenchExportService {
|
||||
|
||||
private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04");
|
||||
|
||||
private final BiWorkbenchService biWorkbenchService;
|
||||
private final ExportService exportService;
|
||||
private final CategoryExportExcelService categoryExportExcelService;
|
||||
|
||||
public BiWorkbenchExportServiceImpl(BiWorkbenchService biWorkbenchService,
|
||||
ExportService exportService,
|
||||
CategoryExportExcelService categoryExportExcelService) {
|
||||
this.biWorkbenchService = biWorkbenchService;
|
||||
this.exportService = exportService;
|
||||
this.categoryExportExcelService = categoryExportExcelService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] exportByShop(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = biWorkbenchService.loadSummaryTables(dto);
|
||||
CompanyExportDTO exportDto = new CompanyExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setShopIds(dto.getShopIds());
|
||||
return exportService.exportShopOverviewFromTable(
|
||||
exportDto, bundle.getShopTable(), "多维度经营明细 - 按店铺汇总");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] exportByPlatform(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = biWorkbenchService.loadSummaryTables(dto);
|
||||
PlatformExportDTO exportDto = new PlatformExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setPlatformCodes(dto.getPlatformCodes());
|
||||
return exportService.exportPlatformOverviewFromTable(
|
||||
exportDto, bundle.getPlatformTable(), "多维度经营明细 - 按平台汇总");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] exportByCategory(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = biWorkbenchService.loadSummaryTables(dto);
|
||||
CategoryExportDTO exportDto = new CategoryExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setCategoryIds(dto.getCategoryIds());
|
||||
exportDto.setShopId(null);
|
||||
return categoryExportExcelService.exportCategoryDimensionsFromTable(
|
||||
exportDto, bundle.getCategoryTable(),
|
||||
"多维度经营明细 - 品类多维度损益汇总", "品类名称");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] exportByProduct(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = biWorkbenchService.loadSummaryTables(dto);
|
||||
CategoryExportDTO exportDto = new CategoryExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setCategoryIds(dto.getProductIds());
|
||||
exportDto.setShopId(null);
|
||||
return categoryExportExcelService.exportCategoryDimensionsFromTable(
|
||||
exportDto, bundle.getProductTable(),
|
||||
"多维度经营明细 - 商品多维度损益汇总", "商品名称");
|
||||
}
|
||||
}
|
||||
+110
-34
@@ -1,4 +1,4 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.service.impl;
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -15,16 +15,19 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto.WorkbenchQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchFinanceSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchPeriodCompareSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchCostSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchDimRowVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchFinancePanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchKpiItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchMultiAnalysisPanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.service.WorkbenchService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchFinanceSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchPeriodCompareSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchCostSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchDimRowVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchFinancePanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchKpiItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchMultiAnalysisPanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.vo.WorkbenchTrendPointVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.query.BiOrderStatQueryService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.service.BiWorkbenchService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.support.BiWorkbenchFeeLoader;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.workbench.model.dto.WorkbenchExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -47,7 +50,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 运营工作台核心聚合实现。
|
||||
* BI 侧运营工作台:订单指标读 Mongo 日汇聚,推广/刷单读 MySQL。
|
||||
* <p>
|
||||
* 口径约定:
|
||||
* <ul>
|
||||
@@ -61,7 +64,7 @@ import java.util.stream.Collectors;
|
||||
* 分 Tab 输出:{@link #financeSlice}、{@link #multiAnalysis}、{@link #salesRank}。
|
||||
*/
|
||||
@Service
|
||||
public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
public class BiWorkbenchServiceImpl implements BiWorkbenchService {
|
||||
|
||||
/** 未传税率时与单店概览等模块默认一致(4%) */
|
||||
private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04");
|
||||
@@ -74,22 +77,28 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
private final ProductMapper productMapper;
|
||||
private final CategoryService categoryService;
|
||||
private final CompanyOverviewService companyOverviewService;
|
||||
private final BiOrderStatQueryService orderStatQueryService;
|
||||
private final BiWorkbenchFeeLoader feeLoader;
|
||||
|
||||
public WorkbenchServiceImpl(CurrentUserContext currentUserContext,
|
||||
ShopService shopService,
|
||||
OrderStatusStatResolver orderStatusStatResolver,
|
||||
ProductMapper productMapper,
|
||||
CategoryService categoryService,
|
||||
CompanyOverviewService companyOverviewService) {
|
||||
public BiWorkbenchServiceImpl(CurrentUserContext currentUserContext,
|
||||
ShopService shopService,
|
||||
OrderStatusStatResolver orderStatusStatResolver,
|
||||
ProductMapper productMapper,
|
||||
CategoryService categoryService,
|
||||
CompanyOverviewService companyOverviewService,
|
||||
BiOrderStatQueryService orderStatQueryService,
|
||||
BiWorkbenchFeeLoader feeLoader) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.orderStatusStatResolver = orderStatusStatResolver;
|
||||
this.productMapper = productMapper;
|
||||
this.categoryService = categoryService;
|
||||
this.companyOverviewService = companyOverviewService;
|
||||
this.orderStatQueryService = orderStatQueryService;
|
||||
this.feeLoader = feeLoader;
|
||||
}
|
||||
|
||||
/** 经营概览 Tab:SQL 聚合 KPI/趋势/饼图 + 底部四表 */
|
||||
/** 经营概览 Tab:Mongo 订单日汇聚 + MySQL 推广/刷单 + 底部四表 */
|
||||
@Override
|
||||
public WorkbenchFinanceSliceVO financeSlice(WorkbenchQueryDTO queryDTO) {
|
||||
ShopContext ctx = resolveShopContext(queryDTO);
|
||||
@@ -99,8 +108,11 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
|
||||
SqlAggBundle agg = loadSqlAgg(ctx);
|
||||
ComparePeriodBundle compare = loadCompareFromSql(ctx);
|
||||
// 店铺日汇总表口径:含 GMV/销售双三角 + 成本;推广/刷单仍用区间聚合
|
||||
Totals cur = buildShopPeriodTotals(ctx, ctx.range(), agg.promoTotal(), agg.brushTotal());
|
||||
BiOrderStatQueryService.ShopPeriodMetrics m = agg.shopMetrics();
|
||||
Totals cur = buildTotals(m.salesAmount(), m.refundAmount(), m.productCost(), m.freightCost(), m.otherCost(),
|
||||
agg.promoTotal(), agg.brushTotal(), ctx.taxRate(),
|
||||
m.salesOrderCount(), m.salesQuantitySum(),
|
||||
m.gmvAmount(), m.gmvOrderCount(), m.gmvQuantitySum());
|
||||
|
||||
WorkbenchFinancePanelVO finance = buildFinancePanelFromSql(ctx, cur, compare, agg);
|
||||
|
||||
@@ -158,6 +170,30 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
.startDate(range.startDate()).endDate(range.endDate()).total(total).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompanyOverviewVO.WorkbenchTableBundle loadSummaryTables(WorkbenchExportDTO dto) {
|
||||
WorkbenchQueryDTO query = new WorkbenchQueryDTO();
|
||||
query.setDateRange(dto.getDateRange());
|
||||
query.setTaxRate(dto.getTaxRate());
|
||||
query.setPlatformCode(dto.getPlatformCode());
|
||||
query.setShopId(dto.getShopId());
|
||||
ShopContext ctx = resolveShopContext(query);
|
||||
if (ctx.shops().isEmpty()) {
|
||||
throw new BusinessException("没有可导出的店铺");
|
||||
}
|
||||
if (ctx.stat().isUnionEmpty()) {
|
||||
return companyOverviewService.buildWorkbenchSummaryTablesFromAgg(
|
||||
ctx.taxRate(), ctx.companyId(), ctx.shops(),
|
||||
List.of(), List.of(), List.of(),
|
||||
ctx.range().startDate(), ctx.range().endDate());
|
||||
}
|
||||
SqlAggBundle agg = loadSqlAgg(ctx);
|
||||
return companyOverviewService.buildWorkbenchSummaryTablesFromAgg(
|
||||
ctx.taxRate(), ctx.companyId(), ctx.shops(),
|
||||
agg.orderRows(), agg.promotionRows(), agg.brushRows(),
|
||||
ctx.range().startDate(), ctx.range().endDate());
|
||||
}
|
||||
|
||||
private WorkbenchFinanceSliceVO emptyFinanceSlice() {
|
||||
return WorkbenchFinanceSliceVO.builder()
|
||||
.finance(emptyFinancePanel())
|
||||
@@ -198,25 +234,55 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
return new ShopContext(taxRate, companyId, range, stat, shops, shopIds, shopById);
|
||||
}
|
||||
|
||||
/** 订单统计读模型已移除:返回空聚合,KPI/趋势降级为 0 */
|
||||
/** 订单:Mongo 日汇聚;推广/刷单:MySQL */
|
||||
private SqlAggBundle loadSqlAgg(ShopContext ctx) {
|
||||
return new SqlAggBundle(Collections.emptyList(), Collections.emptyList(),
|
||||
Collections.emptyList(), Collections.emptyList());
|
||||
Map<Long, String> platformByShop = ctx.shops().stream()
|
||||
.filter(s -> s.getId() != null)
|
||||
.collect(Collectors.toMap(ShopPO::getId, ShopPO::getPlatformCode, (a, b) -> a));
|
||||
var shopDocs = orderStatQueryService.listShopDocs(
|
||||
ctx.companyId(), ctx.shopIds(), ctx.range().startDate(), ctx.range().endDate());
|
||||
var productDocs = orderStatQueryService.listProductDocs(
|
||||
ctx.companyId(), ctx.shopIds(), ctx.range().startDate(), ctx.range().endDate());
|
||||
BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(
|
||||
ctx.companyId(), ctx.shopIds(), ctx.range().startDate(), ctx.range().endDate());
|
||||
return new SqlAggBundle(
|
||||
orderStatQueryService.toShopProductRows(productDocs, platformByShop),
|
||||
orderStatQueryService.toDailyRows(shopDocs),
|
||||
fees.promotionRows(),
|
||||
fees.brushRows(),
|
||||
orderStatQueryService.sumShopDocs(shopDocs));
|
||||
}
|
||||
|
||||
/** 环比/同比:统计读模型移除后各段均为 0 */
|
||||
/** 环比/同比:各自区间的 Mongo 店铺合计 + 费用 */
|
||||
private ComparePeriodBundle loadCompareFromSql(ShopContext ctx) {
|
||||
DateRange lastRange = lastMonthSameSpan(ctx.range());
|
||||
DateRange yoyRange = new DateRange(ctx.range().startDate().minusYears(1), ctx.range().endDate().minusYears(1));
|
||||
Totals prev = buildShopPeriodTotals(ctx, lastRange, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||
Totals yoy = buildShopPeriodTotals(ctx, yoyRange, BigDecimal.ZERO, BigDecimal.ZERO);
|
||||
Totals prev = buildShopPeriodTotals(ctx, lastRange);
|
||||
Totals yoy = buildShopPeriodTotals(ctx, yoyRange);
|
||||
return new ComparePeriodBundle(lastRange, yoyRange, prev, yoy);
|
||||
}
|
||||
|
||||
/** 单时间段店铺 KPI:统计读模型移除后返回 0 */
|
||||
/** 单时间段店铺 KPI:Mongo 店铺日文档合计 + 区间推广/刷单 */
|
||||
private Totals buildShopPeriodTotals(ShopContext ctx, DateRange range) {
|
||||
var shopDocs = orderStatQueryService.listShopDocs(
|
||||
ctx.companyId(), ctx.shopIds(), range.startDate(), range.endDate());
|
||||
BiOrderStatQueryService.ShopPeriodMetrics m = orderStatQueryService.sumShopDocs(shopDocs);
|
||||
BiWorkbenchFeeLoader.FeeBundle fees = feeLoader.load(
|
||||
ctx.companyId(), ctx.shopIds(), range.startDate(), range.endDate());
|
||||
return buildTotals(m.salesAmount(), m.refundAmount(), m.productCost(), m.freightCost(), m.otherCost(),
|
||||
fees.promoTotal(), fees.brushTotal(), ctx.taxRate(),
|
||||
m.salesOrderCount(), m.salesQuantitySum(),
|
||||
m.gmvAmount(), m.gmvOrderCount(), m.gmvQuantitySum());
|
||||
}
|
||||
|
||||
private Totals buildShopPeriodTotals(ShopContext ctx, DateRange range, BigDecimal promotion, BigDecimal brush) {
|
||||
return buildTotals(BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
promotion, brush, ctx.taxRate(), 0, 0, BigDecimal.ZERO, 0, 0);
|
||||
var shopDocs = orderStatQueryService.listShopDocs(
|
||||
ctx.companyId(), ctx.shopIds(), range.startDate(), range.endDate());
|
||||
BiOrderStatQueryService.ShopPeriodMetrics m = orderStatQueryService.sumShopDocs(shopDocs);
|
||||
return buildTotals(m.salesAmount(), m.refundAmount(), m.productCost(), m.freightCost(), m.otherCost(),
|
||||
promotion, brush, ctx.taxRate(),
|
||||
m.salesOrderCount(), m.salesQuantitySum(),
|
||||
m.gmvAmount(), m.gmvOrderCount(), m.gmvQuantitySum());
|
||||
}
|
||||
|
||||
private WorkbenchFinancePanelVO buildFinancePanelFromSql(ShopContext ctx, Totals cur,
|
||||
@@ -272,17 +338,26 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
BigDecimal promotion, BigDecimal brush, BigDecimal taxRate) {
|
||||
BigDecimal sales = BigDecimal.ZERO, refund = BigDecimal.ZERO;
|
||||
BigDecimal pc = BigDecimal.ZERO, fc = BigDecimal.ZERO, oc = BigDecimal.ZERO;
|
||||
BigDecimal gmv = BigDecimal.ZERO;
|
||||
int orderCount = 0;
|
||||
int salesQty = 0;
|
||||
int gmvOrderCount = 0;
|
||||
int gmvQty = 0;
|
||||
for (OverviewAggRows.ShopProductRow row : rows) {
|
||||
sales = sales.add(nz(row.getSalesAmount()));
|
||||
refund = refund.add(nz(row.getRefundAmount()));
|
||||
pc = pc.add(nz(row.getProductCost()));
|
||||
fc = fc.add(nz(row.getFreightCost()));
|
||||
oc = oc.add(nz(row.getOtherCost()));
|
||||
gmv = gmv.add(nz(row.getGmvAllStatus()));
|
||||
orderCount += row.getOrderCount() != null ? row.getOrderCount().intValue() : 0;
|
||||
salesQty += row.getSalesQuantitySum() != null ? row.getSalesQuantitySum().intValue() : 0;
|
||||
gmvOrderCount += row.getGmvOrderCount() != null ? row.getGmvOrderCount().intValue() : 0;
|
||||
gmvQty += row.getGmvQuantitySum() != null ? row.getGmvQuantitySum().intValue() : 0;
|
||||
}
|
||||
return buildTotals(sales, refund, pc, fc, oc, promotion, brush, taxRate, orderCount, 0,
|
||||
BigDecimal.ZERO, 0, 0);
|
||||
// 注意:商品粒度单量跨商品会重复计;多维/排行仅用销售额等金额字段,KPI 走店铺日文档
|
||||
return buildTotals(sales, refund, pc, fc, oc, promotion, brush, taxRate, orderCount, salesQty,
|
||||
gmv, gmvOrderCount, gmvQty);
|
||||
}
|
||||
|
||||
private Totals buildTotals(BigDecimal sales, BigDecimal refund, BigDecimal pc, BigDecimal fc, BigDecimal oc,
|
||||
@@ -406,7 +481,8 @@ public class WorkbenchServiceImpl implements WorkbenchService {
|
||||
private record SqlAggBundle(List<OverviewAggRows.ShopProductRow> orderRows,
|
||||
List<OverviewAggRows.DailyRow> dailyRows,
|
||||
List<OverviewAggRows.PromotionRow> promotionRows,
|
||||
List<OverviewAggRows.BrushRow> brushRows) {
|
||||
List<OverviewAggRows.BrushRow> brushRows,
|
||||
BiOrderStatQueryService.ShopPeriodMetrics shopMetrics) {
|
||||
BigDecimal promoTotal() {
|
||||
return promotionRows.stream().map(r -> nz(r.getFeeAmount())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.bi.workbench.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.brushorder.mapper.BrushOrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.brushorder.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.agg.OverviewAggRows;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.promotion.model.po.PromotionFeePO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 工作台费用侧:推广费 / 刷单仍读 MySQL 小表(不进 Mongo)。
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class BiWorkbenchFeeLoader {
|
||||
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final BrushOrderMapper brushOrderMapper;
|
||||
|
||||
public FeeBundle load(Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
|
||||
if (companyId == null || shopIds == null || shopIds.isEmpty() || start == null || end == null) {
|
||||
return FeeBundle.empty();
|
||||
}
|
||||
return new FeeBundle(loadPromotionRows(companyId, shopIds, start, end),
|
||||
loadBrushRows(companyId, shopIds, start, end));
|
||||
}
|
||||
|
||||
private List<OverviewAggRows.PromotionRow> loadPromotionRows(
|
||||
Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
|
||||
List<PromotionFeePO> fees = promotionFeeMapper.selectList(new LambdaQueryWrapper<PromotionFeePO>()
|
||||
.eq(PromotionFeePO::getCompanyId, companyId)
|
||||
.in(PromotionFeePO::getShopId, shopIds)
|
||||
.ge(PromotionFeePO::getFeeDate, start)
|
||||
.le(PromotionFeePO::getFeeDate, end));
|
||||
Map<String, OverviewAggRows.PromotionRow> merged = new HashMap<>();
|
||||
for (PromotionFeePO fee : fees) {
|
||||
if (fee == null || fee.getShopId() == null) {
|
||||
continue;
|
||||
}
|
||||
Long productId = fee.getProductId();
|
||||
Long categoryId = fee.getCategoryId();
|
||||
String key = fee.getShopId() + ":" + productId + ":" + categoryId;
|
||||
OverviewAggRows.PromotionRow row = merged.computeIfAbsent(key, k -> {
|
||||
OverviewAggRows.PromotionRow r = new OverviewAggRows.PromotionRow();
|
||||
r.setShopId(fee.getShopId());
|
||||
r.setProductId(productId);
|
||||
r.setCategoryId(categoryId);
|
||||
r.setFeeAmount(BigDecimal.ZERO);
|
||||
return r;
|
||||
});
|
||||
row.setFeeAmount(nz(row.getFeeAmount()).add(nz(fee.getFeeAmount())));
|
||||
}
|
||||
return new ArrayList<>(merged.values());
|
||||
}
|
||||
|
||||
private List<OverviewAggRows.BrushRow> loadBrushRows(
|
||||
Long companyId, List<Long> shopIds, LocalDate start, LocalDate end) {
|
||||
LocalDateTime startDt = start.atStartOfDay();
|
||||
LocalDateTime endDt = end.plusDays(1).atStartOfDay();
|
||||
List<BrushOrderPO> rows = brushOrderMapper.selectList(new LambdaQueryWrapper<BrushOrderPO>()
|
||||
.eq(BrushOrderPO::getCompanyId, companyId)
|
||||
.in(BrushOrderPO::getShopId, shopIds)
|
||||
.ge(BrushOrderPO::getBrushTime, startDt)
|
||||
.lt(BrushOrderPO::getBrushTime, endDt));
|
||||
Map<Long, OverviewAggRows.BrushRow> merged = new HashMap<>();
|
||||
for (BrushOrderPO b : rows) {
|
||||
if (b == null || b.getShopId() == null) {
|
||||
continue;
|
||||
}
|
||||
OverviewAggRows.BrushRow row = merged.computeIfAbsent(b.getShopId(), id -> {
|
||||
OverviewAggRows.BrushRow r = new OverviewAggRows.BrushRow();
|
||||
r.setShopId(id);
|
||||
r.setBrushAmount(BigDecimal.ZERO);
|
||||
return r;
|
||||
});
|
||||
row.setBrushAmount(nz(row.getBrushAmount()).add(nz(b.getBrushAmount())));
|
||||
}
|
||||
return new ArrayList<>(merged.values());
|
||||
}
|
||||
|
||||
public record FeeBundle(
|
||||
List<OverviewAggRows.PromotionRow> promotionRows,
|
||||
List<OverviewAggRows.BrushRow> brushRows
|
||||
) {
|
||||
static FeeBundle empty() {
|
||||
return new FeeBundle(List.of(), List.of());
|
||||
}
|
||||
|
||||
public BigDecimal promoTotal() {
|
||||
return promotionRows.stream()
|
||||
.map(r -> nz(r.getFeeAmount()))
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
public BigDecimal brushTotal() {
|
||||
return brushRows.stream()
|
||||
.map(r -> nz(r.getBrushAmount()))
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto.WorkbenchExportDTO;
|
||||
|
||||
/**
|
||||
* 工作台:底部四张汇总表 Excel 导出(与页面筛选、汇总口径一致)。
|
||||
*/
|
||||
public interface WorkbenchExportService {
|
||||
|
||||
byte[] exportByShop(WorkbenchExportDTO dto);
|
||||
|
||||
byte[] exportByPlatform(WorkbenchExportDTO dto);
|
||||
|
||||
byte[] exportByCategory(WorkbenchExportDTO dto);
|
||||
|
||||
byte[] exportByProduct(WorkbenchExportDTO dto);
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto.WorkbenchQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchFinanceSliceVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchMultiAnalysisPanelVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.vo.WorkbenchPeriodCompareSliceVO;
|
||||
|
||||
/**
|
||||
* 工作台:经营概览、多维分析、排行等聚合数据。
|
||||
*/
|
||||
public interface WorkbenchService {
|
||||
|
||||
/** 经营概览 Tab:含 KPI/趋势/饼图 + 底部四表 */
|
||||
WorkbenchFinanceSliceVO financeSlice(WorkbenchQueryDTO queryDTO);
|
||||
|
||||
/** 多维分析 Tab */
|
||||
WorkbenchMultiAnalysisPanelVO multiAnalysis(WorkbenchQueryDTO queryDTO);
|
||||
|
||||
/** 销售额排行 Tab(多维同源,按销售额预排序) */
|
||||
WorkbenchMultiAnalysisPanelVO salesRank(WorkbenchQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 单段日期:返回与「多维度经营明细」店铺表合计行同口径的汇总(轻量,供区间对比双请求)。
|
||||
*/
|
||||
WorkbenchPeriodCompareSliceVO periodCompareSlice(WorkbenchQueryDTO queryDTO);
|
||||
}
|
||||
-197
@@ -1,197 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.workbench.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.agg.OverviewAggRows;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.dto.CategoryExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.dto.CompanyExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.dto.PlatformExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.model.vo.CompanyOverviewVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.service.CategoryExportExcelService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.service.CompanyOverviewService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.overview.service.ExportService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto.WorkbenchExportDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.model.dto.WorkbenchQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.workbench.service.WorkbenchExportService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 工作台多维度导出:复用全店概览「工作台汇总表」构建逻辑,再交给各维度 Excel 导出服务生成字节流。
|
||||
*/
|
||||
@Service
|
||||
public class WorkbenchExportServiceImpl implements WorkbenchExportService {
|
||||
|
||||
/** 与 {@link WorkbenchServiceImpl} 默认税率一致 */
|
||||
private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04");
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopService shopService;
|
||||
private final CompanyOverviewService companyOverviewService;
|
||||
private final ExportService exportService;
|
||||
private final CategoryExportExcelService categoryExportExcelService;
|
||||
|
||||
public WorkbenchExportServiceImpl(
|
||||
CurrentUserContext currentUserContext,
|
||||
ShopService shopService,
|
||||
CompanyOverviewService companyOverviewService,
|
||||
ExportService exportService,
|
||||
CategoryExportExcelService categoryExportExcelService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.companyOverviewService = companyOverviewService;
|
||||
this.exportService = exportService;
|
||||
this.categoryExportExcelService = categoryExportExcelService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从已构建的「店铺维」工作台表导出 Excel。
|
||||
*/
|
||||
@Override
|
||||
public byte[] exportByShop(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = loadSummaryTables(dto);
|
||||
CompanyExportDTO exportDto = new CompanyExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setShopIds(dto.getShopIds());
|
||||
return exportService.exportShopOverviewFromTable(
|
||||
exportDto, bundle.getShopTable(), "多维度经营明细 - 按店铺汇总");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从「平台维」工作台表导出 Excel。
|
||||
*/
|
||||
@Override
|
||||
public byte[] exportByPlatform(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = loadSummaryTables(dto);
|
||||
PlatformExportDTO exportDto = new PlatformExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setPlatformCodes(dto.getPlatformCodes());
|
||||
return exportService.exportPlatformOverviewFromTable(
|
||||
exportDto, bundle.getPlatformTable(), "多维度经营明细 - 按平台汇总");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从「类目维」工作台表导出品类损益 Excel。
|
||||
*/
|
||||
@Override
|
||||
public byte[] exportByCategory(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = loadSummaryTables(dto);
|
||||
CategoryExportDTO exportDto = new CategoryExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setCategoryIds(dto.getCategoryIds());
|
||||
exportDto.setShopId(null);
|
||||
return categoryExportExcelService.exportCategoryDimensionsFromTable(
|
||||
exportDto,
|
||||
bundle.getCategoryTable(),
|
||||
"多维度经营明细 - 品类多维度损益汇总",
|
||||
"品类名称");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从「商品维」工作台表导出商品损益 Excel(复用品类导出服务,列标题改为商品名称)。
|
||||
*/
|
||||
@Override
|
||||
public byte[] exportByProduct(WorkbenchExportDTO dto) {
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = loadSummaryTables(dto);
|
||||
CategoryExportDTO exportDto = new CategoryExportDTO();
|
||||
exportDto.setDateRange(dto.getDateRange());
|
||||
exportDto.setTaxRate(dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE);
|
||||
exportDto.setCategoryIds(dto.getProductIds());
|
||||
exportDto.setShopId(null);
|
||||
return categoryExportExcelService.exportCategoryDimensionsFromTable(
|
||||
exportDto,
|
||||
bundle.getProductTable(),
|
||||
"多维度经营明细 - 商品多维度损益汇总",
|
||||
"商品名称");
|
||||
}
|
||||
|
||||
/** 拉取汇总表/明细聚合后构建四表,与 {@link WorkbenchServiceImpl#financeSlice} 口径一致 */
|
||||
private CompanyOverviewVO.WorkbenchTableBundle loadSummaryTables(WorkbenchExportDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
DateRange range = parseDateRange(toQuery(dto));
|
||||
|
||||
List<ShopPO> shops = loadFilteredShops(companyId, dto.getPlatformCode(), dto.getShopId());
|
||||
if (shops.isEmpty()) {
|
||||
throw new BusinessException("没有可导出的店铺");
|
||||
}
|
||||
|
||||
BigDecimal taxRate = dto.getTaxRate() != null ? dto.getTaxRate() : DEFAULT_TAX_RATE;
|
||||
return companyOverviewService.buildWorkbenchSummaryTablesFromAgg(
|
||||
taxRate, companyId, shops,
|
||||
List.<OverviewAggRows.ShopProductRow>of(),
|
||||
List.<OverviewAggRows.PromotionRow>of(),
|
||||
List.<OverviewAggRows.BrushRow>of(),
|
||||
range.startDate(), range.endDate());
|
||||
}
|
||||
|
||||
/** 导出 DTO 与查询 DTO 字段对齐,仅用于复用 {@link #parseDateRange} */
|
||||
private static WorkbenchQueryDTO toQuery(WorkbenchExportDTO dto) {
|
||||
WorkbenchQueryDTO q = new WorkbenchQueryDTO();
|
||||
q.setDateRange(dto.getDateRange());
|
||||
q.setTaxRate(dto.getTaxRate());
|
||||
q.setPlatformCode(dto.getPlatformCode());
|
||||
q.setShopId(dto.getShopId());
|
||||
return q;
|
||||
}
|
||||
|
||||
/** 与 {@link WorkbenchServiceImpl} 相同:单日为当日,双日为闭区间 */
|
||||
private DateRange parseDateRange(WorkbenchQueryDTO queryDTO) {
|
||||
List<LocalDate> dr = queryDTO.getDateRange();
|
||||
LocalDate start;
|
||||
LocalDate end;
|
||||
if (dr.size() == 1) {
|
||||
start = dr.get(0);
|
||||
end = start;
|
||||
} else {
|
||||
start = dr.get(0);
|
||||
end = dr.get(1);
|
||||
if (start.isAfter(end)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
}
|
||||
return new DateRange(start, end);
|
||||
}
|
||||
|
||||
/** 逻辑同工作台汇总:公司下按平台/单店过滤店铺 */
|
||||
private List<ShopPO> loadFilteredShops(Long companyId, String platformCode, Long shopId) {
|
||||
LambdaQueryWrapper<ShopPO> w = new LambdaQueryWrapper<>();
|
||||
w.eq(ShopPO::getCompanyId, companyId);
|
||||
if (shopId != null) {
|
||||
ShopPO one = shopService.getById(shopId);
|
||||
if (one == null || !companyId.equals(one.getCompanyId())) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
if (platformCode != null && !platformCode.isBlank()
|
||||
&& one.getPlatformCode() != null && !platformCode.equals(one.getPlatformCode())) {
|
||||
throw new BusinessException("店铺与所选平台不一致");
|
||||
}
|
||||
return List.of(one);
|
||||
}
|
||||
if (platformCode != null && !platformCode.isBlank()) {
|
||||
w.eq(ShopPO::getPlatformCode, platformCode.trim());
|
||||
}
|
||||
return shopService.list(w);
|
||||
}
|
||||
|
||||
/** 查询时间闭区间辅助 record */
|
||||
private record DateRange(LocalDate startDate, LocalDate endDate) {
|
||||
LocalDateTime startDateTime() {
|
||||
return startDate.atStartOfDay();
|
||||
}
|
||||
|
||||
LocalDateTime endDateTime() {
|
||||
return endDate.atTime(23, 59, 59);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { requestClient } from '#/api/request';
|
||||
/** 经营概览 Tab:KPI/趋势/饼图 + 底部四表 */
|
||||
export async function getWorkbenchFinanceApi(data: WorkbenchDTO.Query) {
|
||||
return requestClient.post<WorkbenchVO.FinanceSlice>(
|
||||
'/ec/workbench/finance',
|
||||
'/bi/workbench/finance',
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -13,7 +13,7 @@ export async function getWorkbenchFinanceApi(data: WorkbenchDTO.Query) {
|
||||
/** 多维分析 Tab */
|
||||
export async function getWorkbenchMultiAnalysisApi(data: WorkbenchDTO.Query) {
|
||||
return requestClient.post<WorkbenchVO.MultiPanel>(
|
||||
'/ec/workbench/multi-analysis',
|
||||
'/bi/workbench/multi-analysis',
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export async function getWorkbenchMultiAnalysisApi(data: WorkbenchDTO.Query) {
|
||||
/** 销售额排行 Tab */
|
||||
export async function getWorkbenchSalesRankApi(data: WorkbenchDTO.Query) {
|
||||
return requestClient.post<WorkbenchVO.MultiPanel>(
|
||||
'/ec/workbench/sales-rank',
|
||||
'/bi/workbench/sales-rank',
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export async function getWorkbenchSalesRankApi(data: WorkbenchDTO.Query) {
|
||||
/** 区间对比:单段日期,返回店铺汇总「合计」行(轻量) */
|
||||
export async function getWorkbenchPeriodCompareSliceApi(data: WorkbenchDTO.Query) {
|
||||
return requestClient.post<WorkbenchVO.PeriodCompareSlice>(
|
||||
'/ec/workbench/period-compare/slice',
|
||||
'/bi/workbench/period-compare/slice',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
+4
-4
@@ -88,7 +88,7 @@ async function handleShopExport() {
|
||||
payload.shopIds = selectedExportShopIds.value;
|
||||
}
|
||||
await exportByPost(
|
||||
'/ec/workbench/export/by-shop',
|
||||
'/bi/workbench/export/by-shop',
|
||||
payload,
|
||||
`多维度经营明细_按店铺汇总_${dateSegmentForFilename()}.xlsx`,
|
||||
);
|
||||
@@ -112,7 +112,7 @@ async function handlePlatformExport() {
|
||||
payload.platformCodes = selectedExportPlatformCodes.value;
|
||||
}
|
||||
await exportByPost(
|
||||
'/ec/workbench/export/by-platform',
|
||||
'/bi/workbench/export/by-platform',
|
||||
payload,
|
||||
`多维度经营明细_按平台汇总_${dateSegmentForFilename()}.xlsx`,
|
||||
);
|
||||
@@ -136,7 +136,7 @@ async function handleCategoryExport() {
|
||||
payload.categoryIds = selectedExportCategoryIds.value;
|
||||
}
|
||||
await exportByPost(
|
||||
'/ec/workbench/export/by-category',
|
||||
'/bi/workbench/export/by-category',
|
||||
payload,
|
||||
`多维度经营明细_按品类汇总_${dateSegmentForFilename()}.xlsx`,
|
||||
);
|
||||
@@ -160,7 +160,7 @@ async function handleProductExport() {
|
||||
payload.productIds = selectedExportProductIds.value;
|
||||
}
|
||||
await exportByPost(
|
||||
'/ec/workbench/export/by-product',
|
||||
'/bi/workbench/export/by-product',
|
||||
payload,
|
||||
`多维度经营明细_按商品汇总_${dateSegmentForFilename()}.xlsx`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user