admin/src/Oms.SqlSugarCore/Channels/KpiAreaRepository.cs

68 lines
2.9 KiB
C#

using Fake.DependencyInjection;
using Oms.Domain.ChannelsAggregate.Entities;
using Oms.Domain.ChannelsAggregate.Repositories;
using Oms.SqlSugarCore.Repositories;
namespace Oms.SqlSugarCore.Channels;
public class KpiAreaRepository : OmsSqlSugarRepository<KpiArea>, IKpiAreaRepository, IScopedDependency
{
public Task<KpiArea?> GetByAppKeyTypeAndNameAsync(string appKey, string areaType, string name, CancellationToken cancellationToken = default)
{
return FirstOrDefaultAsync(x => x.AppKey == appKey && x.AreaType == areaType && x.Name == name, cancellationToken);
}
public Task<bool> ExistsNameAsync(string appKey, string areaType, string name, CancellationToken cancellationToken = default)
{
return AnyAsync(x => x.AppKey == appKey && x.AreaType == areaType && x.Name == name, cancellationToken);
}
public async Task<List<KpiAreaInfo>> GetInfosAsync(int areaId, int pageIndex, int pageSize, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
return await db.Queryable<KpiAreaInfo>()
.Where(x => x.AreaId == areaId)
.OrderBy(x => x.Id, SqlSugar.OrderByType.Desc)
.ToPageListAsync(pageIndex, pageSize, cancellationToken);
}
public async Task<int> CountInfosAsync(int areaId, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
return await db.Queryable<KpiAreaInfo>().Where(x => x.AreaId == areaId).CountAsync(cancellationToken);
}
public async Task<KpiAreaInfo> InsertInfoAsync(KpiAreaInfo info, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
return await db.Insertable(info).ExecuteReturnEntityAsync();
}
public async Task<KpiAreaInfo?> GetInfoByIdAsync(int id, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
return await db.Queryable<KpiAreaInfo>().FirstAsync(x => x.Id == id, cancellationToken);
}
public async Task UpdateInfoAsync(KpiAreaInfo info, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
await db.Updateable(info).ExecuteCommandAsync(cancellationToken);
}
public async Task DeleteInfoAsync(int id, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
await db.Deleteable<KpiAreaInfo>().Where(x => x.Id == id).ExecuteCommandAsync(cancellationToken);
}
public async Task<List<KpiAreaInfo>> GetAllInfosByAreaIdAsync(int areaId, CancellationToken cancellationToken = default)
{
var db = await GetDbContextAsync(cancellationToken);
return await db.Queryable<KpiAreaInfo>()
.Where(x => x.AreaId == areaId)
.OrderBy(x => x.Id)
.ToListAsync(cancellationToken);
}
}