diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/publish/DefaultFlowPreviewService.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/publish/DefaultFlowPreviewService.java new file mode 100644 index 0000000..9d91635 --- /dev/null +++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/publish/DefaultFlowPreviewService.java @@ -0,0 +1,98 @@ +package com.eip4.platform.metadata.publish; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; + +/** + * 默认服务流「预览/持久态」读取(建物 3 · 发布前人工确认)。 + * + *

flowName 与 {@code com.dsasp.server.core.service.flow.model.DefaultFlowHelper} + * 的 Flow id 完全一致({@code _ADD} 等),在 SYS_SERVICEFLOW 中即主键 sys_serviceflow_id。 + * + * + * + *

不引入保真层重型 POInfo:STATUS 列存在性用元数据 SQL 判断,避免预览阶段触发 POInfo 缓存。 + */ +@Service +public class DefaultFlowPreviewService { + + /** 5 个基础流的有序后缀 → kind / 显名映射。 */ + private static final String[][] BASE_FLOWS = { + {"_ADD", "ADD", "新增"}, + {"_DELETE", "DELETE", "删除"}, + {"_UPDATE", "UPDATE", "更新"}, + {"_SEARCH", "SEARCH", "查询"}, + {"_LOAD", "LOAD", "加载"}, + }; + /** 含 STATUS 列时追加的 2 个提交流。 */ + private static final String[][] STATUS_FLOWS = { + {"_SUBMIT", "SUBMIT", "提交审批"}, + {"_SAVE_AND_SUBMIT", "SAVE_AND_SUBMIT", "保存并提交审批"}, + }; + + private final JdbcTemplate jdbcTemplate; + + public DefaultFlowPreviewService(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + public record FlowItem(String flowName, String displayName, String kind) {} + + public record FlowsPreview(String entityId, String tableName, boolean persisted, List flows) {} + + public FlowsPreview preview(String entityId) { + Integer existing = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM SYS_SERVICEFLOW WHERE entityid=?", Integer.class, entityId); + String tableName = jdbcTemplate.queryForObject( + "SELECT TRIM(tablename) FROM SYS_ENTITY WHERE TRIM(sys_entity_id)=?", String.class, entityId); + if (existing != null && existing >= 1) { + return new FlowsPreview(entityId, tableName, true, persistedFlows(entityId)); + } + return new FlowsPreview(entityId, tableName, false, synthesizedFlows(entityId, tableName)); + } + + private List synthesizedFlows(String entityId, String tableName) { + List out = new ArrayList<>(); + for (String[] f : BASE_FLOWS) { + out.add(new FlowItem(tableName + f[0], tableName + " " + f[2], f[1])); + } + Integer hasStatus = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM SYS_ENTITYATTRIBUTE WHERE entityid=? AND UPPER(TRIM(columnname))='STATUS'", + Integer.class, entityId); + if (hasStatus != null && hasStatus >= 1) { + for (String[] f : STATUS_FLOWS) { + out.add(new FlowItem(tableName + f[0], tableName + " " + f[2], f[1])); + } + } + return out; + } + + private List persistedFlows(String entityId) { + List> rows = jdbcTemplate.queryForList( + "SELECT TRIM(sys_serviceflow_id) AS fid, displayname FROM SYS_SERVICEFLOW WHERE entityid=?" + + " ORDER BY sys_serviceflow_id", entityId); + List out = new ArrayList<>(); + for (Map r : rows) { + String fid = String.valueOf(r.get("fid")); + String display = r.get("displayname") == null ? fid : String.valueOf(r.get("displayname")); + out.add(new FlowItem(fid, display, kindOf(fid))); + } + return out; + } + + private static String kindOf(String flowName) { + int us = flowName.indexOf('_'); + if (us < 0) { + return "UNKNOWN"; + } + return flowName.substring(us + 1); + } +} diff --git a/platform-metadata/src/main/java/com/eip4/platform/metadata/web/DesignFeatureController.java b/platform-metadata/src/main/java/com/eip4/platform/metadata/web/DesignFeatureController.java index 25680ee..a144dd2 100644 --- a/platform-metadata/src/main/java/com/eip4/platform/metadata/web/DesignFeatureController.java +++ b/platform-metadata/src/main/java/com/eip4/platform/metadata/web/DesignFeatureController.java @@ -56,26 +56,30 @@ public class DesignFeatureController { private final TypedPageSchemaValidator strictValidator; private final JdbcTemplate jdbcTemplate; // 仅 requireAdmin 用 private final boolean skipAdminCheck; // 仅单测置 true + private final com.eip4.platform.metadata.publish.DefaultFlowPreviewService flowPreviewService; // Task 10 /** 生产构造(Spring 注入)。 */ public DesignFeatureController(JdbcTemplate jdbcTemplate, PageSchemaWriter pageSchemaWriter, - EntityAttributeReader attributeReader) { + EntityAttributeReader attributeReader, + com.eip4.platform.metadata.publish.DefaultFlowPreviewService flowPreviewService) { this.jdbcTemplate = jdbcTemplate; this.pageSchemaWriter = pageSchemaWriter; this.attributeReader = attributeReader; + this.flowPreviewService = flowPreviewService; this.composer = new RecipePageComposer(MAPPER); this.strictValidator = TypedPageSchemaValidator.defaults(); this.skipAdminCheck = false; } - /** 包级测试构造:脱库 + 可旁路 admin 门禁。 */ + /** 包级测试构造:脱库 + 可旁路 admin 门禁(发布编排依赖在 compile 单测中置 null)。 */ DesignFeatureController(PageSchemaWriter pageSchemaWriter, EntityAttributeReader attributeReader, boolean skipAdminCheck) { this.jdbcTemplate = null; this.pageSchemaWriter = pageSchemaWriter; this.attributeReader = attributeReader; + this.flowPreviewService = null; this.composer = new RecipePageComposer(MAPPER); this.strictValidator = TypedPageSchemaValidator.defaults(); this.skipAdminCheck = skipAdminCheck; @@ -160,6 +164,33 @@ public class DesignFeatureController { return isBlank(req.entityName) ? req.title.trim() : req.entityName.trim(); } + @Operation(summary = "列出实体的 5(+2) 条默认服务流供人工确认(仅管理员)", + description = "未落库则合成预览(含 STATUS 列 +2),已落库则读 SYS_SERVICEFLOW 真实行") + @org.springframework.web.bind.annotation.GetMapping("/flows") + public Map flows( + @org.springframework.web.bind.annotation.RequestParam("entityId") String entityId) { + requireAdmin(); + com.eip4.platform.metadata.publish.DefaultFlowPreviewService.FlowsPreview p = + flowPreviewService.preview(entityId); + List> flowList = new ArrayList<>(); + for (com.eip4.platform.metadata.publish.DefaultFlowPreviewService.FlowItem f : p.flows()) { + Map m = new LinkedHashMap<>(); + m.put("flowName", f.flowName()); + m.put("displayName", f.displayName()); + m.put("kind", f.kind()); + flowList.add(m); + } + Map data = new LinkedHashMap<>(); + data.put("entityId", p.entityId()); + data.put("tableName", p.tableName()); + data.put("persisted", p.persisted()); + data.put("flows", flowList); + Map resp = new LinkedHashMap<>(); + resp.put("status", 0); + resp.put("data", data); + return resp; + } + // ===== admin 门禁(逐字对齐 PageSchemaController.requireAdmin / currentUserId)===== private void requireAdmin() { diff --git a/platform-metadata/src/test/java/com/eip4/platform/metadata/publish/DefaultFlowPreviewServiceTest.java b/platform-metadata/src/test/java/com/eip4/platform/metadata/publish/DefaultFlowPreviewServiceTest.java new file mode 100644 index 0000000..c69beb6 --- /dev/null +++ b/platform-metadata/src/test/java/com/eip4/platform/metadata/publish/DefaultFlowPreviewServiceTest.java @@ -0,0 +1,58 @@ +package com.eip4.platform.metadata.publish; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.jupiter.api.Test; +import org.springframework.jdbc.core.JdbcTemplate; + +class DefaultFlowPreviewServiceTest { + + @Test + void synthesizesFiveFlowsWhenNoServiceflowAndNoStatusColumn() { + JdbcTemplate jdbc = mock(JdbcTemplate.class); + // 无持久流 + when(jdbc.queryForObject( + eq("SELECT COUNT(*) FROM SYS_SERVICEFLOW WHERE entityid=?"), + eq(Integer.class), eq("ENT-1"))).thenReturn(0); + // 实体表名 + when(jdbc.queryForObject( + eq("SELECT TRIM(tablename) FROM SYS_ENTITY WHERE TRIM(sys_entity_id)=?"), + eq(String.class), eq("ENT-1"))).thenReturn("DEMO_TBL"); + // 无 STATUS 列 + when(jdbc.queryForObject( + eq("SELECT COUNT(*) FROM SYS_ENTITYATTRIBUTE WHERE entityid=? AND UPPER(TRIM(columnname))='STATUS'"), + eq(Integer.class), eq("ENT-1"))).thenReturn(0); + + DefaultFlowPreviewService svc = new DefaultFlowPreviewService(jdbc); + DefaultFlowPreviewService.FlowsPreview preview = svc.preview("ENT-1"); + + assertThat(preview.persisted()).isFalse(); + assertThat(preview.tableName()).isEqualTo("DEMO_TBL"); + assertThat(preview.flows()).extracting(DefaultFlowPreviewService.FlowItem::flowName) + .containsExactly("DEMO_TBL_ADD", "DEMO_TBL_DELETE", "DEMO_TBL_UPDATE", + "DEMO_TBL_SEARCH", "DEMO_TBL_LOAD"); + assertThat(preview.flows().get(0).kind()).isEqualTo("ADD"); + } + + @Test + void synthesizesSevenFlowsWhenStatusColumnPresent() { + JdbcTemplate jdbc = mock(JdbcTemplate.class); + when(jdbc.queryForObject( + eq("SELECT COUNT(*) FROM SYS_SERVICEFLOW WHERE entityid=?"), + eq(Integer.class), eq("ENT-2"))).thenReturn(0); + when(jdbc.queryForObject( + eq("SELECT TRIM(tablename) FROM SYS_ENTITY WHERE TRIM(sys_entity_id)=?"), + eq(String.class), eq("ENT-2"))).thenReturn("OA_DOC"); + when(jdbc.queryForObject( + eq("SELECT COUNT(*) FROM SYS_ENTITYATTRIBUTE WHERE entityid=? AND UPPER(TRIM(columnname))='STATUS'"), + eq(Integer.class), eq("ENT-2"))).thenReturn(1); + + DefaultFlowPreviewService.FlowsPreview p = new DefaultFlowPreviewService(jdbc).preview("ENT-2"); + assertThat(p.flows()).extracting(DefaultFlowPreviewService.FlowItem::flowName) + .contains("OA_DOC_SUBMIT", "OA_DOC_SAVE_AND_SUBMIT"); + assertThat(p.flows()).hasSize(7); + } +}