feat(page-schema): converge net-new standard writes to single PageSchemaWriter (M3a)
sys_page_schema standard layer had two runtime writers: the converter import CLI and AiLocalReleaseExecutor's raw JDBC INSERT (the critic-flagged net-new bypass). Introduce PageSchemaWriter as the single runtime write function (typed-recipe validation warn-not-block + etag + UPSERT), and route both a new admin-gated PUT /api/page/schema/{id}/standard endpoint (net-new producer for the design-center 'new feature' path) and AiLocalReleaseExecutor.applyPageSchema through it. No remaining raw INSERT into sys_page_schema in the AI runtime write path.
Scope: page_schema runtime write only. The deployment-package SQL-text generator (AiAgentService.pageSchemaSql, offline human-apply artifact) and SchemaImportCli (batch converter import) are separate legitimate paths. AiLocalReleaseExecutor sys_serviceflow/sys_menu raw writes remain (follow-on). Completion = code-complete, integration-pending (end-to-end render proof env-gated).
Tests: PageSchemaWriterTest (4) + PageSchemaControllerTest putStandard success/403/split (27 total) + AiLocalReleaseExecutorTest/AiAgentApiPipelineTest unchanged-green. TDD.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
package com.eip4.platform.ai.service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HexFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -22,6 +18,7 @@ import org.springframework.web.server.ResponseStatusException;
|
||||
import com.eip4.platform.ai.model.AiApplyStepResult;
|
||||
import com.eip4.platform.ai.model.AiArtifactType;
|
||||
import com.eip4.platform.ai.model.AiDraft;
|
||||
import com.eip4.platform.metadata.schema.PageSchemaWriter;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -31,11 +28,14 @@ public class AiLocalReleaseExecutor {
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final AiSmokeHttpClient httpClient;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final PageSchemaWriter pageSchemaWriter;
|
||||
|
||||
public AiLocalReleaseExecutor(JdbcTemplate jdbcTemplate, AiSmokeHttpClient httpClient, ObjectMapper objectMapper) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.httpClient = httpClient;
|
||||
this.objectMapper = objectMapper;
|
||||
// M3a 收口:标准层页面 schema 写统一走 PageSchemaWriter(与设计中心新建端点共用单一写真相)
|
||||
this.pageSchemaWriter = new PageSchemaWriter(jdbcTemplate);
|
||||
}
|
||||
|
||||
public List<AiApplyStepResult> apply(String baseUrl, List<AiDraft> drafts) {
|
||||
@@ -152,20 +152,10 @@ public class AiLocalReleaseExecutor {
|
||||
}
|
||||
|
||||
private AiApplyStepResult applyPageSchema(AiDraft draft, int index) throws Exception {
|
||||
// M3a 收口:不再裸 INSERT sys_page_schema;走 PageSchemaWriter 唯一写真相(typed 校验告警 + etag + UPSERT)
|
||||
String schemaJson = objectMapper.writeValueAsString(draft.payload());
|
||||
String etag = sha256(schemaJson);
|
||||
long now = System.currentTimeMillis();
|
||||
jdbcTemplate.update("""
|
||||
INSERT INTO sys_page_schema (template_id, name, schema_json, schema_etag, version, update_time)
|
||||
VALUES (?, ?, ?::jsonb, ?, 1, ?)
|
||||
ON CONFLICT (template_id) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
schema_json = EXCLUDED.schema_json,
|
||||
schema_etag = EXCLUDED.schema_etag,
|
||||
version = sys_page_schema.version + 1,
|
||||
update_time = EXCLUDED.update_time
|
||||
""",
|
||||
draft.targetId(), draft.payload().path("title").asText(draft.targetId()), schemaJson, etag, now);
|
||||
String name = draft.payload().path("title").asText(draft.targetId());
|
||||
String etag = pageSchemaWriter.upsertStandard(draft.targetId(), name, schemaJson, "AI_AGENT");
|
||||
return applied(index, draft, "页面 schema 已发布", Map.of("templateId", draft.targetId(), "etag", etag));
|
||||
}
|
||||
|
||||
@@ -321,15 +311,6 @@ public class AiLocalReleaseExecutor {
|
||||
return value == null ? "" : value.trim();
|
||||
}
|
||||
|
||||
private static String sha256(String text) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
return HexFormat.of().formatHex(digest.digest(text.getBytes(StandardCharsets.UTF_8)));
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ApplyContext {
|
||||
private final URI base;
|
||||
private String entityId = "";
|
||||
|
||||
Reference in New Issue
Block a user