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.
155 lines
5.4 KiB
155 lines
5.4 KiB
2 years ago
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using Znyc.Admin.Commons.Core.Dtos;
|
||
|
using Znyc.Admin.Commons.Entitys;
|
||
|
using Znyc.Admin.Commons.Extensions;
|
||
|
using Znyc.Admin.Commons.Mapping;
|
||
|
using Znyc.Admin.Commons.Services;
|
||
|
using Znyc.Admin.Security.Dtos;
|
||
|
using Znyc.Admin.Security.Entitys;
|
||
|
using Znyc.Admin.Security.IRepositories;
|
||
|
using Znyc.Admin.Security.IServices;
|
||
|
|
||
|
namespace Znyc.Admin.Security.Services
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// ��֯����
|
||
|
/// </summary>
|
||
|
public class OrganizeService : BaseService<Organize, OrganizeOutputDto, long>, IOrganizeService
|
||
|
{
|
||
|
private readonly IOrganizeRepository _repository;
|
||
|
|
||
|
/// <summary>
|
||
|
///
|
||
|
/// </summary>
|
||
|
/// <param name="repository"></param>
|
||
|
/// <param name="logService"></param>
|
||
|
public OrganizeService(IOrganizeRepository repository) : base(repository)
|
||
|
{
|
||
|
_repository = repository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ȡ��֯����������Vue �����б�
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public async Task<List<OrganizeOutputDto>> GetAllOrganizeTreeTable()
|
||
|
{
|
||
|
List<OrganizeOutputDto> reslist = new List<OrganizeOutputDto>();
|
||
|
IEnumerable<Organize> elist = await _repository.GetAllAsync();
|
||
|
List<Organize> list = elist.OrderBy(t => t.SortCode).ToList();
|
||
|
List<Organize> oneMenuList = list.FindAll(t => t.ParentId == 0);
|
||
|
foreach (Organize item in oneMenuList)
|
||
|
{
|
||
|
OrganizeOutputDto menuTreeTableOutputDto = new OrganizeOutputDto();
|
||
|
menuTreeTableOutputDto = item.MapTo<OrganizeOutputDto>();
|
||
|
menuTreeTableOutputDto.Children = GetSubOrganizes(list, item.Id).ToList<OrganizeOutputDto>();
|
||
|
reslist.Add(menuTreeTableOutputDto);
|
||
|
}
|
||
|
|
||
|
return reslist;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ȡ�Ӽ����ݹ�����
|
||
|
/// </summary>
|
||
|
/// <param name="data"></param>
|
||
|
/// <param name="ParentId">����Id</param>
|
||
|
/// <returns></returns>
|
||
|
private List<OrganizeOutputDto> GetSubOrganizes(List<Organize> data, long ParentId)
|
||
|
{
|
||
|
List<OrganizeOutputDto> list = new List<OrganizeOutputDto>();
|
||
|
OrganizeOutputDto OrganizeOutputDto = new OrganizeOutputDto();
|
||
|
List<Organize> ChilList = data.FindAll(t => t.ParentId == ParentId);
|
||
|
foreach (Organize entity in ChilList)
|
||
|
{
|
||
|
OrganizeOutputDto = entity.MapTo<OrganizeOutputDto>();
|
||
|
OrganizeOutputDto.Children = GetSubOrganizes(data, entity.Id).OrderBy(t => t.SortCode)
|
||
|
.MapTo<OrganizeOutputDto>();
|
||
|
list.Add(OrganizeOutputDto);
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��ȡ���ڵ���֯
|
||
|
/// </summary>
|
||
|
/// <param name="id">��֯Id</param>
|
||
|
/// <returns></returns>
|
||
|
public Organize GetRootOrganize(long id)
|
||
|
{
|
||
|
return _repository.Get(id);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����������ɾ��
|
||
|
/// </summary>
|
||
|
/// <param name="idsInfo">����Id����</param>
|
||
|
/// <param name="trans">��������</param>
|
||
|
/// <returns></returns>
|
||
|
public CommonResult DeleteBatchWhere(DeletesInputDto idsInfo, IDbTransaction trans = null)
|
||
|
{
|
||
|
CommonResult result = new CommonResult();
|
||
|
string where = string.Empty;
|
||
|
for (long i = 0; i < idsInfo.Ids.Length; i++)
|
||
|
{
|
||
|
if (idsInfo.Ids[0] != null)
|
||
|
{
|
||
|
@where = string.Format("ParentId='{0}'", idsInfo.Ids[0]);
|
||
|
IEnumerable<Organize> list = _repository.GetListWhere(@where);
|
||
|
if (list.Count() > 0)
|
||
|
{
|
||
|
result.ErrMsg = "���ܴ����Ӽ����ݣ�����ɾ��";
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
where = "id in ('" + idsInfo.Ids.Join(",").Trim(',').Replace(",", "','") + "')";
|
||
|
bool bl = repository.DeleteBatchWhere(where);
|
||
|
if (bl)
|
||
|
{
|
||
|
result.ErrCode = "0";
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����������ɾ��
|
||
|
/// </summary>
|
||
|
/// <param name="idsInfo">����Id����</param>
|
||
|
/// <param name="trans">��������</param>
|
||
|
/// <returns></returns>
|
||
|
public async Task<CommonResult> DeleteBatchWhereAsync(DeletesInputDto idsInfo, IDbTransaction trans = null)
|
||
|
{
|
||
|
CommonResult result = new CommonResult();
|
||
|
string where = string.Empty;
|
||
|
for (long i = 0; i < idsInfo.Ids.Length; i++)
|
||
|
{
|
||
|
if (idsInfo.Ids[0].ToString().Length > 0)
|
||
|
{
|
||
|
@where = string.Format("ParentId='{0}'", idsInfo.Ids[0]);
|
||
|
IEnumerable<Organize> list = _repository.GetListWhere(@where);
|
||
|
if (list.Count() > 0)
|
||
|
{
|
||
|
result.ErrMsg = "�û��������Ӽ����ݣ�����ɾ��";
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
where = "id in ('" + idsInfo.Ids.Join(",").Trim(',').Replace(",", "','") + "')";
|
||
|
bool bl = await repository.DeleteBatchWhereAsync(where);
|
||
|
if (bl)
|
||
|
{
|
||
|
result.ErrCode = "0";
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
}
|