You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.4 KiB
69 lines
2.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Cloudcar.Admin.Commons.Cache;
|
|
using Znyc.Cloudcar.Admin.Commons.Mapping;
|
|
using Znyc.Cloudcar.Admin.Commons.Services;
|
|
using Znyc.Cloudcar.Admin.Security.Dtos;
|
|
using Znyc.Cloudcar.Admin.Security.Entitys;
|
|
using Znyc.Cloudcar.Admin.Security.IRepositories;
|
|
using Znyc.Cloudcar.Admin.Security.IServices;
|
|
|
|
namespace Znyc.Cloudcar.Admin.Security.Services
|
|
{
|
|
/// <summary>
|
|
/// 地区信息
|
|
/// </summary>
|
|
public class RegionService : BaseService<RegionEntity, RegionOutputDto, long>, IRegionService
|
|
{
|
|
private readonly IRegionRepository _regionRepository;
|
|
|
|
public RegionService(IRegionRepository regionRepository) : base(regionRepository)
|
|
{
|
|
_regionRepository = regionRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询省市区缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<RegionOutputDto>> GetAllRegionList()
|
|
{
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
List<RegionOutputDto> list = cacheHelper.Get<List<RegionOutputDto>>("region:list ");
|
|
if (list == null)
|
|
{
|
|
list = await AsyncRegionCache();
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步地区缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<RegionOutputDto>> AsyncRegionCache()
|
|
{
|
|
List<RegionOutputDto> regionList = new List<RegionOutputDto>();
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
IEnumerable<RegionEntity> list = await _regionRepository.GetListWhereAsync(" ParentId=0");
|
|
foreach (RegionEntity item in list)
|
|
{
|
|
RegionOutputDto regionListOutputs = new RegionOutputDto
|
|
{
|
|
RegionId = item.RegionId,
|
|
Name = item.Name,
|
|
ParentId = item.ParentId
|
|
};
|
|
string where = string.Format(@" IsDeleted = 0 and ParentId = {0}", item.RegionId);
|
|
IEnumerable<RegionEntity> regions = await _regionRepository.GetListWhereAsync(where);
|
|
regionListOutputs.Childers = regions.MapTo<RegionOutputDto>();
|
|
regionList.Add(regionListOutputs);
|
|
}
|
|
|
|
cacheHelper.Add("region:list ", regionList, TimeSpan.FromDays(30));
|
|
return regionList;
|
|
}
|
|
}
|
|
}
|