_SEARCH},且 TABLE 存在于 SYS_ENTITY →
+ * 调用 {@link DefaultFlowHelper#getDefaultSearch} 运行时合成 FlowDefinition。
+ * 合成结果走 Caffeine 缓存(maxSize 2000);{@link #evict(String)} 与
+ * {@code /api/meta/evict} 钩子对齐。
+ * 其余命名:按 sys_serviceflow_id 列精确查(主键查,O(1),无需 XML 扫描)→
+ * 命中返回哨兵 {@link ResolvedFlow#NAMED_HIT}(调用方用原始名按 PK 直接执行);
+ * 不命中返回 {@link ResolvedFlow#ORPHAN}(调用方应返回 404)。
+ *
+ *
+ * 写操作后缀拒绝:{@code _SAVE/_UPDATE/_DELETE} 结尾的名字(非 UUID 且无法按 _SEARCH 路径处理)
+ * 返回 {@link ResolvedFlow#WRITE_REDIRECT},调用方应引导使用 /api/entity/{x}/save 端点。
+ *
+ *
零改 com.dsasp 文件:DefaultFlowHelper 调用在本类(现代层包),保真层不动。
+ * SQL 全参数化;表名已经过白名单校验(SYS_ENTITY 存在性 = 白名单)。
+ */
+@Component
+public class FlowNameResolver {
+
+ private static final Logger log = LoggerFactory.getLogger(FlowNameResolver.class);
+
+ /** 孤儿服务名日志前缀,便于 grep 汇总 */
+ private static final String ORPHAN_LOG_PREFIX = "[F2-14 ORPHAN]";
+
+ /** 默认搜索合成结果缓存(按 TABLE_SEARCH 名字缓存,失效跟 evict 钩子对齐) */
+ private final Cache> searchCache = Caffeine.newBuilder()
+ .maximumSize(2_000)
+ .build();
+
+ /** UUID 格式正则(36 位,含4个连字符) */
+ private static final java.util.regex.Pattern UUID_PATTERN =
+ java.util.regex.Pattern.compile(
+ "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
+
+ /** 写操作默认后缀,这三种走 /api/entity/{x}/save,不走 flow 查询路径 */
+ private static final java.util.regex.Pattern WRITE_SUFFIX_PATTERN =
+ java.util.regex.Pattern.compile("(?i)_SAVE$|_UPDATE$|_DELETE$");
+
+ private final JdbcTemplate jdbcTemplate;
+ private final SynthesizedFlowRegistry registry;
+
+ public FlowNameResolver(JdbcTemplate jdbcTemplate, SynthesizedFlowRegistry registry) {
+ this.jdbcTemplate = jdbcTemplate;
+ this.registry = registry;
+ }
+
+ /**
+ * 解析结果类型。
+ */
+ public enum ResolveType {
+ /** UUID 格式,调用方走 PK 查引擎(现状逻辑) */
+ UUID_PASSTHROUGH,
+ /** _SEARCH 合成:返回合成 FlowDefinition,调用方直接执行 */
+ SYNTHESIZED,
+ /** 命名服务命中 sys_serviceflow(PK=id),调用方用原始名按 PK 执行 */
+ NAMED_HIT,
+ /** 写操作后缀,应 redirect 到 /api/entity/{x}/save */
+ WRITE_REDIRECT,
+ /** 孤儿:既不是 UUID,也查不到,也合成不了 → 404 */
+ ORPHAN
+ }
+
+ public record ResolvedFlow(ResolveType type, FlowDefinition> definition, String message) {
+ public static final ResolvedFlow UUID_PASSTHROUGH = new ResolvedFlow(ResolveType.UUID_PASSTHROUGH, null, null);
+ public static final ResolvedFlow NAMED_HIT = new ResolvedFlow(ResolveType.NAMED_HIT, null, null);
+ public static final ResolvedFlow ORPHAN = new ResolvedFlow(ResolveType.ORPHAN, null, null);
+ public static final ResolvedFlow WRITE_REDIRECT = new ResolvedFlow(ResolveType.WRITE_REDIRECT, null,
+ "写操作请使用 /api/entity/{table}/save 端点,不走 flow 查询路径");
+ }
+
+ /**
+ * 解析服务名。
+ *
+ * @param flowId 请求路径中的 {id}
+ * @return 解析结果,不会为 null
+ */
+ public ResolvedFlow resolve(String flowId) {
+ if (flowId == null || flowId.isBlank()) {
+ return ResolvedFlow.ORPHAN;
+ }
+
+ // 1. UUID → 原样走 PK 查(现状逻辑)
+ if (UUID_PATTERN.matcher(flowId).matches()) {
+ return ResolvedFlow.UUID_PASSTHROUGH;
+ }
+
+ // 2. 写操作后缀拒绝(_SAVE/_UPDATE/_DELETE)
+ if (WRITE_SUFFIX_PATTERN.matcher(flowId).find()) {
+ return ResolvedFlow.WRITE_REDIRECT;
+ }
+
+ // 3. _SEARCH 后缀 → 运行时合成
+ String upper = flowId.toUpperCase();
+ if (upper.endsWith("_SEARCH")) {
+ String tableName = upper.substring(0, upper.length() - 7); // strip "_SEARCH"
+ ResolvedFlow synthesized = trysynthesize(upper, tableName);
+ if (synthesized != null) {
+ return synthesized;
+ }
+ // tableName 不在 SYS_ENTITY → 继续走第4步(可能是命名服务 SOMETHING_SEARCH)
+ }
+
+ // 4. 其余命名服务:按 sys_serviceflow_id 精确查(主键查)
+ if (existsInServiceFlow(flowId)) {
+ return ResolvedFlow.NAMED_HIT;
+ }
+
+ // 孤儿
+ log.warn("{} 服务名不在任何解析路径: {}", ORPHAN_LOG_PREFIX, sanitize(flowId));
+ return ResolvedFlow.ORPHAN;
+ }
+
+ /**
+ * 尝试合成默认搜索流。
+ * @param cacheKey 缓存键(TABLE_SEARCH 大写)
+ * @param tableName 表名(大写)
+ * @return 合成结果,或 null(表名不在 SYS_ENTITY)
+ */
+ private ResolvedFlow trysynthesize(String cacheKey, String tableName) {
+ // 先查缓存
+ FlowDefinition> cached = searchCache.getIfPresent(cacheKey);
+ if (cached != null) {
+ return new ResolvedFlow(ResolveType.SYNTHESIZED, cached, null);
+ }
+
+ // 查 SYS_ENTITY(参数化,表名不进 SQL 字符串)
+ List