mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 05:49:20 +08:00
feat: 支持快递报价 Excel 导入与标准模板下载
This commit is contained in:
+2
-2
@@ -81,9 +81,9 @@ public class ExpressQuoteImportService {
|
||||
draft.setFormat("CARRIER_MATRIX");
|
||||
}
|
||||
List<ExpressQuoteImportModels.RegionDraft> raw =
|
||||
ExpressQuoteMatrixSheetParser.parse(quoteSheet, draft.getErrors());
|
||||
ExpressQuoteMatrixSheetParser.parse(quoteSheet, draft.getErrors(), draft.getWarnings());
|
||||
if (raw.isEmpty() && draft.getErrors().isEmpty()) {
|
||||
draft.getErrors().add("未解析到任何目的地报价行");
|
||||
draft.getErrors().add("未解析到任何目的地报价行(可解析行均为空或已跳过)");
|
||||
}
|
||||
List<ExpressQuoteImportModels.RegionDraft> merged = ExpressQuoteRegionMerger.merge(raw);
|
||||
draft.setRegions(merged);
|
||||
|
||||
+11
-10
@@ -15,7 +15,7 @@ import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 解析承运商矩阵 / 标准模板「报价」页:支持同 Sheet 多段表头。
|
||||
* 空单元格=该重量带跳过;非空且不可解析=记入 errors(调用方整单失败)。
|
||||
* 空单元格 / 不可解析单元格 / 无有效带的行 → warning 并跳过,不拖垮整单。
|
||||
*/
|
||||
public final class ExpressQuoteMatrixSheetParser {
|
||||
|
||||
@@ -24,7 +24,8 @@ public final class ExpressQuoteMatrixSheetParser {
|
||||
private ExpressQuoteMatrixSheetParser() {
|
||||
}
|
||||
|
||||
public static List<ExpressQuoteImportModels.RegionDraft> parse(Sheet sheet, List<String> errors) {
|
||||
public static List<ExpressQuoteImportModels.RegionDraft> parse(
|
||||
Sheet sheet, List<String> errors, List<String> warnings) {
|
||||
List<ExpressQuoteImportModels.RegionDraft> rows = new ArrayList<>();
|
||||
if (sheet == null) {
|
||||
errors.add("缺少报价工作表");
|
||||
@@ -38,7 +39,6 @@ public final class ExpressQuoteMatrixSheetParser {
|
||||
continue;
|
||||
}
|
||||
String c0 = cellText(row, 0);
|
||||
String c1 = cellText(row, 1);
|
||||
|
||||
// 偏远区域行:内嵌新重量表头
|
||||
if (isSectionMarker(c0) && hasWeightHeaders(row, 2)) {
|
||||
@@ -78,7 +78,7 @@ public final class ExpressQuoteMatrixSheetParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
ExpressQuoteImportModels.RegionDraft region = parseDataRow(row, columns, errors, r + 1);
|
||||
ExpressQuoteImportModels.RegionDraft region = parseDataRow(row, columns, warnings, r + 1);
|
||||
if (region != null) {
|
||||
rows.add(region);
|
||||
}
|
||||
@@ -87,7 +87,8 @@ public final class ExpressQuoteMatrixSheetParser {
|
||||
}
|
||||
|
||||
private static ExpressQuoteImportModels.RegionDraft parseDataRow(
|
||||
Row row, List<ExpressQuoteImportModels.ColumnDef> columns, List<String> errors, int excelRow) {
|
||||
Row row, List<ExpressQuoteImportModels.ColumnDef> columns,
|
||||
List<String> warnings, int excelRow) {
|
||||
String destRaw = cellText(row, 0);
|
||||
if (!StringUtils.hasText(destRaw)) {
|
||||
return null;
|
||||
@@ -110,16 +111,16 @@ public final class ExpressQuoteMatrixSheetParser {
|
||||
raw, col.getDefaultPriceMode(), col.getWeightFromG(), col.getWeightToG());
|
||||
band.ifPresent(bands::add);
|
||||
} catch (PriceCellParser.UnparseablePriceException ex) {
|
||||
errors.add("第" + excelRow + "行「" + destRaw + "」列" + (col.getColIndex() + 1)
|
||||
+ "无法解析: " + ex.getMessage());
|
||||
warnings.add("第" + excelRow + "行「" + destRaw + "」列" + (col.getColIndex() + 1)
|
||||
+ "已跳过(无法解析): " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
if (bands.isEmpty() && errors.stream().noneMatch(e -> e.contains("第" + excelRow + "行"))) {
|
||||
errors.add("第" + excelRow + "行「" + destRaw + "」无任何有效重量带价格");
|
||||
if (bands.isEmpty()) {
|
||||
warnings.add("第" + excelRow + "行「" + destRaw + "」无有效重量带,已跳过该目的地");
|
||||
return null;
|
||||
}
|
||||
region.setBands(bands);
|
||||
return bands.isEmpty() ? null : region;
|
||||
return region;
|
||||
}
|
||||
|
||||
private static String normalizeDestination(String raw) {
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ public final class ExpressQuoteTemplateWriter {
|
||||
"2. 报价页为矩阵:目的省 + 价区 + 各重量列;同价区且价格相同会自动合并。",
|
||||
"3. 重量表头按字面转克,如 0.51-1KG → 510–1000g。",
|
||||
"4. 单元格支持数字(元/票)或「2+0.7元/kg」(首重+续重);空单元格表示该带无报价。",
|
||||
"5. 含「发/转单」等业务分支文案无法解析,将导致整单失败。",
|
||||
"5. 「发极兔/转单」等分支文案、无价格的目的地行会跳过并给出警告,不拖垮整单。",
|
||||
"6. 也可直接上传承运商多段矩阵表(无 Meta 时在提交时补全编码/名称/承运商/生效日)。",
|
||||
};
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
|
||||
+13
-5
@@ -26,14 +26,22 @@ class ExpressQuoteMatrixSheetParserTest {
|
||||
try (InputStream in = Files.newInputStream(path); Workbook wb = WorkbookFactory.create(in)) {
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
List<String> errors = new ArrayList<>();
|
||||
List<String> warnings = new ArrayList<>();
|
||||
List<ExpressQuoteImportModels.RegionDraft> raw =
|
||||
ExpressQuoteMatrixSheetParser.parse(sheet, errors);
|
||||
ExpressQuoteMatrixSheetParser.parse(sheet, errors, warnings);
|
||||
List<ExpressQuoteImportModels.RegionDraft> merged = ExpressQuoteRegionMerger.merge(raw);
|
||||
assertFalse(merged.isEmpty(), "应解析到分区");
|
||||
// 样表含「发极兔/转单」等文案 → 应有错误
|
||||
assertTrue(errors.stream().anyMatch(e -> e.contains("无法解析") || e.contains("发")),
|
||||
"应对不可解析单元格报错: " + errors);
|
||||
// 0.51-1KG → 510
|
||||
assertTrue(errors.isEmpty(), "跳过策略下不应产生硬错误: " + errors);
|
||||
assertTrue(warnings.stream().anyMatch(w -> w.contains("跳过")),
|
||||
"应对发极兔/空行给出跳过警告: " + warnings);
|
||||
boolean hasNeimeng = merged.stream()
|
||||
.flatMap(r -> r.getDestinations().stream())
|
||||
.anyMatch(d -> d.contains("内蒙古"));
|
||||
assertTrue(hasNeimeng, "内蒙古应保留可解析重量带");
|
||||
boolean hasXizang = merged.stream()
|
||||
.flatMap(r -> r.getDestinations().stream())
|
||||
.anyMatch(d -> d.contains("西藏"));
|
||||
assertFalse(hasXizang, "西藏无价格应整行跳过");
|
||||
boolean has510 = merged.stream()
|
||||
.flatMap(r -> r.getBands().stream())
|
||||
.anyMatch(b -> Integer.valueOf(510).equals(b.getWeightFromG()));
|
||||
|
||||
Reference in New Issue
Block a user