MissiveController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Common.Page;
  5. using GxPress.Repository.Interface.Missive;
  6. using GxPress.Request.App.Missive;
  7. using GxPress.Result.App.Missive;
  8. using GxPress.Service.Interface.Missive;
  9. using Microsoft.AspNetCore.Authorization;
  10. using Microsoft.AspNetCore.Mvc;
  11. using System.Linq;
  12. using System;
  13. namespace GxPress.Api.AppControllers
  14. {
  15. /// <summary>
  16. /// 站内信
  17. /// </summary>
  18. [Route("api/web/missive")]
  19. [ApiController]
  20. [Authorize]
  21. public class WebMissiveController : ControllerBase
  22. {
  23. private readonly IMissiveRepository _missiveRepository;
  24. private readonly IMissiveService _missiveService;
  25. private readonly ILoginContext _loginContext;
  26. public WebMissiveController(IMissiveRepository missiveRepository, IMissiveService missiveService,
  27. ILoginContext loginContext)
  28. {
  29. _missiveRepository = missiveRepository;
  30. _missiveService = missiveService;
  31. _loginContext = loginContext;
  32. }
  33. /// <summary>
  34. /// 根据站内信ID获取详情
  35. /// </summary>
  36. /// <param name="missiveId"></param>
  37. /// <returns></returns>
  38. [HttpGet("get/{missiveId}")]
  39. public async Task<MissiveInfoResult> GetMissiveInfo(int missiveId)
  40. {
  41. return await _missiveService.GetMissiveInfoAsync(missiveId, _loginContext.AccountId);
  42. }
  43. /// <summary>
  44. /// 添加/修改站内信
  45. /// </summary>
  46. /// <param name="request"></param>
  47. /// <returns></returns>
  48. [HttpPut("add")]
  49. public async Task<bool> Insert(MissiveInRequest request)
  50. {
  51. // request.HtmlContent = StringUtils.RemoveEmoji(request.HtmlContent);
  52. // request.Content = StringUtils.RemoveEmoji(request.Content);
  53. // request.Title = StringUtils.RemoveEmoji(request.Title);
  54. request.UserId = _loginContext.AccountId;
  55. request.MissiveAddresseeUserIds.Remove(request.UserId);
  56. request.MissiveCcUserIds.Remove(request.UserId);
  57. return await _missiveService.InsertOrUpdateAsync(request);
  58. }
  59. /// <summary>
  60. /// 获取站内信列表
  61. /// </summary>
  62. /// <param name="request"></param>
  63. /// <returns></returns>
  64. [HttpPost("search")]
  65. public async Task<PagedList<MissiveSearchResult>> GetMissiveSearchResult(MissiveSearchRequest request)
  66. {
  67. request.UserId = _loginContext.AccountId;
  68. return await _missiveService.GetMissiveSearchResultAsync(request);
  69. }
  70. /// <summary>
  71. /// 获取站内信详情
  72. /// </summary>
  73. /// <param name="id"></param>
  74. /// <returns></returns>
  75. [HttpGet("{id}")]
  76. public async Task<MissiveDetailResult> GetMissiveDetail(int id)
  77. {
  78. return await _missiveService.GetMissiveDetailAsync(id);
  79. }
  80. /// <summary>
  81. /// 获取站内信详情-web专属
  82. /// </summary>
  83. /// <param name="id"></param>
  84. /// <returns></returns>
  85. [HttpGet("web/{id}")]
  86. [AllowAnonymous]
  87. public async Task<MissiveInfoResult> GetWebMissiveDetail(int id)
  88. {
  89. var missiveInfos = await _missiveService.GetMissiveInfoAsync(id, 0);
  90. missiveInfos.Items = missiveInfos.Items.OrderByDescending(n => Convert.ToDateTime(n.CreatedDate)).ToList();
  91. return missiveInfos;
  92. }
  93. /// <summary>
  94. /// 获取站内信已读未读数据
  95. /// </summary>
  96. /// <param name="request"></param>
  97. /// <returns></returns>
  98. [HttpPost("read")]
  99. public async Task<IEnumerable<MissiveReadListResult>> GetMissiveReadListAsync(MissiveReadListRequest request)
  100. {
  101. return await _missiveService.GetMissiveReadListAsync(request);
  102. }
  103. /// <summary>
  104. /// 站内信撤回
  105. /// </summary>
  106. /// <param name="missiveId"></param>
  107. /// <returns></returns>
  108. [HttpPut("recall/{missiveId}")]
  109. public async Task<bool> RecallAsync(int missiveId)
  110. {
  111. return await _missiveService.RecallAsync(missiveId);
  112. }
  113. }
  114. }