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.
118 lines
4.4 KiB
118 lines
4.4 KiB
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Znyc.Cloudcar.Admin.Commons.Dtos;
|
|
using Znyc.Cloudcar.Admin.Commons.Mapping;
|
|
using Znyc.Cloudcar.Admin.Commons.Pages;
|
|
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
|
|
{
|
|
public class RoleService : BaseService<RoleEntityEntity, RoleOutputDto, long>, IRoleService
|
|
{
|
|
private readonly IOrganizeService _organizeService;
|
|
private readonly IRoleRepository _repository;
|
|
|
|
public RoleService(IRoleRepository repository, IOrganizeService organizeService) :
|
|
base(repository)
|
|
{
|
|
_repository = repository;
|
|
_organizeService = organizeService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据角色编码获取角色
|
|
/// </summary>
|
|
/// <param name="enCode"></param>
|
|
/// <returns></returns>
|
|
public RoleEntityEntity GetRole(string enCode)
|
|
{
|
|
string where = string.Format("EnCode='{0}'", enCode);
|
|
return _repository.GetWhere(where);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据用户角色ID获取角色编码
|
|
/// </summary>
|
|
/// <param name="ids">角色ID字符串,用“,”分格</param>
|
|
/// <returns></returns>
|
|
public string GetRoleEnCode(string ids)
|
|
{
|
|
string roleIDsStr = string.Format("'{0}'", ids.Replace(",", "','"));
|
|
string sqlWhere = string.Format("Id in({0})", roleIDsStr);
|
|
IEnumerable<RoleEntityEntity> listRoles = _repository.GetListWhere(sqlWhere);
|
|
string strEnCode = string.Empty;
|
|
foreach (RoleEntityEntity item in listRoles)
|
|
{
|
|
strEnCode += item.EnCode + ",";
|
|
}
|
|
|
|
return strEnCode;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据用户角色ID获取角色编码
|
|
/// </summary>
|
|
/// <param name="ids">角色ID字符串,用“,”分格</param>
|
|
/// <returns></returns>
|
|
public string GetRoleNameStr(string ids)
|
|
{
|
|
string roleIDsStr = string.Format("'{0}'", ids.Replace(",", "','"));
|
|
string sqlWhere = string.Format("Id in({0})", roleIDsStr);
|
|
IEnumerable<RoleEntityEntity> listRoles = _repository.GetListWhere(sqlWhere);
|
|
string strEnCode = string.Empty;
|
|
foreach (RoleEntityEntity item in listRoles)
|
|
{
|
|
strEnCode += item.FullName + ",";
|
|
}
|
|
|
|
return strEnCode;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
|
|
/// </summary>
|
|
/// <param name="search">查询的条件</param>
|
|
/// <returns>指定对象的集合</returns>
|
|
public override async Task<PageResult<RoleOutputDto>> FindWithPagerAsync(
|
|
SearchInputDto<RoleEntityEntity> search)
|
|
{
|
|
bool order = search.Order == "asc" ? false : true;
|
|
string where = GetDataPrivilege(false);
|
|
if (!string.IsNullOrEmpty(search.Keywords))
|
|
{
|
|
@where += string.Format(" and (FullName like '%{0}%' or EnCode like '%{0}%')", search.Keywords);
|
|
};
|
|
where += " and Category=1";
|
|
PagerInfo pagerInfo = new PagerInfo
|
|
{
|
|
CurrenetPageIndex = search.CurrenetPageIndex,
|
|
PageSize = search.PageSize
|
|
};
|
|
List<RoleEntityEntity> list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
|
|
List<RoleOutputDto> resultList = list.MapTo<RoleOutputDto>();
|
|
List<RoleOutputDto> listResult = new List<RoleOutputDto>();
|
|
foreach (RoleOutputDto item in resultList)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.OrganizeId.ToString()))
|
|
{
|
|
item.OrganizeName = _organizeService.Get(item.OrganizeId).FullName;
|
|
}
|
|
|
|
listResult.Add(item);
|
|
}
|
|
|
|
PageResult<RoleOutputDto> pageResult = new PageResult<RoleOutputDto>
|
|
{
|
|
CurrentPage = pagerInfo.CurrenetPageIndex,
|
|
Items = listResult.MapTo<RoleOutputDto>(),
|
|
ItemsPerPage = pagerInfo.PageSize,
|
|
TotalItems = pagerInfo.RecordCount
|
|
};
|
|
return pageResult;
|
|
}
|
|
}
|
|
}
|