refactor(api): 全店概览导出接口路径统一为 RESTful 风格

- ExportController 路径改为 /ec/store-overview/export/{by-shop|by-category|by-platform}
- ExportFilenameUtils 新增 buildFullStoreOverviewXlsxName 方法
- ShopExportController 路径同步调整
- 前端 store-overview / shop apis 同步适配新接口路径
This commit is contained in:
小蟑螂
2026-05-06 01:32:52 +08:00
parent 330b6f0955
commit 157c5ae3c4
14 changed files with 149 additions and 82 deletions
+6 -3
View File
@@ -71,10 +71,13 @@ ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/
| 模块 | 路径 | 说明 |
|------|------|------|
| 公司概览 | POST /ec/store-overview/statistics | 全店铺汇总统计 |
| 公司概览导出 | POST /ec/store-overview/export | Excel 导出 |
| 全店概览统计 | POST /ec/store/overview | 全店铺汇总统计 |
| 全店概览-按店铺汇总导出 | POST /ec/store-overview/export/by-shop | Excel |
| 全店概览-按品类汇总导出 | POST /ec/store-overview/export/by-category | Excel |
| 全店概览-按平台汇总导出 | POST /ec/store-overview/export/by-platform | Excel |
| 店铺概览 | POST /ec/shop/overview-statistics | 单店铺统计 |
| 店铺导出 | POST /ec/shop/export-overview | Excel 导出 |
| 店铺按商品汇总导出 | POST /ec/shop/export/summary-by-product | Excel |
| 店铺按品类汇总导出 | POST /ec/shop/export/summary-by-category | Excel |
| 订单 | /ec/order/* | CRUD |
| 推广费 | /ec/promotion-fee/* | CRUD |
| 刷单 | /ec/brush-order/* | CRUD |
@@ -16,11 +16,11 @@ import jakarta.servlet.http.HttpServletResponse;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.util.ExportFilenameUtils;
/**
* 概览导出控制器
* 全店概览导出:{@code POST /ec/store-overview/export/{by-shop|by-category|by-platform}}
*/
@Tag(name = "电商-概览导出", description = "概览数据导出接口")
@Tag(name = "电商-全店概览导出", description = "全店概览:按店铺 / 按品类 / 按平台汇总 Excel 导出")
@RestController
@RequestMapping("/ec")
@RequestMapping("/ec/store-overview/export")
public class ExportController {
private final ExportService exportService;
@@ -29,30 +29,30 @@ public class ExportController {
this.exportService = exportService;
}
@Operation(summary = "导出公司概览Excel", description = "导出全店铺概览数据为Excel文件")
@PostMapping("/store-overview/export")
@RequirePermission(value = "data:export", description = "导出公司概览", allowSuper = true)
@Operation(summary = "全店概览-按店铺汇总", description = "导出全店按店铺维度的汇总数据为 Excel,可按店铺筛选")
@PostMapping("/by-shop")
@RequirePermission(value = "data:export", description = "导出全店概览(按店铺汇总)", allowSuper = true)
public void exportCompanyOverview(@Valid @RequestBody CompanyExportDTO dto, HttpServletResponse response) {
byte[] data = exportService.exportCompanyOverview(dto);
String filename = ExportFilenameUtils.buildXlsxName("公司概览", dto.getDateRange());
String filename = ExportFilenameUtils.buildFullStoreOverviewXlsxName("按店铺汇总", dto.getDateRange());
writeExcel(response, filename, data);
}
@Operation(summary = "导出品类概览Excel", description = "导出多品类汇总数据为Excel文件,支持指定品类或导出全部")
@PostMapping("/category-overview/export")
@RequirePermission(value = "data:export", description = "导出品类概览", allowSuper = true)
@Operation(summary = "全店概览-按品类汇总", description = "导出全店按品类维度的汇总数据为 Excel,支持指定品类或导出全部")
@PostMapping("/by-category")
@RequirePermission(value = "data:export", description = "导出全店概览(按品类汇总)", allowSuper = true)
public void exportCategoryOverview(@Valid @RequestBody CategoryExportDTO dto, HttpServletResponse response) {
byte[] data = exportService.exportCategoryOverview(dto);
String filename = ExportFilenameUtils.buildXlsxName("品类概览", dto.getDateRange());
String filename = ExportFilenameUtils.buildFullStoreOverviewXlsxName("按品类汇总", dto.getDateRange());
writeExcel(response, filename, data);
}
@Operation(summary = "导出平台维度汇总Excel", description = "导出平台维度汇总数据为Excel文件,支持指定平台或导出全部")
@PostMapping("/platform-overview/export")
@RequirePermission(value = "data:export", description = "导出平台维度汇总", allowSuper = true)
@Operation(summary = "全店概览-按平台汇总", description = "导出全店按平台维度的汇总数据为 Excel,支持指定平台或导出全部")
@PostMapping("/by-platform")
@RequirePermission(value = "data:export", description = "导出全店概览(按平台汇总)", allowSuper = true)
public void exportPlatformOverview(@Valid @RequestBody PlatformExportDTO dto, HttpServletResponse response) {
byte[] data = exportService.exportPlatformOverview(dto);
String filename = ExportFilenameUtils.buildXlsxName("平台维度汇总", dto.getDateRange());
String filename = ExportFilenameUtils.buildFullStoreOverviewXlsxName("按平台汇总", dto.getDateRange());
writeExcel(response, filename, data);
}
@@ -11,11 +11,11 @@ import java.time.LocalDate;
import java.util.List;
/**
* 品类概览导出DTO
* 全店概览-按品类汇总导出参数
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(description = "品类概览导出DTO")
@Schema(description = "全店概览按品类汇总导出 DTO")
public class CategoryExportDTO {
@Schema(description = "日期范围数组", example = "[\"2024-01-01\", \"2024-01-31\"]", requiredMode = Schema.RequiredMode.REQUIRED)
@@ -28,4 +28,8 @@ public class CategoryExportDTO {
@Schema(description = "税率,默认 0.04", example = "0.04")
private BigDecimal taxRate = new BigDecimal("0.04");
/** 店铺导出接口传入时用于下载文件名(店铺名_按品类汇总统计_日期.xlsx) */
@Schema(description = "店铺ID(店铺侧品类导出时传入,用于生成带店铺名的文件名)", example = "1")
private Long shopId;
}
@@ -11,11 +11,11 @@ import java.time.LocalDate;
import java.util.List;
/**
* 公司概览导出DTO
* 全店概览-按店铺汇总导出参数
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(description = "公司概览导出DTO")
@Schema(description = "全店概览按店铺汇总导出 DTO")
public class CompanyExportDTO {
@Schema(description = "日期范围数组", example = "[\"2024-01-01\", \"2024-01-31\"]", requiredMode = Schema.RequiredMode.REQUIRED)
@@ -11,11 +11,11 @@ import java.time.LocalDate;
import java.util.List;
/**
* 平台维度汇总导出DTO
* 全店概览-按平台汇总导出参数
*/
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(description = "平台维度汇总导出DTO")
@Schema(description = "全店概览按平台汇总导出 DTO")
public class PlatformExportDTO {
@Schema(description = "日期范围数组", example = "[\"2024-01-01\", \"2024-01-31\"]", requiredMode = Schema.RequiredMode.REQUIRED)
@@ -4,31 +4,22 @@ import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CategoryExportD
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyExportDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.PlatformExportDTO;
/**
* 概览导出服务接口
* 全店概览导出服务(按店铺 / 按品类 / 按平台)
*/
public interface ExportService {
/**
* 导出公司概览Excel
*
* @param dto 导出参数
* @return Excel文件字节数组
* 全店概览:按店铺汇总 Excel
*/
byte[] exportCompanyOverview(CompanyExportDTO dto);
/**
* 导出品类概览Excel
*
* @param dto 导出参数
* @return Excel文件字节数组
* 全店概览:按品类汇总 Excel
*/
byte[] exportCategoryOverview(CategoryExportDTO dto);
/**
* 导出平台维度汇总Excel
*
* @param dto 导出参数
* @return Excel文件字节数组
* 全店概览:按平台汇总 Excel
*/
byte[] exportPlatformOverview(PlatformExportDTO dto);
}
@@ -18,4 +18,48 @@ public final class ExportFilenameUtils {
LocalDate end = dateRange.get(dateRange.size() - 1);
return namePrefix + "_" + start.format(SEGMENT_FMT) + "-" + end.format(SEGMENT_FMT) + ".xlsx";
}
/**
* 导出文件名片段净化,避免路径分隔符等在部分系统下非法的字符。
*/
public static String sanitizeFilenameSegment(String segment) {
if (segment == null || segment.isBlank()) {
return "未命名";
}
String s = segment.strip()
.replace('\\', '_')
.replace('/', '_')
.replace(':', '_')
.replace('*', '_')
.replace('?', '_')
.replace('"', '_')
.replace('<', '_')
.replace('>', '_')
.replace('|', '_');
if (s.isBlank()) {
return "未命名";
}
return s;
}
/**
* 店铺导出:{@code 店铺名称_汇总类型说明_开始日期-结束日期.xlsx}(日期段为 yyyyMMdd)
*
* @param summaryKindLabel 如「按商品汇总统计」「按品类汇总统计」
*/
public static String buildShopSummaryXlsxName(
String shopDisplayName, String summaryKindLabel, List<LocalDate> dateRange) {
String safeShop = sanitizeFilenameSegment(shopDisplayName);
String prefix = safeShop + "_" + summaryKindLabel;
return buildXlsxName(prefix, dateRange);
}
/**
* 全店概览导出:{@code 全店概览_按店铺汇总_开始日期-结束日期.xlsx} 等(日期段为 yyyyMMdd)
*
* @param dimensionSummary 如「按店铺汇总」「按品类汇总」「按平台汇总」
*/
public static String buildFullStoreOverviewXlsxName(String dimensionSummary, List<LocalDate> dateRange) {
return buildXlsxName("全店概览_" + dimensionSummary, dateRange);
}
}
@@ -14,37 +14,56 @@ import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CategoryExportDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopExportDTO;
import top.xyquan.ecomdmbbackend.modules.ecom.overview.util.ExportFilenameUtils;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopExportService;
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
/**
* 店铺侧 Excel 导出(路径仍为 /ec/shop/*,与前端约定一致)
* 店铺侧 Excel 导出:{@code /ec/shop/export/summary-by-product}、{@code /ec/shop/export/summary-by-category}
*/
@Tag(name = "电商-店铺导出", description = "店铺概览与门店品类导出")
@Tag(name = "电商-店铺导出", description = "店铺数据按商品/按品类汇总导出")
@RestController
@RequestMapping("/ec/shop")
@RequestMapping("/ec/shop/export")
public class ShopExportController {
private final ShopExportService shopExportService;
private final ShopService shopService;
public ShopExportController(ShopExportService shopExportService) {
public ShopExportController(ShopExportService shopExportService, ShopService shopService) {
this.shopExportService = shopExportService;
this.shopService = shopService;
}
@Operation(summary = "导出店铺概览Excel", description = "导出单店铺概览数据为Excel文件")
@PostMapping("/export-overview")
@RequirePermission(value = "data:export", description = "导出店铺概览", allowSuper = true)
public void exportShopOverview(@Valid @RequestBody ShopExportDTO dto, HttpServletResponse response) {
byte[] data = shopExportService.exportShopOverview(dto);
String filename = ExportFilenameUtils.buildXlsxName("店铺概览", dto.getDateRange());
private String resolveShopDisplayName(Long shopId) {
if (shopId == null) {
return "店铺";
}
ShopPO shop = shopService.getById(shopId);
if (shop != null && shop.getName() != null && !shop.getName().isBlank()) {
return shop.getName();
}
return "店铺" + shopId;
}
@Operation(summary = "店铺数据统计-按商品汇总", description = "导出单店铺按商品维度汇总为 Excel")
@PostMapping("/summary-by-product")
@RequirePermission(value = "data:export", description = "导出店铺按商品汇总", allowSuper = true)
public void exportShopSummaryByProduct(@Valid @RequestBody ShopExportDTO dto, HttpServletResponse response) {
byte[] data = shopExportService.exportShopSummaryByProduct(dto);
String filename = ExportFilenameUtils.buildShopSummaryXlsxName(
resolveShopDisplayName(dto.getShopId()), "按商品汇总统计", dto.getDateRange());
writeExcel(response, filename, data);
}
@Operation(summary = "导出门店品类汇总Excel", description = "导出门店品类多维度数据汇总为Excel文件")
@PostMapping("/export-category")
@RequirePermission(value = "data:export", description = "导出门店品类汇总", allowSuper = true)
public void exportShopCategoryOverview(@Valid @RequestBody CategoryExportDTO dto, HttpServletResponse response) {
byte[] data = shopExportService.exportShopCategoryOverview(dto);
String filename = ExportFilenameUtils.buildXlsxName("门店品类汇总", dto.getDateRange());
@Operation(summary = "店铺数据统计-按品类汇总", description = "导出单店铺按品类维度汇总为 Excel")
@PostMapping("/summary-by-category")
@RequirePermission(value = "data:export", description = "导出店铺按品类汇总", allowSuper = true)
public void exportShopSummaryByCategory(@Valid @RequestBody CategoryExportDTO dto, HttpServletResponse response) {
byte[] data = shopExportService.exportShopSummaryByCategory(dto);
String filename = dto.getShopId() != null
? ExportFilenameUtils.buildShopSummaryXlsxName(
resolveShopDisplayName(dto.getShopId()), "按品类汇总统计", dto.getDateRange())
: ExportFilenameUtils.buildXlsxName("店铺数据统计-按品类汇总", dto.getDateRange());
writeExcel(response, filename, data);
}
@@ -4,12 +4,13 @@ import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CategoryExportD
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopExportDTO;
/**
* 店铺侧 Excel 导出(单店概览、门店品类汇总)
* 店铺侧 Excel 导出(按商品汇总、按品类汇总)
*/
public interface ShopExportService {
byte[] exportShopOverview(ShopExportDTO dto);
/** 单店铺按商品维度汇总 Excel */
byte[] exportShopSummaryByProduct(ShopExportDTO dto);
/** 与品类概览导出逻辑一致,供店铺概览页「门店品类汇总」使用 */
byte[] exportShopCategoryOverview(CategoryExportDTO dto);
/** 单店铺按品类维度汇总 Excel(与品类概览导出逻辑一致) */
byte[] exportShopSummaryByCategory(CategoryExportDTO dto);
}
@@ -41,7 +41,7 @@ public class ShopExportServiceImpl implements ShopExportService {
}
@Override
public byte[] exportShopOverview(ShopExportDTO dto) {
public byte[] exportShopSummaryByProduct(ShopExportDTO dto) {
ShopOverviewQueryDTO queryDTO = new ShopOverviewQueryDTO();
queryDTO.setShopId(dto.getShopId());
queryDTO.setDateRange(dto.getDateRange());
@@ -86,7 +86,7 @@ public class ShopExportServiceImpl implements ShopExportService {
}
@Override
public byte[] exportShopCategoryOverview(CategoryExportDTO dto) {
public byte[] exportShopSummaryByCategory(CategoryExportDTO dto) {
return categoryExportExcelService.exportCategoryOverview(dto);
}
@@ -75,27 +75,27 @@ export async function getShopOverviewStatisticsApi(
}
/**
* 导出店铺概览Excel
* 店铺数据统计-按商品汇总(Excel)
*/
export async function exportShopOverviewApi(params: {
export async function exportShopSummaryByProductApi(params: {
shopId: number;
dateRange: string[];
exportType?: string;
}) {
return requestClient.post('/ec/shop/export-overview', params, {
return requestClient.post('/ec/shop/export/summary-by-product', params, {
responseType: 'blob',
});
}
/**
* 导出公司概览Excel
* 全店概览-按店铺汇总(Excel)
*/
export async function exportCompanyOverviewApi(params: {
dateRange: string[];
shopIds?: number[];
exportType?: string;
}) {
return requestClient.post('/ec/store-overview/export', params, {
return requestClient.post('/ec/store-overview/export/by-shop', params, {
responseType: 'blob',
});
}
@@ -3,11 +3,11 @@ import type { CompanyOverviewDTO, CompanyOverviewVO } from './types';
import { requestClient } from '#/api/request';
/**
* 全店铺概览管理API
* 全店概览 API(统计与导出)
*/
/**
* 获取全店铺概览统计数据
* 获取全店概览统计数据
*/
export async function getCompanyOverviewApi(data: CompanyOverviewDTO.Query) {
return requestClient.post<CompanyOverviewVO.Info>(
@@ -17,27 +17,27 @@ export async function getCompanyOverviewApi(data: CompanyOverviewDTO.Query) {
}
/**
* 导出品类概览Excel
* 全店概览-按品类汇总(Excel)
*/
export async function exportCategoryOverviewApi(params: {
dateRange: string[];
categoryIds?: number[];
taxRate: number;
}) {
return requestClient.post('/ec/category-overview/export', params, {
return requestClient.post('/ec/store-overview/export/by-category', params, {
responseType: 'blob',
});
}
/**
* 导出公司概览Excel
* 全店概览-按店铺汇总(Excel)
*/
export async function exportCompanyOverviewApi(params: {
dateRange: string[];
shopIds?: number[];
exportType?: string;
}) {
return requestClient.post('/ec/store-overview/export', params, {
return requestClient.post('/ec/store-overview/export/by-shop', params, {
responseType: 'blob',
});
}
@@ -71,9 +71,9 @@ const handleCategoryExport = async () => {
}
const [cStart, cEnd] = dateRange.value;
await exportByPost(
'/ec/category-overview/export',
'/ec/store-overview/export/by-category',
params,
`品类概览_${cStart.format('YYYYMMDD')}-${cEnd.format('YYYYMMDD')}.xlsx`,
`全店概览_按品类汇总_${cStart.format('YYYYMMDD')}-${cEnd.format('YYYYMMDD')}.xlsx`,
);
};
@@ -366,7 +366,7 @@ onActivated(async () => {
await refreshOverviewByCurrentParams(true);
});
// 导出公司概览
// 全店概览-按店铺汇总导出
const handleExportCompanyOverview = async () => {
try {
exportLoading.value = true;
@@ -391,9 +391,9 @@ const handleExportCompanyOverview = async () => {
: undefined;
}
const filename = `公司概览_${startDate.format('YYYYMMDD')}-${endDate.format('YYYYMMDD')}.xlsx`;
const filename = `全店概览_按店铺汇总_${startDate.format('YYYYMMDD')}-${endDate.format('YYYYMMDD')}.xlsx`;
await exportByPost(
'/ec/store-overview/export',
'/ec/store-overview/export/by-shop',
{
dateRange: [
startDate.format('YYYY-MM-DD'),
@@ -427,14 +427,14 @@ const togglePlatformExportMode = (enabled: boolean) => {
}
};
// 导出平台维度汇总
// 全店概览-按平台汇总导出
const handlePlatformExport = async () => {
try {
exportLoading.value = true;
const [startDate, endDate] = dateRange.value;
const filename = `平台维度汇总_${startDate.format('YYYYMMDD')}-${endDate.format('YYYYMMDD')}.xlsx`;
const filename = `全店概览_按平台汇总_${startDate.format('YYYYMMDD')}-${endDate.format('YYYYMMDD')}.xlsx`;
await exportByPost(
'/ec/platform-overview/export',
'/ec/store-overview/export/by-platform',
{
dateRange: [
startDate.format('YYYY-MM-DD'),
@@ -218,9 +218,10 @@ const handleExportShopOverview = async () => {
exportLoading.value = true;
const shopName = overviewData.value?.shopName || `店铺${shopId.value}`;
const [startDate, endDate] = dateRange.value;
const filename = `${shopName}_概览_${startDate.format('YYYYMMDD')}-${endDate.format('YYYYMMDD')}.xlsx`;
const safeName = String(shopName).replace(/[/\\:*?"<>|]/g, '_');
const filename = `${safeName}_按商品汇总统计_${startDate.format('YYYYMMDD')}-${endDate.format('YYYYMMDD')}.xlsx`;
await exportByPost(
'/ec/shop/export-overview',
'/ec/shop/export/summary-by-product',
{
shopId: shopId.value,
dateRange: [
@@ -249,18 +250,22 @@ const handleCategoryExport = async () => {
categoryIds?: number[];
dateRange: string[];
taxRate: number;
shopId: number;
} = {
dateRange: dateRange.value.map((d) => d.format('YYYY-MM-DD')),
taxRate: taxRate.value,
shopId: shopId.value,
};
if (selectedExportCategoryIds.value.length > 0) {
params.categoryIds = selectedExportCategoryIds.value;
}
const [catStart, catEnd] = dateRange.value;
const catShopName = overviewData.value?.shopName || `店铺${shopId.value}`;
const catSafeName = String(catShopName).replace(/[/\\:*?"<>|]/g, '_');
await exportByPost(
'/ec/shop/export-category',
'/ec/shop/export/summary-by-category',
params,
`门店品类汇总_${catStart.format('YYYYMMDD')}-${catEnd.format('YYYYMMDD')}.xlsx`,
`${catSafeName}_按品类汇总统计_${catStart.format('YYYYMMDD')}-${catEnd.format('YYYYMMDD')}.xlsx`,
);
} finally {
categoryExportLoading.value = false;