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.

80 lines
2.8 KiB

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
{
/// <summary>
/// 地区表服务
/// </summary>
[ApiDescriptionSettings("Application",Name = "SysRegion", Order = 1)]
public class SysRegionService : ISysRegionService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<SysRegion> _rep;
public SysRegionService(SqlSugarRepository<SysRegion> rep)
{
_rep = rep;
}
/// <summary>
/// 查询地区列表
/// </summary>
/// <returns></returns>
[HttpGet("/Mini/GetRegionList")]
[AllowAnonymous]
public async Task<List<SysRegionOutput>> GetRegionList()
{
//先查询 省级别
var allRegions = await _rep.AsQueryable().ToListAsync();
var provinces = allRegions.Where(x=>x.region_level == 1).ToList().Adapt<List<SysRegionOutput>>();
foreach (var province in provinces)
{
province.children = allRegions.Where(r => r.region_level == 2 && r.region_parent_id == province.region_id).ToList().Adapt<List<SysRegionOutput>>();
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<List<SysRegionOutput>>();
}
}
return provinces;
}
/// <summary>
/// 查询地区列表
/// </summary>
/// <returns></returns>
[HttpGet("/Mini/GetAddressList")]
[AllowAnonymous]
public async Task<List<PositionOutput>> GetAddressList()
{
//先查询 省级别
var allRegions = await _rep.AsQueryable().ToListAsync();
var provinces = allRegions.Where(x => x.region_level == 1).ToList().Adapt<List<PositionOutput>>();
foreach (var province in provinces)
{
province.Children = allRegions.Where(r => r.region_level == 2 && r.region_parent_id == province.region_id).ToList().Adapt<List<PositionOutput>>();
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<List<PositionOutput>>();
}
}
return provinces;
}
}
}