mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
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:
+15
-15
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
+2
-2
@@ -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
-13
@@ -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);
|
||||
}
|
||||
|
||||
+44
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+35
-16
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user