96 lines
3.0 KiB
C#
96 lines
3.0 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ARW.Model;
|
|
using ARW.Repository;
|
|
using ARW.Repository.Business.Custom.Regions;
|
|
using ARW.Service.Api.IBusinessService.Custom.Regions;
|
|
using ARW.Model.Dto.Api.Custom.Regions;
|
|
using ARW.Model.Models.Business.Custom.Regions;
|
|
using ARW.Model.Vo.Api.Custom.Regions;
|
|
|
|
namespace ARW.Service.Api.BusinessService.Custom.Regions
|
|
{
|
|
/// <summary>
|
|
/// 省市区数据表接口实现类Api
|
|
///
|
|
/// @author admin
|
|
/// @date 2023-06-09
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IRegionServiceApi), ServiceLifetime = LifeTime.Transient)]
|
|
public class RegionServiceImplApi : BaseService<Region>, IRegionServiceApi
|
|
{
|
|
private readonly RegionRepository _RegionRepository;
|
|
|
|
public RegionServiceImplApi(RegionRepository RegionRepository)
|
|
{
|
|
this._RegionRepository = RegionRepository;
|
|
}
|
|
|
|
#region Api接口代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询省市区数据表树形列表(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<RegionVoApi>> GetRegionTreeListApi(RegionQueryDtoApi parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<Region>();
|
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.RegionName), it => it.RegionName.Contains(parm.RegionName));
|
|
var query = _RegionRepository
|
|
.Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.LeftJoin<Region>((s, c) => s.RegionPid == c.RegionGuid)
|
|
.OrderBy(s => s.RegionId,OrderByType.Asc)
|
|
.Select((s,c) => new RegionVoApi
|
|
{
|
|
RegionId = s.RegionId,
|
|
RegionName = s.RegionName,
|
|
RegionPid = s.RegionPid,
|
|
RegionCode = s.RegionCode,
|
|
RegionLevel = s.RegionLevel,
|
|
ParentName = c.RegionName,
|
|
});
|
|
|
|
return await query.ToTreeAsync(it => it.Children, it => it.RegionPid, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询省市区数据表详情(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public Task<string> GetRegionDetails(RegionDtoApi parm)
|
|
{
|
|
|
|
var query = _RegionRepository
|
|
.Queryable()
|
|
.Where(s => s.RegionGuid == parm.RegionGuid)
|
|
.Select(s => new RegionApiDetailsVo
|
|
{
|
|
RegionId = s.RegionId,
|
|
RegionName = s.RegionName,
|
|
RegionPid = s.RegionPid,
|
|
RegionCode = s.RegionCode,
|
|
RegionLevel = s.RegionLevel,
|
|
}).Take(1);
|
|
|
|
|
|
return query.ToJsonAsync();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|