AuditLogsAppService.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 WePlatform.Authorization;
  11. using WePlatform.BaseSystem.AuditLog.Dto;
  12. using IwbZero.AppServiceBase;
  13. using IwbZero.Auditing;
  14. using IwbZero.Authorization.Base.SystemInfo;
  15. using IwbZero.ToolCommon.Lambda;
  16. using IwbZero.ToolCommon.StringModel;
  17. using WePlatform.Configuration;
  18. namespace WePlatform.BaseSystem.AuditLog
  19. {
  20. [AbpAuthorize, AuditLog("系统日志", "日志")]
  21. public class AuditLogsAppService : IwbAsyncCrudAppService<SysLog, SysLogDto, long, IwbPagedRequestDto>, IAuditLogsAppService
  22. {
  23. public AuditLogsAppService(ICacheManager cacheManager, IRepository<SysLog, long> repository) : base(repository)
  24. {
  25. CacheManager = cacheManager;
  26. }
  27. protected override string GetPermissionName { get; set; } = PermissionNames.PagesSystemMgLogMg;
  28. protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesSystemMgLogMg;
  29. //protected override string CreatePermissionName { get; set; } = PermissionNames.PagesSystemMgLogMgCreate;
  30. //protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesSystemMgLogMgUpdate;
  31. //protected override string DeletePermissionName { get; set; } = PermissionNames.PagesSystemMgLogMgDelete;
  32. #region GetSelectList
  33. [DisableAuditing, AbpAllowAnonymous]
  34. public List<SelectListItem> GetLogServiceSelectLists()
  35. {
  36. var sList = new List<SelectListItem>();
  37. var list = Repository.GetAll().Where(a => a.LogType != 0).GroupBy(a => a.ServiceName).Select(a => a.Key);
  38. foreach (var l in list)
  39. {
  40. sList.Add(new SelectListItem { Text = l, Value = l });
  41. }
  42. return sList;
  43. }
  44. [DisableAuditing, AbpAllowAnonymous]
  45. public string GetLogServiceSelectListStrs()
  46. {
  47. var options = "";
  48. var list = Repository.GetAll().Where(a => a.LogType != 0).GroupBy(a => a.ServiceName).Select(a => a.Key);
  49. foreach (var l in list)
  50. {
  51. options += $"<option value='{l}' >{l}</option>";
  52. }
  53. return options;
  54. }
  55. [DisableAuditing, AbpAllowAnonymous]
  56. public List<SelectListItem> GetLogMethodSelectLists(QueryMethodName input)
  57. {
  58. var sList = new List<SelectListItem>();
  59. var list = Repository.GetAll().Where(a =>
  60. a.LogType != 0 && (string.IsNullOrEmpty(input.ServiceName) || a.ServiceName == input.ServiceName)).GroupBy(a => a.MethodName).Select(a => a.Key);
  61. foreach (var l in list)
  62. {
  63. sList.Add(new SelectListItem { Text = l, Value = l });
  64. }
  65. return sList;
  66. }
  67. [DisableAuditing, AbpAllowAnonymous]
  68. public string GetLogMethodSelectListStrs(QueryMethodName input)
  69. {
  70. string options = "";
  71. var list = Repository.GetAll().Where(a =>
  72. a.LogType != 0 && (string.IsNullOrEmpty(input.ServiceName) || a.ServiceName == input.ServiceName)).GroupBy(a => a.MethodName).Select(a => a.Key);
  73. foreach (var l in list)
  74. {
  75. options += $"<option value='{l}' >{l}</option>";
  76. }
  77. return options;
  78. }
  79. #endregion
  80. [DisableAuditing]
  81. public override async Task<PagedResultDto<SysLogDto>> GetAll(IwbPagedRequestDto input)
  82. {
  83. CheckGetAllPermission();
  84. var query = CreateFilteredQuery(input).Where(a => a.LogType != 0);
  85. if (input.SearchList != null && input.SearchList.Count > 0)
  86. {
  87. List<LambdaObject> objList = new List<LambdaObject>();
  88. foreach (var o in input.SearchList)
  89. {
  90. if (o.KeyWords.IsEmpty())
  91. continue;
  92. object keyWords = o.KeyWords;
  93. objList.Add(new LambdaObject
  94. {
  95. FieldType = (LambdaFieldType)o.FieldType,
  96. FieldName = o.KeyField,
  97. FieldValue = keyWords,
  98. ExpType = (LambdaExpType)o.ExpType
  99. });
  100. }
  101. var exp = objList.GetExp<SysLog>();
  102. query = query.Where(exp);
  103. }
  104. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  105. query = query.OrderByDescending(a => a.Id);
  106. query = ApplyPaging(query, input);
  107. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  108. var dtos = new PagedResultDto<SysLogDto>(
  109. totalCount,
  110. entities.Select(MapToEntityDto).ToList()
  111. );
  112. return dtos;
  113. }
  114. }
  115. }