style: 优化常量命名风格,XxxConsts => XxxConstants

This commit is contained in:
2023-11-22 23:06:50 +08:00
parent a40e609ea1
commit ec28705b6f
49 changed files with 164 additions and 163 deletions

View File

@@ -39,7 +39,7 @@ import cn.hutool.setting.dialect.PropsUtil;
import top.charles7c.cnadmin.common.enums.QueryTypeEnum;
import top.charles7c.cnadmin.tool.enums.FormTypeEnum;
import top.charles7c.continew.starter.core.constant.StringConsts;
import top.charles7c.continew.starter.core.constant.StringConstants;
/**
* 字段配置实体
@@ -142,7 +142,7 @@ public class FieldConfigDO implements Serializable {
private LocalDateTime createTime;
public FieldConfigDO(@NonNull Column column) {
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConsts.SPACE)[0].toLowerCase();
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConstants.SPACE)[0].toLowerCase();
boolean isRequired = !column.isPk() && !column.isNullable();
this.tableName = column.getTableName();
this.setColumnName(column.getName());

View File

@@ -38,7 +38,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import cn.hutool.core.util.StrUtil;
import top.charles7c.cnadmin.common.constant.RegexConsts;
import top.charles7c.cnadmin.common.constant.RegexConstants;
/**
* 生成配置实体
@@ -76,7 +76,7 @@ public class GenConfigDO implements Serializable {
*/
@Schema(description = "包名称", example = "top.charles7c.cnadmin.system")
@NotBlank(message = "包名称不能为空")
@Pattern(regexp = RegexConsts.PACKAGE_NAME, message = "包名称格式错误")
@Pattern(regexp = RegexConstants.PACKAGE_NAME, message = "包名称格式错误")
@Length(max = 60, message = "包名称不能超过 {max} 个字符")
private String packageName;

View File

@@ -60,7 +60,7 @@ import top.charles7c.cnadmin.tool.model.resp.TableResp;
import top.charles7c.cnadmin.tool.service.GeneratorService;
import top.charles7c.cnadmin.tool.util.MetaUtils;
import top.charles7c.cnadmin.tool.util.Table;
import top.charles7c.continew.starter.core.constant.StringConsts;
import top.charles7c.continew.starter.core.constant.StringConstants;
/**
* 代码生成业务实现
@@ -108,12 +108,12 @@ public class GeneratorServiceImpl implements GeneratorService {
genConfig = new GenConfigDO(tableName);
// 默认包名(当前包名)
String packageName = ClassUtil.getPackage(GeneratorService.class);
genConfig.setPackageName(StrUtil.subBefore(packageName, StringConsts.DOT, true));
genConfig.setPackageName(StrUtil.subBefore(packageName, StringConstants.DOT, true));
// 默认业务名(表注释)
List<Table> tableList = MetaUtils.getTables(dataSource, tableName);
if (CollUtil.isNotEmpty(tableList)) {
Table table = tableList.get(0);
genConfig.setBusinessName(StrUtil.replace(table.getComment(), "", StringConsts.EMPTY));
genConfig.setBusinessName(StrUtil.replace(table.getComment(), "", StringConstants.EMPTY));
}
// 默认作者名称(上次保存使用的作者名称)
GenConfigDO lastGenConfig = genConfigMapper.selectOne(
@@ -122,7 +122,7 @@ public class GeneratorServiceImpl implements GeneratorService {
genConfig.setAuthor(lastGenConfig.getAuthor());
}
// 默认表前缀sys_user -> sys_
int underLineIndex = StrUtil.indexOf(tableName, StringConsts.C_UNDERLINE);
int underLineIndex = StrUtil.indexOf(tableName, StringConstants.C_UNDERLINE);
if (-1 != underLineIndex) {
genConfig.setTablePrefix(StrUtil.subPre(tableName, underLineIndex + 1));
}
@@ -151,7 +151,8 @@ public class GeneratorServiceImpl implements GeneratorService {
FieldConfigDO fieldConfig = fieldConfigMap.get(column.getName());
if (null != fieldConfig) {
// 更新已有字段配置
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConsts.SPACE)[0].toLowerCase();
String columnType =
StrUtil.splitToArray(column.getTypeName(), StringConstants.SPACE)[0].toLowerCase();
fieldConfig.setColumnType(columnType);
fieldConfig.setComment(column.getComment());
} else {
@@ -217,7 +218,7 @@ public class GeneratorServiceImpl implements GeneratorService {
genConfigMap.put("date", DateUtil.date().toString("yyyy/MM/dd HH:mm"));
String packageName = genConfig.getPackageName();
String apiModuleName =
StrUtil.subSuf(packageName, StrUtil.lastIndexOfIgnoreCase(packageName, StringConsts.DOT) + 1);
StrUtil.subSuf(packageName, StrUtil.lastIndexOfIgnoreCase(packageName, StringConstants.DOT) + 1);
genConfigMap.put("apiModuleName", apiModuleName);
genConfigMap.put("apiName", StrUtil.lowerFirst(genConfig.getClassNamePrefix()));
@@ -232,7 +233,7 @@ public class GeneratorServiceImpl implements GeneratorService {
File backendModuleFile = new File(projectPath, genConfig.getModuleName());
// 例如D:/continew-admin/continew-admin-tool/src/main/java/top/charles7c/cnadmin/tool
List<String> backendModuleChildPathList = CollUtil.newArrayList("src", "main", "java");
backendModuleChildPathList.addAll(StrUtil.split(genConfig.getPackageName(), StringConsts.DOT));
backendModuleChildPathList.addAll(StrUtil.split(genConfig.getPackageName(), StringConstants.DOT));
File backendParentFile =
FileUtil.file(backendModuleFile, backendModuleChildPathList.toArray(new String[0]));
// 2、生成代码
@@ -244,7 +245,7 @@ public class GeneratorServiceImpl implements GeneratorService {
genConfigMap.put("className", className);
TemplateConfig templateConfig = templateConfigEntry.getValue();
File classParentFile = FileUtil.file(backendParentFile,
StrUtil.splitToArray(templateConfig.getPackageName(), StringConsts.DOT));
StrUtil.splitToArray(templateConfig.getPackageName(), StringConstants.DOT));
File classFile = new File(classParentFile, className + FileNameUtil.EXT_JAVA);
// 如果已经存在,且不允许覆盖,则跳过
if (classFile.exists() && !isOverride) {