Skip to content

Commit

Permalink
chore(generator): 优化部分代码生成代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Aug 31, 2024
1 parent ad9a600 commit ca9f34d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package top.continew.admin.generator.model.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
Expand All @@ -25,6 +26,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import top.continew.admin.common.constant.RegexConstants;
import top.continew.starter.core.constant.StringConstants;

import java.io.Serial;
import java.io.Serializable;
Expand Down Expand Up @@ -114,6 +116,15 @@ public class GenConfigDO implements Serializable {
private LocalDateTime updateTime;

public GenConfigDO(String tableName) {
this.setTableName(tableName);
}

public void setTableName(String tableName) {
this.tableName = tableName;
// 默认表前缀(sys_user -> sys_)
int underLineIndex = StrUtil.indexOf(tableName, StringConstants.C_UNDERLINE);
if (-1 != underLineIndex) {
this.tablePrefix = StrUtil.subPre(tableName, underLineIndex + 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ public GenConfigDO getGenConfig(String tableName) throws SQLException {
if (null != lastGenConfig) {
genConfig.setAuthor(lastGenConfig.getAuthor());
}
// 默认表前缀(sys_user -> sys_)
int underLineIndex = StrUtil.indexOf(tableName, StringConstants.C_UNDERLINE);
if (-1 != underLineIndex) {
genConfig.setTablePrefix(StrUtil.subPre(tableName, underLineIndex + 1));
}
}
return genConfig;
}
Expand Down Expand Up @@ -245,19 +240,16 @@ public List<GeneratePreviewResp> preview(String tableName) {
GeneratePreviewResp generatePreview = new GeneratePreviewResp();
generatePreview.setBackend(isBackend);
generatePreviewList.add(generatePreview);
if (isBackend) {
generatePreview.setFileName(className + extension);
generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), BeanUtil
.beanToMap(innerGenConfig)));
} else {
generatePreview.setFileName(".vue".equals(extension) && "index".equals(classNameSuffix)
String fileName = className + extension;
if (!isBackend) {
fileName = ".vue".equals(extension) && "index".equals(classNameSuffix)
? "index.vue"
: this.getFrontendFileName(classNamePrefix, className, extension));
innerGenConfig.setFieldConfigs(fieldConfigList);
generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), BeanUtil
.beanToMap(innerGenConfig)));
: this.getFrontendFileName(classNamePrefix, className, extension);
}
setPreviewPath(generatePreview, innerGenConfig, templateConfig);
generatePreview.setFileName(fileName);
generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), BeanUtil
.beanToMap(innerGenConfig)));
this.setPreviewPath(generatePreview, innerGenConfig, templateConfig);
}
return generatePreviewList;
}
Expand Down

0 comments on commit ca9f34d

Please sign in to comment.