feat: add AI agent auto-development pipeline

This commit is contained in:
2026-06-17 07:32:54 +08:00
parent bad7e66b73
commit 3b4d3dbd24
66 changed files with 6136 additions and 12 deletions

View File

@@ -92,7 +92,7 @@ public class MetaController {
// 属性模板:取 SYS_USERGROUP.NAME 属性行做默认值载体
Map<String, Object> attrTpl = loadAttrTemplate(idOf(tplEnt));
List<Map<String, Object>> created = new ArrayList<>();
List<GeneralPOJO> 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));
@@ -125,9 +125,9 @@ public class MetaController {
}
}
// 动态建表
Entity newEnt = (Entity) dataDicService.getSYSEntity(entityId);
String ddl = newEnt.createTableSql();
// 动态建表前先清刚保存实体/属性带来的 POInfo 缓存,保证后续读写立即拿到新字段。
cacheInvalidator.evictByEntityId(entityId, table);
String ddl = createTableDdl(table, created);
dataDicService.executeCreateSql(ddl);
// P1-5:建表后按元数据补索引(外键 uuid 列 + UPDATETIME),引擎只建表不建索引
@@ -224,9 +224,9 @@ public class MetaController {
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) {
private GeneralPOJO 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);
@@ -243,8 +243,100 @@ public class MetaController {
} else {
m.remove("FIELDLENGTH");
}
pojoCRUDService.save(m, "SYS_ENTITYATTRIBUTE", ctx);
return Map.of("column", col, "type", ref);
return pojoCRUDService.save(m, "SYS_ENTITYATTRIBUTE", ctx);
}
static String createTableDdl(String table, List<GeneralPOJO> attrs) {
if (attrs == null || attrs.isEmpty()) {
throw new IllegalStateException("实体属性为空,无法建表: " + table);
}
StringBuilder sql = new StringBuilder();
StringBuilder unique = new StringBuilder();
StringBuilder combUnique = new StringBuilder();
sql.append("CREATE TABLE ").append(table).append("\n");
sql.append("(\n");
for (GeneralPOJO attr : attrs) {
appendColumnDdl(table, attr, sql, unique, combUnique);
}
sql.append(unique);
if (!combUnique.isEmpty()) {
sql.append(combUnique).append("), \n");
}
sql.append("primary key (").append(table).append("_ID)\n");
sql.append("); \n");
return sql.toString();
}
private static void appendColumnDdl(String table, GeneralPOJO attr, StringBuilder sql,
StringBuilder unique, StringBuilder combUnique) {
if (attr.get_ValueAsBoolean("ISREADONLY")) {
return;
}
String ref = value(attr, "REFERENCEID");
if ("LIST".equals(ref) || "BLOB".equals(ref) || "STATUS".equals(ref)) {
return;
}
String col = value(attr, "COLUMNNAME");
if (col == null || !col.matches("[A-Z][A-Z0-9_]{1,60}")) {
throw new IllegalStateException("实体字段名不合法: " + col);
}
if ("CREATEBY".equals(col) || "UPDATEBY".equals(col) || "ORGID".equals(col) || "DEPARTID".equals(col)) {
sql.append(col).append(" character(36) ");
} else if ("NVARCHAR".equals(ref) || "CODE".equals(ref)) {
int length = positiveInt(attr.get_Value("FIELDLENGTH"), 100);
sql.append(col).append(" character varying(").append(length).append(") ");
} else if ("INTEGER".equals(ref) || "BOOLEAN".equals(ref) || "ENUMERATE".equals(ref)) {
sql.append(col).append(" integer ");
} else if ("DECIMAL".equals(ref) || "MONEY".equals(ref)) {
sql.append(col).append(" numeric(18,6) ");
} else if ("DATE".equals(ref) || "TIME".equals(ref)) {
sql.append(col).append(" bigint ");
} else if ("CHAR".equals(ref)) {
sql.append(col).append(" character(36) ");
} else {
sql.append(col).append(" character(36) REFERENCES ").append(table);
}
if (attr.get_ValueAsBoolean("ISMANDATORY")) {
sql.append(" NOT NULL ");
}
String defValue = value(attr, "DEFAULTVALUE");
if (defValue != null && !defValue.isBlank()
&& ("INTEGER".equals(ref) || "BOOLEAN".equals(ref) || "DECIMAL".equals(ref) || "MONEY".equals(ref))) {
sql.append(" DEFAULT ").append(defValue);
}
sql.append(", \n");
if (attr.get_ValueAsBoolean("ISIDENTIFIER")) {
unique.append(" unique (").append(col).append("), \n");
} else if (attr.get_ValueAsBoolean("ISCOMBIDENTIFIER")) {
if (combUnique.isEmpty()) {
combUnique.append(" unique (");
} else {
combUnique.append(",");
}
combUnique.append(col);
}
}
private static int positiveInt(Object value, int defaultValue) {
if (value instanceof Number n && n.intValue() > 0) {
return n.intValue();
}
if (value != null) {
try {
int parsed = Integer.parseInt(value.toString());
if (parsed > 0) {
return parsed;
}
} catch (NumberFormatException ignore) {
return defaultValue;
}
}
return defaultValue;
}
private static String value(GeneralPOJO po, String column) {
Object value = po.get_Value(column);
return value == null ? null : value.toString();
}
private Map<String, Object> loadAttrTemplate(String tplEntityId) {

View File

@@ -0,0 +1,40 @@
package com.eip4.platform.metadata.web;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
class MetaControllerDdlTest {
@Test
@DisplayName("运行态实体 DDL 按旧引擎类型规则生成主键、字符串和布尔列")
void createTableDdlUsesSavedAttributes() {
String ddl = MetaController.createTableDdl("EIP4AI_RT_DEMO", List.of(
attr("EIP4AI_RT_DEMO_ID", "CHAR", null, true),
attr("NAME", "NVARCHAR", 100, true),
attr("ENABLED", "BOOLEAN", null, false)
));
assertTrue(ddl.contains("CREATE TABLE EIP4AI_RT_DEMO"));
assertTrue(ddl.contains("EIP4AI_RT_DEMO_ID character(36) NOT NULL"));
assertTrue(ddl.contains("NAME character varying(100) NOT NULL"));
assertTrue(ddl.contains("ENABLED integer"));
assertTrue(ddl.contains("primary key (EIP4AI_RT_DEMO_ID)"));
}
private static GeneralPOJO attr(String column, String referenceId, Integer length, boolean mandatory) {
GeneralPOJO po = mock(GeneralPOJO.class);
when(po.get_Value("COLUMNNAME")).thenReturn(column);
when(po.get_Value("REFERENCEID")).thenReturn(referenceId);
when(po.get_Value("FIELDLENGTH")).thenReturn(length);
when(po.get_ValueAsBoolean("ISMANDATORY")).thenReturn(mandatory);
return po;
}
}