1
This commit is contained in:
+24
-2
@@ -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<SourceRow> readRows(Sheet sheet, int headerIndex, HeaderMap header) {
|
||||
List<SourceRow> rows = new ArrayList<>();
|
||||
for (int i = headerIndex + 1; i <= sheet.getLastRowNum(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user