代码生成增加service、Repository、Controller层
This commit is contained in:
124
ZR.Admin.WebApi/Template/ControllersTemplate.txt
Normal file
124
ZR.Admin.WebApi/Template/ControllersTemplate.txt
Normal file
@@ -0,0 +1,124 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.Admin.WebApi.Filters;
|
||||
using ZR.Admin.WebApi.Controllers;
|
||||
using ZR.Service;
|
||||
using SqlSugar;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using ZR.Admin.WebApi.Extensions;
|
||||
using ZR.Model;
|
||||
|
||||
namespace ZRAdmin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// T4代码自动生成
|
||||
/// </summary>
|
||||
|
||||
[Verify]
|
||||
[Route("bus/<#=ModelName#>")]
|
||||
public class <#=ControllerName#>Controller: BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// <#=FileName#>接口
|
||||
/// </summary>
|
||||
private readonly I<#=ServiceName#> _<#=ServiceName#>;
|
||||
|
||||
public <#=ControllerName#>Controller(I<#=ServiceName#> <#=ServiceName#>)
|
||||
{
|
||||
_<#=ServiceName#> = <#=ServiceName#>;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询<#=FileName#>列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:list")]
|
||||
public IActionResult Query([FromQuery] <#=ModelName#>QueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件
|
||||
var predicate = Expressionable.Create<<#=ModelName#>>();
|
||||
|
||||
//TODO 搜索条件
|
||||
//predicate = predicate.And(m => m.Name.Contains(parm.Name));
|
||||
|
||||
var response = _<#=ServiceName#>.GetPages(predicate.ToExpression(), parm);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询<#=FileName#>详情
|
||||
/// </summary>
|
||||
/// <param name="{primaryKey}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{{primaryKey}}")]
|
||||
public IActionResult Get(int {primaryKey})
|
||||
{
|
||||
var response = _<#=ServiceName#>.GetId({primaryKey});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加<#=FileName#>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:add")]
|
||||
[Log(Title = "<#=FileName#>添加", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Create([FromBody] <#=ModelName#>Dto parm)
|
||||
{
|
||||
if (parm == null)
|
||||
{
|
||||
throw new CustomException("请求参数错误");
|
||||
}
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<<#=ModelName#>>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
|
||||
return SUCCESS(_<#=ServiceName#>.Add(addModel));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新<#=FileName#>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut("edit")]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:update")]
|
||||
[Log(Title = "<#=FileName#>修改", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update([FromBody] <#=ModelName#>Dto parm)
|
||||
{
|
||||
//从 Dto 映射到 实体
|
||||
var addModel = parm.Adapt<<#=ModelName#>>().ToCreate();
|
||||
//addModel.CreateID = User.Identity.Name;
|
||||
//TODO 字段映射
|
||||
var response = _<#=ServiceName#>.Update(addModel);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除<#=FileName#>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{{primaryKey}}")]
|
||||
[ActionPermissionFilter(Permission = "<#=ModelName#>:delete")]
|
||||
[Log(Title = "<#=FileName#>删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(int {primaryKey} = 0)
|
||||
{
|
||||
if ({primaryKey} <= 0) { return OutputJson(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
|
||||
// 删除<#=FileName#>
|
||||
var response = _<#=ServiceName#>.Delete({primaryKey});
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user