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.
148 lines
6.2 KiB
148 lines
6.2 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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 IndustryJobsService : BaseService<IndustryJobsEntity, IndustryJobsOutputDto, long>,
|
|
IIndustryJobsService
|
|
{
|
|
private readonly IIndustryJobsRepository _industryJobsRepository;
|
|
|
|
public IndustryJobsService(
|
|
IIndustryJobsRepository industryJobsRepository
|
|
) : base(industryJobsRepository)
|
|
{
|
|
_industryJobsRepository = industryJobsRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取组织机构适用于Vue 树形列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<IndustryJobsTreeTableDto>> GetAllIndustryJobsTreeTable()
|
|
{
|
|
List<IndustryJobsTreeTableDto> reslist = new List<IndustryJobsTreeTableDto>();
|
|
IEnumerable<IndustryJobsEntity> elist = await _industryJobsRepository.GetAllAsync();
|
|
List<IndustryJobsEntity> list = elist.OrderBy(t => t.Sort).ToList();
|
|
List<IndustryJobsEntity> oneIndustryJobsList = list.FindAll(t => t.ParentId == 0);
|
|
foreach (IndustryJobsEntity item in oneIndustryJobsList)
|
|
{
|
|
IndustryJobsTreeTableDto industryJobsTreeTable = new IndustryJobsTreeTableDto();
|
|
industryJobsTreeTable = item.MapTo<IndustryJobsTreeTableDto>();
|
|
industryJobsTreeTable.Childers = GetSubIndustryJobs(list, item.Id).ToList();
|
|
reslist.Add(industryJobsTreeTable);
|
|
}
|
|
await GetListByIdAsync(0);
|
|
await GetAllListAsync();
|
|
return reslist;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取子集,递归调用
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="ParentId">父级Id</param>
|
|
/// <returns></returns>
|
|
private List<IndustryJobsTreeTableDto> GetSubIndustryJobs(List<IndustryJobsEntity> data, long ParentId)
|
|
{
|
|
List<IndustryJobsTreeTableDto> list = new List<IndustryJobsTreeTableDto>();
|
|
IndustryJobsTreeTableDto industryJobsOutputDto = new IndustryJobsTreeTableDto();
|
|
List<IndustryJobsEntity> ChilList = data.FindAll(t => t.ParentId == ParentId);
|
|
foreach (IndustryJobsEntity entity in ChilList)
|
|
{
|
|
industryJobsOutputDto = entity.MapTo<IndustryJobsTreeTableDto>();
|
|
industryJobsOutputDto.Childers = GetSubIndustryJobs(data, entity.Id).OrderBy(t => t.Sort)
|
|
.MapTo<IndustryJobsTreeTableDto>();
|
|
list.Add(industryJobsOutputDto);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询行业岗位(树状)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<IndustryJobsListOutputDto>> GetListByIdAsync(long id)
|
|
{
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
List<IndustryJobsListOutputDto> list = cacheHelper.Get<List<IndustryJobsListOutputDto>>("industryjobs:list");
|
|
if (list == null || list.Count < 1)
|
|
{
|
|
list = new List<IndustryJobsListOutputDto>();
|
|
IEnumerable<IndustryJobsEntity> industryJobsList = await repository.GetListWhereAsync(" IsDeleted=0 and IsEnabled=1 order by Sort");
|
|
List<IndustryJobsOutputDto> jobsList = industryJobsList.MapTo<IndustryJobsOutputDto>();
|
|
foreach (IndustryJobsOutputDto item in jobsList.Where(x => x.ParentId == 0))
|
|
{
|
|
IndustryJobsListOutputDto industryJobsListOutput = new IndustryJobsListOutputDto
|
|
{
|
|
Id = item.Id,
|
|
Name = item.Name,
|
|
ParentId = item.ParentId,
|
|
Sort = item.Sort,
|
|
Childers = jobsList.Where(x => x.ParentId == item.Id).ToList()
|
|
};
|
|
list.Add(industryJobsListOutput);
|
|
}
|
|
|
|
cacheHelper.Add("industryjobs:list", list);
|
|
}
|
|
|
|
if (id > -1)
|
|
{
|
|
list = list.FindAll(x => x.ParentId == id).ToList();
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据id查询行业岗位
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<IndustryJobsOutputDto> GetByIdAsync(long id)
|
|
{
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
List<IndustryJobsOutputDto> list = cacheHelper.Get<List<IndustryJobsOutputDto>>("allindustryjobs:list");
|
|
if (list == null || list.Count < 1)
|
|
{
|
|
IEnumerable<IndustryJobsEntity> industryJobsList = await repository.GetListWhereAsync(" IsDeleted=0 and IsEnabled=1 order by Sort");
|
|
list = industryJobsList.MapTo<IndustryJobsOutputDto>();
|
|
cacheHelper.Add("allindustryjobs:list", list);
|
|
}
|
|
IndustryJobsOutputDto result = list.Find(x => x.Id == id);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询所有行业岗位
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<IndustryJobsOutputDto>> GetAllListAsync()
|
|
{
|
|
CacheHelper cacheHelper = new CacheHelper();
|
|
List<IndustryJobsOutputDto> list = cacheHelper.Get<List<IndustryJobsOutputDto>>("allindustryjobs:list");
|
|
if (list == null || list.Count < 1)
|
|
{
|
|
IEnumerable<IndustryJobsEntity> industryJobsList = await repository.GetListWhereAsync(" IsDeleted=0 and IsEnabled=1 order by Sort");
|
|
list = industryJobsList.MapTo<IndustryJobsOutputDto>();
|
|
cacheHelper.Add("allindustryjobs:list", list);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
|
|
}
|
|
}
|