From fe37c0baf306f3f31bbb5ac7dd54da6445356f55 Mon Sep 17 00:00:00 2001 From: van Date: Thu, 8 Oct 2026 00:15:32 +0800 Subject: [PATCH] 1 --- .../system/JDOrderListController.java | 2 +- .../impl/RebateSheetConvertService.java | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/JDOrderListController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/JDOrderListController.java index a5e8c9d..0febfef 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/JDOrderListController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/JDOrderListController.java @@ -287,7 +287,7 @@ public class JDOrderListController extends BaseController } } try { - RebateSheetConvertService.Result result = rebateSheetConvertService.convert(file.getInputStream()); + RebateSheetConvertService.Result result = rebateSheetConvertService.convert(file.getInputStream(), name); if (result.getErrorMessage() != null) { writeJson(response, AjaxResult.error(result.getErrorMessage())); return; diff --git a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/RebateSheetConvertService.java b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/RebateSheetConvertService.java index 8b07802..5aeb966 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/RebateSheetConvertService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/jarvis/service/impl/RebateSheetConvertService.java @@ -53,7 +53,7 @@ public class RebateSheetConvertService { @Resource private OrderRowsMapper orderRowsMapper; - public Result convert(InputStream in) throws Exception { + public Result convert(InputStream in, String originalFilename) throws Exception { Result result = new Result(); try (Workbook workbook = WorkbookFactory.create(in)) { if (workbook.getNumberOfSheets() <= 0) { @@ -83,7 +83,7 @@ public class RebateSheetConvertService { result.totalRows = rows.size(); result.content = writeWorkbook(rows, orders, skuNums, result); - result.filename = "返现表-新表头.xlsx"; + result.filename = downloadName(originalFilename); return result; } } @@ -232,6 +232,28 @@ public class RebateSheetConvertService { return map; } + static String downloadName(String originalFilename) { + String base = originalFilename == null ? "" : originalFilename.trim(); + base = base.replace('\\', '/'); + int slash = base.lastIndexOf('/'); + if (slash >= 0) { + base = base.substring(slash + 1); + } + String lower = base.toLowerCase(java.util.Locale.ROOT); + String stem; + if (lower.endsWith(".xlsx")) { + stem = base.substring(0, base.length() - 5); + } else if (lower.endsWith(".xls")) { + stem = base.substring(0, base.length() - 4); + } else { + stem = base; + } + if (stem.isEmpty()) { + stem = "返现表"; + } + return stem + "新.xlsx"; + } + private static List readRows(Sheet sheet, int headerIndex, HeaderMap header) { List rows = new ArrayList<>(); for (int i = headerIndex + 1; i <= sheet.getLastRowNum(); i++) {