using SJZY.Track.Domain; using SJZY.Track.Domain.Aggregates.KPIAreaAggregate; using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.VEntities; namespace SJZY.Track.Repository.Repositories; public class KpiAreaRepository : BasicRepository, IKpiAreaRepository, ITransientDependency { public async ValueTask CreateAreaAsync(RuleAreaEntity entity) { return await InsertReturnIdentityAsync(entity); } public async ValueTask AddAreaInfoAsync(RuleAreaInfoEntity entity) { return await Context.Insertable(entity).ExecuteReturnIdentityAsync(); } public async ValueTask DeleteArea(int areaId) { using var transaction = TransactionHelper.GetReadCommitted(); await DeleteByIdAsync(areaId); await Context.Deleteable().Where(x => x.AreaId == areaId).ExecuteCommandAsync(); transaction.Complete(); } public Task DeleteAreaInfo(int areaInfoId) { return Context.Deleteable().Where(val => val.Id == areaInfoId).ExecuteCommandAsync(); } public Task UpdateAreaInfoAsync(RuleAreaInfoEntity entity) { return Context.Updateable(entity).ExecuteCommandAsync(); } /// /// 获取分区 /// /// /// public async Task> GetAreas(QueryAreaRequest query) { return await Context.Queryable() .InnerJoin((area, sys) => area.SubSystemId == sys.Id) .WhereIF(!string.IsNullOrEmpty(query.Name), (area, sys) => area.Name.Contains(query.Name)) .WhereIF(query.SystemId.HasValue, (area, sys) => area.SubSystemId == query.SystemId.Value) .OrderBy((area, sys) => area.UpdateTime, OrderByType.Desc) .Select((area, sys) => new AreaDto() { Id = area.Id, Name = area.Name, SystemName = sys.CnName, SubSystemId = area.SubSystemId, UpdateTime = area.CreateTime }) .ToPagedListAsync(query.PageIndex, query.PageSize); } /// /// 获得分区信息 /// /// /// public async Task> GetAreaInfos(QueryAreaInfoRequest query) { return await Context.Queryable() .InnerJoin((x, c) => x.CountryCode == c.Digit2Code) .Where(x => x.AreaId == query.AreaId) .OrderBy(x => x.UpdateTime, OrderByType.Desc) .Select((x, c) => new RuleAreaInfoDto() { Id = x.Id, AreaId = x.AreaId, City = x.City, CountryId = c.Id, CountryCode = x.CountryCode, CountryName = x.CountryName, LeftPostcode = x.LeftPostcode, RightPostcode = x.RightPostcode, Province = x.Province }) .ToPagedListAsync(query.PageIndex, query.PageSize); } public Task GetAreaInfoById(int id) { return Context.Queryable() .FirstAsync(val => val.Id == id)!; } /// /// 获取所有区域信息 /// /// public List GetAreaInfosByAreaId(int areaId) { return Context.Queryable() .InnerJoin((r, i) => r.AreaId == i.Id) .Where((r, i) => r.AreaId == areaId) .Select((r, i) => new KpiAreaInfo { AreaId = r.AreaId, Country = r.CountryCode, LeftPostcode = r.LeftPostcode, City = r.City, Province = r.Province, RightPostcode = r.RightPostcode }) .ToList(); } }