✨ 代码生成自动添加菜单
This commit is contained in:
parent
cdd4b42f0a
commit
ac38886f60
@ -12,6 +12,7 @@ using ZR.CodeGenerator.Model;
|
|||||||
using ZR.CodeGenerator.Service;
|
using ZR.CodeGenerator.Service;
|
||||||
using ZR.Common;
|
using ZR.Common;
|
||||||
using ZR.Model;
|
using ZR.Model;
|
||||||
|
using ZR.Model.System;
|
||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
using ZR.Model.System.Generate;
|
using ZR.Model.System.Generate;
|
||||||
using ZR.Service.System.IService;
|
using ZR.Service.System.IService;
|
||||||
@ -28,16 +29,18 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
private readonly CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
|
private readonly CodeGeneraterService _CodeGeneraterService = new CodeGeneraterService();
|
||||||
private readonly IGenTableService GenTableService;
|
private readonly IGenTableService GenTableService;
|
||||||
private readonly IGenTableColumnService GenTableColumnService;
|
private readonly IGenTableColumnService GenTableColumnService;
|
||||||
|
private readonly ISysMenuService SysMenuService;
|
||||||
private readonly IWebHostEnvironment WebHostEnvironment;
|
private readonly IWebHostEnvironment WebHostEnvironment;
|
||||||
public CodeGeneratorController(
|
public CodeGeneratorController(
|
||||||
IGenTableService genTableService,
|
IGenTableService genTableService,
|
||||||
IGenTableColumnService genTableColumnService,
|
IGenTableColumnService genTableColumnService,
|
||||||
IWebHostEnvironment webHostEnvironment)
|
IWebHostEnvironment webHostEnvironment,
|
||||||
|
ISysMenuService sysMenuService)
|
||||||
{
|
{
|
||||||
GenTableService = genTableService;
|
GenTableService = genTableService;
|
||||||
GenTableColumnService = genTableColumnService;
|
GenTableColumnService = genTableColumnService;
|
||||||
WebHostEnvironment = webHostEnvironment;
|
WebHostEnvironment = webHostEnvironment;
|
||||||
|
SysMenuService = sysMenuService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -257,7 +260,7 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
dto.GenTable = genTableInfo;
|
dto.GenTable = genTableInfo;
|
||||||
//自定义路径
|
//自定义路径
|
||||||
if (genTableInfo.GenType == "1")
|
if (genTableInfo.GenType == "1")
|
||||||
{
|
{
|
||||||
string tempPath = WebHostEnvironment.ContentRootPath;
|
string tempPath = WebHostEnvironment.ContentRootPath;
|
||||||
var parentPath = tempPath[..tempPath.LastIndexOf(@"\")];
|
var parentPath = tempPath[..tempPath.LastIndexOf(@"\")];
|
||||||
//代码生成文件夹路径
|
//代码生成文件夹路径
|
||||||
@ -275,7 +278,10 @@ namespace ZR.Admin.WebApi.Controllers
|
|||||||
CodeGeneratorTool.Generate(dto);
|
CodeGeneratorTool.Generate(dto);
|
||||||
//下载文件
|
//下载文件
|
||||||
FileUtil.ZipGenCode(dto.ZipPath, dto.GenCodePath, zipReturnFileName);
|
FileUtil.ZipGenCode(dto.ZipPath, dto.GenCodePath, zipReturnFileName);
|
||||||
|
if (genTableInfo.Options.GenerateMenu)
|
||||||
|
{
|
||||||
|
SysMenuService.AddSysMenu(genTableInfo, dto.ReplaceDto.PermissionPrefix, dto.ReplaceDto.ShowBtnEdit, dto.ReplaceDto.ShowBtnExport);
|
||||||
|
}
|
||||||
return SUCCESS(new { path = "/Generatecode/" + zipReturnFileName, fileName = dto.ZipFileName });
|
return SUCCESS(new { path = "/Generatecode/" + zipReturnFileName, fileName = dto.ZipFileName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,7 @@ namespace ZR.CodeGenerator
|
|||||||
}
|
}
|
||||||
GenerateVueJs(dto);
|
GenerateVueJs(dto);
|
||||||
GenerateSql(dto);
|
GenerateSql(dto);
|
||||||
|
dto.ReplaceDto = replaceDto;
|
||||||
if (dto.IsPreview) return;
|
if (dto.IsPreview) return;
|
||||||
|
|
||||||
foreach (var item in dto.GenCodes)
|
foreach (var item in dto.GenCodes)
|
||||||
|
|||||||
@ -58,6 +58,7 @@ namespace ZR.CodeGenerator.Model
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string VueParentPath { get; set; }
|
public string VueParentPath { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
public ReplaceDto ReplaceDto { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GenCode
|
public class GenCode
|
||||||
|
|||||||
@ -107,5 +107,9 @@ namespace ZR.Model.System.Generate
|
|||||||
/// 是否生成仓储层
|
/// 是否生成仓储层
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int GenerateRepo { get; set; }
|
public int GenerateRepo { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 自动生成菜单
|
||||||
|
/// </summary>
|
||||||
|
public bool GenerateMenu { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Model.System.Vo;
|
using ZR.Model.System.Vo;
|
||||||
|
using ZR.Model.System.Generate;
|
||||||
|
|
||||||
namespace ZR.Service.System.IService
|
namespace ZR.Service.System.IService
|
||||||
{
|
{
|
||||||
@ -37,6 +38,8 @@ namespace ZR.Service.System.IService
|
|||||||
List<RouterVo> BuildMenus(List<SysMenu> menus);
|
List<RouterVo> BuildMenus(List<SysMenu> menus);
|
||||||
|
|
||||||
List<TreeSelectVo> BuildMenuTreeSelect(List<SysMenu> menus);
|
List<TreeSelectVo> BuildMenuTreeSelect(List<SysMenu> menus);
|
||||||
|
|
||||||
|
void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -7,8 +7,10 @@ using System.Linq;
|
|||||||
using ZR.Common;
|
using ZR.Common;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Model.System.Dto;
|
using ZR.Model.System.Dto;
|
||||||
|
using ZR.Model.System.Generate;
|
||||||
using ZR.Model.System.Vo;
|
using ZR.Model.System.Vo;
|
||||||
using ZR.Service.System.IService;
|
using ZR.Service.System.IService;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
|
||||||
namespace ZR.Service
|
namespace ZR.Service
|
||||||
{
|
{
|
||||||
@ -561,5 +563,114 @@ namespace ZR.Service
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
public void AddSysMenu(GenTable genTableInfo, string permPrefix, bool showEdit, bool showExport)
|
||||||
|
{
|
||||||
|
var menu = GetFirst(f => f.MenuName == genTableInfo.FunctionName);
|
||||||
|
if (menu is null)
|
||||||
|
{
|
||||||
|
menu = new()
|
||||||
|
{
|
||||||
|
MenuName = genTableInfo.FunctionName,
|
||||||
|
ParentId = genTableInfo.Options.ParentMenuId,
|
||||||
|
OrderNum = 0,
|
||||||
|
Path = genTableInfo.BusinessName,
|
||||||
|
Component = $"{genTableInfo.ModuleName.FirstLowerCase()}/{genTableInfo.BusinessName}",
|
||||||
|
Perms = $"{permPrefix}:list",
|
||||||
|
IsFrame = "0",
|
||||||
|
IsCache = "1",
|
||||||
|
MenuType = "C",
|
||||||
|
Visible = "0",
|
||||||
|
Status = "0",
|
||||||
|
Icon = "icon1",
|
||||||
|
Create_by = "system",
|
||||||
|
};
|
||||||
|
menu.MenuId = AddMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SysMenu> menuList = new();
|
||||||
|
|
||||||
|
SysMenu menuQuery = new()
|
||||||
|
{
|
||||||
|
MenuName = "查询",
|
||||||
|
ParentId = menu.MenuId,
|
||||||
|
OrderNum = 1,
|
||||||
|
Perms = $"{permPrefix}:query",
|
||||||
|
IsFrame = "0",
|
||||||
|
MenuType = "F",
|
||||||
|
Visible = "0",
|
||||||
|
Status = "0",
|
||||||
|
Icon = "",
|
||||||
|
};
|
||||||
|
SysMenu menuAdd = new()
|
||||||
|
{
|
||||||
|
MenuName = "新增",
|
||||||
|
ParentId = menu.MenuId,
|
||||||
|
OrderNum = 2,
|
||||||
|
Perms = $"{permPrefix}:add",
|
||||||
|
IsFrame = "0",
|
||||||
|
MenuType = "F",
|
||||||
|
Visible = "0",
|
||||||
|
Status = "0",
|
||||||
|
Icon = "",
|
||||||
|
};
|
||||||
|
SysMenu menuDel = new()
|
||||||
|
{
|
||||||
|
MenuName = "删除",
|
||||||
|
ParentId = menu.MenuId,
|
||||||
|
OrderNum = 3,
|
||||||
|
Perms = $"{permPrefix}:delete",
|
||||||
|
IsFrame = "0",
|
||||||
|
MenuType = "F",
|
||||||
|
Visible = "0",
|
||||||
|
Status = "0",
|
||||||
|
Icon = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
SysMenu menuEdit = new()
|
||||||
|
{
|
||||||
|
MenuName = "修改",
|
||||||
|
ParentId = menu.MenuId,
|
||||||
|
OrderNum = 4,
|
||||||
|
Perms = $"{permPrefix}:edit",
|
||||||
|
IsFrame = "0",
|
||||||
|
MenuType = "F",
|
||||||
|
Visible = "0",
|
||||||
|
Status = "0",
|
||||||
|
Icon = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
SysMenu menuExport = new()
|
||||||
|
{
|
||||||
|
MenuName = "导出",
|
||||||
|
ParentId = menu.MenuId,
|
||||||
|
OrderNum = 5,
|
||||||
|
Perms = $"{permPrefix}:export",
|
||||||
|
IsFrame = "0",
|
||||||
|
MenuType = "F",
|
||||||
|
Visible = "0",
|
||||||
|
Status = "0",
|
||||||
|
Icon = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
menuList.Add(menuQuery);
|
||||||
|
menuList.Add(menuAdd);
|
||||||
|
menuList.Add(menuDel);
|
||||||
|
if (showEdit)
|
||||||
|
{
|
||||||
|
menuList.Add(menuEdit);
|
||||||
|
}
|
||||||
|
if (showExport)
|
||||||
|
{
|
||||||
|
menuList.Add(menuExport);
|
||||||
|
}
|
||||||
|
//Insert(menuList);
|
||||||
|
|
||||||
|
var x = Storageable(menuList)
|
||||||
|
.WhereColumns(it => new { it.MenuName, it.ParentId })
|
||||||
|
.ToStorage();
|
||||||
|
x.AsInsertable.ExecuteCommand();//插入可插入部分;
|
||||||
|
x.AsUpdateable.ExecuteCommand();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user