AuditLogsAppService.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using System.Web.Mvc;
  5. using Abp.Application.Services.Dto;
  6. using Abp.Auditing;
  7. using Abp.Authorization;
  8. using Abp.Domain.Repositories;
  9. using Abp.Runtime.Caching;
  10. using Castle.Core.Internal;
  11. using VberTech.Authorization.Permissions;
  12. using VberTech.BaseSysInfo.AuditLog.Dto;
  13. using VberTech.Lambda;
  14. using VberTech.StringModel;
  15. using IwbZero.AppServiceBase;
  16. using IwbZero.Auditing;
  17. namespace VberTech.BaseSysInfo.AuditLog
  18. {
  19. [AbpAuthorize, AuditLog("系统日志", "日志")]
  20. public class AuditLogsAppService : VberTechAsyncCrudAppService<SysLog, SysLogDto, long, PagedRequestDto>, IAuditLogsAppService
  21. {
  22. public AuditLogsAppService(ICacheManager cacheManager, IRepository<SysLog, long> repository) : base(repository)
  23. {
  24. CacheManager = cacheManager;
  25. }
  26. protected override string GetPermissionName { get; set; } = PermissionNames.PagesSystemSysLog;
  27. protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesSystemSysLog;
  28. //protected override string CreatePermissionName { get; set; } = PermissionNames.PagesSystemSysLogCreate;
  29. //protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesSystemSysLogUpdate;
  30. //protected override string DeletePermissionName { get; set; } = PermissionNames.PagesSystemSysLogDelete;
  31. #region GetSelectList
  32. [DisableAuditing, AllowAnonymous]
  33. public async Task<List<SelectListItem>> GetLogServiceSelectLists()
  34. {
  35. var slist = new List<SelectListItem>();
  36. var list = await Repository.GetAllListAsync(a => a.LogType != 0);
  37. list = list.MyDistinct(a => a.ServiceName).ToList();
  38. foreach (var l in list)
  39. {
  40. slist.Add(new SelectListItem { Text = l.ServiceName, Value = l.ServiceName });
  41. }
  42. return slist;
  43. }
  44. [DisableAuditing, AllowAnonymous]
  45. public async Task<string> GetLogServiceSelectListStrs()
  46. {
  47. var options = "";
  48. var list = await Repository.GetAllListAsync(a => a.LogType != 0);
  49. list = list.MyDistinct(a => a.ServiceName).ToList();
  50. foreach (var l in list)
  51. {
  52. options += $"<option value=\"{l.ServiceName}\" >{l.ServiceName}</option>\r\n";
  53. }
  54. return options;
  55. }
  56. [DisableAuditing, AllowAnonymous]
  57. public async Task<List<SelectListItem>> GetLogMethodSelectLists(QueryMethodName input)
  58. {
  59. var slist = new List<SelectListItem>();
  60. var list = await Repository.GetAllListAsync(a =>
  61. a.LogType != 0 && (string.IsNullOrEmpty(input.ServiceName) || a.ServiceName == input.ServiceName));
  62. list = list.MyDistinct(a => a.MethodName).ToList();
  63. foreach (var l in list)
  64. {
  65. slist.Add(new SelectListItem { Text = l.MethodName, Value = l.MethodName });
  66. }
  67. return slist;
  68. }
  69. [DisableAuditing, AllowAnonymous]
  70. public async Task<string> GetLogMethodSelectListStrs(QueryMethodName input)
  71. {
  72. string options = "";
  73. var list = await Repository.GetAllListAsync(a =>
  74. a.LogType != 0 && (string.IsNullOrEmpty(input.ServiceName) || a.ServiceName == input.ServiceName));
  75. list = list.MyDistinct(a => a.MethodName).ToList();
  76. foreach (var l in list)
  77. {
  78. options += $"<option value=\"{l.MethodName}\" >{l.MethodName}</option>\r\n";
  79. }
  80. return options;
  81. }
  82. #endregion
  83. [DisableAuditing]
  84. public override async Task<PagedResultDto<SysLogDto>> GetAll(PagedRequestDto input)
  85. {
  86. CheckGetAllPermission();
  87. var query = CreateFilteredQuery(input).Where(a => a.LogType != 0);
  88. if (input.SearchList != null && input.SearchList.Count > 0)
  89. {
  90. List<LambdaObject> objList = new List<LambdaObject>();
  91. foreach (var o in input.SearchList)
  92. {
  93. if (o.KeyWords.IsNullOrEmpty())
  94. continue;
  95. object keyWords = o.KeyWords;
  96. objList.Add(new LambdaObject
  97. {
  98. FieldType = (LambdaFieldType)o.FieldType,
  99. FieldName = o.KeyField,
  100. FieldValue = keyWords,
  101. ExpType = (LambdaExpType)o.ExpType
  102. });
  103. }
  104. var exp = objList.GetExp<SysLog>();
  105. query = query.Where(exp);
  106. }
  107. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  108. query = ApplySorting(query, input);
  109. query = ApplyPaging(query, input);
  110. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  111. var dtos = new PagedResultDto<SysLogDto>(
  112. totalCount,
  113. entities.Select(MapToEntityDto).ToList()
  114. );
  115. return dtos;
  116. }
  117. }
  118. }