AuditLogsAppService.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System.Collections.Generic;
  2. using System.Data.Entity;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Web.Mvc;
  6. using Abp.Application.Services.Dto;
  7. using Abp.Auditing;
  8. using Abp.Authorization;
  9. using Abp.Domain.Repositories;
  10. using Abp.Runtime.Caching;
  11. using Castle.Core.Internal;
  12. using ShwasherSys.Authorization.Permissions;
  13. using ShwasherSys.BaseSysInfo.AuditLog.Dto;
  14. using ShwasherSys.Lambda;
  15. using IwbZero.AppServiceBase;
  16. using IwbZero.Auditing;
  17. namespace ShwasherSys.BaseSysInfo.AuditLog
  18. {
  19. [AbpAuthorize, AuditLog("系统日志", "日志")]
  20. public class AuditLogsAppService : ShwasherAsyncCrudAppService<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 = Repository.GetAll().Where(i => i.LogType != 0);
  49. var ss = await list.GroupBy(i => i.ServiceName).Select(a=>new{ ServiceName = a.Key }).ToListAsync();
  50. foreach (var l in ss)
  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 = Repository.GetAll().Where(a =>a.LogType != 0 && (string.IsNullOrEmpty(input.ServiceName) || a.ServiceName == input.ServiceName));
  74. var ss = await list.GroupBy(i => i.MethodName).Select(a => new { MethodName = a.Key }).ToListAsync();
  75. foreach (var l in ss)
  76. {
  77. options += $"<option value=\"{l.MethodName}\" >{l.MethodName}</option>\r\n";
  78. }
  79. return options;
  80. }
  81. #endregion
  82. [DisableAuditing]
  83. public override async Task<PagedResultDto<SysLogDto>> GetAll(PagedRequestDto input)
  84. {
  85. CheckGetAllPermission();
  86. var query = CreateFilteredQuery(input).Where(a => a.LogType != 0);
  87. if (input.SearchList != null && input.SearchList.Count > 0)
  88. {
  89. List<LambdaObject> objList = new List<LambdaObject>();
  90. foreach (var o in input.SearchList)
  91. {
  92. if (o.KeyWords.IsNullOrEmpty())
  93. continue;
  94. object keyWords = o.KeyWords;
  95. objList.Add(new LambdaObject
  96. {
  97. FieldType = (LambdaFieldType)o.FieldType,
  98. FieldName = o.KeyField,
  99. FieldValue = keyWords,
  100. ExpType = (LambdaExpType)o.ExpType
  101. });
  102. }
  103. var exp = objList.GetExp<SysLog>();
  104. query = query.Where(exp);
  105. }
  106. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  107. query = ApplySorting(query, input);
  108. query = ApplyPaging(query, input);
  109. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  110. var dtos = new PagedResultDto<SysLogDto>(
  111. totalCount,
  112. entities.Select(MapToEntityDto).ToList()
  113. );
  114. return dtos;
  115. }
  116. }
  117. }