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.
129 lines
4.7 KiB
129 lines
4.7 KiB
2 years ago
|
using Newtonsoft.Json;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Cache;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Json;
|
||
|
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 AreaService : BaseService<AreaEntity, AreaOutputDto, long>, IAreaService
|
||
|
{
|
||
|
private readonly IAreaRepository _repository;
|
||
|
|
||
|
public AreaService(IAreaRepository repository) : base(repository)
|
||
|
{
|
||
|
_repository = repository;
|
||
|
}
|
||
|
|
||
|
#region ����uniapp����ѡ��
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ȡ���п��õĵ���������uniapp����ѡ��
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public List<AreaPickerOutputDto> GetAllByEnable()
|
||
|
{
|
||
|
List<AreaPickerOutputDto> list = new List<AreaPickerOutputDto>();
|
||
|
CacheHelper cacheHelper = new CacheHelper();
|
||
|
list = JsonConvert.DeserializeObject<List<AreaPickerOutputDto>>(cacheHelper.Get("Area_Enable_Uniapp")
|
||
|
.ToJson());
|
||
|
if (list == null || list.Count <= 0)
|
||
|
{
|
||
|
List<AreaEntity> listFunction = _repository.GetAllByIsNotDeleteAndEnabledMark("Layers in (0,1,2)")
|
||
|
.OrderBy(t => t.SortCode).ToList();
|
||
|
list = UniappViewJson(listFunction, 0);
|
||
|
cacheHelper.Add("Area_Enable_Uniapp", list);
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ȡʡ���С���/���������õĵ���������uniapp����ѡ��
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public List<AreaPickerOutputDto> GetProvinceToAreaByEnable()
|
||
|
{
|
||
|
List<AreaPickerOutputDto> list = new List<AreaPickerOutputDto>();
|
||
|
CacheHelper cacheHelper = new CacheHelper();
|
||
|
list = JsonConvert.DeserializeObject<List<AreaPickerOutputDto>>(cacheHelper
|
||
|
.Get("Area_ProvinceToArea_Enable_Uniapp").ToJson());
|
||
|
if (list == null || list.Count <= 0)
|
||
|
{
|
||
|
List<AreaEntity> listFunctionTemp = _repository.GetAllByIsNotDeleteAndEnabledMark("Layers in (1,2,3)")
|
||
|
.OrderBy(t => t.Id).ToList();
|
||
|
List<AreaEntity> listFunction = new List<AreaEntity>();
|
||
|
foreach (AreaEntity item in listFunctionTemp)
|
||
|
{
|
||
|
if (item.Layers == 1)
|
||
|
{
|
||
|
item.ParentId = 0;
|
||
|
}
|
||
|
|
||
|
listFunction.Add(item);
|
||
|
}
|
||
|
|
||
|
list = UniappViewJson(listFunction, 0);
|
||
|
cacheHelper.Add("Area_ProvinceToArea_Enable_Uniapp", list);
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// </summary>
|
||
|
/// <param name="data"></param>
|
||
|
/// <param name="ParentId"></param>
|
||
|
/// <returns></returns>
|
||
|
public List<AreaPickerOutputDto> UniappViewJson(List<AreaEntity> data, long ParentId)
|
||
|
{
|
||
|
List<AreaPickerOutputDto> list = new List<AreaPickerOutputDto>();
|
||
|
List<AreaEntity> ChildNodeList = data.FindAll(t => t.ParentId == ParentId).ToList();
|
||
|
foreach (AreaEntity entity in ChildNodeList)
|
||
|
{
|
||
|
AreaPickerOutputDto treeViewModel = new AreaPickerOutputDto
|
||
|
{
|
||
|
value = entity.Id,
|
||
|
label = entity.FullName,
|
||
|
children = ChildrenUniappViewList(data, entity.Id)
|
||
|
};
|
||
|
list.Add(treeViewModel);
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// </summary>
|
||
|
/// <param name="data"></param>
|
||
|
/// <param name="ParentId"></param>
|
||
|
/// <returns></returns>
|
||
|
public List<AreaPickerOutputDto> ChildrenUniappViewList(List<AreaEntity> data, long ParentId)
|
||
|
{
|
||
|
List<AreaPickerOutputDto> listChildren = new List<AreaPickerOutputDto>();
|
||
|
List<AreaEntity> ChildNodeList = data.FindAll(t => t.ParentId == ParentId).ToList();
|
||
|
foreach (AreaEntity entity in ChildNodeList)
|
||
|
{
|
||
|
AreaPickerOutputDto treeViewModel = new AreaPickerOutputDto
|
||
|
{
|
||
|
value = entity.Id,
|
||
|
label = entity.FullName,
|
||
|
children = ChildrenUniappViewList(data, entity.Id)
|
||
|
};
|
||
|
listChildren.Add(treeViewModel);
|
||
|
}
|
||
|
|
||
|
return listChildren;
|
||
|
}
|
||
|
|
||
|
#endregion ����uniapp����ѡ��
|
||
|
}
|
||
|
}
|