138 lines
4.4 KiB
Plaintext
138 lines
4.4 KiB
Plaintext
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;
|
||
|
||
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));
|
||
|
||
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.GetId({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);
|
||
}
|
||
}
|
||
} |