Merge remote-tracking branch 'origin/master'

# Conflicts:
#	frontend/src/views/search/SearchView.vue
This commit is contained in:
SUNJIAJINGS
2026-10-22 17:35:56 +08:00
42 changed files with 2956 additions and 332 deletions
@@ -1,6 +1,7 @@
package com.banben.modules.collect.controller;
import com.banben.common.Result;
import com.banben.modules.collect.dto.CollectTableVO;
import com.banben.modules.collect.entity.CollectTask;
import com.banben.modules.collect.service.CollectService;
import io.swagger.v3.oas.annotations.Operation;
@@ -29,11 +30,16 @@ public class CollectController {
return Result.success(collectService.createTask(task));
}
@Operation(summary = "执行采集任务")
@Operation(summary = "测试来源库连接,并查看表字段如何写入版本资源表")
@PostMapping("/preview")
public Result<CollectTableVO> preview(@RequestBody CollectTask source) {
return Result.success(collectService.previewSource(source));
}
@Operation(summary = "执行采集任务:按来源表读取并写入版本资源表")
@PostMapping("/task/{id}/start")
public Result<Void> startTask(@PathVariable Long id) {
collectService.startTask(id);
return Result.success();
public Result<CollectTask> startTask(@PathVariable Long id) {
return Result.success(collectService.startTask(id));
}
@Operation(summary = "采集任务列表")
@@ -0,0 +1,21 @@
package com.banben.modules.collect.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 来源表的一列,以及它会写入版本资源表的哪个字段。
*/
@Data
@Schema(description = "采集字段对应关系")
public class CollectColumnVO {
@Schema(description = "来源列名")
private String columnName;
@Schema(description = "写入 version_resource 的字段名,无法对应时为空")
private String targetField;
@Schema(description = "写入字段的中文名")
private String targetLabel;
}
@@ -0,0 +1,24 @@
package com.banben.modules.collect.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 可采集的数据库表。
*/
@Data
@Schema(description = "可采集数据表")
public class CollectTableVO {
@Schema(description = "表名")
private String tableName;
@Schema(description = "当前行数")
private long rowCount;
@Schema(description = "列与版本资源字段的对应关系")
private List<CollectColumnVO> columns = new ArrayList<>();
}
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -32,6 +33,25 @@ public class CollectTask implements Serializable {
@Schema(description = "数据源类型:MARC/EXCEL/DB/API")
private String sourceType;
@Schema(description = "数据库地址,如 10.1.1.14")
private String dbHost;
@Schema(description = "数据库端口,瀚高默认 5866,PostgreSQL 默认 5432")
private Integer dbPort;
@Schema(description = "数据库名")
private String dbName;
@Schema(description = "数据库用户名")
private String dbUsername;
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@Schema(description = "数据库密码,只用于连接,接口不回传")
private String dbPassword;
@Schema(description = "要采集的表名,可写 schema.table")
private String sourceTable;
@Schema(description = "目标采集量")
private Integer targetCount;
@@ -1,6 +1,7 @@
package com.banben.modules.collect.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.banben.modules.collect.dto.CollectTableVO;
import com.banben.modules.collect.entity.CollectTask;
import java.util.List;
@@ -16,9 +17,14 @@ public interface CollectService extends IService<CollectTask> {
Long createTask(CollectTask task);
/**
* 执行采集任务(异步)。
* 执行采集任务,返回执行后的任务(含采集条数和结果说明)。
*/
void startTask(Long taskId);
CollectTask startTask(Long taskId);
/**
* 按填写的地址、账号和表名连接来源库,返回行数和字段对应关系。
*/
CollectTableVO previewSource(CollectTask source);
/**
* 查询任务列表。
@@ -3,6 +3,7 @@ package com.banben.modules.collect.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.banben.common.BusinessException;
import com.banben.modules.collect.dto.CollectTableVO;
import com.banben.modules.collect.entity.CollectTask;
import com.banben.modules.collect.mapper.CollectTaskMapper;
import com.banben.modules.collect.service.CollectService;
@@ -37,11 +38,14 @@ public class CollectServiceImpl extends ServiceImpl<CollectTaskMapper, CollectTa
/** 数据源类型 → 采集适配器 的映射(key 统一大写)。 */
private final Map<String, Collector> collectorMap;
private final DbTableCollector dbTableCollector;
/**
* 构造注入所有 Collector 实现。
* 若当前没有任何实现类,Spring 注入空集合,运行时会提示「未找到适配器」并跳过实际采集。
*/
public CollectServiceImpl(List<Collector> collectors) {
public CollectServiceImpl(List<Collector> collectors, DbTableCollector dbTableCollector) {
this.dbTableCollector = dbTableCollector;
this.collectorMap = collectors.stream()
.collect(Collectors.toMap(c -> c.sourceType().toUpperCase(), Function.identity(), (a, b) -> a));
}
@@ -60,7 +64,12 @@ public class CollectServiceImpl extends ServiceImpl<CollectTaskMapper, CollectTa
}
@Override
public void startTask(Long taskId) {
public CollectTableVO previewSource(CollectTask source) {
return dbTableCollector.preview(source);
}
@Override
public CollectTask startTask(Long taskId) {
CollectTask task = this.getById(taskId);
if (task == null) {
throw new BusinessException("采集任务不存在");
@@ -78,22 +87,24 @@ public class CollectServiceImpl extends ServiceImpl<CollectTaskMapper, CollectTa
Collector collector = collectorMap.get(sourceType);
int count;
if (collector == null) {
log.warn("未找到数据源类型 [{}] 的采集适配器,任务 {} 跳过实际采集", sourceType, taskId);
count = 0;
} else {
count = collector.collect(task);
throw new BusinessException("未找到数据源类型 " + sourceType + " 的采集适配器");
}
count = collector.collect(task);
task.setCollectedCount(count);
task.setStatus("SUCCESS");
task.setMessage("采集完成");
if (task.getMessage() == null || task.getMessage().isBlank()) {
task.setMessage("采集完成,写入 " + count + " 条");
}
} catch (Exception e) {
log.error("采集任务执行失败: {}", e.getMessage(), e);
task.setStatus("FAILED");
task.setCollectedCount(0);
task.setMessage(e.getMessage());
} finally {
task.setEndTime(LocalDateTime.now());
this.updateById(task);
}
return task;
}
@Override
@@ -0,0 +1,440 @@
package com.banben.modules.collect.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.banben.common.BusinessException;
import com.banben.modules.collect.dto.CollectColumnVO;
import com.banben.modules.collect.dto.CollectTableVO;
import com.banben.modules.collect.entity.CollectTask;
import com.banben.modules.collect.service.Collector;
import com.banben.modules.resource.entity.VersionResource;
import com.banben.modules.resource.enums.GovernStatus;
import com.banben.modules.resource.mapper.VersionResourceMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.function.BiConsumer;
/**
* 从当前数据库的指定表采集记录,按版本资源表的字段写入 {@code version_resource}。
*
* <p>列名与版本资源字段一致时直接填入;书名、作者、出版社等常见别名也会识别。
* 对不上的列不写入。治理状态统一记为原始数据。</p>
*/
@Component
@RequiredArgsConstructor
public class DbTableCollector implements Collector {
private static final DateTimeFormatter DAY = DateTimeFormatter.ofPattern("yyyyMMdd");
private static final int MAX_ROWS = 200000;
private static final Map<String, String> FIELD_BY_COLUMN = new HashMap<>();
private static final Map<String, String> FIELD_LABEL = new LinkedHashMap<>();
private static final Map<String, BiConsumer<VersionResource, String>> SETTERS = new HashMap<>();
static {
label("processNo", "加工编号");
label("title", "正题名");
label("clcCode", "中图分类号");
label("keywords", "主题词或关键词");
label("summary", "摘要");
label("publishYear", "出版年份");
label("processDate", "加工日期");
label("contentForm", "内容形式");
label("mediaType", "媒体类型");
label("format", "格式");
label("pageCount", "页码");
label("language", "语种");
label("submitOrg", "数据提交单位");
label("taskYear", "所属任务年份");
label("sourceLibrary", "来源馆");
label("sourceLibraryAddr", "来源馆地址");
label("fulltextUrl", "全文地址");
label("otherTitle", "其他题名");
label("author", "责任者");
label("responsibility", "责任方式");
label("note", "附注");
label("publisher", "出版者");
label("publishPlace", "出版地");
label("publishDate", "出版日期");
label("edition", "版本");
label("isbn", "ISBN");
label("unifiedBookNo", "统一书号");
label("cdoi", "CDOI");
label("publishUrl", "发布地址");
alias("processNo", "process_no", "processno", "加工编号");
alias("title", "title", "name", "book_name", "bookname", "resource_title", "题名", "正题名", "书名");
alias("clcCode", "clc_code", "clccode", "clc", "class_no", "classno", "分类号", "中图分类号");
alias("keywords", "keywords", "keyword", "subject", "关键词", "主题词");
alias("summary", "summary", "abstract", "intro", "摘要", "简介");
alias("publishYear", "publish_year", "publishyear", "pub_year", "pubyear", "出版年", "出版年份");
alias("processDate", "process_date", "processdate", "加工日期");
alias("contentForm", "content_form", "contentform", "内容形式");
alias("mediaType", "media_type", "mediatype", "媒体类型", "资源类型");
alias("format", "format", "格式");
alias("pageCount", "page_count", "pagecount", "pages", "页码", "页数");
alias("language", "language", "lang", "语种");
alias("submitOrg", "submit_org", "submitorg", "org_name", "orgname", "数据提交单位", "提交单位");
alias("taskYear", "task_year", "taskyear", "所属任务年份", "任务年份");
alias("sourceLibrary", "source_library", "sourcelibrary", "library_name", "libraryname", "来源馆", "馆藏单位");
alias("sourceLibraryAddr", "source_library_addr", "sourcelibraryaddr", "来源馆地址");
alias("fulltextUrl", "fulltext_url", "fulltexturl", "file_url", "fileurl", "ebook_url", "ebookurl", "全文地址");
alias("otherTitle", "other_title", "othertitle", "其他题名");
alias("author", "author", "writer", "作者", "责任者");
alias("responsibility", "responsibility", "责任方式");
alias("note", "note", "remark", "附注", "备注");
alias("publisher", "publisher", "press", "出版者", "出版社");
alias("publishPlace", "publish_place", "publishplace", "出版地");
alias("publishDate", "publish_date", "publishdate", "出版日期");
alias("edition", "edition", "版本", "版次");
alias("isbn", "isbn");
alias("unifiedBookNo", "unified_book_no", "unifiedbookno", "统一书号");
alias("cdoi", "cdoi");
alias("publishUrl", "publish_url", "publishurl", "发布地址");
setter("processNo", VersionResource::setProcessNo, 128);
setter("title", VersionResource::setTitle, 512);
setter("clcCode", VersionResource::setClcCode, 64);
setter("keywords", VersionResource::setKeywords, 512);
setter("summary", VersionResource::setSummary, 0);
setter("publishYear", VersionResource::setPublishYear, 8);
setter("processDate", VersionResource::setProcessDate, 16);
setter("contentForm", VersionResource::setContentForm, 64);
setter("mediaType", VersionResource::setMediaType, 32);
setter("format", VersionResource::setFormat, 64);
setter("pageCount", VersionResource::setPageCount, 64);
setter("language", VersionResource::setLanguage, 16);
setter("submitOrg", VersionResource::setSubmitOrg, 256);
setter("taskYear", VersionResource::setTaskYear, 8);
setter("sourceLibrary", VersionResource::setSourceLibrary, 256);
setter("sourceLibraryAddr", VersionResource::setSourceLibraryAddr, 256);
setter("fulltextUrl", VersionResource::setFulltextUrl, 1024);
setter("otherTitle", VersionResource::setOtherTitle, 512);
setter("author", VersionResource::setAuthor, 512);
setter("responsibility", VersionResource::setResponsibility, 256);
setter("note", VersionResource::setNote, 0);
setter("publisher", VersionResource::setPublisher, 256);
setter("publishPlace", VersionResource::setPublishPlace, 128);
setter("publishDate", VersionResource::setPublishDate, 32);
setter("edition", VersionResource::setEdition, 128);
setter("isbn", VersionResource::setIsbn, 64);
setter("unifiedBookNo", VersionResource::setUnifiedBookNo, 64);
setter("cdoi", VersionResource::setCdoi, 256);
setter("publishUrl", VersionResource::setPublishUrl, 1024);
}
private final VersionResourceMapper resourceMapper;
@Override
public String sourceType() {
return "DB";
}
/**
* 用页面填写的地址、账号和表名连接来源库,返回行数以及列如何写入版本资源表。
*/
public CollectTableVO preview(CollectTask task) {
String[] qualified = qualify(task.getSourceTable());
try (Connection connection = openConnection(task)) {
ensureTable(connection, qualified[0], qualified[1]);
CollectTableVO table = new CollectTableVO();
table.setTableName(qualified[0] + "." + qualified[1]);
table.setRowCount(countRows(connection, qualified[0], qualified[1]));
table.setColumns(readColumns(connection, qualified[0], qualified[1]));
return table;
} catch (SQLException e) {
throw new BusinessException(sqlMessage(e));
}
}
@Override
public int collect(CollectTask task) {
String[] qualified = qualify(task.getSourceTable());
int limit = task.getTargetCount() == null ? MAX_ROWS : Math.min(Math.max(task.getTargetCount(), 1), MAX_ROWS);
List<Map<String, Object>> rows;
try (Connection connection = openConnection(task)) {
ensureTable(connection, qualified[0], qualified[1]);
rows = readRows(connection, qualified[0], qualified[1], limit);
} catch (SQLException e) {
throw new BusinessException(sqlMessage(e));
}
String table = qualified[1];
Set<String> existing = loadProcessNos();
int inserted = 0;
int duplicated = 0;
int missingTitle = 0;
int sequence = 0;
String today = LocalDate.now().format(DAY);
String year = String.valueOf(LocalDate.now().getYear());
for (Map<String, Object> row : rows) {
VersionResource resource = new VersionResource();
for (Map.Entry<String, Object> entry : row.entrySet()) {
String field = FIELD_BY_COLUMN.get(normalize(entry.getKey()));
if (field == null || entry.getValue() == null) {
continue;
}
String value = stringify(entry.getValue());
if (value.isEmpty()) {
continue;
}
SETTERS.get(field).accept(resource, value);
}
if (blank(resource.getTitle())) {
missingTitle++;
continue;
}
if (blank(resource.getProcessNo())) {
Object sourceId = first(row, "id");
sequence++;
String suffix = sourceId == null ? String.valueOf(sequence) : stringify(sourceId);
String prefix = blank(task.getLibraryCode()) ? "DB" : task.getLibraryCode().trim();
resource.setProcessNo(truncate(prefix + "-" + table + "-" + suffix, 128));
}
if (existing.contains(resource.getProcessNo())) {
duplicated++;
continue;
}
if (blank(resource.getSourceLibrary())) {
resource.setSourceLibrary(truncate(task.getLibraryName(), 256));
}
if (blank(resource.getSubmitOrg())) {
resource.setSubmitOrg(truncate(blank(task.getLibraryName()) ? resource.getSourceLibrary() : task.getLibraryName(), 256));
}
if (blank(resource.getTaskYear())) {
resource.setTaskYear(year);
}
if (blank(resource.getProcessDate())) {
resource.setProcessDate(today);
}
resource.setGovernStatus(GovernStatus.RAW.getCode());
resource.setAbnormalFlag(0);
resource.setSensitiveFlag(0);
resource.setIsSpecial(0);
resource.setManageStatus(0);
resource.setDeleted(0);
resourceMapper.insert(resource);
existing.add(resource.getProcessNo());
inserted++;
}
task.setMessage(String.format(
"已从 %s:%s/%s 的表 %s.%s 读取 %d 条,按版本资源字段写入 %d 条,跳过重复 %d 条,缺少正题名 %d 条",
task.getDbHost(), task.getDbPort(), task.getDbName(), qualified[0], qualified[1],
rows.size(), inserted, duplicated, missingTitle));
return inserted;
}
private Connection openConnection(CollectTask task) {
if (blank(task.getDbHost()) || !task.getDbHost().trim().matches("[A-Za-z0-9._-]+")) {
throw new BusinessException("请填写合法的数据库地址");
}
int port = task.getDbPort() == null ? 5432 : task.getDbPort();
if (port < 1 || port > 65535) {
throw new BusinessException("数据库端口应在 1 到 65535 之间");
}
if (blank(task.getDbName()) || !task.getDbName().trim().matches("[A-Za-z0-9_]+")) {
throw new BusinessException("请填写合法的数据库名");
}
if (blank(task.getDbUsername())) {
throw new BusinessException("请填写数据库用户名");
}
if (blank(task.getDbPassword())) {
throw new BusinessException("请填写数据库密码");
}
String url = "jdbc:postgresql://" + task.getDbHost().trim() + ":" + port + "/"
+ task.getDbName().trim() + "?connectTimeout=8&socketTimeout=30";
Properties properties = new Properties();
properties.setProperty("user", task.getDbUsername().trim());
properties.setProperty("password", task.getDbPassword());
try {
return DriverManager.getConnection(url, properties);
} catch (SQLException e) {
throw new BusinessException(sqlMessage(e));
}
}
private String[] qualify(String raw) {
if (blank(raw)) {
throw new BusinessException("请填写要采集的表名");
}
String[] parts = raw.trim().split("\\.");
if (parts.length > 2) {
throw new BusinessException("表名格式应为表名,或模式名.表名");
}
String schema = parts.length == 2 ? parts[0] : "public";
String table = parts.length == 2 ? parts[1] : parts[0];
if (!schema.matches("[A-Za-z_][A-Za-z0-9_]*") || !table.matches("[A-Za-z_][A-Za-z0-9_]*")) {
throw new BusinessException("表名只能包含字母、数字和下划线");
}
return new String[]{schema.toLowerCase(Locale.ROOT), table.toLowerCase(Locale.ROOT)};
}
private void ensureTable(Connection connection, String schema, String table) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement("""
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = ? AND table_name = ?
""")) {
statement.setString(1, schema);
statement.setString(2, table);
try (ResultSet resultSet = statement.executeQuery()) {
resultSet.next();
if (resultSet.getInt(1) == 0) {
throw new BusinessException("来源库中不存在表:" + schema + "." + table);
}
}
}
}
private long countRows(Connection connection, String schema, String table) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(
"SELECT COUNT(*) FROM \"" + schema + "\".\"" + table + "\"");
ResultSet resultSet = statement.executeQuery()) {
resultSet.next();
return resultSet.getLong(1);
}
}
private List<CollectColumnVO> readColumns(Connection connection, String schema, String table) throws SQLException {
List<CollectColumnVO> columns = new ArrayList<>();
try (PreparedStatement statement = connection.prepareStatement("""
SELECT column_name FROM information_schema.columns
WHERE table_schema = ? AND table_name = ?
ORDER BY ordinal_position
""")) {
statement.setString(1, schema);
statement.setString(2, table);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String columnName = resultSet.getString(1);
CollectColumnVO item = new CollectColumnVO();
item.setColumnName(columnName);
String field = FIELD_BY_COLUMN.get(normalize(columnName));
item.setTargetField(field);
item.setTargetLabel(field == null ? null : FIELD_LABEL.get(field));
columns.add(item);
}
}
}
return columns;
}
private List<Map<String, Object>> readRows(Connection connection, String schema, String table, int limit)
throws SQLException {
List<Map<String, Object>> rows = new ArrayList<>();
try (PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM \"" + schema + "\".\"" + table + "\" LIMIT " + limit);
ResultSet resultSet = statement.executeQuery()) {
ResultSetMetaData meta = resultSet.getMetaData();
while (resultSet.next()) {
Map<String, Object> row = new LinkedHashMap<>();
for (int i = 1; i <= meta.getColumnCount(); i++) {
row.put(meta.getColumnLabel(i), resultSet.getObject(i));
}
rows.add(row);
}
}
return rows;
}
private String sqlMessage(SQLException exception) {
String message = exception.getMessage() == null ? "" : exception.getMessage();
String lower = message.toLowerCase(Locale.ROOT);
if (lower.contains("password authentication failed") || lower.contains("authentication failed")) {
return "数据库用户名或密码错误";
}
if (lower.contains("does not exist") && lower.contains("database")) {
return "数据库不存在";
}
if (lower.contains("connection refused")) {
return "连接被拒绝,请检查数据库地址和端口";
}
if (lower.contains("timeout") || lower.contains("timed out")) {
return "连接超时,请检查数据库地址和端口";
}
String brief = message.replaceAll("\\s+", " ").trim();
if (brief.length() > 180) {
brief = brief.substring(0, 180);
}
return brief.isEmpty() ? "连接数据库失败" : "连接数据库失败:" + brief;
}
private Set<String> loadProcessNos() {
LambdaQueryWrapper<VersionResource> query = new LambdaQueryWrapper<>();
query.select(VersionResource::getProcessNo).isNotNull(VersionResource::getProcessNo);
Set<String> nos = new HashSet<>();
for (VersionResource resource : resourceMapper.selectList(query)) {
if (!blank(resource.getProcessNo())) {
nos.add(resource.getProcessNo());
}
}
return nos;
}
private static void label(String field, String text) {
FIELD_LABEL.put(field, text);
}
private static void alias(String field, String... names) {
for (String name : names) {
FIELD_BY_COLUMN.put(normalize(name), field);
}
}
private static void setter(String field, BiConsumer<VersionResource, String> setter, int maxLength) {
SETTERS.put(field, (resource, value) -> setter.accept(resource, maxLength > 0 ? truncate(value, maxLength) : value));
}
private static String normalize(String name) {
if (name == null) {
return "";
}
return name.trim().toLowerCase(Locale.ROOT).replace("_", "").replace("-", "");
}
private static Object first(Map<String, Object> row, String key) {
for (Map.Entry<String, Object> entry : row.entrySet()) {
if (key.equalsIgnoreCase(entry.getKey())) {
return entry.getValue();
}
}
return null;
}
private static String stringify(Object value) {
return value == null ? "" : String.valueOf(value).trim();
}
private static String truncate(String value, int maxLength) {
if (value == null) {
return null;
}
String text = value.trim();
if (text.isEmpty()) {
return null;
}
return text.length() <= maxLength ? text : text.substring(0, maxLength);
}
private static boolean blank(String value) {
return value == null || value.trim().isEmpty();
}
}
@@ -1,12 +1,17 @@
package com.banben.modules.governance.controller;
import com.banben.common.Result;
import com.banben.modules.governance.dto.GovernanceHintVO;
import com.banben.modules.governance.entity.GovernanceJob;
import com.banben.modules.governance.service.GovernanceService;
import com.banben.modules.resource.entity.VersionResource;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@@ -14,6 +19,11 @@ import java.util.List;
* 数据治理接口。
*
* <p>对应「数据治理」四动作:聚同、优化、提示、提纯。</p>
* <ul>
* <li>优化:整合聚同文献的不同描述元数据,生成质量更高、要素更完整的元数据。</li>
* <li>提示:生成疑似同一文献提示清单、疑似元数据错漏提示清单。</li>
* <li>提纯:将相关纸电图书数据从全部图书数据中提取出来,形成版本资源数据集。</li>
* </ul>
*/
@Tag(name = "数据治理", description = "聚同 / 优化 / 提示 / 提纯")
@RestController
@@ -29,22 +39,34 @@ public class GovernanceController {
return Result.success(governanceService.runJob("MERGE"));
}
@Operation(summary = "优化:整合优化元数据描述")
@Operation(summary = "优化:整合聚同文献的不同描述,生成更完整的元数据")
@PostMapping("/optimize")
public Result<GovernanceJob> optimize() {
return Result.success(governanceService.runJob("OPTIMIZE"));
return Result.success(governanceService.optimize());
}
@Operation(summary = "提示:生成疑似同一文献/错漏提示清单")
@Operation(summary = "提示:生成疑似同一文献清单与疑似元数据错漏清单")
@PostMapping("/hint")
public Result<GovernanceJob> hint() {
return Result.success(governanceService.runJob("HINT"));
public Result<GovernanceHintVO> hint() {
return Result.success(governanceService.hint());
}
@Operation(summary = "提纯:提取版本资源数据集")
@Operation(summary = "查看当前疑似同一文献清单与错漏清单")
@GetMapping("/hints")
public Result<GovernanceHintVO> hints() {
return Result.success(governanceService.previewHints());
}
@Operation(summary = "提纯:从全部图书数据中提取纸电图书,形成版本资源数据集")
@PostMapping("/purify")
public Result<GovernanceJob> purify() {
return Result.success(governanceService.runJob("PURIFY"));
return Result.success(governanceService.purify());
}
@Operation(summary = "版本资源数据集(已提纯的纸电图书)")
@GetMapping("/dataset")
public Result<List<VersionResource>> dataset() {
return Result.success(governanceService.listDataset());
}
@Operation(summary = "治理任务历史")
@@ -0,0 +1,36 @@
package com.banben.modules.governance.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 疑似元数据错漏清单中的一条资源。
*/
@Data
@Schema(description = "疑似元数据错漏条目")
public class DefectItemVO {
@Schema(description = "资源ID")
private Long id;
@Schema(description = "加工编号")
private String processNo;
@Schema(description = "正题名")
private String title;
@Schema(description = "责任者")
private String author;
@Schema(description = "来源馆")
private String sourceLibrary;
@Schema(description = "媒体类型")
private String mediaType;
@Schema(description = "错漏说明")
private List<String> issues = new ArrayList<>();
}
@@ -0,0 +1,24 @@
package com.banben.modules.governance.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 一组疑似同一文献。
*/
@Data
@Schema(description = "疑似同一文献分组")
public class DuplicateGroupVO {
@Schema(description = "判定原因")
private String reason;
@Schema(description = "分组依据,如 ISBN 或归一题名")
private String matchKey;
@Schema(description = "组内记录")
private List<DuplicateItemVO> records = new ArrayList<>();
}
@@ -0,0 +1,42 @@
package com.banben.modules.governance.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 疑似同一文献清单中的一条资源。
*/
@Data
@Schema(description = "疑似同一文献条目")
public class DuplicateItemVO {
@Schema(description = "资源ID")
private Long id;
@Schema(description = "加工编号")
private String processNo;
@Schema(description = "正题名")
private String title;
@Schema(description = "责任者")
private String author;
@Schema(description = "出版者")
private String publisher;
@Schema(description = "出版年份")
private String publishYear;
@Schema(description = "ISBN")
private String isbn;
@Schema(description = "媒体类型")
private String mediaType;
@Schema(description = "来源馆")
private String sourceLibrary;
@Schema(description = "治理状态")
private String governStatus;
}
@@ -0,0 +1,31 @@
package com.banben.modules.governance.dto;
import com.banben.modules.governance.entity.GovernanceJob;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 提示动作的两份清单。
*/
@Data
@Schema(description = "治理提示清单")
public class GovernanceHintVO {
@Schema(description = "本次任务;预览时为空")
private GovernanceJob job;
@Schema(description = "疑似同一文献组数")
private int duplicateGroupCount;
@Schema(description = "疑似错漏条数")
private int defectCount;
@Schema(description = "疑似同一文献提示清单")
private List<DuplicateGroupVO> duplicateGroups = new ArrayList<>();
@Schema(description = "疑似元数据错漏提示清单")
private List<DefectItemVO> defects = new ArrayList<>();
}
@@ -1,7 +1,9 @@
package com.banben.modules.governance.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.banben.modules.governance.dto.GovernanceHintVO;
import com.banben.modules.governance.entity.GovernanceJob;
import com.banben.modules.resource.entity.VersionResource;
import java.util.List;
@@ -17,6 +19,31 @@ public interface GovernanceService extends IService<GovernanceJob> {
*/
GovernanceJob runJob(String jobType);
/**
* 优化:整合已聚同文献的不同描述,生成更完整的元数据。
*/
GovernanceJob optimize();
/**
* 提示:生成疑似同一文献清单、疑似元数据错漏清单,并标记错漏记录。
*/
GovernanceHintVO hint();
/**
* 按当前数据预览两份提示清单,不写任务、不改标记。
*/
GovernanceHintVO previewHints();
/**
* 提纯:从全部图书数据中提取纸电图书,形成版本资源数据集。
*/
GovernanceJob purify();
/**
* 已纳入版本资源数据集的记录(治理状态为已提纯)。
*/
List<VersionResource> listDataset();
/**
* 治理任务历史。
*/
@@ -6,6 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.banben.common.BusinessException;
import com.banben.modules.governance.dto.DefectItemVO;
import com.banben.modules.governance.dto.DuplicateGroupVO;
import com.banben.modules.governance.dto.DuplicateItemVO;
import com.banben.modules.governance.dto.GovernanceHintVO;
import com.banben.modules.governance.entity.GovernanceJob;
import com.banben.modules.governance.mapper.GovernanceJobMapper;
import com.banben.modules.governance.service.GovernanceService;
@@ -18,35 +22,40 @@ import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.regex.Pattern;
/**
* 数据治理服务实现(聚同 / 优化 / 提示 / 提纯)。
*
* <pre>
* 【状态流转】每一步都会真实推进 record 的 govern_status:
* 【状态流转】
* RAW 原始
* │ ① 聚同:同组 id 最小者 → MERGED,其余 → MERGED_OUT
* ▼
* MERGED 已聚同
* │ ② 优化:把同组各来源的描述补进主记录 → OPTIMIZED
* ▼
* OPTIMIZED 已优化
* │ ③ 提纯:纸电图书纳入数据集 → FINAL
* ▼
* FINAL 已提纯
*
* 采集入库 ──▶ RAW 原始
* │ ① 聚同(MERGE):同组保留 id 最小者 → MERGED 已聚同
* │ 同组其余记录 → MERGED_OUT 已合并(mergedToId 指向主记录)
* ▼
* MERGED 已聚同
* │ ② 优化(OPTIMIZE):无错漏的已聚同记录 → OPTIMIZED 已优化
* ▼
* OPTIMIZED 已优化
* │ ③ 提纯(PURIFY):纸电资源纳入数据集 → FINAL 已提纯
* ▼
* FINAL 已提纯
*
* ④ 提示(HINT):不改变状态,只产出清单,并把命中错漏的记录标记 abnormal_flag=1
* ④ 提示:不改变治理状态。产出「疑似同一文献」「疑似错漏」两份清单,
* 并把错漏记录标记 abnormal_flag = 1。
* </pre>
*
* <p><b>说明:</b>本实现是可运行的「轻量算法」——聚同判定规则:
* <b>ISBN 相同</b>即同一文献;<b>无 ISBN 时</b>,以「书名 + 作者 + 出版社 + 出版年份」
* 四要素完全一致判定同一文献。批处理逐条提交,任务失败时已处理部分保留、
* 任务记录标记为 FAILED,可重跑(已合并记录不会重复处理)。</p>
* <p>聚同判定:ISBN 相同;无 ISBN 时「书名 + 作者 + 出版社 + 出版年份」完全一致。
* 提示比聚同更宽,用来列出还不能自动合并、但疑似同一文献的记录。</p>
*/
@Slf4j
@Service
@@ -54,31 +63,34 @@ import java.util.Set;
public class GovernanceServiceImpl extends ServiceImpl<GovernanceJobMapper, GovernanceJob>
implements GovernanceService {
/** 支持的治理类型。 */
private static final Set<String> JOB_TYPES = Set.of("MERGE", "OPTIMIZE", "HINT", "PURIFY");
/** 这些内容形式不是纸电图书,提纯时留在全库、不进入版本资源数据集。 */
private static final Set<String> NON_BOOK_FORMS = Set.of("音频", "视频", "图像", "图片", "缩微", "期刊");
private static final Pattern YEAR = Pattern.compile("\\d{4}");
private static final Pattern LANGUAGE = Pattern.compile("[A-Za-z]{3}");
private static final Pattern PAGE = Pattern.compile("\\d+");
private static final Pattern ISBN = Pattern.compile("97[89](?:-\\d+){4}");
private static final Pattern EDITION = Pattern.compile(
"[((]第[0-90-9一二三四五六七八九十]+版[))]|第[0-90-9一二三四五六七八九十]+版|修订版|增订本|增补本");
private static final Pattern PUNCT = Pattern.compile("[·—\\-::,,.。;;、/\\\\'\"“”‘’《》<>\\s\\u3000]+");
private static final int BATCH = 500;
private final VersionResourceMapper resourceMapper;
@Override
public GovernanceJob runJob(String jobType) {
if (jobType == null || !JOB_TYPES.contains(jobType.toUpperCase())) {
throw new BusinessException("不支持的治理类型:" + jobType);
String type = requireType(jobType);
if ("HINT".equals(type)) {
return hint().getJob();
}
String type = jobType.toUpperCase();
// 1) 先落一条 RUNNING 的任务记录,便于前端看到「执行中」
GovernanceJob job = new GovernanceJob();
job.setJobType(type);
job.setStatus("RUNNING");
job.setStartTime(LocalDateTime.now());
this.save(job);
GovernanceJob job = begin(type);
try {
// 2) 按类型分派
switch (type) {
case "MERGE" -> runMerge(job);
case "OPTIMIZE" -> runOptimize(job);
case "HINT" -> runHint(job);
case "PURIFY" -> runPurify(job);
default -> job.setResultSummary("未实现");
}
@@ -88,13 +100,58 @@ public class GovernanceServiceImpl extends ServiceImpl<GovernanceJobMapper, Gove
job.setStatus("FAILED");
job.setResultSummary(e.getMessage());
} finally {
// 3) 无论成败都回写任务结果
job.setEndTime(LocalDateTime.now());
this.updateById(job);
finish(job);
}
return job;
}
@Override
public GovernanceJob optimize() {
return runJob("OPTIMIZE");
}
@Override
public GovernanceHintVO hint() {
GovernanceJob job = begin("HINT");
GovernanceHintVO vo = emptyHint(job);
try {
vo = buildHints(true);
job.setAffectedCount(vo.getDuplicateGroupCount() + vo.getDefectCount());
job.setResultSummary(String.format(
"疑似同一文献 %d 组;疑似元数据错漏 %d 条(错漏记录已标记,请人工核验)",
vo.getDuplicateGroupCount(), vo.getDefectCount()));
job.setStatus("SUCCESS");
vo.setJob(job);
} catch (Exception e) {
log.error("提示清单生成失败: {}", e.getMessage(), e);
job.setStatus("FAILED");
job.setResultSummary(e.getMessage());
vo.setJob(job);
} finally {
finish(job);
}
return vo;
}
@Override
public GovernanceHintVO previewHints() {
return buildHints(false);
}
@Override
public GovernanceJob purify() {
return runJob("PURIFY");
}
@Override
public List<VersionResource> listDataset() {
LambdaQueryWrapper<VersionResource> query = new LambdaQueryWrapper<>();
query.eq(VersionResource::getGovernStatus, GovernStatus.FINAL.getCode())
.orderByDesc(VersionResource::getUpdateTime)
.orderByAsc(VersionResource::getId);
return resourceMapper.selectList(query);
}
@Override
public List<GovernanceJob> listJobs() {
LambdaQueryWrapper<GovernanceJob> wrapper = new LambdaQueryWrapper<>();
@@ -105,32 +162,21 @@ public class GovernanceServiceImpl extends ServiceImpl<GovernanceJobMapper, Gove
// ==================== ① 聚同 ====================
/**
* 聚同:将「不同来源 / 不同媒体类型」的同一文献元数据聚合为一条,并标注来源。
*
* <p>判定规则(两级):</p>
* <ol>
* <li><b>ISBN 相同</b>(非空)即视为同一文献;</li>
* <li>ISBN 为空时,<b>「书名 + 作者 + 出版社 + 出版年份」四要素完全一致</b>
* 即视为同一文献。</li>
* </ol>
* <p>同组内按 id 升序取第一条为主记录 → 标记 {@code MERGED};
* 其余记录 → 标记 {@code MERGED_OUT} 并把 {@code merged_to_id} 指向主记录。
* 已 {@code MERGED_OUT} 的记录不参与再次聚同,因此任务可重复执行而结果稳定。</p>
* 聚同:将不同来源、不同媒体类型的同一文献聚合为一条,并标注来源。
* 同组 id 最小者为主记录(MERGED),其余标记 MERGED_OUT 并指向主记录。
*/
private void runMerge(GovernanceJob job) {
int[] counters = {0, 0}; // [0]=聚同组数, [1]=影响条数
int[] counters = {0, 0};
// 规则一:ISBN 相同(非空)→ 同一文献
for (Map<String, Object> group : isbnDuplicateGroups()) {
Object isbn = group.get("isbn");
LambdaQueryWrapper<VersionResource> query = new LambdaQueryWrapper<>();
query.eq(VersionResource::getIsbn, isbn)
.ne(VersionResource::getGovernStatus, GovernStatus.MERGED_OUT.getCode())
.and(this::notMergedOut)
.orderByAsc(VersionResource::getId);
mergeGroup(resourceMapper.selectList(query), counters);
}
// 规则二:无 ISBN →「书名 + 作者 + 出版社 + 出版年份」完全一致 → 同一文献
for (Map<String, Object> group : fieldDuplicateGroups()) {
LambdaQueryWrapper<VersionResource> query = new LambdaQueryWrapper<>();
query.eq(VersionResource::getTitle, group.get("title"));
@@ -138,7 +184,7 @@ public class GovernanceServiceImpl extends ServiceImpl<GovernanceJobMapper, Gove
eqOrIsNull(query, VersionResource::getPublisher, group.get("publisher"));
eqOrIsNull(query, VersionResource::getPublishYear, group.get("publish_year"));
query.and(x -> x.isNull(VersionResource::getIsbn).or().eq(VersionResource::getIsbn, ""))
.ne(VersionResource::getGovernStatus, GovernStatus.MERGED_OUT.getCode())
.and(this::notMergedOut)
.orderByAsc(VersionResource::getId);
mergeGroup(resourceMapper.selectList(query), counters);
}
@@ -146,26 +192,20 @@ public class GovernanceServiceImpl extends ServiceImpl<GovernanceJobMapper, Gove
job.setAffectedCount(counters[1]);
job.setResultSummary(String.format(
"聚同 %d 组、影响 %d 条(ISBN 相同,或无 ISBN 时「书名+作者+出版社+出版年份」"
+ "完全一致的记录聚合:组内 id 最小者保留为「已聚同」,其余标记「已合并」并指向主记录)",
+ "完全一致:组内 id 最小者保留为「已聚同」,其余标记「已合并」并指向主记录)",
counters[0], counters[1]));
}
/**
* 组内聚同:id 最小者为主记录(MERGED),其余标记 MERGED_OUT 并指向主记录。
*/
private void mergeGroup(List<VersionResource> list, int[] counters) {
if (list == null || list.size() < 2) {
return;
}
// 主记录:保留为「已聚同」
VersionResource master = list.get(0);
master.setGovernStatus(GovernStatus.MERGED.getCode());
master.setMergedToId(null);
resourceMapper.updateById(master);
counters[1]++;
// 从记录:标记「已合并」并指向主记录
for (int i = 1; i < list.size(); i++) {
VersionResource slave = list.get(i);
slave.setGovernStatus(GovernStatus.MERGED_OUT.getCode());
@@ -176,7 +216,6 @@ public class GovernanceServiceImpl extends ServiceImpl<GovernanceJobMapper, Gove
counters[0]++;
}
/** 值为空时按 IS NULL 匹配,否则按等值匹配(分组键可能为 NULL 的字段用) */
private void eqOrIsNull(LambdaQueryWrapper<VersionResource> query,
SFunction<VersionResource, ?> column, Object value) {
if (value == null || "".equals(value)) {
@@ -189,102 +228,654 @@ public class GovernanceServiceImpl extends ServiceImpl<GovernanceJobMapper, Gove
// ==================== ② 优化 ====================
/**
* 优化:把「已聚同」且无错漏的元数据推进为「已优化」。
*
* <p>真正的字段级整合优化(多来源描述合并、要素补全)可在此基础上扩展,
* 当前实现负责状态推进与统计。</p>
* 优化:整合已聚同主记录与其来源记录上的不同描述。
* 空缺字段用组内非空值补齐,摘要取更完整的一条,主题词去重合并,
* 附注中写明各来源馆和媒体类型。补全后不再错漏的记录清除疑似标记。
*/
private void runOptimize(GovernanceJob job) {
LambdaUpdateWrapper<VersionResource> update = new LambdaUpdateWrapper<>();
update.set(VersionResource::getGovernStatus, GovernStatus.OPTIMIZED.getCode())
.eq(VersionResource::getGovernStatus, GovernStatus.MERGED.getCode())
.eq(VersionResource::getAbnormalFlag, 0);
int rows = resourceMapper.update(null, update);
LambdaQueryWrapper<VersionResource> mastersQuery = new LambdaQueryWrapper<>();
mastersQuery.eq(VersionResource::getGovernStatus, GovernStatus.MERGED.getCode())
.orderByAsc(VersionResource::getId);
List<VersionResource> masters = resourceMapper.selectList(mastersQuery);
if (masters.isEmpty()) {
job.setAffectedCount(0);
job.setResultSummary("没有可优化的「已聚同」记录,请先执行聚同");
return;
}
job.setAffectedCount(rows);
job.setResultSummary("已将 " + rows + " 条「已聚同」且无错漏的元数据推进为「已优化」");
int filled = 0;
for (VersionResource master : masters) {
LambdaQueryWrapper<VersionResource> slaveQuery = new LambdaQueryWrapper<>();
slaveQuery.eq(VersionResource::getMergedToId, master.getId())
.eq(VersionResource::getGovernStatus, GovernStatus.MERGED_OUT.getCode())
.orderByAsc(VersionResource::getId);
List<VersionResource> group = new ArrayList<>();
group.add(master);
group.addAll(resourceMapper.selectList(slaveQuery));
int[] counter = {0};
integrate(master, group, counter);
List<String> issues = defectsOf(master);
master.setAbnormalFlag(issues.isEmpty() ? 0 : 1);
master.setGovernStatus(GovernStatus.OPTIMIZED.getCode());
resourceMapper.updateById(master);
filled += counter[0];
}
job.setAffectedCount(masters.size());
job.setResultSummary(String.format(
"已优化 %d 条聚同主记录,补全或合并 %d 处描述要素"
+ "(空缺取组内非空值,摘要取更完整者,主题词去重合并,附注标注各来源馆与媒体类型)",
masters.size(), filled));
}
private void integrate(VersionResource master, List<VersionResource> group, int[] filled) {
List<VersionResource> donors = group.subList(1, group.size());
fillIfBlank(master, donors, VersionResource::getClcCode, VersionResource::setClcCode, filled);
fillIfBlank(master, donors, VersionResource::getPublishYear, VersionResource::setPublishYear, filled);
fillIfBlank(master, donors, VersionResource::getProcessDate, VersionResource::setProcessDate, filled);
fillIfBlank(master, donors, VersionResource::getContentForm, VersionResource::setContentForm, filled);
fillIfBlank(master, donors, VersionResource::getFormat, VersionResource::setFormat, filled);
fillIfBlank(master, donors, VersionResource::getPageCount, VersionResource::setPageCount, filled);
fillIfBlank(master, donors, VersionResource::getLanguage, VersionResource::setLanguage, filled);
fillIfBlank(master, donors, VersionResource::getSubmitOrg, VersionResource::setSubmitOrg, filled);
fillIfBlank(master, donors, VersionResource::getTaskYear, VersionResource::setTaskYear, filled);
fillIfBlank(master, donors, VersionResource::getSourceLibraryAddr, VersionResource::setSourceLibraryAddr, filled);
fillIfBlank(master, donors, VersionResource::getFulltextUrl, VersionResource::setFulltextUrl, filled);
fillIfBlank(master, donors, VersionResource::getAuthor, VersionResource::setAuthor, filled);
fillIfBlank(master, donors, VersionResource::getResponsibility, VersionResource::setResponsibility, filled);
fillIfBlank(master, donors, VersionResource::getPublisher, VersionResource::setPublisher, filled);
fillIfBlank(master, donors, VersionResource::getPublishPlace, VersionResource::setPublishPlace, filled);
fillIfBlank(master, donors, VersionResource::getPublishDate, VersionResource::setPublishDate, filled);
fillIfBlank(master, donors, VersionResource::getRelation, VersionResource::setRelation, filled);
fillIfBlank(master, donors, VersionResource::getTimeRange, VersionResource::setTimeRange, filled);
fillIfBlank(master, donors, VersionResource::getSpaceRange, VersionResource::setSpaceRange, filled);
fillIfBlank(master, donors, VersionResource::getEdition, VersionResource::setEdition, filled);
fillIfBlank(master, donors, VersionResource::getIsbn, VersionResource::setIsbn, filled);
fillIfBlank(master, donors, VersionResource::getUnifiedBookNo, VersionResource::setUnifiedBookNo, filled);
fillIfBlank(master, donors, VersionResource::getCdoi, VersionResource::setCdoi, filled);
fillIfBlank(master, donors, VersionResource::getPublishUrl, VersionResource::setPublishUrl, filled);
mergeKeywords(master, group, filled);
mergeSummary(master, group, filled);
mergeOtherTitles(master, group, filled);
mergeNotes(master, group, filled);
}
private void fillIfBlank(VersionResource master, List<VersionResource> donors,
Function<VersionResource, String> getter,
BiConsumer<VersionResource, String> setter,
int[] filled) {
if (!blank(getter.apply(master))) {
return;
}
for (VersionResource donor : donors) {
if (!blank(getter.apply(donor))) {
setter.accept(master, getter.apply(donor).trim());
filled[0]++;
return;
}
}
}
private void mergeKeywords(VersionResource master, List<VersionResource> group, int[] filled) {
LinkedHashSet<String> words = new LinkedHashSet<>();
for (VersionResource resource : group) {
if (blank(resource.getKeywords())) {
continue;
}
for (String part : resource.getKeywords().split("[;;,,]")) {
if (!blank(part)) {
words.add(part.trim());
}
}
}
if (words.isEmpty()) {
return;
}
String merged = String.join(";", words);
if (!merged.equals(text(master.getKeywords()))) {
master.setKeywords(merged);
filled[0]++;
}
}
private void mergeSummary(VersionResource master, List<VersionResource> group, int[] filled) {
String best = null;
for (VersionResource resource : group) {
if (blank(resource.getSummary())) {
continue;
}
String summary = resource.getSummary().trim();
if (best == null || summary.length() > best.length()) {
best = summary;
}
}
if (best == null) {
return;
}
if (text(master.getSummary()).length() < best.length()) {
master.setSummary(best);
filled[0]++;
}
}
private void mergeOtherTitles(VersionResource master, List<VersionResource> group, int[] filled) {
LinkedHashSet<String> titles = new LinkedHashSet<>();
for (VersionResource resource : group) {
if (!blank(resource.getOtherTitle())) {
for (String part : resource.getOtherTitle().split("[;;]")) {
if (!blank(part)) {
titles.add(part.trim());
}
}
}
if (resource != master && !blank(resource.getTitle())
&& !text(resource.getTitle()).equals(text(master.getTitle()))) {
titles.add(resource.getTitle().trim());
}
}
if (titles.isEmpty()) {
return;
}
String merged = String.join(";", titles);
if (!merged.equals(text(master.getOtherTitle()))) {
master.setOtherTitle(merged);
filled[0]++;
}
}
private void mergeNotes(VersionResource master, List<VersionResource> group, int[] filled) {
LinkedHashSet<String> notes = new LinkedHashSet<>();
for (VersionResource resource : group) {
if (blank(resource.getNote())) {
continue;
}
for (String line : resource.getNote().split("\\n")) {
String trimmed = line.trim();
if (!trimmed.isEmpty() && !trimmed.startsWith("聚同来源:")) {
notes.add(trimmed);
}
}
}
String sources = group.stream()
.map(resource -> (blank(resource.getSourceLibrary()) ? "未知来源馆" : resource.getSourceLibrary().trim())
+ "(" + (blank(resource.getMediaType()) ? "未知媒体" : resource.getMediaType().trim()) + ")")
.distinct()
.reduce((a, b) -> a + ";" + b)
.orElse("未知来源馆");
StringBuilder merged = new StringBuilder();
for (String note : notes) {
if (!merged.isEmpty()) {
merged.append('\n');
}
merged.append(note);
}
if (!merged.isEmpty()) {
merged.append('\n');
}
merged.append("聚同来源:").append(sources);
if (!merged.toString().equals(text(master.getNote()))) {
master.setNote(merged.toString());
filled[0]++;
}
}
// ==================== ③ 提示 ====================
/**
* 提示:生成「疑似同一文献」与「疑似元数据错漏」清单。
*
* <p>这是唯一<b>不改变治理状态</b>的动作:它把命中错漏的记录标记
* {@code abnormal_flag = 1},供人工核验;清单本身体现在任务的 resultSummary 中。</p>
* 疑似同一文献:ISBN 相同,或题名归一后与责任者相同,或题名互相包含且责任者相同。
* 已经合并掉的从记录不重复进入清单。
* 疑似错漏:必备要素缺失、摘要不足 100 字、年份/语种/页码/ISBN 格式不正确。
*/
private void runHint(GovernanceJob job) {
// 疑似同一文献:题名 + 责任者 相同且多于 1 条
int dupGroups = findDuplicateGroups().size();
private GovernanceHintVO buildHints(boolean persistFlag) {
List<VersionResource> active = loadActive();
GovernanceHintVO vo = new GovernanceHintVO();
vo.setDuplicateGroups(findSuspectedDuplicates(active));
vo.setDuplicateGroupCount(vo.getDuplicateGroups().size());
// 疑似错漏:必备字段缺失(中图分类 / 摘要)→ 标记 abnormal_flag = 1
LambdaUpdateWrapper<VersionResource> missUpdate = new LambdaUpdateWrapper<>();
missUpdate.set(VersionResource::getAbnormalFlag, 1)
.and(x -> x.isNull(VersionResource::getClcCode)
.or().eq(VersionResource::getClcCode, "")
.or().isNull(VersionResource::getSummary)
.or().eq(VersionResource::getSummary, ""));
int missCount = resourceMapper.update(null, missUpdate);
List<DefectItemVO> defects = new ArrayList<>();
List<Long> badIds = new ArrayList<>();
List<Long> clearIds = new ArrayList<>();
for (VersionResource resource : active) {
List<String> issues = defectsOf(resource);
if (!issues.isEmpty()) {
defects.add(toDefect(resource, issues));
badIds.add(resource.getId());
} else if (flagged(resource)) {
clearIds.add(resource.getId());
}
}
vo.setDefects(defects);
vo.setDefectCount(defects.size());
if (persistFlag) {
updateFlag(badIds, 1);
updateFlag(clearIds, 0);
}
return vo;
}
job.setAffectedCount(dupGroups + missCount);
job.setResultSummary(String.format(
"疑似同一文献 %d 组;疑似元数据错漏 %d 条(已标记 abnormalFlag=1,请人工核验)",
dupGroups, missCount));
private List<DuplicateGroupVO> findSuspectedDuplicates(List<VersionResource> active) {
List<DuplicateGroupVO> groups = new ArrayList<>();
Set<Long> emitted = new HashSet<>();
Map<String, List<VersionResource>> byIsbn = new LinkedHashMap<>();
for (VersionResource resource : active) {
if (!blank(resource.getIsbn())) {
byIsbn.computeIfAbsent(resource.getIsbn().trim(), key -> new ArrayList<>()).add(resource);
}
}
for (Map.Entry<String, List<VersionResource>> entry : byIsbn.entrySet()) {
if (entry.getValue().size() < 2) {
continue;
}
groups.add(toDuplicateGroup("ISBN 相同,疑似同一文献", entry.getKey(), entry.getValue()));
entry.getValue().forEach(resource -> emitted.add(resource.getId()));
}
Map<String, List<VersionResource>> byTitleAuthor = new LinkedHashMap<>();
for (VersionResource resource : active) {
String key = normalizeTitle(resource.getTitle()) + "\u0001" + normalizeTitle(resource.getAuthor());
if ("\u0001".equals(key) || key.startsWith("\u0001") || key.endsWith("\u0001")) {
continue;
}
byTitleAuthor.computeIfAbsent(key, ignored -> new ArrayList<>()).add(resource);
}
for (Map.Entry<String, List<VersionResource>> entry : byTitleAuthor.entrySet()) {
List<VersionResource> members = entry.getValue();
if (members.size() < 2 || sameNonBlankIsbn(members)) {
continue;
}
String reason = sameFourFields(members)
? "书名、责任者、出版社、出版年份一致,疑似同一文献"
: "题名归一后与责任者相同,但 ISBN 或出版信息不一致,疑似同一文献";
String key = normalizeTitle(members.get(0).getTitle());
groups.add(toDuplicateGroup(reason, key, members));
members.forEach(resource -> emitted.add(resource.getId()));
}
groups.addAll(containmentGroups(active, emitted));
return groups;
}
/**
* 同一责任者下,题名互相包含(如「联合作战指挥」与「联合作战指挥学」)视为疑似同一文献。
*/
private List<DuplicateGroupVO> containmentGroups(List<VersionResource> active, Set<Long> emitted) {
Map<String, List<VersionResource>> byAuthor = new LinkedHashMap<>();
for (VersionResource resource : active) {
if (emitted.contains(resource.getId()) || blank(resource.getAuthor()) || blank(resource.getTitle())) {
continue;
}
byAuthor.computeIfAbsent(normalizeTitle(resource.getAuthor()), key -> new ArrayList<>()).add(resource);
}
List<DuplicateGroupVO> groups = new ArrayList<>();
for (List<VersionResource> bucket : byAuthor.values()) {
if (bucket.size() < 2) {
continue;
}
Map<Long, Long> parent = new HashMap<>();
for (int i = 0; i < bucket.size(); i++) {
String left = normalizeTitle(bucket.get(i).getTitle());
for (int j = i + 1; j < bucket.size(); j++) {
String right = normalizeTitle(bucket.get(j).getTitle());
if (titleContains(left, right)) {
union(parent, bucket.get(i).getId(), bucket.get(j).getId());
}
}
}
Map<Long, List<VersionResource>> clustered = new LinkedHashMap<>();
for (VersionResource resource : bucket) {
if (!parent.containsKey(resource.getId())) {
continue;
}
clustered.computeIfAbsent(find(parent, resource.getId()), key -> new ArrayList<>()).add(resource);
}
for (List<VersionResource> members : clustered.values()) {
if (members.size() < 2) {
continue;
}
members.sort(Comparator.comparing(VersionResource::getId));
groups.add(toDuplicateGroup(
"题名互相包含且责任者相同,疑似同一文献",
normalizeTitle(members.get(0).getTitle()),
members));
}
}
return groups;
}
private boolean titleContains(String left, String right) {
if (left.equals(right) || left.length() < 4 || right.length() < 4) {
return false;
}
String shorter = left.length() <= right.length() ? left : right;
String longer = left.length() <= right.length() ? right : left;
return longer.contains(shorter) && shorter.length() * 2 >= longer.length();
}
private List<String> defectsOf(VersionResource resource) {
List<String> issues = new ArrayList<>();
if (blank(resource.getClcCode())) {
issues.add("缺少中图分类号");
}
if (blank(resource.getKeywords())) {
issues.add("缺少主题词或关键词");
}
if (blank(resource.getSummary())) {
issues.add("缺少摘要");
} else if (resource.getSummary().trim().length() < 100) {
issues.add("摘要不足100字");
}
if (blank(resource.getPublishYear())) {
issues.add("缺少出版年份");
} else if (!YEAR.matcher(resource.getPublishYear().trim()).matches()) {
issues.add("出版年份不是4位年份");
}
if (blank(resource.getMediaType())) {
issues.add("缺少媒体类型");
} else if (!"纸质".equals(resource.getMediaType().trim()) && !"电子".equals(resource.getMediaType().trim())) {
issues.add("媒体类型不是纸质或电子");
}
if (blank(resource.getLanguage()) || !LANGUAGE.matcher(resource.getLanguage().trim()).matches()) {
issues.add("语种不是3位代码");
}
if (blank(resource.getPageCount()) || !PAGE.matcher(resource.getPageCount().trim()).matches()) {
issues.add("页码缺失或不是数字");
}
if (blank(resource.getAuthor())) {
issues.add("缺少责任者");
}
if (blank(resource.getFulltextUrl())) {
issues.add("缺少全文地址");
}
if (blank(resource.getSourceLibrary())) {
issues.add("缺少来源馆");
}
if (!blank(resource.getIsbn()) && !ISBN.matcher(resource.getIsbn().trim()).matches()) {
issues.add("ISBN格式疑似有误");
}
return issues;
}
// ==================== ④ 提纯 ====================
/**
* 提纯:将相关纸电图书数据提取出来,形成版本资源数据集。
*
* <p>把媒体类型为「纸质 / 电子」且已聚同或已优化的记录标记为 {@code FINAL},
* 即「已纳入版本资源数据集」。</p>
* 提纯:从全部在库图书中抽出纸质、电子图书,形成版本资源数据集。
* 不纳入:已合并的从记录、音频/视频/图像/缩微/期刊、敏感或已屏蔽数据、
* 尚未聚同的重复文献、已聚同但还没优化的主记录、仍有错漏的记录。
*/
private void runPurify(GovernanceJob job) {
LambdaUpdateWrapper<VersionResource> update = new LambdaUpdateWrapper<>();
update.set(VersionResource::getGovernStatus, GovernStatus.FINAL.getCode())
.in(VersionResource::getMediaType, List.of("纸质", "电子"))
.in(VersionResource::getGovernStatus,
List.of(GovernStatus.MERGED.getCode(), GovernStatus.OPTIMIZED.getCode()));
int rows = resourceMapper.update(null, update);
List<VersionResource> active = loadActive();
Set<Long> unresolved = unresolvedDuplicateIds(active);
job.setAffectedCount(rows);
job.setResultSummary("已将 " + rows + " 条纸电版本资源纳入版本资源数据集(标记为「已提纯」)");
int nonBook = 0;
int sensitive = 0;
int blocked = 0;
int duplicated = 0;
int waitOptimize = 0;
int defect = 0;
List<Long> accepted = new ArrayList<>();
for (VersionResource resource : active) {
if (GovernStatus.FINAL.getCode().equals(resource.getGovernStatus())) {
continue;
}
if (!paperElectronicBook(resource)) {
nonBook++;
continue;
}
if (resource.getSensitiveFlag() != null && resource.getSensitiveFlag() == 1) {
sensitive++;
continue;
}
if (resource.getManageStatus() != null && resource.getManageStatus() != 0) {
blocked++;
continue;
}
if (unresolved.contains(resource.getId())) {
duplicated++;
continue;
}
if (GovernStatus.MERGED.getCode().equals(resource.getGovernStatus())) {
waitOptimize++;
continue;
}
if (!defectsOf(resource).isEmpty()) {
defect++;
continue;
}
accepted.add(resource.getId());
}
updateStatus(accepted, GovernStatus.FINAL.getCode());
job.setAffectedCount(accepted.size());
job.setResultSummary(String.format(
"已将 %d 条纸电图书纳入版本资源数据集。"
+ "未纳入:非纸电图书 %d 条,敏感 %d 条,已屏蔽或下架 %d 条,"
+ "尚未聚同的重复文献 %d 条,已聚同但未优化 %d 条,仍有错漏 %d 条",
accepted.size(), nonBook, sensitive, blocked, duplicated, waitOptimize, defect));
}
/**
* 仍有多条在库记录指向同一文献(聚同还没把它们收成一条)的资源 ID。
*/
private Set<Long> unresolvedDuplicateIds(List<VersionResource> active) {
Set<Long> ids = new HashSet<>();
Map<String, List<VersionResource>> byIsbn = new LinkedHashMap<>();
Map<String, List<VersionResource>> byField = new LinkedHashMap<>();
for (VersionResource resource : active) {
if (!blank(resource.getIsbn())) {
byIsbn.computeIfAbsent(resource.getIsbn().trim(), key -> new ArrayList<>()).add(resource);
} else {
String key = text(resource.getTitle()) + "\u0001" + text(resource.getAuthor())
+ "\u0001" + text(resource.getPublisher()) + "\u0001" + text(resource.getPublishYear());
byField.computeIfAbsent(key, ignored -> new ArrayList<>()).add(resource);
}
}
byIsbn.values().stream().filter(group -> group.size() > 1)
.forEach(group -> group.forEach(resource -> ids.add(resource.getId())));
byField.values().stream().filter(group -> group.size() > 1)
.forEach(group -> group.forEach(resource -> ids.add(resource.getId())));
return ids;
}
private boolean paperElectronicBook(VersionResource resource) {
String media = text(resource.getMediaType());
if (!"纸质".equals(media) && !"电子".equals(media)) {
return false;
}
String form = text(resource.getContentForm());
return form.isEmpty() || !NON_BOOK_FORMS.contains(form);
}
// ==================== 公共方法 ====================
/**
* 查询「疑似同一文献」的重复组 = ISBN 重复组 + 四要素重复组(聚同与「提示」共用)。
* 排除已被合并的记录,保证重复执行时不重复处理。
*/
private List<Map<String, Object>> findDuplicateGroups() {
List<Map<String, Object>> groups = new ArrayList<>(isbnDuplicateGroups());
groups.addAll(fieldDuplicateGroups());
return groups;
private List<VersionResource> loadActive() {
LambdaQueryWrapper<VersionResource> query = new LambdaQueryWrapper<>();
query.and(this::notMergedOut).orderByAsc(VersionResource::getId);
return resourceMapper.selectList(query);
}
private void notMergedOut(LambdaQueryWrapper<VersionResource> query) {
query.isNull(VersionResource::getGovernStatus)
.or()
.ne(VersionResource::getGovernStatus, GovernStatus.MERGED_OUT.getCode());
}
/** ISBN 相同(非空)且多于 1 条的重复组 */
private List<Map<String, Object>> isbnDuplicateGroups() {
QueryWrapper<VersionResource> wrapper = new QueryWrapper<>();
wrapper.select("isbn")
.isNotNull("isbn")
.ne("isbn", "")
.ne("govern_status", GovernStatus.MERGED_OUT.getCode())
.and(x -> x.isNull("govern_status").or().ne("govern_status", GovernStatus.MERGED_OUT.getCode()))
.groupBy("isbn")
.having("COUNT(*) > 1");
return resourceMapper.selectMaps(wrapper);
}
/** 无 ISBN 时,「书名 + 作者 + 出版社 + 出版年份」完全一致且多于 1 条的重复组 */
private List<Map<String, Object>> fieldDuplicateGroups() {
QueryWrapper<VersionResource> wrapper = new QueryWrapper<>();
wrapper.select("title", "author", "publisher", "publish_year")
.isNotNull("title")
.and(x -> x.isNull("isbn").or().eq("isbn", ""))
.ne("govern_status", GovernStatus.MERGED_OUT.getCode())
.and(x -> x.isNull("govern_status").or().ne("govern_status", GovernStatus.MERGED_OUT.getCode()))
.groupBy("title", "author", "publisher", "publish_year")
.having("COUNT(*) > 1");
return resourceMapper.selectMaps(wrapper);
}
private void updateFlag(List<Long> ids, int flag) {
for (int i = 0; i < ids.size(); i += BATCH) {
List<Long> part = ids.subList(i, Math.min(i + BATCH, ids.size()));
LambdaUpdateWrapper<VersionResource> update = new LambdaUpdateWrapper<>();
update.set(VersionResource::getAbnormalFlag, flag).in(VersionResource::getId, part);
resourceMapper.update(null, update);
}
}
private void updateStatus(List<Long> ids, String status) {
for (int i = 0; i < ids.size(); i += BATCH) {
List<Long> part = ids.subList(i, Math.min(i + BATCH, ids.size()));
LambdaUpdateWrapper<VersionResource> update = new LambdaUpdateWrapper<>();
update.set(VersionResource::getGovernStatus, status).in(VersionResource::getId, part);
resourceMapper.update(null, update);
}
}
private DuplicateGroupVO toDuplicateGroup(String reason, String matchKey, List<VersionResource> members) {
DuplicateGroupVO group = new DuplicateGroupVO();
group.setReason(reason);
group.setMatchKey(matchKey);
List<DuplicateItemVO> records = new ArrayList<>();
for (VersionResource resource : members) {
records.add(toDuplicateItem(resource));
}
group.setRecords(records);
return group;
}
private DuplicateItemVO toDuplicateItem(VersionResource resource) {
DuplicateItemVO item = new DuplicateItemVO();
item.setId(resource.getId());
item.setProcessNo(resource.getProcessNo());
item.setTitle(resource.getTitle());
item.setAuthor(resource.getAuthor());
item.setPublisher(resource.getPublisher());
item.setPublishYear(resource.getPublishYear());
item.setIsbn(resource.getIsbn());
item.setMediaType(resource.getMediaType());
item.setSourceLibrary(resource.getSourceLibrary());
item.setGovernStatus(resource.getGovernStatus());
return item;
}
private DefectItemVO toDefect(VersionResource resource, List<String> issues) {
DefectItemVO item = new DefectItemVO();
item.setId(resource.getId());
item.setProcessNo(resource.getProcessNo());
item.setTitle(resource.getTitle());
item.setAuthor(resource.getAuthor());
item.setSourceLibrary(resource.getSourceLibrary());
item.setMediaType(resource.getMediaType());
item.setIssues(issues);
return item;
}
private boolean sameNonBlankIsbn(List<VersionResource> members) {
String isbn = null;
for (VersionResource resource : members) {
if (blank(resource.getIsbn())) {
return false;
}
if (isbn == null) {
isbn = resource.getIsbn().trim();
} else if (!isbn.equals(resource.getIsbn().trim())) {
return false;
}
}
return isbn != null;
}
private boolean sameFourFields(List<VersionResource> members) {
VersionResource first = members.get(0);
for (int i = 1; i < members.size(); i++) {
VersionResource other = members.get(i);
if (!text(first.getTitle()).equals(text(other.getTitle()))
|| !text(first.getAuthor()).equals(text(other.getAuthor()))
|| !text(first.getPublisher()).equals(text(other.getPublisher()))
|| !text(first.getPublishYear()).equals(text(other.getPublishYear()))) {
return false;
}
}
return true;
}
private String normalizeTitle(String value) {
if (blank(value)) {
return "";
}
String normalized = EDITION.matcher(value.trim()).replaceAll("");
normalized = PUNCT.matcher(normalized).replaceAll("");
return normalized.toLowerCase();
}
private void union(Map<Long, Long> parent, Long left, Long right) {
long rootLeft = find(parent, left);
long rootRight = find(parent, right);
if (rootLeft != rootRight) {
parent.put(rootLeft, rootRight);
}
}
private long find(Map<Long, Long> parent, Long id) {
parent.putIfAbsent(id, id);
long current = parent.get(id);
if (current != id) {
current = find(parent, current);
parent.put(id, current);
}
return current;
}
private boolean flagged(VersionResource resource) {
return resource.getAbnormalFlag() != null && resource.getAbnormalFlag() == 1;
}
private boolean blank(String value) {
return value == null || value.trim().isEmpty();
}
private String text(String value) {
return blank(value) ? "" : value.trim();
}
private String requireType(String jobType) {
if (jobType == null || !JOB_TYPES.contains(jobType.toUpperCase())) {
throw new BusinessException("不支持的治理类型:" + jobType);
}
return jobType.toUpperCase();
}
private GovernanceJob begin(String type) {
GovernanceJob job = new GovernanceJob();
job.setJobType(type);
job.setStatus("RUNNING");
job.setStartTime(LocalDateTime.now());
this.save(job);
return job;
}
private void finish(GovernanceJob job) {
job.setEndTime(LocalDateTime.now());
this.updateById(job);
}
private GovernanceHintVO emptyHint(GovernanceJob job) {
GovernanceHintVO vo = new GovernanceHintVO();
vo.setJob(job);
vo.setDuplicateGroups(new ArrayList<>());
vo.setDefects(new ArrayList<>());
return vo;
}
}
@@ -0,0 +1,312 @@
-- =====================================================================
-- 治理演示数据(可重复执行)
-- 覆盖:同一文献多来源纸电、无 ISBN 的四要素重复、疑似同一文献、
-- 元数据错漏、非纸电图书、敏感图书、可直接提纯的独立纸电图书
-- =====================================================================
ALTER TABLE version_resource ADD COLUMN IF NOT EXISTS merged_to_id BIGINT;
ALTER TABLE version_resource ADD COLUMN IF NOT EXISTS abnormal_flag SMALLINT DEFAULT 0;
UPDATE version_resource SET abnormal_flag = 0 WHERE abnormal_flag IS NULL;
-- 010x ISBN 相同:纸质著录缺摘要长度和版次,电子本描述更完整,供聚同后优化补全
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0101', '信息化战争概论', 'E81', '信息化;战争', '概述信息化战争的基本特点。', '2023', '20261018',
'文本', '纸质', 'PDF', '286', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0101',
'王磊', '著', NULL,
'解放军出版社', NULL, '20230101', NULL, '978-7-80237-1101-1',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0101' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0102', '信息化战争概论', NULL, '信息化战争;联合作战',
'本书从信息化战争的基本概念、作战力量构成和指挥控制方式出发,结合近期局部战争案例,说明信息主导、体系对抗和精确打击对现代作战的影响。书中对战场态势感知、数据链路运用和后装保障协同作了教学化整理,适合军队院校生长军官课程与部队指挥员自学使用。',
'2023', '20261018',
'文本', '电子', 'PDF', '302', 'chi', '陆军步兵学院', '2026',
'国防大学图书馆', '10.0.0.31:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0102',
'王磊', '著', '电子版附教学课件。',
'解放军出版社', '北京', '20230301', '第2版', '978-7-80237-1101-1',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0102' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0103', '信息化战争概论', 'E81', '指挥;信息化', NULL, '2023', '20261018',
'文本', '纸质', 'PDF', '286', 'chi', '陆军步兵学院', '2026',
'陆军指挥学院图书馆', '10.0.0.41:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0103',
'王磊', '著', '纸本另有复本,藏于阅览室。',
'解放军出版社', '南京', '20230101', NULL, '978-7-80237-1101-1',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0103' AND deleted = 0);
-- 020x 无 ISBN,书名+作者+出版社+出版年份一致,供聚同;主题词与分类号分别缺在两条上,供优化互为补充
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0201', '陆军战术学教程', 'E83', NULL,
'本教程依据现行战斗条令,按进攻、防御和行军宿营的顺序讲解陆军战术的基本原则、兵力部署和协同动作。各章配有想定作业与思考题,便于院校教学和分队干部自学,也可作为合同战术训练的基础读本。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2022', '20261018',
'文本', '纸质', 'PDF', '248', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0201',
'赵明', '编著', NULL,
'军事科学出版社', '北京', '20220601', '第1版', NULL,
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0201' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0202', '陆军战术学教程', NULL, '战术学;陆军', '简介陆军战术基本原则。', '2022', '20261018',
'文本', '电子', 'PDF', '248', 'chi', '陆军步兵学院', '2026',
'南京陆军指挥学院图书馆', '10.0.0.21:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0202',
'赵明', '编著', '电子版由纸本数字化加工。',
'军事科学出版社', '北京', '20220601', NULL, NULL,
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0202' AND deleted = 0);
-- 030x 题名相近但 ISBN、版次不同,聚同不会自动合并,只出现在疑似同一文献清单
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0301', '合成营战术', 'E83', '合成营;战术',
'本书围绕合成营进攻与防御的组织实施,说明兵力编成、火力计划和步坦协同的基本方法。内容按课堂教学进度编排,并附有班组讨论题目,供陆军院校合成指挥专业学员使用。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2021', '20261018',
'文本', '纸质', 'PDF', '196', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0301',
'陈刚', '著', NULL,
'解放军出版社', '北京', '20210901', '第1版', '978-7-111-2201-6',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0301' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0302', '合成营战术(第二版)', 'E83', '合成营;无人装备',
'第二版在原有合成营战术框架上补充了无人装备协同和城镇战斗的内容,对指挥流程、通信组织和战损评估作了修订。全书仍面向生长军官培训,可作为部队分队战术训练的配套教材。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2024', '20261018',
'文本', '电子', 'PDF', '228', 'chi', '陆军步兵学院', '2026',
'国防大学图书馆', '10.0.0.31:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0302',
'陈刚', '著', NULL,
'解放军出版社', '北京', '20240301', '第2版', '978-7-111-2202-3',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0302' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0303', '联合作战指挥', 'E81', '联合作战;指挥',
'本书讲述联合作战指挥的职责区分、计划拟制和情况处置,强调情报、火力与后装保障的一体运用。案例选自院校想定作业,适合指挥员任职培训和参谋业务教学参考。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2020', '20261018',
'文本', '纸质', 'PDF', '264', 'chi', '陆军步兵学院', '2026',
'陆军指挥学院图书馆', '10.0.0.41:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0303',
'刘洋', '主编', NULL,
'国防大学出版社', '北京', '20200501', '第1版', '978-7-5065-3301-4',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0303' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0304', '联合作战指挥学', 'E81', '联合作战;指挥机构',
'本书在联合作战指挥的基础上,进一步讨论指挥机构编成、命令文书和跨军种协同的方法。各章附有思考题,可供中级指挥培训班和相关专业研究生教学使用。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2023', '20261018',
'文本', '电子', 'PDF', '310', 'chi', '陆军步兵学院', '2026',
'南京陆军指挥学院图书馆', '10.0.0.21:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0304',
'刘洋', '主编', NULL,
'国防大学出版社', '北京', '20230901', '第1版', '978-7-5065-3304-5',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0304' AND deleted = 0);
-- 040x 错漏:缺分类号/摘要过短/年份和语种、ISBN、页码、责任者不规范,或全文地址、主题词缺失
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0401', '边防侦察教材', NULL, '边防;侦察', '介绍边防侦察的一般方法。', '202x', '20261018',
'文本', '纸质', 'PDF', NULL, '中文', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0401',
NULL, '编', '著录信息残缺,供错漏提示演示。',
'解放军出版社', '昆明', NULL, NULL, '978-错误',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0401' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0402', '军事地形学基础', 'E991', NULL,
'讲解军事地形图识读、距离判定和简易测图,供分队干部短训使用。',
'2019', '20261018',
'文本', '电子', 'PDF', '96', 'chi', '陆军步兵学院', '2026',
'国防大学图书馆', '10.0.0.31:8080', NULL,
'孙伟', '著', NULL,
'军事科学出版社', '北京', '20190801', '第1版', '978-7-80237-5102-7',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0402' AND deleted = 0);
-- 050x 非纸电图书:字段完整,提纯时应留在全库之外
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0501', '队列条令讲解录音', 'E22', '队列;条令',
'本录音按照队列条令的章节顺序讲解单个军人队列动作和班队列动作,供新兵入伍训练阶段对照收听,也可作为队列教学的辅助材料。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2024', '20261018',
'音频', '电子', 'MP3', '48', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0501',
'队列教研室', '讲解', NULL,
'解放军出版社', '北京', '20240101', NULL, '978-7-80237-6101-2',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0501' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0502', '战术动作示范', 'E83', '战术动作;教学片',
'本片以分队战术动作为主线,演示利用地形、冲击发起和伤员救护的基本动作,供战术课直观教学和班排训练对照使用。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2023', '20261018',
'视频', '电子', 'MP4', '36', 'chi', '陆军步兵学院', '2026',
'国防大学图书馆', '10.0.0.31:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0502',
'战术教研室', '演示', NULL,
'军事科学出版社', '北京', '20230601', NULL, '978-7-80237-6102-9',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0502' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0503', '军事学术2024年合订本', 'E0', '军事学术;期刊',
'本合订本汇集当年军事学术论文,内容涉及作战理论、训练方法和院校教育。作为连续出版物样例入库,用于区分期刊与纸电图书。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2024', '20261018',
'期刊', '纸质', 'PDF', '480', 'chi', '陆军步兵学院', '2026',
'陆军指挥学院图书馆', '10.0.0.41:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0503',
'军事学术编辑部', '辑', NULL,
'军事科学出版社', '北京', '20241201', NULL, '978-7-80237-6103-6',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0503' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0504', '民国军事旧籍选', 'E296', '民国;缩微',
'本书为馆藏缩微复制的民国时期军事旧籍,保留原书题名与出版信息,介质为缩微胶片,仅作非纸电图书对照样例。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'1948', '20261018',
'缩微', '纸质', 'TIF', '120', 'chi', '陆军步兵学院', '2026',
'南京陆军指挥学院图书馆', '10.0.0.21:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0504',
'佚名', '辑', NULL,
'军事科学出版社', '南京', '19480101', NULL, '978-7-80237-6104-3',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0504' AND deleted = 0);
-- 060x 敏感图书:字段完整,但不得进入版本资源数据集
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0601', '部队内部编制手册', 'E15', '编制;实力',
'本手册整理部队编制和实力统计的一般格式,字段完整,但内容已标记为敏感,提纯时应当从版本资源数据集中剔除。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2025', '20261018',
'文本', '纸质', 'PDF', '86', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0601',
'训练部', '编', NULL,
'解放军出版社', '北京', '20250101', '内部', '978-7-80237-7101-5',
'RAW', 1, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0601' AND deleted = 0);
-- 070x 独立、著录完整的纸电图书,提纯时可直接纳入数据集
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0701', '步兵班战术', 'E83', '步兵班;战术',
'本书按班进攻、班防御和夜间战斗的顺序,说明步兵班的战斗队形、火器配置和指挥口令。文字通俗,配有要图说明,适合预提指挥士官和新兵骨干训练使用。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2022', '20261018',
'文本', '纸质', 'PDF', '168', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0701',
'周强', '著', NULL,
'解放军出版社', '北京', '20220401', '第1版', '978-7-80237-4101-8',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0701' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0702', '电子对抗基础', 'TN97', '电子对抗;干扰',
'本书介绍电子对抗的侦察、干扰和防护基础,说明常见装备的运用时机和分队协同要求。内容面向初级任职教育,可作为电子对抗和指挥专业的入门教材。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2021', '20261018',
'文本', '电子', 'PDF', '214', 'chi', '陆军步兵学院', '2026',
'国防大学图书馆', '10.0.0.31:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0702',
'吴敏', '著', NULL,
'国防大学出版社', '北京', '20211101', '第1版', '978-7-80237-4102-5',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0702' AND deleted = 0);
INSERT INTO version_resource (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn,
govern_status, sensitive_flag, is_special, abnormal_flag, manage_status, deleted)
SELECT 'BB-DEMO-0703', '合同战术演习指南', 'E83', '合同战术;演习',
'本指南说明合同战术演习的筹划、导调和裁决方法,包括情况设想、演习文书和复盘讲评的一般步骤。可供院校导演人员和部队训练机构组织实兵或兵棋演习时参考。著录要素按版本资源元数据标准整理,可供治理演示时对照不同来源、不同媒体记录之间的字段差异与补全效果。',
'2024', '20261018',
'文本', '纸质', 'PDF', '176', 'chi', '陆军步兵学院', '2026',
'陆军指挥学院图书馆', '10.0.0.41:8080', 'http://cdio.example.org/fulltext/BB-DEMO-0703',
'郑凯', '编著', NULL,
'军事科学出版社', '北京', '20240201', '第1版', '978-7-80237-4103-2',
'RAW', 0, 0, 0, 0, 0
WHERE NOT EXISTS (SELECT 1 FROM version_resource WHERE process_no = 'BB-DEMO-0703' AND deleted = 0);
+2
View File
@@ -24,4 +24,6 @@ VALUES
-- 样例数据用显式 id 插入,需同步自增序列起点,避免后续新增主键冲突
SELECT setval('version_resource_id_seq', GREATEST(COALESCE((SELECT MAX(id) FROM version_resource), 0), 1), true);
-- 治理演示数据(多来源重复、疑似同一文献、错漏、非纸电图书)见 data-governance-demo.sql
SELECT setval('special_resource_id_seq', GREATEST(COALESCE((SELECT MAX(id) FROM special_resource), 0), 1), true);
@@ -52,6 +52,12 @@ CREATE TABLE IF NOT EXISTS collect_task
library_code VARCHAR(64) NOT NULL, -- 单位编码
library_name VARCHAR(256), -- 单位名称
source_type VARCHAR(64), -- 数据源类型:MARC/EXCEL/DB/API
db_host VARCHAR(256), -- 来源库地址
db_port INTEGER, -- 来源库端口
db_name VARCHAR(128), -- 来源库名
db_username VARCHAR(128), -- 来源库用户名
db_password VARCHAR(256), -- 来源库密码
source_table VARCHAR(128), -- 数据库采集的来源表名
target_count INTEGER DEFAULT 200000, -- 目标采集量
collected_count INTEGER DEFAULT 0, -- 已采集量
status VARCHAR(32) DEFAULT 'PENDING', -- PENDING/RUNNING/SUCCESS/FAILED
+118
View File
@@ -0,0 +1,118 @@
-- =====================================================================
-- v8:数据采集按表名入库
-- 1. 采集任务记录来源表名
-- 2. 馆藏源表 src_library_catalog,字段与 version_resource 著录项对齐
-- =====================================================================
ALTER TABLE collect_task ADD COLUMN IF NOT EXISTS source_table VARCHAR(128);
COMMENT ON COLUMN collect_task.source_table IS '数据库采集时的来源表名';
CREATE TABLE IF NOT EXISTS src_library_catalog
(
id BIGSERIAL NOT NULL PRIMARY KEY,
process_no VARCHAR(128),
title VARCHAR(512) NOT NULL,
clc_code VARCHAR(64),
keywords VARCHAR(512),
summary TEXT,
publish_year VARCHAR(8),
process_date VARCHAR(16),
content_form VARCHAR(64),
media_type VARCHAR(32),
format VARCHAR(64),
page_count VARCHAR(64),
language VARCHAR(16),
submit_org VARCHAR(256),
task_year VARCHAR(8),
source_library VARCHAR(256),
source_library_addr VARCHAR(256),
fulltext_url VARCHAR(1024),
author VARCHAR(512),
responsibility VARCHAR(256),
note TEXT,
publisher VARCHAR(256),
publish_place VARCHAR(128),
publish_date VARCHAR(32),
edition VARCHAR(128),
isbn VARCHAR(64)
);
COMMENT ON TABLE src_library_catalog IS '馆藏源表,供数据采集按表名读取后写入 version_resource';
INSERT INTO src_library_catalog (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn)
SELECT 'SRC-2026-1001', '合同进攻战斗教材', 'E83', '合同进攻;战斗;战术',
'本教材讲解合同进攻战斗的任务区分、火力组织和步坦协同,供陆军院校分队战术课使用。',
'2022', '20261020', '文本', '纸质', 'PDF', '246', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/SRC-2026-1001',
'何军', '编著', '馆藏源表样例,采集后写入版本资源表。',
'解放军出版社', '北京', '20220301', '第1版', '978-7-80237-8101-6'
WHERE NOT EXISTS (SELECT 1 FROM src_library_catalog WHERE process_no = 'SRC-2026-1001');
INSERT INTO src_library_catalog (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn)
SELECT 'SRC-2026-1002', '防空兵战术学', 'E84', '防空兵;战术;对空射击',
'本书说明防空兵兵力部署、对空射击指挥和与被掩护部队的协同方法。',
'2021', '20261020', '文本', '电子', 'PDF', '318', 'chi', '陆军防空兵学院', '2026',
'陆军防空兵学院图书馆', '10.0.0.61:8080', 'http://cdio.example.org/fulltext/SRC-2026-1002',
'马林', '著', '电子本由纸本数字化加工。',
'军事科学出版社', '北京', '20210901', '第2版', '978-7-80237-8102-3'
WHERE NOT EXISTS (SELECT 1 FROM src_library_catalog WHERE process_no = 'SRC-2026-1002');
INSERT INTO src_library_catalog (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn)
SELECT 'SRC-2026-1003', '军事后勤学概论', 'E13', '军事后勤;保障;供应',
'概论军事后勤的体制、供应方式和战时保障组织,适合生长军官基础课阅读。',
'2019', '20261020', '文本', '纸质', 'PDF', '402', 'chi', '陆军勤务学院', '2026',
'陆军勤务学院图书馆', '10.0.0.71:8080', 'http://cdio.example.org/fulltext/SRC-2026-1003',
'周宁', '主编', NULL,
'国防大学出版社', '北京', '20190501', '第1版', '978-7-80237-8103-0'
WHERE NOT EXISTS (SELECT 1 FROM src_library_catalog WHERE process_no = 'SRC-2026-1003');
INSERT INTO src_library_catalog (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn)
SELECT 'SRC-2026-1004', '外军陆军编制研究', 'E1-3', '外军;编制;陆军',
'比较若干国家陆军师旅营编制和装备编成,供指挥院校外军研究课程参考。',
'2018', '20261020', '文本', '纸质', 'PDF', '276', 'chi', '陆军指挥学院', '2026',
'陆军指挥学院图书馆', '10.0.0.41:8080', 'http://cdio.example.org/fulltext/SRC-2026-1004',
'韩雪', '著', NULL,
'军事科学出版社', '北京', '20181101', '第1版', '978-7-80237-8104-7'
WHERE NOT EXISTS (SELECT 1 FROM src_library_catalog WHERE process_no = 'SRC-2026-1004');
INSERT INTO src_library_catalog (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn)
SELECT 'SRC-2026-1005', '战场电磁环境', 'TN97', '电磁环境;电子对抗;频谱',
'介绍战场电磁环境的构成、测量和分队用频管理,可作为电子对抗入门读物。',
'2023', '20261020', '文本', '电子', 'PDF', '188', 'chi', '国防科技大学', '2026',
'国防科技大学图书馆', '10.0.0.91:8080', 'http://cdio.example.org/fulltext/SRC-2026-1005',
'吴敏', '编著', NULL,
'国防工业出版社', '北京', '20230601', '第1版', '978-7-118-12005-8'
WHERE NOT EXISTS (SELECT 1 FROM src_library_catalog WHERE process_no = 'SRC-2026-1005');
INSERT INTO src_library_catalog (
process_no, title, clc_code, keywords, summary, publish_year, process_date,
content_form, media_type, format, page_count, language, submit_org, task_year,
source_library, source_library_addr, fulltext_url, author, responsibility, note,
publisher, publish_place, publish_date, edition, isbn)
SELECT 'SRC-2026-1006', '陆军院校图书馆纸电目录规范', 'G254', '纸电目录;著录;图书馆',
'规范陆军院校图书馆纸质书与电子书目录的著录项目和交换格式,供联合采集对照。',
'2024', '20261020', '文本', '电子', 'PDF', '132', 'chi', '陆军步兵学院', '2026',
'陆军步兵学院图书馆', '10.0.0.11:8080', 'http://cdio.example.org/fulltext/SRC-2026-1006',
'目录组', '编', '字段名与版本资源表一致,采集时按同名字段写入。',
'解放军出版社', '南昌', '20240101', '第1版', '978-7-80237-8106-1'
WHERE NOT EXISTS (SELECT 1 FROM src_library_catalog WHERE process_no = 'SRC-2026-1006');
@@ -0,0 +1,12 @@
-- 采集任务保存来源库连接信息。密码只用于再次执行采集,接口不回传。
ALTER TABLE collect_task ADD COLUMN IF NOT EXISTS db_host VARCHAR(256);
ALTER TABLE collect_task ADD COLUMN IF NOT EXISTS db_port INTEGER;
ALTER TABLE collect_task ADD COLUMN IF NOT EXISTS db_name VARCHAR(128);
ALTER TABLE collect_task ADD COLUMN IF NOT EXISTS db_username VARCHAR(128);
ALTER TABLE collect_task ADD COLUMN IF NOT EXISTS db_password VARCHAR(256);
COMMENT ON COLUMN collect_task.db_host IS '来源数据库地址';
COMMENT ON COLUMN collect_task.db_port IS '来源数据库端口';
COMMENT ON COLUMN collect_task.db_name IS '来源数据库名';
COMMENT ON COLUMN collect_task.db_username IS '来源数据库用户名';
COMMENT ON COLUMN collect_task.db_password IS '来源数据库密码';