diff --git a/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/controller/GeneratorController.java b/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/controller/GeneratorController.java index d0685c2..2a396a8 100644 --- a/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/controller/GeneratorController.java +++ b/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/controller/GeneratorController.java @@ -66,7 +66,9 @@ public class GeneratorController { // 检查是否有错误 if (result.containsKey("error")) { - return R.fail(result.get("error")); + String errorMsg = result.get("error"); + log.warn("代码生成失败: {}", errorMsg); + return R.fail(errorMsg); } // 记录模板使用日志 diff --git a/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/service/GeneratorServiceImpl.java b/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/service/GeneratorServiceImpl.java index 3bbf71d..12d118a 100644 --- a/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/service/GeneratorServiceImpl.java +++ b/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/service/GeneratorServiceImpl.java @@ -62,6 +62,7 @@ public class GeneratorServiceImpl implements IGeneratorService { // 1. 解析SQL获取表结构信息 String tableSql = MapUtil.getString(options, "tableSql"); String ignorePrefix = MapUtil.getString(options, "ignorePrefix", ""); + String dataType = MapUtil.getString(options, "dataType", "sql"); if (StringUtils.isBlank(tableSql)) { log.error("SQL语句为空"); @@ -69,13 +70,52 @@ public class GeneratorServiceImpl implements IGeneratorService { return result; } - ClassInfo classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix); - if (classInfo == null) { - log.error("解析SQL失败"); - result.put("error", "解析SQL失败"); + // 根据解析引擎类型选择不同的解析方法 + ClassInfo classInfo = null; + try { + switch (dataType) { + case "sql": + classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix); + break; + case "select-sql": + log.warn("SELECT SQL解析引擎暂未实现,使用DDL引擎降级处理"); + result.put("error", "SELECT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句"); + return result; + case "create-sql": + log.warn("CREATE SQL@JSqlParser引擎暂未实现,使用DDL引擎降级处理"); + result.put("error", "CREATE SQL@JSqlParser引擎暂未实现,请使用DDL SQL@自研引擎"); + return result; + case "json": + log.warn("JSON解析引擎暂未实现,使用DDL引擎降级处理"); + result.put("error", "JSON解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句"); + return result; + case "insert-sql": + log.warn("INSERT SQL解析引擎暂未实现,使用DDL引擎降级处理"); + result.put("error", "INSERT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句"); + return result; + default: + log.warn("未知的解析引擎类型: {}", dataType); + classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix); + break; + } + } catch (Exception e) { + log.error("解析SQL失败,引擎类型: {}", dataType, e); + result.put("error", "解析SQL失败: " + e.getMessage()); return result; } + if (classInfo == null) { + log.error("解析SQL失败,无法获取表结构信息"); + result.put("error", "解析SQL失败,请检查SQL语句格式是否正确"); + return result; + } + + // 确保classComment不为空,提供默认值 + if (StringUtils.isBlank(classInfo.getClassComment())) { + classInfo.setClassComment("数据表"); + log.info("表注释为空,使用默认值: 数据表"); + } + // 2. 设置生成参数 options.put("classInfo", classInfo); options.put("tableName", classInfo.getTableName()); @@ -199,16 +239,47 @@ public class GeneratorServiceImpl implements IGeneratorService { // 1. 解析SQL获取表结构信息 String tableSql = MapUtil.getString(options, "tableSql"); String ignorePrefix = MapUtil.getString(options, "ignorePrefix", ""); + String dataType = MapUtil.getString(options, "dataType", "sql"); if (StringUtils.isBlank(tableSql)) { log.error("SQL语句为空"); return "// 错误: SQL语句不能为空"; } - ClassInfo classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix); + // 根据解析引擎类型选择不同的解析方法 + ClassInfo classInfo = null; + try { + switch (dataType) { + case "sql": + classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix); + break; + case "select-sql": + return "// 错误: SELECT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句"; + case "create-sql": + return "// 错误: CREATE SQL@JSqlParser引擎暂未实现,请使用DDL SQL@自研引擎"; + case "json": + return "// 错误: JSON解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句"; + case "insert-sql": + return "// 错误: INSERT SQL解析引擎暂未实现,请使用DDL SQL引擎或提供CREATE TABLE语句"; + default: + log.warn("未知的解析引擎类型: {}, 使用默认DDL引擎", dataType); + classInfo = TableParseUtil.parseTableSql(tableSql, ignorePrefix); + break; + } + } catch (Exception e) { + log.error("解析SQL失败,引擎类型: {}", dataType, e); + return "// 错误: 解析SQL失败: " + e.getMessage(); + } + if (classInfo == null) { - log.error("解析SQL失败"); - return "// 错误: 解析SQL失败"; + log.error("解析SQL失败,无法获取表结构信息"); + return "// 错误: 解析SQL失败,请检查SQL语句格式是否正确"; + } + + // 确保classComment不为空,提供默认值 + if (StringUtils.isBlank(classInfo.getClassComment())) { + classInfo.setClassComment("数据表"); + log.info("表注释为空,使用默认值: 数据表"); } // 2. 设置生成参数 diff --git a/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/util/TableParseUtil.java b/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/util/TableParseUtil.java index ebdc4fd..6d2efa2 100644 --- a/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/util/TableParseUtil.java +++ b/agileboot-system/wol-codegenerator/src/main/java/com/agileboot/codegen/util/TableParseUtil.java @@ -26,17 +26,31 @@ public class TableParseUtil { return null; } - ClassInfo classInfo = new ClassInfo(); - List fieldList = new ArrayList<>(); + try { + ClassInfo classInfo = new ClassInfo(); + List fieldList = new ArrayList<>(); - // 解析表名和注释 - parseTableInfo(sql, classInfo, ignorePrefix); + // 解析表名和注释 + parseTableInfo(sql, classInfo, ignorePrefix); - // 解析字段信息 - parseFieldInfo(sql, fieldList); + // 解析字段信息 + parseFieldInfo(sql, fieldList); - classInfo.setFieldList(fieldList); - return classInfo; + classInfo.setFieldList(fieldList); + + // 验证解析结果 + if (StringUtils.isBlank(classInfo.getTableName())) { + throw new RuntimeException("无法解析表名,请检查SQL语句格式"); + } + + if (fieldList.isEmpty()) { + throw new RuntimeException("无法解析字段信息,请检查SQL语句格式"); + } + + return classInfo; + } catch (Exception e) { + throw new RuntimeException("解析DDL SQL失败: " + e.getMessage(), e); + } } /** diff --git a/agileboot-system/wol-codegenerator/src/main/resources/template.json b/agileboot-system/wol-codegenerator/src/main/resources/template.json index 4c98552..0aad48a 100644 --- a/agileboot-system/wol-codegenerator/src/main/resources/template.json +++ b/agileboot-system/wol-codegenerator/src/main/resources/template.json @@ -1,11 +1,31 @@ -[ - { +[{ "group": "ui", "templates": [{ "id": "10", "name": "swagger-ui", "description": "swagger-ui" - }] + }, + { + "id": "11", + "name": "element-ui", + "description": "element-ui" + }, + { + "id": "12", + "name": "bootstrap-ui", + "description": "bootstrap-ui" + }, + { + "id": "13", + "name": "layui-edit", + "description": "layui-edit" + }, + { + "id": "14", + "name": "layui-list", + "description": "layui-list" + } + ] }, { "group": "mybatis", @@ -46,6 +66,60 @@ } ] }, + { + "group": "jpa", + "templates": [{ + "id": "30", + "name": "entity", + "description": "entity" + }, + { + "id": "31", + "name": "repository", + "description": "repository" + }, + { + "id": "32", + "name": "jpacontroller", + "description": "jpacontroller" + } + ] + }, + + { + "group": "jdbc-template", + "templates": [{ + "id": "40", + "name": "jtdao", + "description": "jtdao" + }, + { + "id": "41", + "name": "jtdaoimpl", + "description": "jtdaoimpl" + } + ] + }, + + { + "group": "beetlsql", + "templates": [{ + "id": "50", + "name": "beetlmd", + "description": "beetlmd" + }, + { + "id": "51", + "name": "beetlentity", + "description": "beetlentity" + }, + { + "id": "52", + "name": "beetlcontroller", + "description": "beetlcontroller" + } + ] + }, { "group": "mybatis-plus", @@ -70,5 +144,152 @@ "description": "plusentity" } ] + }, + + { + "group": "util", + "templates": [{ + "id": "70", + "name": "beanutil", + "description": "beanutil" + }, + { + "id": "71", + "name": "json", + "description": "json" + }, + { + "id": "72", + "name": "xml", + "description": "xml" + }, + { + "id": "73", + "name": "sql", + "description": "sql" + }, + { + "id": "74", + "name": "swagger-yml", + "description": "swagger-yml" + } + ] + }, + + { + "group": "common-mapper", + "templates": [{ + "id": "81", + "name": "tkentity", + "description": "tkentity" + }, + { + "id": "82", + "name": "tkmapper", + "description": "tkmapper" + } + ] + }, + + { + "group": "renren-fast", + "templates": [{ + "id": "91", + "name": "menu-sql", + "description": "menu-sql" + }, + { + "id": "92", + "name": "vue-list", + "description": "vue-list" + }, + { + "id": "93", + "name": "vue-edit", + "description": "vue-edit" + }, + { + "id": "94", + "name": "rr-controller", + "description": "rr-controller" + }, + { + "id": "95", + "name": "rr-dao", + "description": "rr-dao" + }, + { + "id": "96", + "name": "rr-daoxml", + "description": "rr-daoxml" + }, + { + "id": "97", + "name": "rr-service", + "description": "rr-service" + } + ] + }, + { + "group": "jpa-starp", + "templates": [{ + "id": "101", + "name": "starp-entity", + "description": "entity" + }, + { + "id": "102", + "name": "starp-repository", + "description": "repository" + }, + { + "id": "103", + "name": "starp-jpa-controller", + "description": "jpacontroller" + } + ] + }, + { + "group": "bi", + "templates": [{ + "id": "201", + "name": "qliksense", + "description": "qlik sense" + }] + }, + { + "group": "cloud", + "templates": [ + { + "id": "301", + "name": "bigquery", + "description": "GCP BigQuery" + }, + { + "id": "302", + "name": "dataflowjjs", + "description": "GCP Dataflow JJS" + } + ] + }, + { + "group": "tk-mybatis", + "templates": [ + { + "id": "401", + "name": "tk-entity", + "description": "tk-entity" + }, + { + "id": "402", + "name": "tk-mapper", + "description": "tk-mapper" + }, + { + "id": "403", + "name": "tk-controller", + "description": "tk-controller" + } + ] } ] diff --git a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/element-ui.ftl b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/element-ui.ftl index 9f9e224..2c86759 100644 --- a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/element-ui.ftl +++ b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/element-ui.ftl @@ -1,7 +1,7 @@
- ${classInfo.classComment} + ${classInfo.classComment!'数据管理'} 提交 返回
diff --git a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/layui-list.ftl b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/layui-list.ftl index a3de299..768d05c 100644 --- a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/layui-list.ftl +++ b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/layui-list.ftl @@ -10,13 +10,13 @@
- +
- +
@@ -31,8 +31,8 @@ diff --git a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/swagger-ui.ftl b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/swagger-ui.ftl index 0e50659..9f01d2c 100644 --- a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/swagger-ui.ftl +++ b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/ui/swagger-ui.ftl @@ -1,8 +1,8 @@ -@ApiOperation(value = "${classInfo.classComment}", notes = "${classInfo.classComment}") +@ApiOperation(value = "${classInfo.classComment!'API接口'}", notes = "${classInfo.classComment!'API接口说明'}") @ApiImplicitParams({ <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> <#list classInfo.fieldList as fieldItem > - @ApiImplicitParam(name = "${fieldItem.fieldName}", value = "${fieldItem.fieldComment}", required = false, dataType = "${fieldItem.fieldClass}")<#if fieldItem_has_next>, + @ApiImplicitParam(name = "${fieldItem.fieldName}", value = "${fieldItem.fieldComment!''}", required = false, dataType = "${fieldItem.fieldClass}")<#if fieldItem_has_next>, } diff --git a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/beanutil.ftl b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/beanutil.ftl index 108e27a..7a65bf0 100644 --- a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/beanutil.ftl +++ b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/beanutil.ftl @@ -1,5 +1,5 @@ /** -* ${classInfo.classComment}对象Get Set +* ${classInfo.classComment!'数据'}对象Get Set * @author ${authorName} ${.now?string('yyyy-MM-dd')} */ diff --git a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/xml.ftl b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/xml.ftl index 3959cfc..b6f291f 100644 --- a/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/xml.ftl +++ b/agileboot-system/wol-codegenerator/src/main/resources/templates/code-generator/util/xml.ftl @@ -1,5 +1,5 @@ <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>