新增代码生成到指定菜单目录下下

This commit is contained in:
izory 2021-09-27 17:38:09 +08:00
parent 56a04bbf73
commit d5087a1725
20 changed files with 87 additions and 52 deletions

View File

@ -5,6 +5,7 @@ using Mapster;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -89,7 +90,8 @@ namespace ZR.Admin.WebApi.Controllers
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId); var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId); genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
Dictionary<string, object> options = JsonConvert.DeserializeObject<Dictionary<string, object>>(genTableInfo.Options);
dto.ParentMenuId = (long)options.GetValueOrDefault("parentMenuId", 0);
dto.GenTable = genTableInfo; dto.GenTable = genTableInfo;
//生成代码 //生成代码
CodeGeneratorTool.Generate(genTableInfo, dto); CodeGeneratorTool.Generate(genTableInfo, dto);
@ -211,6 +213,7 @@ namespace ZR.Admin.WebApi.Controllers
if (genTableDto == null) throw new CustomException("请求参数错误"); if (genTableDto == null) throw new CustomException("请求参数错误");
var genTable = genTableDto.Adapt<GenTable>().ToUpdate(HttpContext); var genTable = genTableDto.Adapt<GenTable>().ToUpdate(HttpContext);
genTable.Options = JsonConvert.SerializeObject(new { parentMenuId = genTableDto.ParentMenuId });
int rows = GenTableService.UpdateGenTable(genTable); int rows = GenTableService.UpdateGenTable(genTable);
if (rows > 0) if (rows > 0)
{ {

View File

@ -20,8 +20,8 @@ namespace ZR.Admin.WebApi.Controllers
/// <summary> /// <summary>
/// 代码生成演示Controller /// 代码生成演示Controller
/// ///
/// @author zhaorui /// @author zr
/// @date 2021-09-24 /// @date 2021-09-27
/// </summary> /// </summary>
[Verify] [Verify]
[Route("business/Gendemo")] [Route("business/Gendemo")]

View File

@ -1,6 +1,6 @@
-- 菜单 -- 菜单
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', sysdate(), '', NULL, '{ModelTypeDesc}菜单'); VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', sysdate(), '', NULL, '{FunctionName}菜单');
-- 按钮父菜单id -- 按钮父菜单id
SELECT @menuId := LAST_INSERT_ID(); SELECT @menuId := LAST_INSERT_ID();

View File

@ -12,7 +12,7 @@ namespace {RepositoriesNamespace}
/// @date {DateTime} /// @date {DateTime}
/// </summary> /// </summary>
[AppService(ServiceLifetime = LifeTime.Transient)] [AppService(ServiceLifetime = LifeTime.Transient)]
public class {ModelTypeName}Repository : BaseRepository public class {ModelTypeName}Repository : BaseRepository<ModelTypeName>
{ {
#region 业务逻辑代码 #region 业务逻辑代码
#endregion #endregion

View File

@ -21,10 +21,10 @@ namespace {ServicesNamespace}.Business
[AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)] [AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
public class {ModelTypeName}Service: BaseService<{ModelTypeName}>, I{ModelTypeName}Service public class {ModelTypeName}Service: BaseService<{ModelTypeName}>, I{ModelTypeName}Service
{ {
private readonly {ModelTypeName}Repository _repository; private readonly {ModelTypeName}Repository _{ModelTypeName}repository;
public {ModelTypeName}Service({ModelTypeName}Repository repository) public {ModelTypeName}Service({ModelTypeName}Repository repository)
{ {
_repository = repository; _{ModelTypeName}repository = repository;
} }
#region 业务逻辑代码 #region 业务逻辑代码

View File

@ -1,6 +1,6 @@
-- 菜单 -- 菜单
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark) INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time, update_by, update_time, remark)
VALUES ('{FunctionName}', 0, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', GETDATE(), '', NULL, '{ModelTypeDesc}'); VALUES ('{FunctionName}', {ParentId}, 1, '/{ModuleName}/{ModelTypeName}', '{ModuleName}/{ViewsFileName}/index', 0, 0, 'C', '0', '0', '{Permission}:list', '#', '', GETDATE(), '', NULL, '{FunctionName}');
-- 按钮父菜单id -- 按钮父菜单id
declare @menuId int = @@identity declare @menuId int = @@identity
@ -19,5 +19,5 @@ INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isC
VALUES ('修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', GETDATE(), '', NULL, NULL); VALUES ('修改', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '{Permission}:update', '', '', GETDATE(), '', NULL, NULL);
GO GO
SELECT * FROM sys_menu WHERE parentId = @menuId; SELECT * FROM sys_menu WHERE parentId = {ParentId};
SELECT * FROM sys_menu WHERE menuId = @menuId; SELECT * FROM sys_menu WHERE menuId = @menuId;

View File

@ -38,7 +38,7 @@ export function update{ModelTypeName}(data) {
/** /**
* 获取{FunctionName}详情 * 获取{FunctionName}详情
* @param {Id} {ModelTypeDesc}Id * @param {Id} {FunctionName}Id
*/ */
export function get{ModelTypeName}(id) { export function get{ModelTypeName}(id) {
return request({ return request({

View File

@ -53,7 +53,6 @@ namespace ZR.CodeGenerator
ReplaceDto replaceDto = new(); ReplaceDto replaceDto = new();
replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名 replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
replaceDto.TableName = tableInfo.TableName;//表名 replaceDto.TableName = tableInfo.TableName;//表名
replaceDto.TableDesc = tableInfo.TableComment;//表说明描述
replaceDto.Permission = $"{tableInfo.ModuleName}:{tableInfo.ClassName.ToLower()}";//权限 replaceDto.Permission = $"{tableInfo.ModuleName}:{tableInfo.ClassName.ToLower()}";//权限
replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName); replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName);
replaceDto.Author = tableInfo.FunctionAuthor; replaceDto.Author = tableInfo.FunctionAuthor;
@ -393,9 +392,9 @@ namespace ZR.CodeGenerator
var content = FileHelper.ReadTemplate($"{tempName}.txt") var content = FileHelper.ReadTemplate($"{tempName}.txt")
.Replace("{ModelTypeName}", replaceDto.ModelTypeName) .Replace("{ModelTypeName}", replaceDto.ModelTypeName)
.Replace("{Permission}", replaceDto.Permission) .Replace("{Permission}", replaceDto.Permission)
.Replace("{ModelTypeDesc}", replaceDto.TableDesc)
.Replace("{ModuleName}", generateDto.GenTable.ModuleName) .Replace("{ModuleName}", generateDto.GenTable.ModuleName)
.Replace("{ViewsFileName}", replaceDto.ViewsFileName) .Replace("{ViewsFileName}", replaceDto.ViewsFileName)
.Replace("{ParentId}", generateDto.ParentMenuId.ToString())
.Replace("{FunctionName}", generateDto.GenTable.FunctionName); .Replace("{FunctionName}", generateDto.GenTable.FunctionName);
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, content)); generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, content));

View File

@ -45,6 +45,10 @@ namespace ZR.CodeGenerator.Model
/// 代码生成压缩包名称 /// 代码生成压缩包名称
/// </summary> /// </summary>
public string ZipFileName { get; set; } public string ZipFileName { get; set; }
/// <summary>
/// 父级菜单id
/// </summary>
public long ParentMenuId { get; set; }
#endregion #endregion
} }

View File

@ -8,13 +8,6 @@ namespace ZR.CodeGenerator.Model
{ {
public class ReplaceDto public class ReplaceDto
{ {
//public string ModelsNamespace { get; set; }
//public string DtosNamespace { get; set; }
//public string RepositoriesNamespace { get; set; }
//public string IRepositoriesNamespace { get; set; }
//public string IServicsNamespace { get; set; }
//public string ServicesNamespace { get; set; }
/// <summary> /// <summary>
/// 主键字段 /// 主键字段
/// </summary> /// </summary>
@ -36,10 +29,6 @@ namespace ZR.CodeGenerator.Model
/// </summary> /// </summary>
public string TableName { get; set; } public string TableName { get; set; }
/// <summary> /// <summary>
/// 表描述、说明
/// </summary>
public string TableDesc { get; set; }
/// <summary>
/// 修改列 /// 修改列
/// </summary> /// </summary>
public string UpdateColumn { get; set; } public string UpdateColumn { get; set; }

View File

@ -6,8 +6,8 @@ namespace ZR.Model.Models
/// <summary> /// <summary>
/// 代码生成演示,数据实体对象 /// 代码生成演示,数据实体对象
/// ///
/// @author zhaorui /// @author zr
/// @date 2021-09-24 /// @date 2021-09-27
/// </summary> /// </summary>
[SqlSugar.SugarTable("gen_demo")] [SqlSugar.SugarTable("gen_demo")]
public class Gendemo public class Gendemo

View File

@ -21,6 +21,10 @@ namespace ZR.Model.System.Dto
public string FunctionAuthor { get; set; } public string FunctionAuthor { get; set; }
public string GenType { get; set; } public string GenType { get; set; }
public string Options { get; set; } public string Options { get; set; }
/// <summary>
/// 上级菜单id
/// </summary>
public int ParentMenuId { get; set; }
public List<GenTableColumnDto> Columns { get; set; } public List<GenTableColumnDto> Columns { get; set; }
} }

View File

@ -10,23 +10,64 @@ namespace ZR.Model.System.Generate
[SqlSugar.SugarTable("gen_table")] [SqlSugar.SugarTable("gen_table")]
public class GenTable: SysBase public class GenTable: SysBase
{ {
/// <summary>
/// 表id
/// </summary>
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)] [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int TableId { get; set; } public int TableId { get; set; }
/// <summary>
/// 表名
/// </summary>
public string TableName { get; set; } public string TableName { get; set; }
/// <summary>
/// 表描述
/// </summary>
public string TableComment { get; set; } public string TableComment { get; set; }
/// <summary>
/// 关联父表的表名
/// </summary>
public string SubTableName { get; set; } public string SubTableName { get; set; }
/// <summary>
/// 本表关联父表的外键名
/// </summary>
public string SubTableFkName { get; set; } public string SubTableFkName { get; set; }
/// <summary>
/// csharp类名
/// </summary>
public string ClassName { get; set; } public string ClassName { get; set; }
/// <summary>
/// 使用的模板crud单表操作 tree树表操作 sub主子表操作
/// </summary>
public string TplCategory { get; set; } public string TplCategory { get; set; }
/// <summary>
/// 基本命名空间前缀
/// </summary>
public string BaseNameSpace { get; set; } public string BaseNameSpace { get; set; }
/// <summary>
/// 生成模块名
/// </summary>
public string ModuleName { get; set; } public string ModuleName { get; set; }
/// <summary>
/// 生成业务名
/// </summary>
public string BusinessName { get; set; } public string BusinessName { get; set; }
/// <summary>
/// 生成功能名
/// </summary>
public string FunctionName { get; set; } public string FunctionName { get; set; }
/// <summary>
/// 生成作者名
/// </summary>
public string FunctionAuthor { get; set; } public string FunctionAuthor { get; set; }
/// <summary>
/// 生成代码方式0zip压缩包 1自定义路径
/// </summary>
public string GenType { get; set; } public string GenType { get; set; }
/// <summary>
/// 其他生成选项
/// </summary>
public string Options { get; set; } public string Options { get; set; }
/** 表列信息 */ /** 表列信息 */
[SqlSugar.SugarColumn(IsIgnore = true)] [SqlSugar.SugarColumn(IsIgnore = true)]
public List<GenTableColumn> Columns { get; set; } public List<GenTableColumn> Columns { get; set; }

View File

@ -2,22 +2,18 @@ using System;
using Infrastructure.Attribute; using Infrastructure.Attribute;
using ZR.Repository.System; using ZR.Repository.System;
using ZR.Model.Models; using ZR.Model.Models;
using SqlSugar;
namespace ZR.Repository namespace ZR.Repository
{ {
/// <summary> /// <summary>
/// 代码生成演示仓储接口的实现 /// 代码生成演示仓储接口的实现
/// ///
/// @author zhaorui /// @author zr
/// @date 2021-09-24 /// @date 2021-09-27
/// </summary> /// </summary>
[AppService(ServiceLifetime = LifeTime.Transient)] [AppService(ServiceLifetime = LifeTime.Transient)]
public class GendemoRepository : BaseRepository<Gendemo> public class GendemoRepository : BaseRepository<Gendemo>
{ {
public GendemoRepository(SqlSugarClient dbContext) : base(dbContext)
{
}
#region #region
#endregion #endregion
} }

View File

@ -15,19 +15,17 @@ namespace ZR.Service.Business
/// <summary> /// <summary>
/// 代码生成演示Service业务层处理 /// 代码生成演示Service业务层处理
/// ///
/// @author zhaorui /// @author zr
/// @date 2021-09-24 /// @date 2021-09-27
/// </summary> /// </summary>
[AppService(ServiceType = typeof(IGendemoService), ServiceLifetime = LifeTime.Transient)] [AppService(ServiceType = typeof(IGendemoService), ServiceLifetime = LifeTime.Transient)]
public class GendemoService : BaseService<Gendemo>, IGendemoService public class GendemoService: BaseService<Gendemo>, IGendemoService
{ {
//private readonly SqlSugarClient _client; private readonly GendemoRepository _repository;
public GendemoService(GendemoRepository repository)
//public GendemoService(SqlSugarClient client, int db =1) : base(db) {
//{ _repository = repository;
// _client = client; }
//}
#region #region
#endregion #endregion

View File

@ -6,8 +6,8 @@ namespace ZR.Service.Business
/// <summary> /// <summary>
/// 代码生成演示service接口 /// 代码生成演示service接口
/// ///
/// @author zhaorui /// @author zr
/// @date 2021-09-24 /// @date 2021-09-27
/// </summary> /// </summary>
public interface IGendemoService: IBaseService<Gendemo> public interface IGendemoService: IBaseService<Gendemo>
{ {

View File

@ -1,6 +1,7 @@
using Infrastructure.Attribute; using Infrastructure.Attribute;
using Infrastructure.Extensions; using Infrastructure.Extensions;
using Infrastructure.Model; using Infrastructure.Model;
using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@ -113,7 +113,7 @@
<script> <script>
import { updateGenTable, queryColumnInfo } from "@/api/tool/gen"; import { updateGenTable, queryColumnInfo } from "@/api/tool/gen";
import { listType } from "@/api/system/dict/type"; import { listType } from "@/api/system/dict/type";
// import { listMenu as getMenuTreeselect } from "@/api/system/menu"; import { listMenu as getMenuTreeselect } from "@/api/system/menu";
import basicInfoForm from "./basicInfoForm"; import basicInfoForm from "./basicInfoForm";
import genInfoForm from "./genInfoForm"; import genInfoForm from "./genInfoForm";
import Sortable from "sortablejs"; import Sortable from "sortablejs";
@ -161,9 +161,9 @@ export default {
this.dictOptions = response.data.result; this.dictOptions = response.data.result;
}); });
/** 查询菜单下拉列表 */ /** 查询菜单下拉列表 */
// getMenuTreeselect().then((response) => { getMenuTreeselect().then((response) => {
// this.menus = this.handleTree(response.data, "menuId"); this.menus = this.handleTree(response.data, "menuId");
// }); });
} }
}, },
/** 提交按钮 */ /** 提交按钮 */

View File

@ -60,7 +60,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<!-- <el-col :span="12"> <el-col :span="12">
<el-form-item> <el-form-item>
<span slot="label"> <span slot="label">
上级菜单 上级菜单
@ -70,7 +70,7 @@
</span> </span>
<treeselect :append-to-body="true" v-model="info.parentMenuId" :options="menus" :normalizer="normalizer" :show-count="true" placeholder="请选择系统菜单" /> <treeselect :append-to-body="true" v-model="info.parentMenuId" :options="menus" :normalizer="normalizer" :show-count="true" placeholder="请选择系统菜单" />
</el-form-item> </el-form-item>
</el-col> --> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item prop="genType"> <el-form-item prop="genType">

View File

@ -31,8 +31,8 @@
<summary> <summary>
代码生成演示Controller 代码生成演示Controller
@author zhaorui @author zr
@date 2021-09-24 @date 2021-09-27
</summary> </summary>
</member> </member>
<member name="F:ZR.Admin.WebApi.Controllers.GendemoController._GendemoService"> <member name="F:ZR.Admin.WebApi.Controllers.GendemoController._GendemoService">