auto(27632decbddc): session end @ 2026-08-01T10:18:05 (+4f)
This commit is contained in:
1 parent
3cfba24556
commit
066d2cc3b5
4 files changed
+106
-25
No files matched your search
+23
-11
@@ -1,5 +1,8 @@
|
||||
package ssw.sswflow.schema;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -13,35 +16,39 @@ import java.sql.Statement;
|
||||
*
|
||||
* 受属性保护的 idempotent 增量迁移 (design §4.4 + plan §7 Step 4):
|
||||
* - 仅当 `dataset_auth` 缺 f_workflow_instance_id 或 f_workflow_operator_id 才执行
|
||||
* - 属性开关: `sswflow.schema.migrate=true` (默认 false)
|
||||
* - 属性开关: `sswflow.schema.migrate=true` (默认 false, Spring @Value 注入)
|
||||
* - SQL 仅为 `ALTER TABLE ... ADD COLUMN IF NOT EXISTS`
|
||||
* - 严禁 DROP / TRUNCATE / DELETE
|
||||
*
|
||||
* 设计依据: design §2.3 数据保护规则 (不 DROP / 不创建第二个 DB / 不破坏数据).
|
||||
*
|
||||
* 注意: 此文件已落地但 mvn 编译需 JNPF nexus (环境拦截, 见 debug.md §2.3).
|
||||
* 启动时只在 ssw-sswflow 模块被加载时执行; 默认 OFF.
|
||||
* 注意:
|
||||
* - 通过 @Value("${sswflow.schema.migrate:false}") 注入; Spring 启动时即可读 application.yml.
|
||||
* - 启动失败仅记日志, 不阻断应用 (红线).
|
||||
* - 仅在 ssw-sswflow 模块被加载时执行; 默认 OFF.
|
||||
*/
|
||||
@Component
|
||||
@Order(1)
|
||||
public class WorkflowLinkSchemaMigration implements CommandLineRunner {
|
||||
|
||||
/** 启动属性 key, 必须显式 true 才执行 (避免误改物理表) */
|
||||
private static final Logger log = LoggerFactory.getLogger(WorkflowLinkSchemaMigration.class);
|
||||
|
||||
/** 启动属性 key, 必须显式 true 才执行 (避免误改物理表). 默认 false. */
|
||||
public static final String PROP_ENABLED = "sswflow.schema.migrate";
|
||||
|
||||
private final DataSource dataSource;
|
||||
private final boolean enabled;
|
||||
|
||||
public WorkflowLinkSchemaMigration(DataSource dataSource) {
|
||||
public WorkflowLinkSchemaMigration(DataSource dataSource,
|
||||
@Value("${" + PROP_ENABLED + ":false}") boolean enabled) {
|
||||
this.dataSource = dataSource;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
boolean enabled = Boolean.getBoolean(PROP_ENABLED);
|
||||
// 注: Spring Boot 默认通过 System.getProperty() 读不到 application.yml
|
||||
// 这里仅作为占位, 真实接入走 @Value("${sswflow.schema.migrate:false}")
|
||||
// 编译就绪后由 SswflowExecutorConfig 注入.
|
||||
if (!enabled) {
|
||||
log.info("WorkflowLinkSchemaMigration skipped (property {} is not true)", PROP_ENABLED);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -53,10 +60,15 @@ public class WorkflowLinkSchemaMigration implements CommandLineRunner {
|
||||
stmt.execute(
|
||||
"ALTER TABLE dataset_auth ADD COLUMN IF NOT EXISTS f_workflow_operator_id varchar(50)"
|
||||
);
|
||||
log.info("WorkflowLinkSchemaMigration executed (property {}={})", PROP_ENABLED, enabled);
|
||||
} catch (Exception e) {
|
||||
// 严禁启动失败 (红线), 仅记日志
|
||||
org.slf4j.LoggerFactory.getLogger(WorkflowLinkSchemaMigration.class)
|
||||
.warn("WorkflowLinkSchemaMigration failed: {}", e.getMessage());
|
||||
log.warn("WorkflowLinkSchemaMigration failed: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/** 暴露给单测的入口: 在不启动 Spring 的情况下模拟一次执行. */
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
+23
@@ -20,6 +20,7 @@ import ssw.sswflow.entity.DatasetAuthEntity;
|
||||
import ssw.sswflow.entity.DatasetEntity;
|
||||
import ssw.sswflow.service.DatasetAuthService;
|
||||
import ssw.sswflow.service.DatasetService;
|
||||
import ssw.sswflow.workflow.DatasetAuthWorkflowBridge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -49,6 +50,9 @@ public class DatasetController extends SswflowCrudController<DatasetEntity> {
|
||||
@Autowired
|
||||
private DatasetAuthService datasetAuthService;
|
||||
|
||||
@Autowired
|
||||
private DatasetAuthWorkflowBridge datasetAuthWorkflowBridge;
|
||||
|
||||
@Override
|
||||
protected SuperService<DatasetEntity> service() {
|
||||
return datasetService;
|
||||
@@ -200,6 +204,25 @@ public class DatasetController extends SswflowCrudController<DatasetEntity> {
|
||||
return decide(authId, "REVOKED", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把授权状态同步到工作流最终审批结果 (sswflow M1 Task 5).
|
||||
* <p>
|
||||
* 流程: 发起授权时上游平台会写 {@code dataset_auth.f_workflow_instance_id},
|
||||
* 当用户在 JNPF 工作流完成审批后, 通过此端点把授权状态机拉到 PENDING -> APPROVED/REJECTED.
|
||||
* <p>
|
||||
* 安全约束:
|
||||
* - 端点不接受任何 decision 参数 (审批结果只来自工作流服务, 调用方不得伪造)
|
||||
* - 重复同步幂等: 终态 (APPROVED/REJECTED/REVOKED) 直接返回当前状态
|
||||
* - 工作流未结束返回业务错误, 不静默放过
|
||||
*/
|
||||
@PostMapping("/Auth/{authId}/SyncWorkflow")
|
||||
@Operation(summary = "同步授权状态到工作流最终结果",
|
||||
description = "根据 dataset_auth.f_workflow_instance_id 回读 JNPF 工作流审批结果并更新授权状态")
|
||||
public ActionResult<String> syncWorkflow(@PathVariable("authId") String authId) {
|
||||
String status = datasetAuthWorkflowBridge.sync(authId);
|
||||
return ActionResult.success("授权状态已同步", status);
|
||||
}
|
||||
|
||||
private ActionResult<String> decide(String authId, String status, String reason) {
|
||||
DatasetAuthEntity auth = datasetAuthService.getById(authId);
|
||||
if (auth == null) {
|
||||
|
||||
+52
-14
@@ -1,5 +1,6 @@
|
||||
package ssw.sswflow.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -15,6 +16,8 @@ import ssw.sswflow.entity.DatasetEntity;
|
||||
import ssw.sswflow.entity.DatasourceEntity;
|
||||
import ssw.sswflow.service.DatasetService;
|
||||
import ssw.sswflow.service.DatasourceService;
|
||||
import ssw.sswflow.service.probe.DatasourceConfigProtector;
|
||||
import ssw.sswflow.service.probe.PostgresqlProbe;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -40,6 +43,12 @@ public class DatasourceController extends SswflowCrudController<DatasourceEntity
|
||||
@Autowired
|
||||
private DatasetService datasetService;
|
||||
|
||||
@Autowired
|
||||
private PostgresqlProbe postgresqlProbe;
|
||||
|
||||
@Autowired
|
||||
private DatasourceConfigProtector configProtector;
|
||||
|
||||
@Override
|
||||
protected SuperService<DatasourceEntity> service() {
|
||||
return datasourceService;
|
||||
@@ -95,29 +104,58 @@ public class DatasourceController extends SswflowCrudController<DatasourceEntity
|
||||
/**
|
||||
* 连通性测试。
|
||||
* <p>
|
||||
* 当前阶段先做形式校验(配置是否完整、必填项是否齐全),
|
||||
* 真正的 JDBC/对象存储探活等接入各参与方节点代理后再补——
|
||||
* 平台侧直连对方内网库本身就不是隐私计算该有的姿势。
|
||||
* POSTGRESQL 走真实 SELECT 1 探活 (PostgresqlProbe, 独立 DriverManager 连接);
|
||||
* 其它类型返回 UNSUPPORTED + realProbe=false (等节点代理接入).
|
||||
* 响应固定为: status, message, realProbe; 任何错误脱敏, 不回显明文密码.
|
||||
*/
|
||||
@PostMapping("/{id}/Test")
|
||||
@Operation(summary = "连通性测试", description = "当前为配置完整性校验,节点代理接入后升级为真实探活")
|
||||
@Operation(summary = "连通性测试", description = "POSTGRESQL 真实 SELECT 1 探活,其它类型 UNSUPPORTED")
|
||||
public ActionResult<Map<String, Object>> test(@PathVariable("id") String id) {
|
||||
DatasourceEntity entity = getAlive(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail("数据源不存在");
|
||||
}
|
||||
boolean configured = entity.getConfig() != null && !entity.getConfig().isBlank();
|
||||
String status = configured ? "AVAILABLE" : "UNCONFIGURED";
|
||||
|
||||
DatasourceEntity update = new DatasourceEntity();
|
||||
update.setId(id);
|
||||
update.setStatus(status);
|
||||
datasourceService.updateById(update);
|
||||
String stored = entity.getConfig();
|
||||
String type = entity.getType() == null ? "POSTGRESQL" : entity.getType();
|
||||
|
||||
PostgresqlProbe.ProbeResult result;
|
||||
if (stored == null || stored.isBlank()) {
|
||||
result = PostgresqlProbe.ProbeResult.unconfigured("连接配置为空, 请先填写");
|
||||
} else {
|
||||
JSONObject decrypted;
|
||||
try {
|
||||
decrypted = configProtector.decryptForProbe(stored);
|
||||
} catch (Exception e) {
|
||||
log.warn("DatasourceController#test decrypt failed: id={}, err={}", id, e.getMessage());
|
||||
result = PostgresqlProbe.ProbeResult.failed("配置解析失败");
|
||||
Map<String, Object> data = toMap(result);
|
||||
return ActionResult.success(data);
|
||||
}
|
||||
result = postgresqlProbe.probe(type, decrypted);
|
||||
}
|
||||
|
||||
// 持久化状态机更新 (仅 AVAILABLE / FAILED 时反映真实结果, UNCONFIGURED / UNSUPPORTED 不动)
|
||||
if (result.status() == PostgresqlProbe.Status.AVAILABLE
|
||||
|| result.status() == PostgresqlProbe.Status.FAILED) {
|
||||
DatasourceEntity update = new DatasourceEntity();
|
||||
update.setId(id);
|
||||
update.setStatus(result.status().name());
|
||||
try {
|
||||
datasourceService.updateById(update);
|
||||
} catch (Exception e) {
|
||||
log.warn("DatasourceController#test status update failed: id={}, err={}", id, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.success(toMap(result));
|
||||
}
|
||||
|
||||
private static Map<String, Object> toMap(PostgresqlProbe.ProbeResult r) {
|
||||
Map<String, Object> data = new HashMap<>(4);
|
||||
data.put("status", status);
|
||||
data.put("message", configured ? "配置完整" : "连接配置为空,请先填写");
|
||||
data.put("realProbe", false);
|
||||
return ActionResult.success(data);
|
||||
data.put("status", r.status().name());
|
||||
data.put("message", r.message());
|
||||
data.put("realProbe", r.realProbe());
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,12 @@ public class DatasetAuthEntity extends SuperExtendEntity<String> {
|
||||
|
||||
@TableField("f_reject_reason")
|
||||
private String rejectReason;
|
||||
|
||||
/** 关联 JNPF flowable 流程实例 ID; 来源: 发起审批时绑定, 由 DatasetAuthWorkflowBridge 回读 */
|
||||
@TableField("f_workflow_instance_id")
|
||||
private String workflowInstanceId;
|
||||
|
||||
/** 最后一次同步流程审批结果时的经办人; 由 DatasetAuthWorkflowBridge 写入, 不可由调用方伪造 */
|
||||
@TableField("f_workflow_operator_id")
|
||||
private String workflowOperatorId;
|
||||
}
|
||||
Reference in new issue
Block a user