You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

63 lines
1.4 KiB

using Mapster;
using Microsoft.AspNetCore.Mvc;
using Wood.Data.Repository;
using Wood.Entity;
namespace Wood.Service.BaseService
{
public class ApiCRUDService<T, TDTO, TAddParam, TUpdateParam> : ApiService
where T : EntityBase, new()
where TAddParam : class, new()
where TUpdateParam : class, new()
{
protected SqlSugarRepository<T> _repository { get; set; }
public ApiCRUDService(SqlSugarRepository<T> repository)
{
_repository = repository;
}
/// <summary>
/// 获取明细
/// </summary>
/// <returns></returns>
public virtual async Task<TDTO> GetDetail(BaseIdParam param)
{
var dto = await _repository.GetByIdAsync(param.Id);
return dto.Adapt<TDTO>();
}
/// <summary>
/// 新增
/// </summary>
/// <returns></returns>
[UnitOfWork]
public virtual async Task Add(TAddParam param)
{
var input = param.Adapt<T>();
await _repository.InsertAsync(input);
}
/// <summary>
/// 更新
/// </summary>
/// <returns></returns>
[UnitOfWork]
public virtual async Task Update(TUpdateParam param)
{
var input = param.Adapt<T>();
await _repository.UpdateAsync(input);
}
/// <summary>
/// 批量删除
/// 假删除
/// </summary>
/// <returns></returns>
[UnitOfWork]
public virtual async Task Delete(BaseIdListParam param)
{
if(param.Ids.Any())
await _repository.FakeDeleteAsync(it=>param.Ids.Contains(it.Id));
}
}
}