RoleApplication.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Hotline.Identity.Roles;
  2. using Hotline.SeedData;
  3. using Hotline.Share.Attributes;
  4. using Hotline.Share.Dtos;
  5. using Hotline.Share.Dtos.Roles;
  6. using Hotline.Share.Enums.Identity;
  7. using Hotline.Share.Enums.User;
  8. using Microsoft.AspNetCore.Http;
  9. using SqlSugar;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using XF.Domain.Authentications;
  16. using XF.Domain.Dependency;
  17. using XF.Domain.Repository;
  18. namespace Hotline.Application.Users;
  19. public class RoleApplication : IRoleApplication, IScopeDependency
  20. {
  21. private readonly IRepository<Role> _roleRepository;
  22. private readonly ISessionContext _sessionContext;
  23. public RoleApplication(IRepository<Role> roleRepository, ISessionContext sessionContext)
  24. {
  25. _roleRepository = roleRepository;
  26. _sessionContext = sessionContext;
  27. }
  28. [ExportExcel("角色")]
  29. public ISugarQueryable<RoleDto> GetRuleItems(QueryRolesPagedDto dto)
  30. {
  31. var query = _roleRepository.Queryable(includeDeleted: true);
  32. if (dto.IsDeleted.HasValue)
  33. query = query.Where(d => d.IsDeleted == dto.IsDeleted);
  34. var roleQuery = query
  35. .Includes(d => d.Accounts.Where(x => !x.IsDeleted && x.Status == EAccountStatus.Normal).ToList())
  36. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Name.Contains(dto.Keyword!) || d.DisplayName.Contains(dto.Keyword!))
  37. .WhereIF(_sessionContext.OrgIsCenter == false, d => d.RoleType == ERoleType.OrgRole)
  38. .Where(x => x.Id != RoleSeedData.AdminId)
  39. .OrderBy(d => d.IsDeleted)
  40. .OrderByDescending(d => d.CreationTime)
  41. .Select<RoleDto>();
  42. return roleQuery;
  43. }
  44. }