chore: 落地 eip4-platform 多模块骨架基线(PoC→工程化)
从 eip4-poc 迁入双层制模块化单体:保真层 platform-legacy-core (com.dsasp 引擎原样)+ 现代层 platform-metadata/auth/flow-gateway/ converter/ai + platform-app 启动器。ArchUnit 纪律固化(保真层禁依赖现代层)。 此为 C1 对拍工作的编译通过基线。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.eip4.platform.converter.TemplateToAmisConverter;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.networknt.schema.JsonSchema;
|
||||
import com.networknt.schema.JsonSchemaFactory;
|
||||
import com.networknt.schema.SpecVersion;
|
||||
import com.networknt.schema.ValidationMessage;
|
||||
|
||||
/**
|
||||
* WS2:模板 XML → amis schema 转换 + 官方 schema.json(draft-07)机器校验闭环。
|
||||
* /api/poc/amis-schema 返回转换后的页面 schema(amis SDK 直接渲染)
|
||||
* /api/poc/amis-validate 转换 + 经 amis-schema-6.13.0.json 校验,返回映射台账与校验结果
|
||||
*/
|
||||
@RestController
|
||||
public class AmisSchemaController {
|
||||
|
||||
private final TemplateToAmisConverter converter;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private volatile JsonSchema amisSchema;
|
||||
|
||||
public AmisSchemaController(TemplateToAmisConverter converter, JdbcTemplate jdbcTemplate) {
|
||||
this.converter = converter;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@GetMapping("/api/poc/amis-schema")
|
||||
public Map<String, Object> schema(@RequestParam(defaultValue = "角色维护") String template) throws Exception {
|
||||
return converter.convert(loadXml(template), new ArrayList<>());
|
||||
}
|
||||
|
||||
@GetMapping("/api/poc/amis-validate")
|
||||
public Map<String, Object> validate(@RequestParam(defaultValue = "角色维护") String template) throws Exception {
|
||||
List<String> notes = new ArrayList<>();
|
||||
Map<String, Object> schema = converter.convert(loadXml(template), notes);
|
||||
|
||||
JsonNode node = mapper.valueToTree(schema);
|
||||
Set<ValidationMessage> errors = officialSchema().validate(node);
|
||||
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("template", template);
|
||||
resp.put("schemaValid", errors.isEmpty());
|
||||
resp.put("validationErrors", errors.stream()
|
||||
.map(ValidationMessage::getMessage).limit(20).collect(Collectors.toList()));
|
||||
resp.put("mappingNotes", notes);
|
||||
resp.put("schema", schema);
|
||||
return resp;
|
||||
}
|
||||
|
||||
/** 校验任意 amis 页面 schema(WS5:AI 生成的 schema 走这里过闸)。 */
|
||||
@org.springframework.web.bind.annotation.PostMapping("/api/poc/validate-schema")
|
||||
public Map<String, Object> validateSchema(@org.springframework.web.bind.annotation.RequestBody JsonNode schema) throws Exception {
|
||||
Set<ValidationMessage> errors = officialSchema().validate(schema);
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("schemaValid", errors.isEmpty());
|
||||
resp.put("validationErrors", errors.stream()
|
||||
.map(ValidationMessage::getMessage).limit(20).collect(Collectors.toList()));
|
||||
return resp;
|
||||
}
|
||||
|
||||
private String loadXml(String template) {
|
||||
return jdbcTemplate.queryForList(
|
||||
"SELECT xml::text FROM VIEW_TEMPLATE WHERE NAME=? AND xml IS NOT NULL ORDER BY length(xml::text) ASC",
|
||||
String.class, template)
|
||||
.get(0);
|
||||
}
|
||||
|
||||
private JsonSchema officialSchema() throws Exception {
|
||||
if (amisSchema == null) {
|
||||
synchronized (this) {
|
||||
if (amisSchema == null) {
|
||||
JsonNode schemaNode = mapper.readTree(
|
||||
getClass().getResourceAsStream("/amis-schema-6.13.0.json"));
|
||||
// amis 官方 schema 大量使用 {"$ref":..., "additionalProperties":true} 的
|
||||
// 兄弟键覆盖写法——这是 VSCode/Monaco 的宽松合并语义;严格 draft-07 下
|
||||
// 兄弟键被忽略,被引用定义里的 additionalProperties:false 会拒绝一切输入。
|
||||
// 预处理:全局剥除 additionalProperties:false,保留类型/必填/结构校验。
|
||||
// 边界:未知渲染器类型无法被识别(schema 含 Loose 宽松分支,属设计内)。
|
||||
stripStrictAdditionalProperties(schemaNode);
|
||||
amisSchema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)
|
||||
.getSchema(schemaNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return amisSchema;
|
||||
}
|
||||
|
||||
private static void stripStrictAdditionalProperties(JsonNode node) {
|
||||
if (node instanceof com.fasterxml.jackson.databind.node.ObjectNode obj) {
|
||||
JsonNode ap = obj.get("additionalProperties");
|
||||
if (ap != null && ap.isBoolean() && !ap.asBoolean()) {
|
||||
obj.remove("additionalProperties");
|
||||
}
|
||||
obj.properties().forEach(e -> stripStrictAdditionalProperties(e.getValue()));
|
||||
} else if (node instanceof com.fasterxml.jackson.databind.node.ArrayNode arr) {
|
||||
arr.forEach(AmisSchemaController::stripStrictAdditionalProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.EnumerateItem;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
|
||||
/**
|
||||
* 字典接口:模板 search@field 的 comboboxid(枚举类型)→ amis select options。
|
||||
* 数据来自引擎 getEnumerateItems(SYS_ENUMERATE 表)。
|
||||
*/
|
||||
@RestController
|
||||
public class DictController {
|
||||
|
||||
private final DataDicService dataDicService;
|
||||
|
||||
public DictController(DataDicService dataDicService) {
|
||||
this.dataDicService = dataDicService;
|
||||
}
|
||||
|
||||
@GetMapping("/api/poc/dict/{type}")
|
||||
public Map<String, Object> dict(@PathVariable String type) {
|
||||
List<Map<String, Object>> options = new ArrayList<>();
|
||||
List<EnumerateItem> items = dataDicService.getEnumerateItems(type);
|
||||
if (items != null) {
|
||||
for (EnumerateItem i : items) {
|
||||
Map<String, Object> o = new LinkedHashMap<>();
|
||||
o.put("label", i.getCodeDes());
|
||||
o.put("value", i.getCodeValue());
|
||||
options.add(o);
|
||||
}
|
||||
}
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
resp.put("data", Map.of("options", options));
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
/**
|
||||
* WS1 冒烟接口:直接驱动移植后的 POJOCRUDService 引擎。
|
||||
* 响应封装为 amis CRUD 约定格式 {status, msg, data:{items,total}},WS2 直接对接。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/entity")
|
||||
public class EntityController {
|
||||
|
||||
private final POJOCRUDService pojoCRUDService;
|
||||
|
||||
public EntityController(POJOCRUDService pojoCRUDService) {
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
}
|
||||
|
||||
/** 分页查询:GET /api/entity/{table}/list?page=1&perPage=10&列名=值(amis filter 透传) */
|
||||
@GetMapping("/{table}/list")
|
||||
public Map<String, Object> list(@PathVariable String table,
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "10") int perPage,
|
||||
@RequestParam Map<String, String> allParams) {
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
Map<String, Object> cond = new HashMap<>();
|
||||
cond.put(POJOCRUDService.PAGE_START, (page - 1) * perPage);
|
||||
cond.put(POJOCRUDService.PAGE_SIZE, perPage);
|
||||
// amis filter 表单值透传为引擎查询条件(保留大写列名约定,跳过分页参数与空值)
|
||||
allParams.forEach((k, v) -> {
|
||||
if (!"page".equals(k) && !"perPage".equals(k) && v != null && !v.isBlank()) {
|
||||
cond.put(k.toUpperCase(), v);
|
||||
}
|
||||
});
|
||||
|
||||
Map<String, Object> result = pojoCRUDService.listSelect(cond, table.toUpperCase(), ctx);
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("items", toRows(result.get(POJOCRUDService.LIST_RESULT)));
|
||||
data.put("total", result.get(POJOCRUDService.PAGE_COUNT));
|
||||
|
||||
Map<String, Object> resp = new HashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
resp.put("data", data);
|
||||
return resp;
|
||||
}
|
||||
|
||||
/** 单条加载:GET /api/entity/{table}/{id} */
|
||||
@GetMapping("/{table}/{id}")
|
||||
public Map<String, Object> load(@PathVariable String table, @PathVariable String id) {
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
Object pojo = pojoCRUDService.loadPOJO(id, table.toUpperCase(), ctx, false);
|
||||
Map<String, Object> resp = new HashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "");
|
||||
resp.put("data", pojo instanceof GeneralPOJO p ? toRow(p) : pojo);
|
||||
return resp;
|
||||
}
|
||||
|
||||
/** GeneralPOJO 值存于内部数组(非 bean getter),手工展开为平面 map 供 JSON 序列化。 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> toRows(Object listResult) {
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
if (listResult instanceof List<?> list) {
|
||||
for (Object o : list) {
|
||||
if (o instanceof GeneralPOJO p) {
|
||||
rows.add(toRow(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
private Map<String, Object> toRow(GeneralPOJO p) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("_id", p.get_ID());
|
||||
for (int i = 0; i < p.get_ColumnCount(); i++) {
|
||||
row.put(p.get_ColumnName(i), p.get_Value(i));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.dataDic.bean.Entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
/**
|
||||
* 元数据 API(未来 MCP 工具面的雏形,WS5 AI 闭环用):
|
||||
* POST /api/meta/entity 创建实体(元数据 + 动态物理表),
|
||||
* DELETE /api/meta/entity/{table} 删除实体(表 + 元数据)。
|
||||
*
|
||||
* 请求体示例:
|
||||
* {"tablename":"EIP4AI_DEMO","name":"演示实体","attributes":[
|
||||
* {"column":"TITLE","display":"标题","type":"string","length":200,"mandatory":true},
|
||||
* {"column":"AMOUNT","display":"金额","type":"number"},
|
||||
* {"column":"QTY","display":"数量","type":"integer"},
|
||||
* {"column":"HAPPENED","display":"发生日期","type":"date"},
|
||||
* {"column":"DONE","display":"已完成","type":"boolean"}]}
|
||||
* 标准列(主键/审计/版本)自动补齐,调用方不要自带。
|
||||
*/
|
||||
@RestController
|
||||
public class MetaController {
|
||||
|
||||
private final DataDicService dataDicService;
|
||||
private final POJOCRUDService pojoCRUDService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public MetaController(DataDicService dataDicService,
|
||||
POJOCRUDService pojoCRUDService,
|
||||
JdbcTemplate jdbcTemplate) {
|
||||
this.dataDicService = dataDicService;
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建实体:写入 SYS_ENTITY/SYS_ENTITYATTRIBUTE 元数据并动态创建物理表")
|
||||
@PostMapping("/api/meta/entity")
|
||||
public Map<String, Object> createEntity(@RequestBody Map<String, Object> req) {
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
String table = String.valueOf(req.get("tablename")).toUpperCase();
|
||||
if (!table.matches("[A-Z][A-Z0-9_]{2,40}")) {
|
||||
return err("tablename 不合法(大写字母数字下划线): " + table);
|
||||
}
|
||||
if (dataDicService.getSYSEntityByTableName(table) != null) {
|
||||
return err("实体已存在: " + table);
|
||||
}
|
||||
|
||||
// 实体行:克隆 SYS_USERGROUP 的实体元数据做载体(与 write-test 同法)
|
||||
Entity tplEnt = (Entity) dataDicService.getSYSEntityByTableName("SYS_USERGROUP");
|
||||
GeneralPOJO tplPo = pojoCRUDService.loadPOJO(idOf(tplEnt), "SYS_ENTITY", ctx, false);
|
||||
Map<String, Object> entityMap = copyValues(tplPo);
|
||||
entityMap.remove("SYS_ENTITY_ID");
|
||||
entityMap.put("TABLENAME", table);
|
||||
entityMap.put("NAME", String.valueOf(req.getOrDefault("name", table)));
|
||||
entityMap.put("DESCRIPTION", "AI 闭环创建 (eip4-poc WS5)");
|
||||
GeneralPOJO newEntity = (GeneralPOJO) dataDicService.save(entityMap, ctx);
|
||||
String entityId = newEntity.get_ID();
|
||||
|
||||
// 属性模板:取 SYS_USERGROUP.NAME 属性行做默认值载体
|
||||
Map<String, Object> attrTpl = loadAttrTemplate(idOf(tplEnt));
|
||||
|
||||
List<Map<String, Object>> created = new ArrayList<>();
|
||||
// 标准列
|
||||
created.add(saveAttr(attrTpl, entityId, table + "_ID", "主键", "CHAR", 36, true, true, ctx));
|
||||
created.add(saveAttr(attrTpl, entityId, "VERSION", "版本", "INTEGER", null, true, false, ctx));
|
||||
created.add(saveAttr(attrTpl, entityId, "CREATETIME", "创建时间", "TIME", null, true, false, ctx));
|
||||
created.add(saveAttr(attrTpl, entityId, "UPDATETIME", "更新时间", "TIME", null, true, false, ctx));
|
||||
created.add(saveAttr(attrTpl, entityId, "CREATEBY", "创建人", "NVARCHAR", 36, true, false, ctx));
|
||||
created.add(saveAttr(attrTpl, entityId, "UPDATEBY", "更新人", "NVARCHAR", 36, true, false, ctx));
|
||||
created.add(saveAttr(attrTpl, entityId, "ISACTIVE", "是否有效", "BOOLEAN", null, true, false, ctx));
|
||||
|
||||
// 业务列
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> attrs = (List<Map<String, Object>>) req.get("attributes");
|
||||
if (attrs != null) {
|
||||
for (Map<String, Object> a : attrs) {
|
||||
String col = String.valueOf(a.get("column")).toUpperCase();
|
||||
String type = String.valueOf(a.getOrDefault("type", "string"));
|
||||
String ref = switch (type) {
|
||||
case "integer" -> "INTEGER";
|
||||
case "number" -> "DECIMAL";
|
||||
case "date" -> "DATE";
|
||||
case "datetime" -> "TIME";
|
||||
case "boolean" -> "BOOLEAN";
|
||||
default -> "NVARCHAR";
|
||||
};
|
||||
Integer len = "NVARCHAR".equals(ref)
|
||||
? (a.get("length") instanceof Number n ? n.intValue() : 100) : null;
|
||||
boolean mandatory = Boolean.TRUE.equals(a.get("mandatory"));
|
||||
created.add(saveAttr(attrTpl, entityId,
|
||||
col, String.valueOf(a.getOrDefault("display", col)), ref, len, mandatory, false, ctx));
|
||||
}
|
||||
}
|
||||
|
||||
// 动态建表
|
||||
Entity newEnt = (Entity) dataDicService.getSYSEntity(entityId);
|
||||
String ddl = newEnt.createTableSql();
|
||||
dataDicService.executeCreateSql(ddl);
|
||||
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "created");
|
||||
resp.put("data", Map.of(
|
||||
"entityId", entityId,
|
||||
"tablename", table,
|
||||
"attributeCount", created.size(),
|
||||
"listApi", "/api/entity/" + table + "/list"));
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Operation(summary = "删除实体:drop 物理表并清除元数据(仅限 EIP4AI_ 前缀,防误删)")
|
||||
@DeleteMapping("/api/meta/entity/{table}")
|
||||
public Map<String, Object> dropEntity(@PathVariable String table) {
|
||||
String t = table.toUpperCase();
|
||||
if (!t.startsWith("EIP4")) {
|
||||
return err("仅允许删除 EIP4 前缀的测试实体");
|
||||
}
|
||||
jdbcTemplate.execute("DROP TABLE IF EXISTS " + t);
|
||||
int a = jdbcTemplate.update(
|
||||
"DELETE FROM SYS_ENTITYATTRIBUTE WHERE ENTITYID IN (SELECT SYS_ENTITY_ID FROM SYS_ENTITY WHERE TABLENAME=?)", t);
|
||||
int e = jdbcTemplate.update("DELETE FROM SYS_ENTITY WHERE TABLENAME=?", t);
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", "dropped attrs=" + a + " entity=" + e);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private Map<String, Object> saveAttr(Map<String, Object> tpl, String entityId, String col,
|
||||
String display, String ref, Integer len,
|
||||
boolean mandatory, boolean isKey, Properties ctx) {
|
||||
Map<String, Object> m = new HashMap<>(tpl);
|
||||
m.remove("SYS_ENTITYATTRIBUTE_ID");
|
||||
m.put("ENTITYID", entityId);
|
||||
m.put("COLUMNNAME", col);
|
||||
m.put("DISPLAYNAME", display);
|
||||
m.put("REFERENCEID", ref);
|
||||
m.put("ISMANDATORY", mandatory ? 1 : 0);
|
||||
m.put("ISKEY", isKey ? 1 : 0);
|
||||
m.put("ISIDENTIFIER", 0);
|
||||
m.put("ISCOMBIDENTIFIER", 0);
|
||||
m.put("ISREADONLY", 0);
|
||||
if (len != null) {
|
||||
m.put("FIELDLENGTH", len);
|
||||
} else {
|
||||
m.remove("FIELDLENGTH");
|
||||
}
|
||||
pojoCRUDService.save(m, "SYS_ENTITYATTRIBUTE", ctx);
|
||||
return Map.of("column", col, "type", ref);
|
||||
}
|
||||
|
||||
private Map<String, Object> loadAttrTemplate(String tplEntityId) {
|
||||
Map<String, Object> cond = new HashMap<>();
|
||||
cond.put("ENTITYID", tplEntityId);
|
||||
cond.put("COLUMNNAME", "NAME");
|
||||
cond.put(POJOCRUDService.PAGE_START, 0);
|
||||
cond.put(POJOCRUDService.PAGE_SIZE, 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GeneralPOJO> rows = (List<GeneralPOJO>) pojoCRUDService
|
||||
.listSelect(cond, "SYS_ENTITYATTRIBUTE", UserSession.getAdmin())
|
||||
.get(POJOCRUDService.LIST_RESULT);
|
||||
return copyValues(rows.get(0));
|
||||
}
|
||||
|
||||
private static String idOf(Entity e) {
|
||||
return e.getPo().get_ID() != null ? e.getPo().get_ID()
|
||||
: (String) e.getPo().get_Value("SYS_ENTITY_ID");
|
||||
}
|
||||
|
||||
private static Map<String, Object> copyValues(GeneralPOJO po) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
for (int i = 0; i < po.get_ColumnCount(); i++) {
|
||||
Object v = po.get_Value(i);
|
||||
if (v != null) {
|
||||
m.put(po.get_ColumnName(i), v);
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Map<String, Object> err(String msg) {
|
||||
Map<String, Object> r = new LinkedHashMap<>();
|
||||
r.put("status", 1);
|
||||
r.put("msg", msg);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
/**
|
||||
* WS1 主子表级联验证:SYS_DATA_LOG(主) → DETAILLIST → SYS_DATA_LOGITEM(子)。
|
||||
* 验证 GeneralPO 对 LIST 列 List<Map> 载荷的子表转换、外键自动回填、
|
||||
* 层级回读、updateSubTable 的 diff 语义(保留改/移除删)与级联删除。
|
||||
* 测试行以 COLUMNNAME=EIP4POC_* 标记,结束后行数断言复原,残留兜底清理。
|
||||
*/
|
||||
@RestController
|
||||
public class PocMasterSubController {
|
||||
|
||||
// 首选 SYS_DATA_LOG 对在 diff 更新时暴露了选表不当:其子表为 insert-only 设计
|
||||
// (无 UPDATETIME/UPDATEBY 物理列,而引擎 updatePO 无条件追加审计列——老系统行为一致)。
|
||||
// 改用带标准审计列的考勤日志主子对。
|
||||
private static final String MASTER = "HR_ATTENDLOG";
|
||||
private static final String CHILD = "HR_ATTENDLOGDETAIL";
|
||||
private static final String LIST_COL = "ATTENDDETAILS";
|
||||
private static final String CHILD_FK = "HR_ATTENDLOGID";
|
||||
|
||||
private final POJOCRUDService pojoCRUDService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public PocMasterSubController(POJOCRUDService pojoCRUDService, JdbcTemplate jdbcTemplate) {
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@PostMapping("/api/poc/mastersub-test")
|
||||
public Map<String, Object> masterSubTest(@RequestParam(defaultValue = "false") boolean keep) {
|
||||
List<Map<String, Object>> report = new ArrayList<>();
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
String masterId = null;
|
||||
long mBefore = count(MASTER, null, null);
|
||||
long cBefore = count(CHILD, null, null);
|
||||
|
||||
try {
|
||||
// 1. 取真实主行做载荷模板
|
||||
Map<String, Object> cond = new HashMap<>();
|
||||
cond.put(POJOCRUDService.PAGE_START, 0);
|
||||
cond.put(POJOCRUDService.PAGE_SIZE, 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GeneralPOJO> tpl = (List<GeneralPOJO>) pojoCRUDService
|
||||
.listSelect(cond, MASTER, ctx).get(POJOCRUDService.LIST_RESULT);
|
||||
Map<String, Object> master = copyValues(tpl.get(0));
|
||||
master.remove(MASTER + "_ID");
|
||||
// 组合唯一约束 USERID+ATTENDDATE:考勤日期改为远未来值避免与源行冲突
|
||||
// (DATE 显示类型在引擎内为 joda DateTime)
|
||||
master.put("ATTENDDATE", new org.joda.time.DateTime(2100, 1, 1, 0, 0));
|
||||
|
||||
// 2. 挂 2 个子行(FK 不传,验证引擎自动回填)。
|
||||
// 标记/断言列用 TIMES:UNITNAME 在元数据存在但物理表缺失(库内漂移),不可用
|
||||
master.put(LIST_COL, List.of(childMap(8), childMap(9)));
|
||||
|
||||
GeneralPOJO saved = pojoCRUDService.save(master, MASTER, ctx);
|
||||
masterId = saved.get_ID();
|
||||
long fkOk = count(CHILD, CHILD_FK, masterId);
|
||||
step(report, "1-级联INSERT", masterId != null && fkOk == 2,
|
||||
"masterId=" + masterId + ", 子行(FK自动回填)=" + fkOk);
|
||||
|
||||
// 3. 层级回读
|
||||
GeneralPOJO loaded = pojoCRUDService.loadPOJO(masterId, MASTER, ctx, true);
|
||||
Object listVal = loaded.get_Value(LIST_COL);
|
||||
int loadedChildren = (listVal instanceof List<?> l) ? l.size() : -1;
|
||||
step(report, "2-层级回读", loadedChildren == 2, "DETAILLIST 子行数=" + loadedChildren);
|
||||
|
||||
// 4. diff 更新:保留第 1 个(改值),移除第 2 个
|
||||
String keepId = null;
|
||||
if (listVal instanceof List<?> l) {
|
||||
for (Object o : l) {
|
||||
GeneralPOJO c = (GeneralPOJO) o;
|
||||
if (String.valueOf(c.get_Value("TIMES")).startsWith("8")) {
|
||||
keepId = c.get_ID();
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, Object> keepChild = childMap(7);
|
||||
keepChild.put(CHILD + "_ID", keepId);
|
||||
Map<String, Object> upd = new HashMap<>();
|
||||
upd.put(MASTER + "_ID", masterId);
|
||||
upd.put(LIST_COL, List.of(keepChild));
|
||||
pojoCRUDService.update(upd, MASTER, ctx);
|
||||
|
||||
long after = count(CHILD, CHILD_FK, masterId);
|
||||
String keptId = jdbcTemplate.queryForObject(
|
||||
"SELECT " + CHILD + "_ID FROM " + CHILD + " WHERE " + CHILD_FK + "=? LIMIT 1",
|
||||
String.class, masterId);
|
||||
String newTimes = jdbcTemplate.queryForObject(
|
||||
"SELECT TIMES FROM " + CHILD + " WHERE " + CHILD_FK + "=? LIMIT 1",
|
||||
String.class, masterId);
|
||||
boolean sameRowUpdated = keepId != null && keptId != null && keptId.trim().equals(keepId.trim());
|
||||
step(report, "3-子表diff更新", after == 1 && newTimes != null && newTimes.startsWith("7"),
|
||||
"更新后子行=" + after + ", TIMES=" + newTimes
|
||||
+ ", 保留行为同一物理行=" + sameRowUpdated + "(保留改/移除删)");
|
||||
|
||||
// 5. 级联删除
|
||||
if (!keep) {
|
||||
pojoCRUDService.delete(masterId, MASTER, ctx);
|
||||
long mLeft = count(MASTER, MASTER + "_ID", masterId);
|
||||
long cLeft = count(CHILD, CHILD_FK, masterId);
|
||||
step(report, "4-级联DELETE", mLeft == 0 && cLeft == 0,
|
||||
"主行残留=" + mLeft + ", 子行残留=" + cLeft);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
step(report, "EXCEPTION", false, e.getClass().getSimpleName() + ": " + e.getMessage());
|
||||
} finally {
|
||||
if (!keep && masterId != null) {
|
||||
// 兜底物理清理(引擎若为逻辑删,这里保证测试库复原)
|
||||
int c = jdbcTemplate.update("DELETE FROM " + CHILD + " WHERE " + CHILD_FK + "=?", masterId);
|
||||
int m = jdbcTemplate.update("DELETE FROM " + MASTER + " WHERE " + MASTER + "_ID=?", masterId);
|
||||
long mAfter = count(MASTER, null, null);
|
||||
long cAfter = count(CHILD, null, null);
|
||||
step(report, "5-复原断言", mAfter == mBefore && cAfter == cBefore,
|
||||
"兜底清理 m=" + m + " c=" + c + ";行数 主 " + mBefore + "→" + mAfter
|
||||
+ " 子 " + cBefore + "→" + cAfter);
|
||||
}
|
||||
}
|
||||
|
||||
boolean allOk = report.stream().allMatch(r -> Boolean.TRUE.equals(r.get("ok")));
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("passed", allOk);
|
||||
resp.put("steps", report);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private static Map<String, Object> childMap(int times) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
m.put("CHECKATTENDANCESTATE", 4);
|
||||
m.put("TIMES", new java.math.BigDecimal(times));
|
||||
m.put("VERSION", 0);
|
||||
return m;
|
||||
}
|
||||
|
||||
private long count(String table, String col, String val) {
|
||||
Long n = (col == null)
|
||||
? jdbcTemplate.queryForObject("SELECT COUNT(*) FROM " + table, Long.class)
|
||||
: jdbcTemplate.queryForObject("SELECT COUNT(*) FROM " + table + " WHERE " + col + "=?", Long.class, val);
|
||||
return n == null ? -1 : n;
|
||||
}
|
||||
|
||||
private static Map<String, Object> copyValues(GeneralPOJO po) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
for (int i = 0; i < po.get_ColumnCount(); i++) {
|
||||
Object v = po.get_Value(i);
|
||||
if (v != null) {
|
||||
m.put(po.get_ColumnName(i), v);
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private static void step(List<Map<String, Object>> report, String s, boolean ok, String d) {
|
||||
Map<String, Object> r = new LinkedHashMap<>();
|
||||
r.put("step", s);
|
||||
r.put("ok", ok);
|
||||
r.put("detail", d);
|
||||
report.add(r);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.script.SimpleBindings;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.dataDic.binding.ScriptingEnginesManager;
|
||||
|
||||
import groovy.lang.Closure;
|
||||
|
||||
/**
|
||||
* WS3 脚本验证:从客户库 VIEW_TEMPLATE 取**真实存量 Groovy 脚本**,
|
||||
* 经移植后的 ScriptingEnginesManager(JSR-223 + Groovy 4 + 编译缓存)执行。
|
||||
* UI 函数(enableButton 等)以 facade 闭包注入,脚本对 UI 的操作被捕获为
|
||||
* 指令列表——即「脚本文本零修改,换 facade 实现」方案的最小实证。
|
||||
*/
|
||||
@RestController
|
||||
public class PocScriptTestController {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public PocScriptTestController(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@PostMapping("/api/poc/script-test")
|
||||
public Map<String, Object> scriptTest(@RequestParam(defaultValue = "通知管理归档") String template) throws Exception {
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
|
||||
// 1. 取真实模板 XML 并抽出脚本
|
||||
List<String> xmls = jdbcTemplate.queryForList(
|
||||
"SELECT xml::text FROM VIEW_TEMPLATE WHERE NAME=? AND xml IS NOT NULL", String.class, template);
|
||||
String script = null;
|
||||
for (String xml : xmls) {
|
||||
Document doc = DocumentHelper.parseText(xml);
|
||||
for (org.dom4j.Node n : doc.selectNodes("//script")) {
|
||||
if (n instanceof Element e) {
|
||||
// getTextTrim 会压扁换行破坏 Groovy 源码,必须用 getText 保留原文
|
||||
String t = e.getText().strip();
|
||||
if (t.length() > 10) {
|
||||
script = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (script != null) break;
|
||||
}
|
||||
if (script == null) {
|
||||
resp.put("passed", false);
|
||||
resp.put("error", "模板无脚本: " + template);
|
||||
return resp;
|
||||
}
|
||||
resp.put("template", template);
|
||||
resp.put("scriptSource", script);
|
||||
|
||||
// 2. 用两组行数据分别执行,验证分支行为
|
||||
Map<String, Object> runs = new LinkedHashMap<>();
|
||||
for (String state : new String[]{"待归档", "已归档"}) {
|
||||
List<String> captured = new ArrayList<>();
|
||||
|
||||
Map<String, Object> item = new HashMap<>();
|
||||
item.put("ISPLACE", state);
|
||||
|
||||
SimpleBindings bindings = new SimpleBindings();
|
||||
bindings.put("item", item);
|
||||
// facade:原 Vaadin 端 enableButton(name, enabled) → 捕获为 amis 指令
|
||||
bindings.put("enableButton", new Closure<Object>(null) {
|
||||
@SuppressWarnings("unused")
|
||||
public Object doCall(String name, boolean enabled) {
|
||||
captured.add("{\"actionType\":\"setButtonState\",\"button\":\"" + name + "\",\"enabled\":" + enabled + "}");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
ScriptingEnginesManager.getScriptingEnginesManager()
|
||||
.evaluateGroovy("poc:" + template + ":" + state, script, bindings);
|
||||
runs.put("ISPLACE=" + state, captured);
|
||||
}
|
||||
resp.put("runs", runs);
|
||||
resp.put("passed", true);
|
||||
resp.put("note", "脚本文本零修改,Groovy 4/JDK17 编译缓存执行,UI 调用被 facade 捕获为前端指令");
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
package com.eip4.platform.metadata.web;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.dataDic.bean.Entity;
|
||||
|
||||
/**
|
||||
* WS1 写路径一键验证(PoC 方案 3.1 步骤 7):
|
||||
* 克隆既有小实体的元数据 → 动态生成并执行 CREATE TABLE → CRUD 往返 → 全量清理。
|
||||
* 所有产物以 target 表名隔离(默认 EIP4POCTEST),结束后物理表与元数据一并删除。
|
||||
*/
|
||||
@RestController
|
||||
public class PocWriteTestController {
|
||||
|
||||
private final DataDicService dataDicService;
|
||||
private final POJOCRUDService pojoCRUDService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public PocWriteTestController(DataDicService dataDicService,
|
||||
POJOCRUDService pojoCRUDService,
|
||||
JdbcTemplate jdbcTemplate) {
|
||||
this.dataDicService = dataDicService;
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@PostMapping("/api/poc/write-test")
|
||||
public Map<String, Object> writeTest(@RequestParam(defaultValue = "SYS_USERGROUP") String source,
|
||||
@RequestParam(defaultValue = "EIP4POCTEST") String target) {
|
||||
List<Map<String, Object>> report = new ArrayList<>();
|
||||
Properties ctx = UserSession.getAdmin();
|
||||
String newEntityId = null;
|
||||
boolean tableCreated = false;
|
||||
|
||||
try {
|
||||
// 0. 防御:目标残留先清掉
|
||||
cleanup(target, null, report, "0-预清理");
|
||||
|
||||
// 1. 克隆 SYS_ENTITY 元数据
|
||||
Entity src = (Entity) dataDicService.getSYSEntityByTableName(source);
|
||||
if (src == null) {
|
||||
return fail(report, "source 实体不存在: " + source);
|
||||
}
|
||||
String srcEntityId = pojoIdOf(src);
|
||||
GeneralPOJO srcPo = loadEntityPojo(srcEntityId);
|
||||
Map<String, Object> entityMap = copyValues(srcPo);
|
||||
entityMap.remove("SYS_ENTITY_ID");
|
||||
entityMap.put("TABLENAME", target);
|
||||
entityMap.put("NAME", "EIP4 PoC 写路径测试");
|
||||
entityMap.put("DESCRIPTION", "eip4-poc write-test,自动创建自动删除");
|
||||
GeneralPOJO newEntity = (GeneralPOJO) dataDicService.save(entityMap, ctx);
|
||||
newEntityId = newEntity.get_ID();
|
||||
step(report, "1-克隆实体元数据", true, "SYS_ENTITY_ID=" + newEntityId);
|
||||
|
||||
// 2. 克隆 SYS_ENTITYATTRIBUTE(用 listSelect 条件查询,读路径已全量验证)
|
||||
Map<String, Object> attrCond = new HashMap<>();
|
||||
attrCond.put("ENTITYID", srcEntityId);
|
||||
attrCond.put(POJOCRUDService.PAGE_START, 0);
|
||||
attrCond.put(POJOCRUDService.PAGE_SIZE, 200);
|
||||
Map<String, Object> attrRes = pojoCRUDService.listSelect(attrCond, "SYS_ENTITYATTRIBUTE", ctx);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GeneralPOJO> attrs = (List<GeneralPOJO>) attrRes.get(POJOCRUDService.LIST_RESULT);
|
||||
int n = 0;
|
||||
for (GeneralPOJO a : attrs) {
|
||||
Map<String, Object> am = copyValues(a);
|
||||
am.remove("SYS_ENTITYATTRIBUTE_ID");
|
||||
am.put("ENTITYID", newEntityId);
|
||||
// 源表主键属性列随表名改名(EIP3 设计器建实体时也按 {表名}_ID 生成)
|
||||
if ((source + "_ID").equalsIgnoreCase(String.valueOf(am.get("COLUMNNAME")))) {
|
||||
am.put("COLUMNNAME", target + "_ID");
|
||||
}
|
||||
try {
|
||||
pojoCRUDService.save(am, "SYS_ENTITYATTRIBUTE", ctx);
|
||||
} catch (Exception ex) {
|
||||
step(report, "2-克隆属性元数据", false,
|
||||
"失败于第" + (n + 1) + "个属性, map键=" + am.keySet() + ", err=" + ex.getMessage());
|
||||
throw ex;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
step(report, "2-克隆属性元数据", true, n + " 个属性");
|
||||
|
||||
// 3. 动态建表(引擎生成 DDL → 执行)
|
||||
Entity newEnt = (Entity) dataDicService.getSYSEntity(newEntityId);
|
||||
String ddl = newEnt.createTableSql();
|
||||
dataDicService.executeCreateSql(ddl);
|
||||
tableCreated = true;
|
||||
Integer exists = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM information_schema.tables WHERE LOWER(table_name)=LOWER(?)",
|
||||
Integer.class, target);
|
||||
step(report, "3-动态建表", exists != null && exists > 0,
|
||||
ddl.lines().findFirst().orElse("") + " ... (表存在=" + exists + ")");
|
||||
|
||||
// 4. INSERT:取源表真实一行的值作为载荷(外键值天然合法),引擎生成新 UUID 主键
|
||||
Map<String, Object> oneCond = new HashMap<>();
|
||||
oneCond.put(POJOCRUDService.PAGE_START, 0);
|
||||
oneCond.put(POJOCRUDService.PAGE_SIZE, 1);
|
||||
Map<String, Object> oneRes = pojoCRUDService.listSelect(oneCond, source, ctx);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GeneralPOJO> srcRows = (List<GeneralPOJO>) oneRes.get(POJOCRUDService.LIST_RESULT);
|
||||
if (srcRows == null || srcRows.isEmpty()) {
|
||||
return fail(report, "source 表无数据可作插入载荷: " + source);
|
||||
}
|
||||
Map<String, Object> row = copyValues(srcRows.get(0));
|
||||
row.remove(source + "_ID");
|
||||
GeneralPOJO saved = pojoCRUDService.save(row, target, ctx);
|
||||
String rowId = saved.get_ID();
|
||||
step(report, "4-INSERT", rowId != null, "_id=" + rowId);
|
||||
|
||||
// 选一个 NVARCHAR 列做回读/更新断言列
|
||||
String strCol = attrs.stream()
|
||||
.filter(a -> "NVARCHAR".equals(a.get_Value("REFERENCEID")))
|
||||
.map(a -> (String) a.get_Value("COLUMNNAME"))
|
||||
.filter(c -> !"CREATEBY".equals(c) && !"UPDATEBY".equals(c))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
// 5. SELECT 回读
|
||||
GeneralPOJO loaded = pojoCRUDService.loadPOJO(rowId, target, ctx, false);
|
||||
boolean loadOk = loaded != null && (strCol == null
|
||||
|| String.valueOf(loaded.get_Value(strCol)).equals(String.valueOf(row.get(strCol))));
|
||||
step(report, "5-SELECT回读", loadOk, "断言列=" + strCol + " 值=" + (loaded != null ? loaded.get_Value(strCol) : null));
|
||||
|
||||
// 6. UPDATE
|
||||
boolean updOk;
|
||||
if (strCol != null) {
|
||||
Map<String, Object> upd = new HashMap<>();
|
||||
upd.put(target + "_ID", rowId);
|
||||
upd.put(strCol, "eip4poc-updated");
|
||||
pojoCRUDService.update(upd, target, ctx);
|
||||
GeneralPOJO re = pojoCRUDService.loadPOJO(rowId, target, ctx, false);
|
||||
updOk = re != null && "eip4poc-updated".equals(re.get_Value(strCol));
|
||||
} else {
|
||||
updOk = true;
|
||||
}
|
||||
step(report, "6-UPDATE", updOk, strCol + " → eip4poc-updated " + (updOk ? "回读一致" : "未生效"));
|
||||
|
||||
// 7. DELETE
|
||||
pojoCRUDService.delete(rowId, target, ctx);
|
||||
Integer left = jdbcTemplate.queryForObject(
|
||||
"SELECT COUNT(*) FROM " + target, Integer.class);
|
||||
step(report, "7-DELETE", left != null,
|
||||
"删除后剩余行数=" + left + "(逻辑删或物理删以引擎行为为准)");
|
||||
|
||||
} catch (Exception e) {
|
||||
step(report, "EXCEPTION", false, e.getClass().getSimpleName() + ": " + e.getMessage());
|
||||
} finally {
|
||||
cleanup(target, newEntityId, report, "8-清理");
|
||||
}
|
||||
|
||||
boolean allOk = report.stream()
|
||||
.filter(r -> !String.valueOf(r.get("step")).contains("清理"))
|
||||
.allMatch(r -> Boolean.TRUE.equals(r.get("ok")));
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("passed", allOk);
|
||||
resp.put("steps", report);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private void cleanup(String target, String entityId, List<Map<String, Object>> report, String label) {
|
||||
StringBuilder detail = new StringBuilder();
|
||||
try {
|
||||
jdbcTemplate.execute("DROP TABLE IF EXISTS " + target);
|
||||
detail.append("drop table; ");
|
||||
} catch (Exception e) {
|
||||
detail.append("drop失败:").append(e.getMessage()).append("; ");
|
||||
}
|
||||
try {
|
||||
if (entityId != null) {
|
||||
jdbcTemplate.update("DELETE FROM SYS_ENTITYATTRIBUTE WHERE ENTITYID=?", entityId);
|
||||
jdbcTemplate.update("DELETE FROM SYS_ENTITY WHERE SYS_ENTITY_ID=?", entityId);
|
||||
detail.append("元数据已删");
|
||||
} else {
|
||||
int a = jdbcTemplate.update(
|
||||
"DELETE FROM SYS_ENTITYATTRIBUTE WHERE ENTITYID IN (SELECT SYS_ENTITY_ID FROM SYS_ENTITY WHERE TABLENAME=?)", target);
|
||||
int b = jdbcTemplate.update("DELETE FROM SYS_ENTITY WHERE TABLENAME=?", target);
|
||||
detail.append("残留元数据清理 attr=").append(a).append(" entity=").append(b);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
detail.append("元数据清理失败:").append(e.getMessage());
|
||||
}
|
||||
step(report, label, true, detail.toString());
|
||||
}
|
||||
|
||||
private GeneralPOJO loadEntityPojo(String entityId) {
|
||||
return pojoCRUDService.loadPOJO(entityId, "SYS_ENTITY", UserSession.getAdmin(), false);
|
||||
}
|
||||
|
||||
private static String pojoIdOf(Entity e) {
|
||||
return e.getPo().get_ID() != null ? e.getPo().get_ID()
|
||||
: (String) e.getPo().get_Value("SYS_ENTITY_ID");
|
||||
}
|
||||
|
||||
private static Map<String, Object> copyValues(GeneralPOJO po) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
for (int i = 0; i < po.get_ColumnCount(); i++) {
|
||||
Object v = po.get_Value(i);
|
||||
if (v != null) {
|
||||
m.put(po.get_ColumnName(i), v);
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private static void step(List<Map<String, Object>> report, String step, boolean ok, String detail) {
|
||||
Map<String, Object> r = new LinkedHashMap<>();
|
||||
r.put("step", step);
|
||||
r.put("ok", ok);
|
||||
r.put("detail", detail);
|
||||
report.add(r);
|
||||
}
|
||||
|
||||
private static Map<String, Object> fail(List<Map<String, Object>> report, String msg) {
|
||||
step(report, "ABORT", false, msg);
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("passed", false);
|
||||
resp.put("steps", report);
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
34161
platform-metadata/src/main/resources/amis-schema-6.13.0.json
Normal file
34161
platform-metadata/src/main/resources/amis-schema-6.13.0.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user