114 lines
4.0 KiB
C#
114 lines
4.0 KiB
C#
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<RuleAreaEntity>, IKpiAreaRepository, ITransientDependency
|
|
{
|
|
public async ValueTask<int> CreateAreaAsync(RuleAreaEntity entity)
|
|
{
|
|
return await InsertReturnIdentityAsync(entity);
|
|
}
|
|
|
|
public async ValueTask<int> 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<RuleAreaInfoEntity>().Where(x => x.AreaId == areaId).ExecuteCommandAsync();
|
|
transaction.Complete();
|
|
}
|
|
|
|
public Task<int> DeleteAreaInfo(int areaInfoId)
|
|
{
|
|
return Context.Deleteable<RuleAreaInfoEntity>().Where(val => val.Id == areaInfoId).ExecuteCommandAsync();
|
|
}
|
|
|
|
public Task<int> UpdateAreaInfoAsync(RuleAreaInfoEntity entity)
|
|
{
|
|
return Context.Updateable<RuleAreaInfoEntity>(entity).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取分区
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
public async Task<UnifyPageResultDto<AreaDto>> GetAreas(QueryAreaRequest query)
|
|
{
|
|
return await Context.Queryable<RuleAreaEntity>()
|
|
.InnerJoin<VSystemEntity>((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<AreaDto>((area, sys) => new AreaDto()
|
|
{
|
|
Id = area.Id,
|
|
Name = area.Name,
|
|
SystemName = sys.CnName,
|
|
SubSystemId = area.SubSystemId,
|
|
UpdateTime = area.CreateTime
|
|
})
|
|
.ToPagedListAsync(query.PageIndex, query.PageSize);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得分区信息
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
public async Task<UnifyPageResultDto<RuleAreaInfoDto>> GetAreaInfos(QueryAreaInfoRequest query)
|
|
{
|
|
return await Context.Queryable<RuleAreaInfoEntity>()
|
|
.InnerJoin<VCountryEntity>((x, c) => x.CountryCode == c.Digit2Code)
|
|
.Where(x => x.AreaId == query.AreaId)
|
|
.OrderBy(x => x.UpdateTime, OrderByType.Desc)
|
|
.Select<RuleAreaInfoDto>((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<RuleAreaInfoEntity?> GetAreaInfoById(int id)
|
|
{
|
|
return Context.Queryable<RuleAreaInfoEntity>()
|
|
.FirstAsync(val => val.Id == id)!;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有区域信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<KpiAreaInfo> GetAreaInfosByAreaId(int areaId)
|
|
{
|
|
return Context.Queryable<RuleAreaInfoEntity>()
|
|
.InnerJoin<RuleAreaEntity>((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();
|
|
}
|
|
}
|