NoticeController.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Common.Page;
  5. using GxPress.Common.Tools;
  6. using GxPress.Entity;
  7. using GxPress.Repository.Interface;
  8. using GxPress.Request.Notice;
  9. using GxPress.Request.NoticeAnalyze;
  10. using GxPress.Result.Notice;
  11. using GxPress.Service.Interface.Notice;
  12. using Microsoft.AspNetCore.Authorization;
  13. using Microsoft.AspNetCore.Mvc;
  14. namespace GxPress.Api.AppControllers
  15. {
  16. /// <summary>
  17. /// 通知
  18. /// </summary>
  19. [Route("api/app/notice")]
  20. [ApiController]
  21. [Authorize]
  22. public class NoticeController : ControllerBase
  23. {
  24. private readonly INoticeRepository _noticeRepository;
  25. private readonly INoticeFolderRepository _noticeFolderRepository;
  26. private readonly INoticeService _noticeService;
  27. private readonly ILoginContext _loginContext;
  28. public NoticeController(INoticeRepository noticeRepository, INoticeFolderRepository noticeFolderRepository,INoticeService noticeService, ILoginContext loginContext)
  29. {
  30. _noticeRepository = noticeRepository;
  31. _noticeFolderRepository = noticeFolderRepository;
  32. _noticeService = noticeService;
  33. _loginContext = loginContext;
  34. }
  35. /// <summary>
  36. /// 添加通知
  37. /// </summary>
  38. /// <param name="request"></param>
  39. /// <returns></returns>
  40. [HttpPut("add")]
  41. public async Task<bool> Insert(NoticeInRequest request)
  42. {
  43. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  44. // request.Content = StringUtils.RemoveEmoji(request.Content);
  45. request.UserId = _loginContext.AccountId;
  46. var boolValue = await _noticeService.InsertAsync(request);
  47. return boolValue;
  48. }
  49. /// <summary>
  50. /// 自己删除
  51. /// </summary>
  52. /// <param name="request"></param>
  53. /// <returns></returns>
  54. [HttpDelete("delete")]
  55. public async Task<bool> Delete(NoticeDeRequest request)
  56. {
  57. return await _noticeRepository.DeleteAsync(request);
  58. }
  59. /// <summary>
  60. /// 获取通知详情
  61. /// </summary>
  62. /// <param name="id"></param>
  63. /// <returns></returns>
  64. [HttpGet("app-detail/{id}")]
  65. public async Task<Result.Notice.NoticeDetailResult> GetNoticeDetailResult(int id)
  66. {
  67. return await _noticeService.GetNoticeDetailAsync(id, _loginContext.AccountId);
  68. }
  69. /// <summary>
  70. /// app通知分页列表
  71. /// </summary>
  72. /// <param name="request"></param>
  73. /// <returns></returns>
  74. [HttpPost("list-page")]
  75. public async Task<PagedList<NoticeListPageResult>> GetNoticeListPage(NoticePageSearchRequest request)
  76. {
  77. request.UserId = _loginContext.AccountId;
  78. return await _noticeService.GetNoticeListPageAsync(request);
  79. }
  80. /// <summary>
  81. /// 恢复删除通知
  82. /// </summary>
  83. /// <param name="request"></param>
  84. /// <returns></returns>
  85. [HttpPost("recover")]
  86. public async Task<bool> RecoverDelete(NoticeDeRequest request)
  87. {
  88. return await _noticeRepository.RecoverDeleteAsync(request);
  89. }
  90. /// <summary>
  91. /// 详情
  92. /// </summary>
  93. /// <param name="id"></param>
  94. /// <returns></returns>
  95. [HttpGet("detail/{id}")]
  96. public async Task<NoticeEditDetailResult> Detail(int id)
  97. {
  98. return await _noticeService.NoticeEditDetailAsync(id);
  99. }
  100. /// <summary>
  101. /// 详情 web专属
  102. /// </summary>
  103. /// <param name="id"></param>
  104. /// <returns></returns>
  105. [HttpGet("web-detail/{id}")]
  106. [AllowAnonymous]
  107. public async Task<NoticeEditDetailResult> WebDetail(int id)
  108. {
  109. return await _noticeService.NoticeEditDetailAsync(id);
  110. }
  111. /// <summary>
  112. /// 修改详情
  113. /// </summary>
  114. /// <param name="request"></param>
  115. /// <returns></returns>
  116. [HttpPost("edit")]
  117. public async Task<bool> Edit([FromBody] NoticeUpRequest request)
  118. {
  119. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  120. // request.Content = StringUtils.RemoveEmoji(request.Content);
  121. request.UserId = _loginContext.AccountId;
  122. return await _noticeService.NoticeUpAsync(request);
  123. }
  124. /// <summary>
  125. /// 查询通知已读未读信息
  126. /// </summary>
  127. /// <param name="request"></param>
  128. /// <returns></returns>
  129. [HttpPost("read")]
  130. public async Task<IEnumerable<NoticeReadListResult>> NoticeReadList(NoticeReadListRequest request)
  131. {
  132. return await _noticeService.NoticeReadListAsync(request);
  133. }
  134. /// <summary>
  135. /// 撤销通知
  136. /// </summary>
  137. /// <param name="id"></param>
  138. /// <returns></returns>
  139. [HttpPut("recall/{id}")]
  140. public async Task<bool> RecallAsync(int id)
  141. {
  142. return await _noticeService.RecallAsync(id);
  143. }
  144. }
  145. }