2022-04-06 18:05:00 +08:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Microsoft.Extensions.Localization;
|
2022-09-10 20:49:46 +08:00
|
|
|
|
using Yi.Framework.Common.Helper;
|
2022-04-06 18:05:00 +08:00
|
|
|
|
using Yi.Framework.Common.Models;
|
2022-04-08 23:44:25 +08:00
|
|
|
|
using Yi.Framework.Interface;
|
2022-04-09 16:16:32 +08:00
|
|
|
|
using Yi.Framework.Language;
|
2022-04-08 23:44:25 +08:00
|
|
|
|
using Yi.Framework.Model.Models;
|
2022-04-06 18:05:00 +08:00
|
|
|
|
using Yi.Framework.Model.Query;
|
|
|
|
|
|
using Yi.Framework.Repository;
|
2022-04-06 22:22:45 +08:00
|
|
|
|
using Yi.Framework.WebCore.AttributeExtend;
|
2022-04-06 18:05:00 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Yi.Framework.ApiMicroservice.Controllers
|
|
|
|
|
|
{
|
2022-04-07 22:48:10 +08:00
|
|
|
|
/// <summary>
|
2022-04-12 18:09:13 +08:00
|
|
|
|
/// Json To Sql 类比模式,通用模型
|
2022-04-07 22:48:10 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2022-04-06 18:05:00 +08:00
|
|
|
|
[ApiController]
|
2022-09-28 18:05:49 +08:00
|
|
|
|
public class BaseCrudController<T> : BaseExcelController<T> where T : class,new()
|
2022-04-06 18:05:00 +08:00
|
|
|
|
{
|
2022-09-28 18:05:49 +08:00
|
|
|
|
protected readonly ILogger<T> _logger;
|
|
|
|
|
|
protected IBaseService<T> _baseService;
|
|
|
|
|
|
public BaseCrudController(ILogger<T> logger, IBaseService<T> iBaseService):base(iBaseService._repository)
|
2022-04-06 18:05:00 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
2022-04-08 23:44:25 +08:00
|
|
|
|
_baseService = iBaseService;
|
2022-04-06 18:05:00 +08:00
|
|
|
|
}
|
2022-04-07 22:48:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 主键查询
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2022-04-06 18:05:00 +08:00
|
|
|
|
[HttpGet]
|
2022-04-26 18:29:18 +08:00
|
|
|
|
public virtual async Task<Result> GetById(long id)
|
2022-04-06 22:22:45 +08:00
|
|
|
|
{
|
2022-04-08 23:44:25 +08:00
|
|
|
|
return Result.Success().SetData(await _repository.GetByIdAsync(id));
|
2022-04-06 22:22:45 +08:00
|
|
|
|
}
|
2022-04-07 22:48:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 列表查询
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2022-04-08 23:44:25 +08:00
|
|
|
|
[HttpPost]
|
2022-04-26 18:29:18 +08:00
|
|
|
|
public virtual async Task<Result> GetList(QueryCondition queryCondition)
|
2022-04-06 18:05:00 +08:00
|
|
|
|
{
|
2022-04-08 23:44:25 +08:00
|
|
|
|
return Result.Success().SetData(await _repository.GetListAsync(queryCondition));
|
2022-04-06 18:05:00 +08:00
|
|
|
|
}
|
2022-04-07 22:48:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 条件分页查询
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="queryCondition"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2022-04-06 18:05:00 +08:00
|
|
|
|
[HttpPost]
|
2022-04-26 18:29:18 +08:00
|
|
|
|
public virtual async Task<Result> PageList(QueryPageCondition queryCondition)
|
2022-04-06 18:05:00 +08:00
|
|
|
|
{
|
2022-04-10 22:56:45 +08:00
|
|
|
|
return Result.Success().SetData(await _repository.CommonPageAsync(queryCondition));
|
2022-04-06 18:05:00 +08:00
|
|
|
|
}
|
2022-04-07 22:48:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2022-04-06 18:05:00 +08:00
|
|
|
|
[HttpPost]
|
2022-04-26 18:29:18 +08:00
|
|
|
|
public virtual async Task<Result> Add(T entity)
|
2022-04-06 18:05:00 +08:00
|
|
|
|
{
|
2022-04-09 16:16:32 +08:00
|
|
|
|
return Result.Success().SetData(await _repository.InsertReturnSnowflakeIdAsync(entity));
|
2022-04-06 18:05:00 +08:00
|
|
|
|
}
|
2022-04-07 22:48:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2022-04-06 18:05:00 +08:00
|
|
|
|
[HttpPut]
|
2022-04-26 18:29:18 +08:00
|
|
|
|
public virtual async Task<Result> Update(T entity)
|
2022-04-06 18:05:00 +08:00
|
|
|
|
{
|
2022-04-10 22:56:45 +08:00
|
|
|
|
return Result.Success().SetStatus(await _repository.UpdateIgnoreNullAsync(entity));
|
2022-04-06 18:05:00 +08:00
|
|
|
|
}
|
2022-04-07 22:48:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 列表删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2022-04-06 18:05:00 +08:00
|
|
|
|
[HttpDelete]
|
2022-04-26 18:29:18 +08:00
|
|
|
|
public virtual async Task<Result> DeleteList(List<long> ids)
|
2022-04-06 18:05:00 +08:00
|
|
|
|
{
|
2022-09-10 20:49:46 +08:00
|
|
|
|
return Result.Success().SetStatus(await _repository.DeleteByIdAsync(ids.ToDynamicArray()));
|
2022-04-06 18:05:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|