namespace Easy.Admin.Application; public abstract class BaseService : IDynamicApiController where TEntity : Entity, ISoftDelete, IAvailability, new() { private readonly ISqlSugarRepository _repository; protected BaseService(ISqlSugarRepository repository) { _repository = repository; } /// /// 删除信息 /// /// /// [DisplayName("删除信息"), HttpDelete("delete")] public virtual async Task Delete(KeyDto dto) { bool success = await _repository.UpdateAsync(x => new TEntity() { DeleteMark = true }, x => x.Id == dto.Id); if (!success) { throw Oops.Bah("删除失败"); } await ClearCache(); } /// /// 修改状态 /// /// /// [DisplayName("修改状态"), HttpPatch("setStatus")] public virtual async Task SetStatus(AvailabilityDto dto) { bool success = await _repository.UpdateAsync(x => new TEntity() { Status = dto.Status }, x => x.Id == dto.Id); if (!success) { throw Oops.Bah("修改失败"); } await ClearCache(); } /// /// 清除缓存 /// /// internal virtual Task ClearCache() { return Task.CompletedTask; } }