ShortMsgDetailsApplicationService.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Abp.Application.Services.Dto;
  6. using Abp.Auditing;
  7. using Abp.Authorization;
  8. using Abp.Domain.Repositories;
  9. using Abp.Extensions;
  10. using IwbZero.AppServiceBase;
  11. using ShwasherSys.Authorization.Permissions;
  12. using ShwasherSys.EntityFramework;
  13. using ShwasherSys.NotificationInfo.Dto;
  14. namespace ShwasherSys.NotificationInfo
  15. {
  16. [AbpAuthorize]
  17. public class ShortMsgDetailAppService : ShwasherAsyncCrudAppService<ShortMsgDetail, ShortMsgDetailDto, int, PagedRequestDto, ShortMsgDetailCreateDto, ShortMsgDetailUpdateDto >,IShortMsgDetailAppService
  18. {
  19. protected IRepository<ShortMessage> ShortMessageRepository;
  20. protected ISqlExecuter SqlExecuter { get; }
  21. public ShortMsgDetailAppService(IRepository<ShortMsgDetail, int> repository, IRepository<ShortMessage> shortMessageRepository, ISqlExecuter sqlExecuter) : base(repository)
  22. {
  23. ShortMessageRepository = shortMessageRepository;
  24. SqlExecuter = sqlExecuter;
  25. }
  26. protected override string GetPermissionName { get; set; } //= PermissionNames.PagesShortMsgDetail;
  27. protected override string GetAllPermissionName { get; set; } //= PermissionNames.PagesShortMsgDetail;
  28. protected override string CreatePermissionName { get; set; } //= PermissionNames.PagesShortMsgDetailCreate;
  29. protected override string UpdatePermissionName { get; set; } //= PermissionNames.PagesShortMsgDetailUpdate;
  30. protected override string DeletePermissionName { get; set; } //= PermissionNames.PagesShortMsgDetailDelete;
  31. [DisableAuditing]
  32. [AbpAuthorize(PermissionNames.PagesNotificationInfoShortMsgMgQuery)]
  33. public async Task<PagedResultDto<ShortMsgDetailDto>> GetAllByUser(PagedRequestDto input)
  34. {
  35. string currentUser = AbpSession.UserName;
  36. var msgDetails = Repository.GetAll().Where(i =>i.RecvUserID == currentUser);
  37. var msgs = ShortMessageRepository.GetAll().Where(i => i.IsDelete == "N");
  38. var shortMsgDetailDtos = from d in msgDetails
  39. join m in msgs on d.MsgID equals m.Id
  40. select new ShortMsgDetailDto()
  41. {
  42. Content = m.Content,
  43. Id = d.Id,
  44. SendTime = m.SendTime,
  45. IsRead = d.IsRead,
  46. MsgID = m.Id,
  47. RecvUserID = d.RecvUserID,
  48. SendUserID = m.SendUserID,
  49. Title = m.Title
  50. };
  51. var totalCount = await AsyncQueryableExecuter.CountAsync(shortMsgDetailDtos);
  52. shortMsgDetailDtos = shortMsgDetailDtos.OrderByDescending(i=>i.SendTime);
  53. shortMsgDetailDtos = shortMsgDetailDtos.Skip(input.SkipCount).Take(input.MaxResultCount);
  54. var entities = await AsyncQueryableExecuter.ToListAsync(shortMsgDetailDtos);
  55. var dtos = new PagedResultDto<ShortMsgDetailDto>(
  56. totalCount,
  57. entities
  58. );
  59. return dtos;
  60. }
  61. public NoticeAlarmDto GetMsgByUser()
  62. {
  63. try
  64. {
  65. string currentUser = AbpSession.UserName;
  66. var msgDetails = Repository.GetAll().Where(i => i.RecvUserID == currentUser);
  67. var msgs = ShortMessageRepository.GetAll().Where(i => i.IsDelete == "N");
  68. var shortMsgDetailDtos = from d in msgDetails
  69. join m in msgs on d.MsgID equals m.Id
  70. select new ShortMsgDetailDto()
  71. {
  72. Content = m.Content,
  73. Id = d.Id,
  74. SendTime = m.SendTime,
  75. IsRead = d.IsRead,
  76. MsgID = m.Id,
  77. RecvUserID = d.RecvUserID,
  78. SendUserID = m.SendUserID,
  79. Title = m.Title
  80. };
  81. shortMsgDetailDtos = shortMsgDetailDtos.Where(i => i.IsRead == "N");
  82. int total = shortMsgDetailDtos.Count();
  83. shortMsgDetailDtos = shortMsgDetailDtos.OrderByDescending(i => i.SendTime);
  84. shortMsgDetailDtos = shortMsgDetailDtos.Take(5);
  85. NoticeAlarmDto loNoticeAlarmDto = new NoticeAlarmDto()
  86. {
  87. Total = total,
  88. Items = shortMsgDetailDtos.ToList()
  89. };
  90. return loNoticeAlarmDto;
  91. }
  92. catch (Exception e)
  93. {
  94. Console.WriteLine(e);
  95. //throw;
  96. }
  97. return null;
  98. }
  99. [AbpAuthorize(PermissionNames.PagesNotificationInfoShortMsgMgSetRead)]
  100. public ShortMsgDetail ChangeIsRead(EntityDto<int> input)
  101. {
  102. var msgDetails = Repository.FirstOrDefault(input.Id);
  103. if (msgDetails != null)
  104. {
  105. msgDetails.IsRead = "Y";
  106. Repository.UpdateAsync(msgDetails);
  107. }
  108. return msgDetails;
  109. }
  110. [AbpAuthorize(PermissionNames.PagesNotificationInfoShortMsgMgSetRead)]
  111. public async Task SetRead(EntityDto<string> input)
  112. {
  113. if (!input.Id.IsNullOrWhiteSpace())
  114. {
  115. string condition = input.Id.Substring(0, input.Id.Length - 1);
  116. await SqlExecuter.ExecuteAsync("update ShortMsgDetail set IsRead='Y' where DetailID in (" + condition + ")");
  117. }
  118. }
  119. [AbpAuthorize(PermissionNames.PagesNotificationInfoShortMsgMgDelete)]
  120. public async Task BatchDelete(EntityDto<string> input)
  121. {
  122. if (!input.Id.IsNullOrWhiteSpace())
  123. {
  124. string condition = input.Id.Substring(0, input.Id.Length - 1);
  125. await SqlExecuter.ExecuteAsync("delete from ShortMsgDetail where DetailID in (" + condition + ")");
  126. }
  127. }
  128. }
  129. }