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

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

View File

@ -20,8 +20,8 @@ namespace ZR.Admin.WebApi.Controllers
/// <summary>
/// 代码生成演示Controller
///
/// @author zhaorui
/// @date 2021-09-24
/// @author zr
/// @date 2021-09-27
/// </summary>
[Verify]
[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)
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
SELECT @menuId := LAST_INSERT_ID();

View File

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

View File

@ -21,10 +21,10 @@ namespace {ServicesNamespace}.Business
[AppService(ServiceType = typeof(I{ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
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)
{
_repository = repository;
_{ModelTypeName}repository = repository;
}
#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)
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
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);
GO
SELECT * FROM sys_menu WHERE parentId = @menuId;
SELECT * FROM sys_menu WHERE parentId = {ParentId};
SELECT * FROM sys_menu WHERE menuId = @menuId;

View File

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

View File

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

View File

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

View File

@ -8,13 +8,6 @@ namespace ZR.CodeGenerator.Model
{
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>
@ -36,10 +29,6 @@ namespace ZR.CodeGenerator.Model
/// </summary>
public string TableName { get; set; }
/// <summary>
/// 表描述、说明
/// </summary>
public string TableDesc { get; set; }
/// <summary>
/// 修改列
/// </summary>
public string UpdateColumn { get; set; }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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