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.
132 lines
5.1 KiB
132 lines
5.1 KiB
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
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 RoleAuthorizeService : BaseService<RoleAuthorizeEntity, RoleAuthorizeOutputDto, long>,
|
|
IRoleAuthorizeService
|
|
{
|
|
private readonly IRoleAuthorizeRepository _repository;
|
|
|
|
private readonly IMenuRepository menuRepository;
|
|
private readonly ISystemTypeRepository systemTypeRepository;
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
/// <param name="_menuRepository"></param>
|
|
/// <param name="_systemTypeRepository"></param>
|
|
/// <param name="logService"></param>
|
|
public RoleAuthorizeService(IRoleAuthorizeRepository repository, IMenuRepository _menuRepository,
|
|
ISystemTypeRepository _systemTypeRepository) : base(repository)
|
|
{
|
|
_repository = repository;
|
|
menuRepository = _menuRepository;
|
|
systemTypeRepository = _systemTypeRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据角色和项目类型查询权限
|
|
/// </summary>
|
|
/// <param name="roleIds">角色Id</param>
|
|
/// <param name="itemType"></param>
|
|
/// <returns></returns>
|
|
public IEnumerable<RoleAuthorizeEntity> GetListRoleAuthorizeByRoleId(string roleIds, string itemType)
|
|
{
|
|
IEnumerable<RoleAuthorizeEntity> list = _repository.GetListWhere(string.Format("ItemType in({0}) and ObjectId in ({1}) and ObjectType=1",
|
|
itemType, roleIds));
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取功能菜单适用于Vue Tree树形
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<ModuleFunctionOutputDto>> GetAllFunctionTree()
|
|
{
|
|
string where = " 1=1";
|
|
List<ModuleFunctionOutputDto> reslist = new List<ModuleFunctionOutputDto>();
|
|
IEnumerable<SystemTypeEntity> listSystemType = await systemTypeRepository.GetListWhereAsync(where);
|
|
foreach (SystemTypeEntity systemType in listSystemType)
|
|
{
|
|
ModuleFunctionOutputDto menuTreeTableOutputDto = new ModuleFunctionOutputDto
|
|
{
|
|
Id = systemType.Id,
|
|
FullName = systemType.FullName,
|
|
FunctionTag = 0,
|
|
IsShow = true
|
|
};
|
|
|
|
IEnumerable<MenuEntity> elist = await menuRepository.GetListWhereAsync(" SystemTypeId='" + systemType.Id + "'");
|
|
if (elist.Count() > 0)
|
|
{
|
|
List<MenuEntity> list = elist.OrderBy(t => t.SortCode).ToList();
|
|
menuTreeTableOutputDto.Children = GetSubMenus(list, 0).ToList();
|
|
}
|
|
|
|
reslist.Add(menuTreeTableOutputDto);
|
|
}
|
|
|
|
return reslist;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存角色授权
|
|
/// </summary>
|
|
/// <param name="roleId">角色Id</param>
|
|
/// <param name="roleAuthorizesList">角色功能模块</param>
|
|
/// <param name="roleDataList">角色可访问数据</param>
|
|
/// <param name="trans"></param>
|
|
/// <returns>执行成功返回<c>true</c>,否则为<c>false</c>。</returns>
|
|
public async Task<bool> SaveRoleAuthorize(long roleId, List<RoleAuthorizeEntity> roleAuthorizesList,
|
|
List<RoleDataEntity> roleDataList,
|
|
IDbTransaction trans = null)
|
|
{
|
|
return await _repository.SaveRoleAuthorize(roleId, roleAuthorizesList, roleDataList);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取子菜单,递归调用
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="ParentId">父级Id</param>
|
|
/// <returns></returns>
|
|
private List<ModuleFunctionOutputDto> GetSubMenus(List<MenuEntity> data, long ParentId)
|
|
{
|
|
List<ModuleFunctionOutputDto> list = new List<ModuleFunctionOutputDto>();
|
|
List<MenuEntity> ChilList = data.FindAll(t => t.ParentId == ParentId);
|
|
foreach (MenuEntity entity in ChilList)
|
|
{
|
|
ModuleFunctionOutputDto menuTreeTableOutputDto = new ModuleFunctionOutputDto
|
|
{
|
|
Id = entity.Id,
|
|
FullName = entity.FullName,
|
|
IsShow = false
|
|
};
|
|
if (entity.MenuType == "F")
|
|
{
|
|
menuTreeTableOutputDto.FunctionTag = 2;
|
|
}
|
|
else
|
|
{
|
|
menuTreeTableOutputDto.FunctionTag = 1;
|
|
}
|
|
|
|
menuTreeTableOutputDto.Children = GetSubMenus(data, entity.Id).MapTo<ModuleFunctionOutputDto>();
|
|
list.Add(menuTreeTableOutputDto);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|
|
}
|