mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
refactor(代码生成): 删除 config.json 配置,默认属性从配置文件中获取
json -> YAML (cherry picked from commit 021e7435e294c874d1032d38411db17051ae75c5)
This commit is contained in:
1 parent
860a3f72f5
commit
9e5cbd4fb5
7 files changed
+110
-108
No files matched your search
+76
@@ -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";
|
||||
|
||||
}
|
||||
+9
-11
@@ -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<GenTable> {
|
||||
|
||||
/**
|
||||
* 获取默认配置信息
|
||||
*
|
||||
* @return map
|
||||
*/
|
||||
Map<String, Object> getGeneratorConfig();
|
||||
|
||||
/**
|
||||
* 查询对应数据源的表
|
||||
* @param page 分页信息
|
||||
*
|
||||
* @param page 分页信息
|
||||
* @param table 查询条件
|
||||
* @return 表
|
||||
*/
|
||||
@@ -51,7 +45,8 @@ public interface GenTableService extends IService<GenTable> {
|
||||
|
||||
/**
|
||||
* 查询表信息(列),然后插入到中间表中
|
||||
* @param dsName 数据源
|
||||
*
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名
|
||||
* @return GenTable
|
||||
*/
|
||||
@@ -60,7 +55,7 @@ public interface GenTableService extends IService<GenTable> {
|
||||
/**
|
||||
* 查询表ddl 语句
|
||||
*
|
||||
* @param dsName 数据源名称
|
||||
* @param dsName 数据源名称
|
||||
* @param tableName 表名称
|
||||
* @return ddl 语句
|
||||
* @throws Exception
|
||||
@@ -69,6 +64,7 @@ public interface GenTableService extends IService<GenTable> {
|
||||
|
||||
/**
|
||||
* 查询数据源里面的全部表
|
||||
*
|
||||
* @param dsName 数据源名称
|
||||
* @return table
|
||||
*/
|
||||
@@ -76,9 +72,11 @@ public interface GenTableService extends IService<GenTable> {
|
||||
|
||||
/**
|
||||
* 查询表的全部字段
|
||||
* @param dsName 数据源
|
||||
*
|
||||
* @param dsName 数据源
|
||||
* @param tableName 表名称
|
||||
* @return column
|
||||
*/
|
||||
List<String> queryTableColumn(String dsName, String tableName);
|
||||
|
||||
}
|
||||
+18
-32
@@ -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<GenTableMapper, GenTable> 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<String, Object> 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<GenTableMapper, GenTable> i
|
||||
Table tableMetadata = service.metadata().table(tableName);
|
||||
Database database = service.metadata().database();
|
||||
// 获取默认表配置信息 ()
|
||||
Map<String, Object> 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");
|
||||
|
||||
+7
-8
@@ -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<GenTemplateEntity> templateList = groupVo.getTemplateList();
|
||||
|
||||
Map<String, Object> 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<GenTemplateEntity> templateList = genGroupService.getGroupVoById(style).getTemplateList();
|
||||
|
||||
Map<String, Object> 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();
|
||||
|
||||
-19
@@ -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;
|
||||
|
||||
}
|
||||
-26
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user