diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/PigxCodeGenDefaultProperties.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/PigxCodeGenDefaultProperties.java new file mode 100644 index 000000000..82cf67fc3 --- /dev/null +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/config/PigxCodeGenDefaultProperties.java @@ -0,0 +1,76 @@ +package com.pig4cloud.pigx.codegen.config; + +import cn.smallbun.screw.core.constant.DefaultConstants; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * 代码生成默认配置类 + * + * @author lengleng + * @date 2024/7/15 + */ +@Data +@Configuration(proxyBeanMethods = false) +@ConfigurationProperties(prefix = PigxCodeGenDefaultProperties.PREFIX) +public class PigxCodeGenDefaultProperties { + + public static final String PREFIX = "codegen"; + + /** + * 是否开启在线更新 + */ + private boolean autoCheckVersion = true; + + /** + * 模板项目地址 + */ + private String onlineUrl = DefaultConstants.CGTM_URL; + + /** + * 生成代码的包名 + */ + private String packageName = "com.pig4cloud.pigx"; + + /** + * 生成代码的版本 + */ + private String version = "1.0.0"; + + /** + * 生成代码的模块名 + */ + private String moduleName = "admin"; + + /** + * 生成代码的后端路径 + */ + private String backendPath = "pigx"; + + /** + * 生成代码的前端路径 + */ + private String frontendPath = "pigx-ui"; + + /** + * 生成代码的作者 + */ + private String author = "pigx"; + + /** + * 生成代码的邮箱 + */ + private String email = "sw@pigx.vip"; + + /** + * 表单布局(一列、两列) + */ + private Integer formLayout = 2; + + /** + * 下载方式 (0 文件下载、1写入目录) + */ + private String generatorType = "0"; + +} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java index 899c35531..acfe10ba2 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/GenTableService.java @@ -24,7 +24,6 @@ import com.pig4cloud.pigx.codegen.entity.GenTable; import org.anyline.metadata.Table; import java.util.List; -import java.util.Map; /** * 列属性 @@ -34,16 +33,11 @@ import java.util.Map; */ public interface GenTableService extends IService { - /** - * 获取默认配置信息 - * - * @return map - */ - Map getGeneratorConfig(); /** * 查询对应数据源的表 - * @param page 分页信息 + * + * @param page 分页信息 * @param table 查询条件 * @return 表 */ @@ -51,7 +45,8 @@ public interface GenTableService extends IService { /** * 查询表信息(列),然后插入到中间表中 - * @param dsName 数据源 + * + * @param dsName 数据源 * @param tableName 表名 * @return GenTable */ @@ -60,7 +55,7 @@ public interface GenTableService extends IService { /** * 查询表ddl 语句 * - * @param dsName 数据源名称 + * @param dsName 数据源名称 * @param tableName 表名称 * @return ddl 语句 * @throws Exception @@ -69,6 +64,7 @@ public interface GenTableService extends IService { /** * 查询数据源里面的全部表 + * * @param dsName 数据源名称 * @return table */ @@ -76,9 +72,11 @@ public interface GenTableService extends IService { /** * 查询表的全部字段 - * @param dsName 数据源 + * + * @param dsName 数据源 * @param tableName 表名称 * @return column */ List queryTableColumn(String dsName, String tableName); + } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java index fc493e120..ec86008a5 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GenTableServiceImpl.java @@ -17,18 +17,15 @@ package com.pig4cloud.pigx.codegen.service.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.io.resource.ClassPathResource; import cn.hutool.core.text.NamingCase; import cn.hutool.core.util.EnumUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.pig4cloud.pigx.codegen.config.PigxCodeGenDefaultProperties; import com.pig4cloud.pigx.codegen.entity.GenGroupEntity; import com.pig4cloud.pigx.codegen.entity.GenTable; import com.pig4cloud.pigx.codegen.entity.GenTableColumnEntity; @@ -36,7 +33,10 @@ import com.pig4cloud.pigx.codegen.mapper.GenTableMapper; import com.pig4cloud.pigx.codegen.service.GenGroupService; import com.pig4cloud.pigx.codegen.service.GenTableColumnService; import com.pig4cloud.pigx.codegen.service.GenTableService; -import com.pig4cloud.pigx.codegen.util.*; +import com.pig4cloud.pigx.codegen.util.AutoFillEnum; +import com.pig4cloud.pigx.codegen.util.BoolFillEnum; +import com.pig4cloud.pigx.codegen.util.CommonColumnFiledEnum; +import com.pig4cloud.pigx.codegen.util.GenKit; import lombok.RequiredArgsConstructor; import org.anyline.metadata.Column; import org.anyline.metadata.Database; @@ -48,7 +48,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Objects; /** * 列属性 @@ -60,25 +63,12 @@ import java.util.*; @RequiredArgsConstructor public class GenTableServiceImpl extends ServiceImpl implements GenTableService { - /** - * 默认配置信息 - */ - private static final String CONFIG_PATH = "template/config.json"; + private final PigxCodeGenDefaultProperties defaultProperties; private final GenTableColumnService columnService; private final GenGroupService genGroupService; - /** - * 获取配置信息 - * @return map - */ - @Override - public Map getGeneratorConfig() { - ClassPathResource classPathResource = new ClassPathResource(CONFIG_PATH); - JSONObject jsonObject = JSONUtil.parseObj(IoUtil.readUtf8(classPathResource.getStream())); - return jsonObject.getRaw(); - } /** * 查询表ddl 语句 @@ -185,24 +175,20 @@ public class GenTableServiceImpl extends ServiceImpl i Table tableMetadata = service.metadata().table(tableName); Database database = service.metadata().database(); // 获取默认表配置信息 () - Map generatorConfig = getGeneratorConfig(); - JSONObject project = (JSONObject) generatorConfig.get("project"); - JSONObject developer = (JSONObject) generatorConfig.get("developer"); - - table.setPackageName(project.getStr("packageName")); - table.setVersion(project.getStr("version")); - table.setBackendPath(project.getStr("backendPath")); - table.setFrontendPath(project.getStr("frontendPath")); - table.setAuthor(developer.getStr("author")); - table.setEmail(developer.getStr("email")); + table.setPackageName(defaultProperties.getPackageName()); + table.setVersion(defaultProperties.getVersion()); + table.setBackendPath(defaultProperties.getBackendPath()); + table.setFrontendPath(defaultProperties.getFrontendPath()); + table.setAuthor(defaultProperties.getAuthor()); + table.setEmail(defaultProperties.getEmail()); table.setTableName(tableName); table.setDsName(dsName); table.setTableComment(tableMetadata.getComment()); table.setDbType(database.getDatabase().title()); - table.setFormLayout(FormLayoutEnum.TWO.getValue()); - table.setGeneratorType(GeneratorTypeEnum.ZIP_DOWNLOAD.getValue()); + table.setFormLayout(defaultProperties.getFormLayout()); + table.setGeneratorType(defaultProperties.getGeneratorType()); table.setClassName(NamingCase.toPascalCase(tableName)); // 模块名称默认为 admin table.setModuleName("admin"); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java index a52eb138a..bb10ea51b 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/service/impl/GeneratorServiceImpl.java @@ -25,6 +25,7 @@ import cn.hutool.core.text.NamingCase; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONObject; +import com.pig4cloud.pigx.codegen.config.PigxCodeGenDefaultProperties; import com.pig4cloud.pigx.codegen.entity.GenFormConf; import com.pig4cloud.pigx.codegen.entity.GenTable; import com.pig4cloud.pigx.codegen.entity.GenTableColumnEntity; @@ -55,6 +56,8 @@ import java.util.zip.ZipOutputStream; @RequiredArgsConstructor public class GeneratorServiceImpl implements GeneratorService { + private final PigxCodeGenDefaultProperties defaultProperties; + private final GenTableColumnService columnService; private final GenFormConfService formConfService; @@ -84,10 +87,8 @@ public class GeneratorServiceImpl implements GeneratorService { GroupVO groupVo = genGroupService.getGroupVoById(style); List templateList = groupVo.getTemplateList(); - Map generatorConfig = tableService.getGeneratorConfig(); - JSONObject project = (JSONObject) generatorConfig.get("project"); - String frontendPath = project.getStr("frontendPath"); - String backendPath = project.getStr("backendPath"); + String frontendPath = defaultProperties.getFrontendPath(); + String backendPath = defaultProperties.getBackendPath(); for (GenTemplateEntity template : templateList) { String templateCode = template.getTemplateCode(); @@ -124,10 +125,8 @@ public class GeneratorServiceImpl implements GeneratorService { // 获取模板列表,Lambda 表达式简化代码 List templateList = genGroupService.getGroupVoById(style).getTemplateList(); - Map generatorConfig = tableService.getGeneratorConfig(); - JSONObject project = (JSONObject) generatorConfig.get("project"); - String frontendPath = project.getStr("frontendPath"); - String backendPath = project.getStr("backendPath"); + String frontendPath = defaultProperties.getFrontendPath(); + String backendPath = defaultProperties.getBackendPath(); return templateList.stream().map(template -> { String templateCode = template.getTemplateCode(); diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/FormLayoutEnum.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/FormLayoutEnum.java deleted file mode 100644 index 55a35ecd5..000000000 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/FormLayoutEnum.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.pig4cloud.pigx.codegen.util; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 表单布局 枚举 - * - * @author 阿沐 babamu@126.com - */ -@Getter -@AllArgsConstructor -public enum FormLayoutEnum { - - ONE(1), TWO(2); - - private final Integer value; - -} diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GeneratorTypeEnum.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GeneratorTypeEnum.java deleted file mode 100644 index 20902119a..000000000 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GeneratorTypeEnum.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.pig4cloud.pigx.codegen.util; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * 代码生成方式 枚举 - * - * @author 阿沐 babamu@126.com - */ -@Getter -@RequiredArgsConstructor -public enum GeneratorTypeEnum { - - /** - * zip压缩包 0 - */ - ZIP_DOWNLOAD("0"), - /** - * 自定义目录 1 - */ - CUSTOM_DIRECTORY("1"); - - private final String value; - -} diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/config.json b/pigx-visual/pigx-codegen/src/main/resources/template/config.json deleted file mode 100644 index fb5751783..000000000 --- a/pigx-visual/pigx-codegen/src/main/resources/template/config.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "project": { - "packageName": "com.pig4cloud.pigx", - "version": "1.0.0", - "backendPath": "pigx", - "frontendPath": "pigx-ui" - }, - "developer": { - "author": "pig", - "email": "sw@pigx.vip" - } -}