refactor(phase-3): 3A 拆薄第一笔——appearancepatent 的死 Excel 读取件出仓 70 行
AppearancePatentTaskService 棘轮读数 3458→3388。删的是八枚私有件: readHeaders/readRowValues/buildHeaderMap/findRequiredHeader/ findOptionalHeader/findOptionalHeaderExact/normalizeHeaderAlias/cell, 连同因此悬空的两个 POI import(DataFormatter、Row)。 判据不是"看着没人用":这八枚是 AppearancePatentExcelParser 抽走解析本体后的残留, 逐条数过文件内出现次数=1(只有定义行),src/test 全树零命中,跨五棵树的同名 命中全在别的模块自己的 parser 里(SimilarAsinExcelParser/SplitRunService/ AppearancePatentExcelParser 各有一份,不是对本支的引用)。私有方法没有反射、 DI、动态路由面(§1 铁律 2 五路复扫)。同段落里 isAppearanceResultWorkbook/ hasHeader/shouldInspectRow/baseId/normalizeDisplayId 仍在用,一个没碰。 门禁:AppearancePatent*Test 236 例全绿(含 parse-snapshot golden 那支), mvn -o compile 干净。golden 文件一字未动。
This commit is contained in:
-70
@@ -59,8 +59,6 @@ import com.nanri.aiimage.modules.task.service.TaskProgressSnapshotService;
|
||||
import com.nanri.aiimage.modules.task.service.TransientPayloadStorageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -2847,23 +2845,6 @@ public class AppearancePatentTaskService {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> readHeaders(Row header, DataFormatter formatter) {
|
||||
List<String> headers = new ArrayList<>();
|
||||
for (int i = 0; i < header.getLastCellNum(); i++) {
|
||||
String val = normalize(formatter.formatCellValue(header.getCell(i)));
|
||||
headers.add(val.isBlank() ? "列" + (i + 1) : val);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
private Map<String, String> readRowValues(Row row, List<String> headers, DataFormatter formatter) {
|
||||
Map<String, String> values = new LinkedHashMap<>();
|
||||
for (int i = 0; i < headers.size(); i++) {
|
||||
values.put(headers.get(i), cell(row, i, formatter));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private boolean isAppearanceResultWorkbook(List<String> headers) {
|
||||
return hasHeader(headers, "状态")
|
||||
&& (hasHeader(headers, "结论")
|
||||
@@ -2894,57 +2875,6 @@ public class AppearancePatentTaskService {
|
||||
return row != null && (!normalize(row.getTitle()).isBlank() || !normalize(row.getUrl()).isBlank());
|
||||
}
|
||||
|
||||
private Map<String, Integer> buildHeaderMap(Row header, DataFormatter formatter) {
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
for (int i = 0; i < header.getLastCellNum(); i++) {
|
||||
String val = normalize(formatter.formatCellValue(header.getCell(i)));
|
||||
if (!val.isBlank()) {
|
||||
map.putIfAbsent(val.toLowerCase(Locale.ROOT), i);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private int findRequiredHeader(Map<String, Integer> map, String... names) {
|
||||
int idx = findOptionalHeader(map, names);
|
||||
if (idx < 0) {
|
||||
throw new BusinessException("缺少必要表头: " + String.join("/", names));
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
private int findOptionalHeader(Map<String, Integer> map, String... names) {
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
for (String name : names) {
|
||||
if (entry.getKey().contains(name.toLowerCase(Locale.ROOT))) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findOptionalHeaderExact(Map<String, Integer> map, String... names) {
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
String normalizedHeader = normalizeHeaderAlias(entry.getKey());
|
||||
for (String name : names) {
|
||||
if (normalizedHeader.equals(normalizeHeaderAlias(name))) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private String normalizeHeaderAlias(String value) {
|
||||
String normalized = normalize(value).toLowerCase(Locale.ROOT);
|
||||
return normalized.replaceAll("[\\s_\\-()()\\[\\]{}::/\\\\]+", "");
|
||||
}
|
||||
|
||||
private String cell(Row row, int col, DataFormatter formatter) {
|
||||
return col < 0 ? "" : normalize(formatter.formatCellValue(row.getCell(col)));
|
||||
}
|
||||
|
||||
private String baseId(String id) {
|
||||
String s = normalize(id);
|
||||
int idx = s.indexOf('_');
|
||||
|
||||
Reference in New Issue
Block a user