Skip to content

Commit

Permalink
[代码优化](v2.6):代码生成优化
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Dec 19, 2020
1 parent 4639387 commit 9883854
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,24 @@ public GenConfig find(String tableName) {

@Override
public GenConfig update(String tableName, GenConfig genConfig) {
// 如果 api 路径为空,则自动生成路径
if(StringUtils.isBlank(genConfig.getApiPath())){
String separator = File.separator;
String[] paths;
String symbol = "\\";
if (symbol.equals(separator)) {
paths = genConfig.getPath().split("\\\\");
} else {
paths = genConfig.getPath().split(File.separator);
}
StringBuilder api = new StringBuilder();
for (String path : paths) {
api.append(path);
api.append(separator);
if ("src".equals(path)) {
api.append("api");
break;
}
String separator = File.separator;
String[] paths;
String symbol = "\\";
if (symbol.equals(separator)) {
paths = genConfig.getPath().split("\\\\");
} else {
paths = genConfig.getPath().split(File.separator);
}
StringBuilder api = new StringBuilder();
for (String path : paths) {
api.append(path);
api.append(separator);
if ("src".equals(path)) {
api.append("api");
break;
}
genConfig.setApiPath(api.toString());
}
genConfig.setApiPath(api.toString());
return genConfigRepository.save(genConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public static void generatorCode(List<ColumnInfo> columnInfos, GenConfig genConf
List<String> templates = getAdminTemplateNames();
for (String templateName : templates) {
Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl");
String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), System.getProperty("user.dir"));
String rootPath = System.getProperty("user.dir");
String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), rootPath);

assert filePath != null;
File file = new File(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package me.zhengjie.modules.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.system.domain.Menu;
import me.zhengjie.modules.system.domain.Role;
Expand Down Expand Up @@ -268,15 +268,16 @@ public List<MenuVo> buildMenus(List<MenuDto> menuDtos) {
// 如果不是外链
if(!menuDTO.getIFrame()){
if(menuDTO.getPid() == null){
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent())?"Layout":menuDTO.getComponent());
}else if(menuDTO.getPid() != null && menuDTO.getType() == 0){
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent())?"ParentView":menuDTO.getComponent());
}else if(!StrUtil.isEmpty(menuDTO.getComponent())){
menuVo.setComponent(StringUtils.isEmpty(menuDTO.getComponent())?"Layout":menuDTO.getComponent());
// 如果不是一级菜单,并且菜单类型为目录,则代表是多级菜单
}else if(menuDTO.getType() == 0){
menuVo.setComponent(StringUtils.isEmpty(menuDTO.getComponent())?"ParentView":menuDTO.getComponent());
}else if(StringUtils.isNoneBlank(menuDTO.getComponent())){
menuVo.setComponent(menuDTO.getComponent());
}
}
menuVo.setMeta(new MenuMetaVo(menuDTO.getTitle(),menuDTO.getIcon(),!menuDTO.getCache()));
if(menuDtoList !=null && menuDtoList.size()!=0){
if(CollectionUtil.isNotEmpty(menuDtoList)){
menuVo.setAlwaysShow(true);
menuVo.setRedirect("noredirect");
menuVo.setChildren(buildMenus(menuDtoList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ${className} implements Serializable {
@NotNull
</#if>
</#if>
<#if (column.dateAnnotation)??>
<#if (column.dateAnnotation)?? && column.dateAnnotation != ''>
<#if column.dateAnnotation = 'CreationTimestamp'>
@CreationTimestamp
<#else>
Expand Down

0 comments on commit 9883854

Please sign in to comment.