替换代码生成模板
This commit is contained in:
parent
76b0affa48
commit
995c88cd92
@ -151,8 +151,8 @@ namespace ZR.Admin.WebApi.Controllers
|
||||
BusinessName = CodeGeneratorTool.GetBusinessName(tableName),
|
||||
FunctionAuthor = ConfigUtils.Instance.GetConfig(GenConstants.Gen_author),
|
||||
TableName = tableName,
|
||||
TableComment = string.IsNullOrEmpty(tabInfo.Description) ? tableName : tabInfo.Description,
|
||||
FunctionName = string.IsNullOrEmpty(tabInfo.Description) ? tableName : tabInfo.Description,
|
||||
TableComment = tabInfo?.Description,
|
||||
FunctionName = tabInfo?.Description,
|
||||
Create_by = userName,
|
||||
};
|
||||
genTable.TableId = GenTableService.ImportGenTable(genTable);
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using Hei.Captcha;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Extensions;
|
||||
using JinianNet.JNTemplate;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
@ -43,7 +42,7 @@ namespace ZR.Admin.WebApi
|
||||
{
|
||||
c.AddPolicy("Policy", policy =>
|
||||
{
|
||||
policy.WithOrigins(corsUrls.Split(',', System.StringSplitOptions.RemoveEmptyEntries))
|
||||
policy.WithOrigins(corsUrls.Split(',', StringSplitOptions.RemoveEmptyEntries))
|
||||
.AllowAnyHeader()//允许任意头
|
||||
.AllowCredentials()//允许cookie
|
||||
.AllowAnyMethod();//允许任意方法
|
||||
|
||||
@ -17,12 +17,6 @@
|
||||
<Compile Remove="Middleware\RequestIPMiddleware.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="wwwroot\CodeGenTemplate\InputDtoTemplate.txt" />
|
||||
<Content Remove="wwwroot\CodeGenTemplate\ModelTemplate.txt" />
|
||||
<Content Remove="wwwroot\CodeGenTemplate\RepositoryTemplate.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EPPlus" Version="5.8.3" />
|
||||
<PackageReference Include="Hei.Captcha" Version="0.3.0" />
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
"dbType": 1, //MySql = 0, SqlServer = 1
|
||||
"autoPre": true, //自动去除表前缀
|
||||
"author": "zr",
|
||||
"tablePrefix": "live_,sys_" //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
|
||||
"tablePrefix": "sys_" //"表前缀(生成类名不会包含表前缀,多个用逗号分隔)",
|
||||
},
|
||||
//邮箱配置信息
|
||||
"MailOptions": {
|
||||
|
||||
@ -1,154 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using {ModelsNamespace}.Dto;
|
||||
using {ModelsNamespace}.Models;
|
||||
using {ServicesNamespace}.Business;
|
||||
using {ApiControllerNamespace}.Extensions;
|
||||
using {ApiControllerNamespace}.Filters;
|
||||
using ZR.Common;
|
||||
using Infrastructure.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace {ApiControllerNamespace}.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}Controller
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("{ModuleName}/{ModelName}")]
|
||||
public class {ModelName}Controller: BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}接口
|
||||
/// </summary>
|
||||
private readonly I{ModelName}Service _{ModelName}Service;
|
||||
|
||||
public {ModelName}Controller(I{ModelName}Service {ModelName}Service)
|
||||
{
|
||||
_{ModelName}Service = {ModelName}Service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{FunctionName}列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:list")]
|
||||
public IActionResult Query{ModelName}([FromQuery] {ModelName}QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<{ModelName}>();
|
||||
|
||||
//TODO 自己实现搜索条件查询语法参考Sqlsugar,默认查询所有
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
{QueryCondition}
|
||||
var response = _{ModelName}Service.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询{FunctionName}详情
|
||||
/// </summary>
|
||||
/// <param name="{PrimaryKey}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{{PrimaryKey}}")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:query")]
|
||||
public IActionResult Get{ModelName}({PKCsharpType} {PrimaryKey})
|
||||
{
|
||||
var response = _{ModelName}Service.GetFirst(x => x.{PrimaryKey} == {PrimaryKey});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加{FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:add")]
|
||||
[Log(Title = "{FunctionName}", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Add{ModelName}([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<{ModelName}>().ToCreate(HttpContext);
|
||||
|
||||
return SUCCESS(_{ModelName}Service.Insert(model, it => new
|
||||
{
|
||||
{InsertColumn}
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新{FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:update")]
|
||||
[Log(Title = "{FunctionName}", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update{ModelName}([FromBody] {ModelName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<{ModelName}>().ToUpdate(HttpContext);
|
||||
|
||||
var response = _{ModelName}Service.Update(w => w.{PrimaryKey} == model.{PrimaryKey}, it => new {ModelName}()
|
||||
{
|
||||
//Update 字段映射
|
||||
{UpdateColumn}
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除{FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:delete")]
|
||||
[Log(Title = "{FunctionName}", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete{ModelName}(string ids)
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
var response = _{ModelName}Service.Delete(idsArr);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// {FunctionName}导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "{FunctionName}")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "{Permission}:export")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = _{ModelName}Service.GetAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "{ModelName}", "{FunctionName}");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ${ModelsNamespace}.Dto;
|
||||
using ${ModelsNamespace}.Models;
|
||||
|
||||
namespace ${DtosNamespace}.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// ${FunctionName}输入对象模型
|
||||
/// </summary>
|
||||
public class ${ModelTypeName}Dto
|
||||
{
|
||||
${PropertyName}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ${FunctionName}查询对象模型
|
||||
/// </summary>
|
||||
public class ${ModelTypeName}QueryDto: PagerInfo
|
||||
{
|
||||
${QueryProperty}
|
||||
public DateTime? BeginTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
|
||||
namespace {ModelsNamespace}.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName},数据实体对象
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[SugarTable("{TableName}")]
|
||||
public class {ModelTypeName}
|
||||
{
|
||||
{PropertyName}
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,25 @@
|
||||
-- 菜单
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by, create_time, remark)
|
||||
VALUES ('${genTable.functionName}', ${parentId}, 1, '${genTable.ModuleName}/${replaceDto.ModelTypeName}', '${genTable.ModuleName}/${replaceDto.ViewsFileName}/index', 0, 0, 'C', '0', '0', '${replaceDto.permission}:list', 'icon1', '', sysdate(), '${genTable.functionName}菜单');
|
||||
VALUES ('${genTable.functionName}', ${parentId}, 1, '${genTable.ModuleName}/${replaceDto.ModelTypeName}', '${genTable.ModuleName}/${replaceDto.ViewsFileName}/index', 0, 0, 'C', '0', '0', '${replaceDto.PermissionPrefix}:list', 'icon1', '', sysdate(), '${genTable.functionName}菜单');
|
||||
|
||||
-- 按钮父菜单id
|
||||
SELECT @menuId := LAST_INSERT_ID();
|
||||
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
|
||||
VALUES ('${genTable.functionName}查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:query', '', sysdate());
|
||||
VALUES ('${genTable.functionName}查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
|
||||
VALUES ('${genTable.functionName}新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:add', '', sysdate());
|
||||
VALUES ('${genTable.functionName}新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
|
||||
VALUES ('${genTable.functionName}删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:delete', '', sysdate());
|
||||
VALUES ('${genTable.functionName}删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
|
||||
VALUES ('${genTable.functionName}修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:update', '', sysdate());
|
||||
VALUES ('${genTable.functionName}修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', sysdate());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time)
|
||||
VALUES ('${genTable.functionName}导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:export', '', sysdate());
|
||||
VALUES ('${genTable.functionName}导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', sysdate());
|
||||
|
||||
SELECT * FROM sys_menu WHERE parentId = @menuId;
|
||||
SELECT * FROM sys_menu WHERE menuId = @menuId;
|
||||
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using {RepositoriesNamespace}.System;
|
||||
using {ModelsNamespace}.Models;
|
||||
|
||||
namespace {RepositoriesNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// {FunctionName}仓储接口的实现
|
||||
///
|
||||
/// @author {Author}
|
||||
/// @date {DateTime}
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class {ModelTypeName}Repository : BaseRepository<{ModelTypeName}>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,25 @@
|
||||
-- ${genTable.functionName}菜单
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_time, remark)
|
||||
VALUES ('${genTable.functionName}', ${parentId}, 1, '${genTable.ModuleName}/${replaceDto.ModelTypeName}', '${genTable.ModuleName}/${replaceDto.ViewsFileName}/index', 0, 0, 'C', '0', '0', '${replaceDto.permission}:list', 'icon1', GETDATE(), '${genTable.functionName}');
|
||||
VALUES ('${genTable.functionName}', ${parentId}, 1, '${genTable.ModuleName}/${replaceDto.ModelTypeName}', '${genTable.ModuleName}/${replaceDto.ViewsFileName}/index', 0, 0, 'C', '0', '0', '${replaceDto.PermissionPrefix}:list', 'icon1', GETDATE(), '${genTable.functionName}');
|
||||
|
||||
-- 按钮父菜单id
|
||||
declare @menuId int = @@identity
|
||||
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||
VALUES ('${genTable.functionName}查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:query', '', '', GETDATE());
|
||||
VALUES ('${genTable.functionName}查询', @menuId, 1, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:query', '', '', GETDATE());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||
VALUES ('${genTable.functionName}新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:add', '', '', GETDATE());
|
||||
VALUES ('${genTable.functionName}新增', @menuId, 2, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:add', '', '', GETDATE());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||
VALUES ('${genTable.functionName}删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:delete', '', '', GETDATE());
|
||||
VALUES ('${genTable.functionName}删除', @menuId, 3, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:delete', '', '', GETDATE());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||
VALUES ('${genTable.functionName}修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:update', '', '', GETDATE());
|
||||
VALUES ('${genTable.functionName}修改', @menuId, 4, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:update', '', '', GETDATE());
|
||||
|
||||
INSERT INTO sys_menu(menuName, parentId, orderNum, path, component, isFrame, isCache, menuType, visible, status, perms, icon, create_by,create_time)
|
||||
VALUES ('${genTable.functionName}导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.permission}:export', '', '', GETDATE());
|
||||
VALUES ('${genTable.functionName}导出', @menuId, 5, '#', NULL, 0, 0, 'F', '0', '0', '${replaceDto.PermissionPrefix}:export', '', '', GETDATE());
|
||||
|
||||
SELECT * FROM sys_menu WHERE parentId = @menuId;
|
||||
SELECT * FROM sys_menu WHERE menuId = @menuId;
|
||||
154
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt
Normal file
154
ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt
Normal file
@ -0,0 +1,154 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using ${options.ModelsNamespace}.Dto;
|
||||
using ${options.ModelsNamespace}.Models;
|
||||
using ${options.ServicesNamespace}.Business;
|
||||
using ${options.ApiControllerNamespace}.Extensions;
|
||||
using ${options.ApiControllerNamespace}.Filters;
|
||||
using ZR.Common;
|
||||
using Infrastructure.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace ${options.ApiControllerNamespace}.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.functionName}Controller
|
||||
///
|
||||
/// @author ${replaceDto.Author}
|
||||
/// @date ${replaceDto.AddTime}
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("${genTable.ModuleName}/${replaceDto.ModelTypeName}")]
|
||||
public class ${replaceDto.ModelTypeName}Controller : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}接口
|
||||
/// </summary>
|
||||
private readonly I${replaceDto.ModelTypeName}Service _${replaceDto.ModelTypeName}Service;
|
||||
|
||||
public ${replaceDto.ModelTypeName}Controller(I${replaceDto.ModelTypeName}Service ${replaceDto.ModelTypeName}Service)
|
||||
{
|
||||
_${replaceDto.ModelTypeName}Service = ${replaceDto.ModelTypeName}Service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:list")]
|
||||
public IActionResult Query${replaceDto.ModelTypeName}([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
|
||||
|
||||
//TODO 自己实现搜索条件查询语法参考Sqlsugar,默认查询所有
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
${QueryCondition}
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}详情
|
||||
/// </summary>
|
||||
/// <param name="${replaceDto.PKName}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{${replaceDto.PKName}}")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:query")]
|
||||
public IActionResult Get${replaceDto.ModelTypeName}(${replaceDto.PKType} ${replaceDto.PKName})
|
||||
{
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetFirst(x => x.${replaceDto.PKName} == ${replaceDto.PKName});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:add")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Add${replaceDto.ModelTypeName}([FromBody] ${replaceDto.ModelTypeName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<${replaceDto.ModelTypeName}>().ToCreate(HttpContext);
|
||||
|
||||
return SUCCESS(_${replaceDto.ModelTypeName}Service.Insert(model, it => new
|
||||
{
|
||||
${InsertColumn}
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:update")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update${replaceDto.ModelTypeName}([FromBody] ${replaceDto.ModelTypeName}Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求实体不能为空");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var model = parm.Adapt<${replaceDto.ModelTypeName}>().ToUpdate(HttpContext);
|
||||
|
||||
var response = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == model.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}()
|
||||
{
|
||||
//Update 字段映射
|
||||
${UpdateColumn}
|
||||
});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete${replaceDto.ModelTypeName}(string ids)
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
var response = _${replaceDto.ModelTypeName}Service.Delete(idsArr);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "${genTable.FunctionName}")]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:export")]
|
||||
public IActionResult Export()
|
||||
{
|
||||
var list = _${replaceDto.ModelTypeName}Service.GetAll();
|
||||
|
||||
string sFileName = ExportExcel(list, "${replaceDto.ModelTypeName}", "${genTable.FunctionName}");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,7 @@ namespace ZR.CodeGenerator
|
||||
ReplaceDto replaceDto = new();
|
||||
replaceDto.ModelTypeName = dto.GenTable.ClassName;//表名对应C# 实体类名
|
||||
replaceDto.TableName = dto.GenTable.TableName;//表名
|
||||
replaceDto.Permission = $"{dto.GenTable.ModuleName}:{dto.GenTable.ClassName.ToLower()}";//权限
|
||||
replaceDto.PermissionPrefix = $"{dto.GenTable.ModuleName}:{dto.GenTable.ClassName.ToLower()}";//权限
|
||||
replaceDto.Author = dto.GenTable.FunctionAuthor;
|
||||
replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName);
|
||||
|
||||
@ -94,12 +94,10 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
|
||||
CodeGenerateTemplate.GetQueryDtoProperty(dbFieldInfo, replaceDto);
|
||||
//replaceDto.ModelProperty += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
|
||||
replaceDto.VueViewFormHtml += CodeGenerateTemplate.TplVueFormContent(dbFieldInfo);
|
||||
CodeGenerateTemplate.TplVueJsMethod(dbFieldInfo, replaceDto);
|
||||
replaceDto.VueViewFormHtml += CodeGenerateTemplate.TplVueFormContent(dbFieldInfo);
|
||||
replaceDto.VueViewListHtml += CodeGenerateTemplate.TplTableColumn(dbFieldInfo);
|
||||
replaceDto.VueViewEditFormRuleContent += CodeGenerateTemplate.TplFormRules(dbFieldInfo);
|
||||
//replaceDto.InputDtoProperty += CodeGenerateTemplate.GetDtoProperty(dbFieldInfo);
|
||||
replaceDto.VueQueryFormHtml += CodeGenerateTemplate.TplQueryFormHtml(dbFieldInfo);
|
||||
}
|
||||
replaceDto.VueDataContent = sb1.ToString();
|
||||
@ -144,7 +142,7 @@ namespace ZR.CodeGenerator
|
||||
var tpl = FileHelper.ReadJtTemplate("TplModel.txt");
|
||||
var result = tpl.Render();
|
||||
|
||||
generateDto.GenCodes.Add(new GenCode(1, "实体类", fullPath, result));
|
||||
generateDto.GenCodes.Add(new GenCode(1, "Model", fullPath, result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -159,7 +157,7 @@ namespace ZR.CodeGenerator
|
||||
var tpl = FileHelper.ReadJtTemplate("TplDto.txt");
|
||||
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(2, "数据传输实体类", fullPath, result));
|
||||
generateDto.GenCodes.Add(new GenCode(2, "Dto", fullPath, result));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -177,7 +175,7 @@ namespace ZR.CodeGenerator
|
||||
var tpl = FileHelper.ReadJtTemplate("TplRepository.txt");
|
||||
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(3, "仓储层", fullPath, result));
|
||||
generateDto.GenCodes.Add(new GenCode(3, "Repository", fullPath, result));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -195,7 +193,7 @@ namespace ZR.CodeGenerator
|
||||
var tpl = FileHelper.ReadJtTemplate("IServiceTemplate.txt");
|
||||
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(4, "接口层", fullPath, result));
|
||||
generateDto.GenCodes.Add(new GenCode(4, "IService", fullPath, result));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -208,7 +206,7 @@ namespace ZR.CodeGenerator
|
||||
var tpl = FileHelper.ReadJtTemplate("ServiceTemplate.txt");
|
||||
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(4, "服务层", fullPath, result));
|
||||
generateDto.GenCodes.Add(new GenCode(4, "Service", fullPath, result));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -217,36 +215,47 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 生成控制器ApiControllers文件
|
||||
/// </summary>
|
||||
//private static void GenerateControllers(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
//{
|
||||
// var fullPath = Path.Combine(generateDto.GenCodePath, _option.ApiControllerNamespace, "Controllers", generateDto.GenTable.ModuleName, $"{replaceDto.ModelTypeName}Controller.cs");
|
||||
|
||||
// var content = FileHelper.ReadTemplate("ControllersTemplate.txt")
|
||||
// .Replace("{ApiControllerNamespace}", _option.ApiControllerNamespace)
|
||||
// .Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
// .Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
// .Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
// .Replace("{ModelName}", replaceDto.ModelTypeName)
|
||||
// .Replace("{Permission}", replaceDto.Permission)
|
||||
// .Replace("{PrimaryKey}", replaceDto.PKName)
|
||||
// .Replace("{ModuleName}", generateDto.GenTable.ModuleName)
|
||||
// .Replace("{PKCsharpType}", replaceDto.PKType)
|
||||
// .Replace("{Author}", replaceDto.Author)
|
||||
// .Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
// if (replaceDto.UpdateColumn != null)
|
||||
// {
|
||||
// content = content.Replace("{UpdateColumn}", replaceDto.UpdateColumn.TrimEnd('\n'));
|
||||
// }
|
||||
// if (replaceDto.InsertColumn != null)
|
||||
// {
|
||||
// content = content.Replace("{InsertColumn}", replaceDto.InsertColumn.TrimEnd('\n'));
|
||||
// }
|
||||
// if (replaceDto.QueryCondition != null)
|
||||
// {
|
||||
// content = content.Replace("{QueryCondition}", replaceDto.QueryCondition);
|
||||
// }
|
||||
// generateDto.GenCodes.Add(new GenCode(5, "控制器", fullPath, content));
|
||||
//}
|
||||
private static void GenerateControllers(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ApiControllerNamespace, "Controllers", generateDto.GenTable.ModuleName, $"{replaceDto.ModelTypeName}Controller.cs");
|
||||
|
||||
var content = FileHelper.ReadTemplate("ControllersTemplate.txt")
|
||||
.Replace("{ApiControllerNamespace}", _option.ApiControllerNamespace)
|
||||
.Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{ModelName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{PrimaryKey}", replaceDto.PKName)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName)
|
||||
.Replace("{PKCsharpType}", replaceDto.PKType)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
if (replaceDto.UpdateColumn != null)
|
||||
{
|
||||
content = content.Replace("{UpdateColumn}", replaceDto.UpdateColumn.TrimEnd('\n'));
|
||||
}
|
||||
if (replaceDto.InsertColumn != null)
|
||||
{
|
||||
content = content.Replace("{InsertColumn}", replaceDto.InsertColumn.TrimEnd('\n'));
|
||||
}
|
||||
if (replaceDto.QueryCondition != null)
|
||||
{
|
||||
content = content.Replace("{QueryCondition}", replaceDto.QueryCondition);
|
||||
}
|
||||
generateDto.GenCodes.Add(new GenCode(5, "控制器", fullPath, content));
|
||||
var tpl = FileHelper.ReadJtTemplate("TplControllers.txt");
|
||||
tpl.Set("QueryCondition", replaceDto.QueryCondition);
|
||||
tpl.Set("InsertColumn", replaceDto.InsertColumn.TrimEnd('\n'));
|
||||
tpl.Set("UpdateColumn", replaceDto.UpdateColumn.TrimEnd('\n'));
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(5, "Controller", fullPath, result));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -262,7 +271,7 @@ namespace ZR.CodeGenerator
|
||||
.Replace("{VueViewListContent}", replaceDto.VueViewListHtml)//查询 table列
|
||||
.Replace("{VueViewFormContent}", replaceDto.VueViewFormHtml)//添加、修改表单
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{Permission}", replaceDto.PermissionPrefix)
|
||||
.Replace("{VueViewFormResetHtml}", replaceDto.VueViewFormResetHtml)
|
||||
.Replace("{vueJsMethod}", replaceDto.VueJsMethod)
|
||||
.Replace("{vueQueryFormHtml}", replaceDto.VueQueryFormHtml)
|
||||
@ -312,7 +321,7 @@ namespace ZR.CodeGenerator
|
||||
break;
|
||||
}
|
||||
var tpl = FileHelper.ReadJtTemplate($"{tempName}.txt");
|
||||
|
||||
tpl.Set("parentId", generateDto.GenTable.ParentMenuId);
|
||||
var result = tpl.Render();
|
||||
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, result));
|
||||
}
|
||||
@ -355,8 +364,8 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
int lastIndex = tableName.LastIndexOf("_");
|
||||
int nameLength = tableName.Length;
|
||||
string businessName = tableName.Substring(lastIndex + 1, nameLength);
|
||||
return businessName;
|
||||
string businessName = tableName.Substring(nameLength - lastIndex + 1);
|
||||
return businessName.ToLower();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -494,7 +503,7 @@ namespace ZR.CodeGenerator
|
||||
/// <param name="replaceDto"></param>
|
||||
private static void InitJntTemplate(GenerateDto dto, ReplaceDto replaceDto)
|
||||
{
|
||||
//Engine.Current.Clean();
|
||||
Engine.Current.Clean();
|
||||
|
||||
//jnt模板引擎全局变量
|
||||
Engine.Configure((options) =>
|
||||
@ -503,6 +512,8 @@ namespace ZR.CodeGenerator
|
||||
options.TagSuffix = "}";
|
||||
options.TagFlag = '$';
|
||||
options.OutMode = OutMode.Auto;
|
||||
//options.DisableeLogogram = true;//禁用简写
|
||||
options.Data.Set("${flag}", "$");//特殊标签替换
|
||||
options.Data.Set("replaceDto", replaceDto);
|
||||
options.Data.Set("options", dto.GenOptions);
|
||||
options.Data.Set("genTable", dto.GenTable);
|
||||
|
||||
@ -20,7 +20,7 @@ namespace ZR.CodeGenerator.Model
|
||||
/// <summary>
|
||||
/// 控制器权限
|
||||
/// </summary>
|
||||
public string Permission { get; set; }
|
||||
public string PermissionPrefix { get; set; }
|
||||
/// <summary>
|
||||
/// C#类名
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user