|
|
@@ -34,6 +34,7 @@ public final class AiRejectCollector {
|
|
|
private final Long fileId;
|
|
|
private final Long sheetId;
|
|
|
private final Integer blockNo;
|
|
|
+ private final Map<String, String> columnNameCn;
|
|
|
private final int sampleLimit;
|
|
|
private final boolean logAll;
|
|
|
|
|
|
@@ -48,12 +49,13 @@ public final class AiRejectCollector {
|
|
|
private final List<Map<String, Object>> samples = new ArrayList<>();
|
|
|
|
|
|
public AiRejectCollector(Long jobId, Long caseId, Long fileId, Long sheetId, Integer blockNo,
|
|
|
- int sampleLimit, boolean logAll) {
|
|
|
+ Map<String, String> columnNameCn, int sampleLimit, boolean logAll) {
|
|
|
this.jobId = jobId;
|
|
|
this.caseId = caseId;
|
|
|
this.fileId = fileId;
|
|
|
this.sheetId = sheetId;
|
|
|
this.blockNo = blockNo;
|
|
|
+ this.columnNameCn = columnNameCn == null ? Map.of() : columnNameCn;
|
|
|
this.sampleLimit = Math.max(0, sampleLimit);
|
|
|
this.logAll = logAll;
|
|
|
}
|
|
|
@@ -78,21 +80,22 @@ public final class AiRejectCollector {
|
|
|
ColumnError first = result.firstBlocking();
|
|
|
AiRejectReason reason = first == null ? AiRejectReason.REQUIRED_EMPTY : first.reason();
|
|
|
String column = first == null ? null : first.columnName();
|
|
|
+ String columnCn = blankToNull(cnOf(column));
|
|
|
reasonCounts.merge(reason.name(), 1, Integer::sum);
|
|
|
if (column != null) {
|
|
|
- columnCounts.merge(column, 1, Integer::sum);
|
|
|
+ // 统计键带中文表头,排障时一眼能看出是哪一列
|
|
|
+ columnCounts.merge(display(column, columnCn), 1, Integer::sum);
|
|
|
}
|
|
|
pending.add(new AiRejectRecord(jobId, caseId, fileId, sheetId, blockNo, (int) rowNo,
|
|
|
- first == null ? null : first.colIndex(), column, reason.name(),
|
|
|
+ first == null ? null : first.colIndex(), column, columnCn, reason.name(),
|
|
|
errorsJson(result.errors())));
|
|
|
if (samples.size() < MAX_SAMPLES) {
|
|
|
- samples.add(sample(rowNo, first));
|
|
|
+ samples.add(sample(rowNo, first, columnCn));
|
|
|
}
|
|
|
if (logAll || rejected <= sampleLimit) {
|
|
|
- log.warn("AI 清洗拒绝: jobId={}, fileId={}, sheetId={}, rowNo={}, col={}({}), reason={}, value={}",
|
|
|
+ log.warn("AI 清洗拒绝: jobId={}, fileId={}, sheetId={}, rowNo={}, col={}, reason={}, value={}",
|
|
|
jobId, fileId, sheetId, rowNo,
|
|
|
- first == null ? null : first.columnName(),
|
|
|
- first == null ? null : first.colIndex(),
|
|
|
+ displayWithIndex(column, columnCn, first == null ? null : first.colIndex()),
|
|
|
reason.name(),
|
|
|
first == null ? null : first.valuePreview());
|
|
|
}
|
|
|
@@ -105,7 +108,8 @@ public final class AiRejectCollector {
|
|
|
warned++;
|
|
|
for (ColumnError e : result.errors()) {
|
|
|
if (!e.blocking()) {
|
|
|
- optionalCounts.merge(e.columnName() + ":" + e.reason().name(), 1, Integer::sum);
|
|
|
+ optionalCounts.merge(display(e.columnName(), blankToNull(cnOf(e.columnName())))
|
|
|
+ + ":" + e.reason().name(), 1, Integer::sum);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -120,7 +124,7 @@ public final class AiRejectCollector {
|
|
|
"reason", AiRejectReason.WRITER_ERROR.name(),
|
|
|
"value", message == null ? "" : message)));
|
|
|
pending.add(new AiRejectRecord(jobId, caseId, fileId, sheetId, blockNo, (int) rowNo,
|
|
|
- null, null, AiRejectReason.WRITER_ERROR.name(), detail));
|
|
|
+ null, null, null, AiRejectReason.WRITER_ERROR.name(), detail));
|
|
|
flush();
|
|
|
}
|
|
|
|
|
|
@@ -160,13 +164,14 @@ public final class AiRejectCollector {
|
|
|
return Json.toStr(out);
|
|
|
}
|
|
|
|
|
|
- private static String errorsJson(List<ColumnError> errors) {
|
|
|
+ private String errorsJson(List<ColumnError> errors) {
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
if (errors != null) {
|
|
|
for (ColumnError e : errors) {
|
|
|
Map<String, Object> m = new LinkedHashMap<>();
|
|
|
m.put("colIndex", e.colIndex());
|
|
|
m.put("column", e.columnName());
|
|
|
+ m.put("columnCn", blankToNull(cnOf(e.columnName())));
|
|
|
m.put("reason", e.reason() == null ? null : e.reason().name());
|
|
|
m.put("value", e.valuePreview());
|
|
|
m.put("blocking", e.blocking());
|
|
|
@@ -176,13 +181,42 @@ public final class AiRejectCollector {
|
|
|
return Json.toStr(list);
|
|
|
}
|
|
|
|
|
|
- private static Map<String, Object> sample(long rowNo, ColumnError first) {
|
|
|
+ private Map<String, Object> sample(long rowNo, ColumnError first, String columnCn) {
|
|
|
Map<String, Object> m = new LinkedHashMap<>();
|
|
|
m.put("rowNo", rowNo);
|
|
|
m.put("column", first == null ? null : first.columnName());
|
|
|
+ m.put("columnCn", columnCn);
|
|
|
m.put("colIndex", first == null ? null : first.colIndex());
|
|
|
m.put("reason", first == null ? null : first.reason().name());
|
|
|
m.put("value", first == null ? null : first.valuePreview());
|
|
|
return m;
|
|
|
}
|
|
|
+
|
|
|
+ private String cnOf(String column) {
|
|
|
+ return column == null ? null : columnNameCn.get(column);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 统计/展示用:c1(身份证号);没有中文名时退回 c1 */
|
|
|
+ private static String display(String column, String columnCn) {
|
|
|
+ if (column == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ return columnCn == null || columnCn.isBlank() || columnCn.equals(column)
|
|
|
+ ? column : column + "(" + columnCn + ")";
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 日志用:没有中文名时保留列序号,c1(列 1) */
|
|
|
+ private static String displayWithIndex(String column, String columnCn, Integer colIndex) {
|
|
|
+ if (column == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (columnCn != null && !columnCn.isBlank() && !columnCn.equals(column)) {
|
|
|
+ return column + "(" + columnCn + ")";
|
|
|
+ }
|
|
|
+ return colIndex == null ? column : column + "(列 " + colIndex + ")";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String blankToNull(String value) {
|
|
|
+ return value == null || value.isBlank() ? null : value;
|
|
|
+ }
|
|
|
}
|