简单基类控制器封装
This commit is contained in:
@@ -102,6 +102,46 @@
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseSimpleCrudController`1">
|
||||
<summary>
|
||||
Json To Sql 类比模式,通用模型
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseSimpleCrudController`1.GetById(System.Int64)">
|
||||
<summary>
|
||||
主键查询
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseSimpleCrudController`1.GetList(Yi.Framework.Model.Query.QueryCondition)">
|
||||
<summary>
|
||||
全部列表查询
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseSimpleCrudController`1.Add(`0)">
|
||||
<summary>
|
||||
添加
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseSimpleCrudController`1.Update(`0)">
|
||||
<summary>
|
||||
修改
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.BaseSimpleCrudController`1.DelList(System.Collections.Generic.List{System.Int64})">
|
||||
<summary>
|
||||
列表删除
|
||||
</summary>
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.DictionaryController.PageList(Yi.Framework.Model.Models.DictionaryEntity,Yi.Framework.Common.Models.PageParModel)">
|
||||
<summary>
|
||||
动态条件分页查询
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Language;
|
||||
@@ -15,7 +16,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[ApiController]
|
||||
public class BaseCrudController<T> : ControllerBase where T : class, IBaseModelEntity,new()
|
||||
public class BaseCrudController<T> : ControllerBase where T : class,new()
|
||||
{
|
||||
private readonly ILogger<T> _logger;
|
||||
private IBaseService<T> _baseService;
|
||||
@@ -95,7 +96,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
[HttpDelete]
|
||||
public virtual async Task<Result> DeleteList(List<long> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.DeleteByLogicAsync(ids));
|
||||
return Result.Success().SetStatus(await _repository.DeleteByIdAsync(ids.ToDynamicArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Language;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Model.Query;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Json To Sql 类比模式,通用模型
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[ApiController]
|
||||
public class BaseSimpleCrudController<T> : ControllerBase where T : class, new()
|
||||
{
|
||||
private readonly ILogger<T> _logger;
|
||||
private IBaseService<T> _baseService;
|
||||
private IRepository<T> _repository;
|
||||
public BaseSimpleCrudController(ILogger<T> logger, IBaseService<T> iBaseService)
|
||||
{
|
||||
_logger = logger;
|
||||
_baseService = iBaseService;
|
||||
_repository = iBaseService._repository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主键查询
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get")]
|
||||
[HttpGet]
|
||||
public virtual async Task<Result> GetById(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetByIdAsync(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部列表查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get")]
|
||||
[HttpPost]
|
||||
public virtual async Task<Result> GetList()
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetListAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:add")]
|
||||
[HttpPost]
|
||||
public virtual async Task<Result> Add(T entity)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.InsertReturnSnowflakeIdAsync(entity));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:update")]
|
||||
[HttpPut]
|
||||
public virtual async Task<Result> Update(T entity)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.UpdateIgnoreNullAsync(entity));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表删除
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:del")]
|
||||
[HttpDelete]
|
||||
public virtual async Task<Result> DelList(List<long> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.DeleteByIdsAsync(ids.ToDynamicArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class DictionaryController
|
||||
public class DictionaryController :BaseSimpleCrudController<DictionaryEntity>
|
||||
{
|
||||
private IDictionaryService _iDictionaryService;
|
||||
private IDictionaryInfoService _iDictionaryInfoService;
|
||||
public DictionaryController(ILogger<DictionaryEntity> logger, IDictionaryService iDictionaryService, IDictionaryInfoService iDictionaryInfoService)
|
||||
public DictionaryController(ILogger<DictionaryEntity> logger, IDictionaryService iDictionaryService):base(logger, iDictionaryService)
|
||||
{
|
||||
_iDictionaryService = iDictionaryService;
|
||||
_iDictionaryInfoService = iDictionaryInfoService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,63 +38,5 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryService.SelctPageList(dic, page));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加字典表
|
||||
/// </summary>
|
||||
/// <param name="dic"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(DictionaryEntity dic)
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryService._repository.InsertReturnSnowflakeIdAsync(dic));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典id获取字典表
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<Result> GetById(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryService._repository.GetByIdAsync(id));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部字典表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetList()
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryService._repository.GetListAsync());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// id范围删除
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
|
||||
public async Task<Result> DelList(List<long> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iDictionaryService._repository.DeleteByIdsAsync(ids.ToDynamicArray()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="dic"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(DictionaryEntity dic)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iDictionaryService._repository.UpdateIgnoreNullAsync(dic));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class DictionaryInfoController
|
||||
public class DictionaryInfoController:BaseSimpleCrudController<DictionaryInfoEntity>
|
||||
{
|
||||
private IDictionaryService _iDictionaryService;
|
||||
private IDictionaryInfoService _iDictionaryInfoService;
|
||||
public DictionaryInfoController(ILogger<DictionaryEntity> logger, IDictionaryService iDictionaryService, IDictionaryInfoService iDictionaryInfoService)
|
||||
public DictionaryInfoController(ILogger<DictionaryInfoEntity> logger, IDictionaryInfoService iDictionaryInfoService):base(logger, iDictionaryInfoService)
|
||||
{
|
||||
_iDictionaryService = iDictionaryService;
|
||||
_iDictionaryInfoService = iDictionaryInfoService;
|
||||
}
|
||||
|
||||
@@ -41,17 +39,6 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
return Result.Success().SetData(await _iDictionaryInfoService.SelctPageList(dicInfo, page));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加字典信息表
|
||||
/// </summary>
|
||||
/// <param name="dicInfo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(DictionaryInfoEntity dicInfo)
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryInfoService._repository.InsertReturnSnowflakeIdAsync(dicInfo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典类别获取字典信息
|
||||
/// </summary>
|
||||
@@ -63,42 +50,5 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryInfoService._repository.GetListAsync(u=>u.DictType==type&&u.IsDeleted==false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// id范围删除
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete]
|
||||
|
||||
public async Task<Result> DelList(List<long> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iDictionaryInfoService._repository.DeleteByIdsAsync(ids.ToDynamicArray()));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="dicInfo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(DictionaryInfoEntity dicInfo)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iDictionaryInfoService._repository.UpdateIgnoreNullAsync(dicInfo));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据字典id获取字典信息表
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<Result> GetById(long id)
|
||||
{
|
||||
return Result.Success().SetData(await _iDictionaryInfoService._repository.GetByIdAsync(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user