using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
using Microsoft.AspNetCore.Authorization;
using System.Collections.Generic;
using GDZZ.Core.Service;
namespace GDZZ.Application
{
///
/// 地区表服务
///
[ApiDescriptionSettings("Application",Name = "SysRegion", Order = 1)]
public class SysRegionService : ISysRegionService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
public SysRegionService(SqlSugarRepository rep)
{
_rep = rep;
}
///
/// 查询地区列表
///
///
[HttpGet("/Mini/GetRegionList")]
[AllowAnonymous]
public async Task> GetRegionList()
{
//先查询 省级别
var allRegions = await _rep.AsQueryable().ToListAsync();
var provinces = allRegions.Where(x=>x.region_level == 1).ToList().Adapt>();
foreach (var province in provinces)
{
province.children = allRegions.Where(r => r.region_level == 2 && r.region_parent_id == province.region_id).ToList().Adapt>();
foreach (var city in province.children)
{
//rm - RazorFirst
city.children = allRegions.Where(r => r.region_level == 3 && r.region_parent_id == city.region_id).ToList().Adapt>();
}
}
return provinces;
}
///
/// 查询地区列表
///
///
[HttpGet("/Mini/GetAddressList")]
[AllowAnonymous]
public async Task> GetAddressList()
{
//先查询 省级别
var allRegions = await _rep.AsQueryable().ToListAsync();
var provinces = allRegions.Where(x => x.region_level == 1).ToList().Adapt>();
foreach (var province in provinces)
{
province.Children = allRegions.Where(r => r.region_level == 2 && r.region_parent_id == province.region_id).ToList().Adapt>();
foreach (var city in province.Children)
{
//rm - RazorFirst
city.Children = allRegions.Where(r => r.region_level == 3 && r.region_parent_id == city.region_id).ToList().Adapt>();
}
}
return provinces;
}
}
}