元数据模板导出 excel导入 带五条实例

This commit is contained in:
2026-10-23 19:17:09 +08:00
parent ddc0864f06
commit b522734c92
4 changed files with 80 additions and 2 deletions
@@ -26,6 +26,9 @@ public class ImportResult {
/** 失败条数 */
private int failed;
/** 跳过的模板示例行数 */
private int skipped;
/** 失败明细,格式如「第 5 行:正题名不能为空」 */
private List<String> errors = new ArrayList<>();
@@ -37,7 +37,7 @@ public class VersionResourceExcelService {
}
private static final List<Column> COLUMNS = List.of(
new Column("正题名*", "title", VersionResource::setTitle, 512, "必填"),
new Column("正题名*", "title", VersionResource::setTitle, 512, "必填;示例行可覆盖或直接删除"),
new Column("加工编号", "processNo", VersionResource::setProcessNo, 128, "选填;系统中已存在则更新该条"),
new Column("责任者", "author", VersionResource::setAuthor, 512, "选填;多人用 ; 分隔"),
new Column("责任方式", "responsibility", VersionResource::setResponsibility, 256, "选填;如 著、编、译"),
@@ -62,6 +62,38 @@ public class VersionResourceExcelService {
new Column("是否特藏", "isSpecial", (r, v) -> { }, 4, "选填;是 或 否")
);
/**
* 模板自带的 5 条示例数据,列顺序与 {@link #COLUMNS} 严格一致。
* 正题名统一以「示例:」开头,导入时会被自动跳过。
*/
private static final String[][] SAMPLES = {
{"示例:军事理论教程", "EX-2026-0001", "张明", "著", "E0-43", "军事理论;教程",
"系统介绍军事理论的基本概念、发展脉络与研究方法,适用于院校教学参考。",
"2026", "军事科学出版社", "北京", "2026-03-01", "第2版", "978-7-80137-001-1",
"文本", "纸质", "PDF", "286", "chi", "陆军步兵学院图书馆", "陆军步兵学院",
"2026", "", "否"},
{"示例:版本资源元数据著录规范", "EX-2026-0002", "李华", "编", "G254.3", "元数据;著录",
"依据国家与军队相关标准,规范版本资源元数据的著录字段、格式与质量控制要求。",
"2025", "国防大学出版社", "北京", "2025-09-15", "第1版", "978-7-5626-002-2",
"文本", "电子", "PDF", "210", "chi", "南京某院校图书馆", "陆军步兵学院",
"2026", "http://cdio.example.org/fulltext/EX-2026-0002", "否"},
{"示例:中国古代兵书辑要", "EX-2026-0003", "王强", "整理", "E892", "兵书;古籍",
"收录先秦至明清重要兵书,附版本源流考述与校勘记,供版本比对研究使用。",
"2024", "中华书局", "北京", "2024-06-20", "影印本", "978-7-101-0033-3",
"文本", "纸质", "PDF", "520", "chi", "陆军勤务学院图书馆", "陆军勤务学院",
"2025", "", "是"},
{"示例:数字图书馆建设实践", "EX-2026-0004", "赵敏", "著", "G250.76", "数字图书馆;建设",
"围绕数字图书馆的资源组织、平台架构与服务模式展开,含多个建设案例分析。",
"2023", "国家图书馆出版社", "北京", "2023-11-10", "第1版", "978-7-5013-0044-4",
"文本", "电子", "EPUB", "340", "chi", "陆军指挥学院图书馆", "陆军指挥学院",
"2025", "", "否"},
{"示例:外军装备发展研究", "EX-2026-0005", "陈刚", "主编", "E92", "装备;外军",
"分析外军主战装备的发展路径、技术特点与体系构成,供装备论证参考。",
"2025", "国防工业出版社", "北京", "2025-05-08", "", "978-7-118-0055-5",
"文本", "纸质", "PDF", "415", "chi", "陆军航空兵学院图书馆", "陆军航空兵学院",
"2026", "", "否"}
};
// ==================== 模板导出 ====================
public void writeTemplate(OutputStream out) throws IOException {
@@ -96,6 +128,18 @@ public class VersionResourceExcelService {
sheet.createFreezePane(0, 2);
// 5 条示例数据:供对照填写,导入时自动跳过
CellStyle sampleStyle = buildSampleStyle(wb);
for (int r = 0; r < SAMPLES.length; r++) {
Row row = sheet.createRow(2 + r);
row.setHeightInPoints(20);
for (int c = 0; c < SAMPLES[r].length && c < COLUMNS.size(); c++) {
Cell cell = row.createCell(c);
cell.setCellValue(SAMPLES[r][c]);
cell.setCellStyle(sampleStyle);
}
}
// 媒体类型、是否特藏加下拉,避免填错
addDropdown(sheet, indexOf("mediaType"), new String[]{"纸质", "电子"});
addDropdown(sheet, indexOf("isSpecial"), new String[]{"是", "否"});
@@ -133,6 +177,17 @@ public class VersionResourceExcelService {
return style;
}
private CellStyle buildSampleStyle(Workbook wb) {
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setFontHeightInPoints((short) 10);
font.setColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFont(font);
style.setVerticalAlignment(VerticalAlignment.CENTER);
border(style);
return style;
}
private void border(CellStyle style) {
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
@@ -242,6 +297,12 @@ public class VersionResourceExcelService {
continue;
}
// 模板自带的示例行:跳过,不参与导入
if (res.getTitle().startsWith("示例:") || res.getTitle().startsWith("示例:")) {
result.setSkipped(result.getSkipped() + 1);
continue;
}
if (StrUtil.isBlank(res.getGovernStatus())) {
res.setGovernStatus("RAW");
}
@@ -259,7 +320,9 @@ public class VersionResourceExcelService {
result.setTotal(parsed.size());
if (parsed.isEmpty()) {
if (result.getFailed() == 0) {
result.addError(0, "未读取到有效数据行,请从第 3 行开始填写");
result.addError(0, result.getSkipped() > 0
? "仅读取到模板示例数据,请填写实际数据后再导入"
: "未读取到有效数据行,请从第 3 行开始填写");
}
return result;
}
+2
View File
@@ -92,6 +92,8 @@ export interface ImportResult {
inserted: number
updated: number
failed: number
/** 自动跳过的模板示例行数 */
skipped: number
errors: string[]
}
@@ -412,6 +412,10 @@ onMounted(fetchData)
</div>
</div>
<p v-if="importResult?.skipped" class="imp-skip-tip">
已自动跳过 {{ importResult.skipped }} 行模板示例数据。
</p>
<div v-if="importResult?.errors?.length" class="imp-errors">
<div class="imp-errors-title">失败明细</div>
<ul>
@@ -532,6 +536,12 @@ onMounted(fetchData)
color: #3f7d5c;
}
.imp-skip-tip {
margin: 0 0 12px;
font-size: 12px;
color: var(--text-muted);
}
.special-tag {
margin-right: 6px;
background: var(--brand-primary);