diff --git a/backend/pom.xml b/backend/pom.xml
index 68c848e..f52c2c7 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -63,6 +63,11 @@
postgresql
runtime
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
diff --git a/backend/src/main/java/com/banben/modules/collect/controller/CollectController.java b/backend/src/main/java/com/banben/modules/collect/controller/CollectController.java
index 0ed0f66..7ded032 100644
--- a/backend/src/main/java/com/banben/modules/collect/controller/CollectController.java
+++ b/backend/src/main/java/com/banben/modules/collect/controller/CollectController.java
@@ -30,6 +30,20 @@ public class CollectController {
return Result.success(collectService.createTask(task));
}
+ @Operation(summary = "修改采集任务")
+ @PutMapping("/task/{id}")
+ public Result updateTask(@PathVariable Long id, @RequestBody CollectTask task) {
+ collectService.updateTask(id, task);
+ return Result.success();
+ }
+
+ @Operation(summary = "删除采集任务")
+ @DeleteMapping("/task/{id}")
+ public Result removeTask(@PathVariable Long id) {
+ collectService.removeTask(id);
+ return Result.success();
+ }
+
@Operation(summary = "测试来源库连接,并查看表字段如何写入版本资源表")
@PostMapping("/preview")
public Result preview(@RequestBody CollectTask source) {
diff --git a/backend/src/main/java/com/banben/modules/collect/dto/CollectFieldCompareVO.java b/backend/src/main/java/com/banben/modules/collect/dto/CollectFieldCompareVO.java
new file mode 100644
index 0000000..4b3ce40
--- /dev/null
+++ b/backend/src/main/java/com/banben/modules/collect/dto/CollectFieldCompareVO.java
@@ -0,0 +1,27 @@
+package com.banben.modules.collect.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * 版本资源表字段与来源列的对照。
+ */
+@Data
+@Schema(description = "版本资源字段对照")
+public class CollectFieldCompareVO {
+
+ @Schema(description = "version_resource 字段名")
+ private String targetField;
+
+ @Schema(description = "字段中文名")
+ private String targetLabel;
+
+ @Schema(description = "是否为必备字段")
+ private boolean required;
+
+ @Schema(description = "对应的来源列名,没有则为空")
+ private String sourceColumn;
+
+ @Schema(description = "来源表是否有列对应到该字段")
+ private boolean matched;
+}
diff --git a/backend/src/main/java/com/banben/modules/collect/dto/CollectTableVO.java b/backend/src/main/java/com/banben/modules/collect/dto/CollectTableVO.java
index e186dd6..1928608 100644
--- a/backend/src/main/java/com/banben/modules/collect/dto/CollectTableVO.java
+++ b/backend/src/main/java/com/banben/modules/collect/dto/CollectTableVO.java
@@ -21,4 +21,7 @@ public class CollectTableVO {
@Schema(description = "列与版本资源字段的对应关系")
private List columns = new ArrayList<>();
+
+ @Schema(description = "版本资源表字段与来源列的对照")
+ private List compares = new ArrayList<>();
}
diff --git a/backend/src/main/java/com/banben/modules/collect/entity/CollectTask.java b/backend/src/main/java/com/banben/modules/collect/entity/CollectTask.java
index 49601c9..67e00e5 100644
--- a/backend/src/main/java/com/banben/modules/collect/entity/CollectTask.java
+++ b/backend/src/main/java/com/banben/modules/collect/entity/CollectTask.java
@@ -36,7 +36,10 @@ public class CollectTask implements Serializable {
@Schema(description = "数据库地址,如 10.1.1.14")
private String dbHost;
- @Schema(description = "数据库端口,瀚高默认 5866,PostgreSQL 默认 5432")
+ @Schema(description = "来源数据库类型:MYSQL 或 POSTGRESQL(瀚高走 PostgreSQL 协议)")
+ private String dbType;
+
+ @Schema(description = "数据库端口。MySQL 常用 3306,PostgreSQL 常用 5432,瀚高常用 5866")
private Integer dbPort;
@Schema(description = "数据库名")
diff --git a/backend/src/main/java/com/banben/modules/collect/service/CollectService.java b/backend/src/main/java/com/banben/modules/collect/service/CollectService.java
index c48409c..835ab3a 100644
--- a/backend/src/main/java/com/banben/modules/collect/service/CollectService.java
+++ b/backend/src/main/java/com/banben/modules/collect/service/CollectService.java
@@ -16,6 +16,16 @@ public interface CollectService extends IService {
*/
Long createTask(CollectTask task);
+ /**
+ * 修改采集任务的连接信息。密码留空则保持原密码。
+ */
+ void updateTask(Long id, CollectTask task);
+
+ /**
+ * 删除采集任务。
+ */
+ void removeTask(Long id);
+
/**
* 执行采集任务,返回执行后的任务(含采集条数和结果说明)。
*/
diff --git a/backend/src/main/java/com/banben/modules/collect/service/impl/CollectServiceImpl.java b/backend/src/main/java/com/banben/modules/collect/service/impl/CollectServiceImpl.java
index 9c58fba..2838461 100644
--- a/backend/src/main/java/com/banben/modules/collect/service/impl/CollectServiceImpl.java
+++ b/backend/src/main/java/com/banben/modules/collect/service/impl/CollectServiceImpl.java
@@ -50,7 +50,7 @@ public class CollectServiceImpl extends ServiceImpl c.sourceType().toUpperCase(), Function.identity(), (a, b) -> a));
}
- /** 创建任务:初始状态 PENDING、已采集量 0,目标量缺省为 20 万条。 */
+ /** 创建任务:初始状态 PENDING、已采集量 0。来源表至少要有一列能写入版本资源表。 */
@Override
public Long createTask(CollectTask task) {
task.setId(null);
@@ -59,15 +59,78 @@ public class CollectServiceImpl extends ServiceImpl column.getTargetField() != null);
+ if (!matched) {
+ throw new BusinessException("来源表至少要有一列能对应到版本资源表");
+ }
+ }
+
@Override
public CollectTask startTask(Long taskId) {
CollectTask task = this.getById(taskId);
diff --git a/backend/src/main/java/com/banben/modules/collect/service/impl/DbTableCollector.java b/backend/src/main/java/com/banben/modules/collect/service/impl/DbTableCollector.java
index 564478a..1f78e28 100644
--- a/backend/src/main/java/com/banben/modules/collect/service/impl/DbTableCollector.java
+++ b/backend/src/main/java/com/banben/modules/collect/service/impl/DbTableCollector.java
@@ -3,6 +3,7 @@ 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.CollectFieldCompareVO;
import com.banben.modules.collect.dto.CollectTableVO;
import com.banben.modules.collect.entity.CollectTask;
import com.banben.modules.collect.service.Collector;
@@ -44,6 +45,12 @@ public class DbTableCollector implements Collector {
private static final DateTimeFormatter DAY = DateTimeFormatter.ofPattern("yyyyMMdd");
private static final int MAX_ROWS = 200000;
+ /** 写入 version_resource 时建议具备的字段。正题名未对应则该行无法入库。 */
+ private static final List REQUIRED_FIELDS = List.of(
+ "title", "processNo", "clcCode", "keywords", "summary", "publishYear", "processDate",
+ "contentForm", "mediaType", "format", "language", "fulltextUrl"
+ );
+
private static final Map FIELD_BY_COLUMN = new HashMap<>();
private static final Map FIELD_LABEL = new LinkedHashMap<>();
private static final Map> SETTERS = new HashMap<>();
@@ -151,13 +158,14 @@ public class DbTableCollector implements Collector {
* 用页面填写的地址、账号和表名连接来源库,返回行数以及列如何写入版本资源表。
*/
public CollectTableVO preview(CollectTask task) {
- String[] qualified = qualify(task.getSourceTable());
+ String[] qualified = qualify(task);
try (Connection connection = openConnection(task)) {
- ensureTable(connection, qualified[0], qualified[1]);
+ qualified[1] = canonicalTable(connection, qualified[0], qualified[1], mysql(task));
CollectTableVO table = new CollectTableVO();
table.setTableName(qualified[0] + "." + qualified[1]);
- table.setRowCount(countRows(connection, qualified[0], qualified[1]));
+ table.setRowCount(countRows(connection, qualified[0], qualified[1], mysql(task)));
table.setColumns(readColumns(connection, qualified[0], qualified[1]));
+ table.setCompares(buildCompares(table.getColumns()));
return table;
} catch (SQLException e) {
throw new BusinessException(sqlMessage(e));
@@ -166,12 +174,16 @@ public class DbTableCollector implements Collector {
@Override
public int collect(CollectTask task) {
- String[] qualified = qualify(task.getSourceTable());
+ String[] qualified = qualify(task);
int limit = task.getTargetCount() == null ? MAX_ROWS : Math.min(Math.max(task.getTargetCount(), 1), MAX_ROWS);
List