feat: 代码生成添加菜单路由生成
This commit is contained in:
@@ -3,7 +3,6 @@ package com.youlai.system.model.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
import com.youlai.system.common.base.BaseEntity;
|
import com.youlai.system.common.base.BaseEntity;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ public class GenConfig extends BaseEntity {
|
|||||||
private String businessName;
|
private String businessName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上级菜单ID
|
* 父菜单ID
|
||||||
*/
|
*/
|
||||||
private Long parentMenuId;
|
private Long parentMenuId;
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ public class GenFieldConfig extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private Integer isRequired;
|
private Integer isRequired;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TypeScript类型
|
* TypeScript类型
|
||||||
*/
|
*/
|
||||||
@@ -101,12 +100,8 @@ public class GenFieldConfig extends BaseEntity {
|
|||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private String tsType;
|
private String tsType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典类型
|
* 字典类型
|
||||||
*/
|
*/
|
||||||
private String dictType;
|
private String dictType;
|
||||||
|
|
||||||
@TableLogic
|
|
||||||
private Integer isDeleted;
|
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,9 @@ public class GenConfigForm {
|
|||||||
@Schema(description = "作者",example = "youlaitech")
|
@Schema(description = "作者",example = "youlaitech")
|
||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
|
@Schema(description = "上级菜单ID",example = "1")
|
||||||
|
private Long parentMenuId;
|
||||||
|
|
||||||
@Schema(description = "字段配置列表")
|
@Schema(description = "字段配置列表")
|
||||||
private List<FieldConfig> fieldConfigs;
|
private List<FieldConfig> fieldConfigs;
|
||||||
|
|
||||||
|
|||||||
@@ -63,4 +63,12 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||||||
* @param id 菜单ID
|
* @param id 菜单ID
|
||||||
*/
|
*/
|
||||||
boolean deleteMenu(Long id);
|
boolean deleteMenu(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为代码生成添加菜单
|
||||||
|
*
|
||||||
|
* @param parentMenuId 父菜单ID
|
||||||
|
* @param entityName 实体名
|
||||||
|
*/
|
||||||
|
void addMenuForCodeGeneration(Long parentMenuId,String businessName, String entityName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.youlai.system.model.vo.TablePageVO;
|
|||||||
import com.youlai.system.service.GeneratorService;
|
import com.youlai.system.service.GeneratorService;
|
||||||
import com.youlai.system.service.GenConfigService;
|
import com.youlai.system.service.GenConfigService;
|
||||||
import com.youlai.system.service.GenFieldConfigService;
|
import com.youlai.system.service.GenFieldConfigService;
|
||||||
|
import com.youlai.system.service.SysMenuService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
private final GenConfigService genConfigService;
|
private final GenConfigService genConfigService;
|
||||||
private final GenFieldConfigService genFieldConfigService;
|
private final GenFieldConfigService genFieldConfigService;
|
||||||
private final GenConfigConverter genConfigConverter;
|
private final GenConfigConverter genConfigConverter;
|
||||||
|
private final SysMenuService menuService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据表分页列表
|
* 数据表分页列表
|
||||||
@@ -98,9 +100,6 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
String entityName = StrUtil.toCamelCase(StrUtil.removePrefix(tableName, tableName.split("_")[0]));
|
String entityName = StrUtil.toCamelCase(StrUtil.removePrefix(tableName, tableName.split("_")[0]));
|
||||||
genConfig.setEntityName(entityName);
|
genConfig.setEntityName(entityName);
|
||||||
|
|
||||||
String packageName = SystemApplication.class.getPackageName();
|
|
||||||
genConfig.setPackageName(packageName);
|
|
||||||
|
|
||||||
genConfig.setAuthor(generatorProperties.getDefaultConfig().getAuthor());
|
genConfig.setAuthor(generatorProperties.getDefaultConfig().getAuthor());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -172,6 +171,12 @@ public class GeneratorServiceImpl implements GeneratorService {
|
|||||||
GenConfig genConfig = genConfigConverter.toGenConfig(formData);
|
GenConfig genConfig = genConfigConverter.toGenConfig(formData);
|
||||||
genConfigService.saveOrUpdate(genConfig);
|
genConfigService.saveOrUpdate(genConfig);
|
||||||
|
|
||||||
|
// 如果选择上级菜单
|
||||||
|
Long parentMenuId = formData.getParentMenuId();
|
||||||
|
if (parentMenuId != null) {
|
||||||
|
menuService.addMenuForCodeGeneration(parentMenuId,genConfig.getBusinessName(),genConfig.getEntityName());
|
||||||
|
}
|
||||||
|
|
||||||
List<GenFieldConfig> genFieldConfigs = genConfigConverter.toGenFieldConfig(formData.getFieldConfigs());
|
List<GenFieldConfig> genFieldConfigs = genConfigConverter.toGenFieldConfig(formData.getFieldConfigs());
|
||||||
|
|
||||||
if (CollectionUtil.isEmpty(genFieldConfigs)) {
|
if (CollectionUtil.isEmpty(genFieldConfigs)) {
|
||||||
|
|||||||
@@ -351,4 +351,41 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为代码生成添加菜单
|
||||||
|
*
|
||||||
|
* @param parentMenuId 父菜单ID
|
||||||
|
* @param entityName 实体名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addMenuForCodeGeneration(Long parentMenuId, String businessName, String entityName) {
|
||||||
|
SysMenu parentMenu = this.getById(parentMenuId);
|
||||||
|
Assert.notNull(parentMenu, "父菜单不存在");
|
||||||
|
|
||||||
|
long count = this.count(new LambdaQueryWrapper<SysMenu>().eq(SysMenu::getRouteName, entityName));
|
||||||
|
if (count > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SysMenu menu = new SysMenu();
|
||||||
|
menu.setParentId(parentMenuId);
|
||||||
|
menu.setName(businessName);
|
||||||
|
|
||||||
|
menu.setRouteName(entityName);
|
||||||
|
menu.setRoutePath(StrUtil.toUnderlineCase(entityName));
|
||||||
|
menu.setComponent(StrUtil.toUnderlineCase(entityName) + "/index");
|
||||||
|
menu.setType(MenuTypeEnum.CATALOG);
|
||||||
|
menu.setSort(0);
|
||||||
|
menu.setVisible(1);
|
||||||
|
boolean result = this.save(menu);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
// 生成treePath
|
||||||
|
String treePath = generateMenuTreePath(parentMenuId);
|
||||||
|
menu.setTreePath(treePath);
|
||||||
|
this.updateById(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user