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, IKpiAreaRepository, IScopedDependency { public Task 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 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> GetInfosAsync(int areaId, int pageIndex, int pageSize, CancellationToken cancellationToken = default) { var db = await GetDbContextAsync(cancellationToken); return await db.Queryable() .Where(x => x.AreaId == areaId) .OrderBy(x => x.Id, SqlSugar.OrderByType.Desc) .ToPageListAsync(pageIndex, pageSize, cancellationToken); } public async Task CountInfosAsync(int areaId, CancellationToken cancellationToken = default) { var db = await GetDbContextAsync(cancellationToken); return await db.Queryable().Where(x => x.AreaId == areaId).CountAsync(cancellationToken); } public async Task InsertInfoAsync(KpiAreaInfo info, CancellationToken cancellationToken = default) { var db = await GetDbContextAsync(cancellationToken); return await db.Insertable(info).ExecuteReturnEntityAsync(); } public async Task GetInfoByIdAsync(int id, CancellationToken cancellationToken = default) { var db = await GetDbContextAsync(cancellationToken); return await db.Queryable().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().Where(x => x.Id == id).ExecuteCommandAsync(cancellationToken); } public async Task> GetAllInfosByAreaIdAsync(int areaId, CancellationToken cancellationToken = default) { var db = await GetDbContextAsync(cancellationToken); return await db.Queryable() .Where(x => x.AreaId == areaId) .OrderBy(x => x.Id) .ToListAsync(cancellationToken); } }