GroupChatUserController.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using Datory;
  4. using GxPress.Auth;
  5. using GxPress.Common.Exceptions;
  6. using GxPress.Common.Tools;
  7. using GxPress.Repository.Interface;
  8. using GxPress.Request.GroupChatUser;
  9. using GxPress.Result.GroupChatUser;
  10. using GxPress.Service.Interface;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Mvc;
  13. namespace GxPress.Api.AppControllers
  14. {
  15. /// <summary>
  16. /// 群聊组员
  17. /// </summary>
  18. [Route("api/app/group-chat-user")]
  19. [ApiController]
  20. [Authorize]
  21. public class GroupChatUserController : ControllerBase
  22. {
  23. private readonly IGroupChatUserRepository _groupChatUserRepository;
  24. private readonly IGroupChatUserService _groupChatUserService;
  25. private readonly IGroupChatRepository _groupChatRepository;
  26. private readonly IOftenContactRepository _oftenContactRepository;
  27. private readonly ILoginContext _loginContext;
  28. public GroupChatUserController(IGroupChatUserRepository groupChatUserRepository,
  29. IGroupChatUserService groupChatUserService, IGroupChatRepository groupChatRepository,
  30. ILoginContext loginContext, IOftenContactRepository oftenContactRepository)
  31. {
  32. _groupChatUserRepository = groupChatUserRepository;
  33. _groupChatUserService = groupChatUserService;
  34. _groupChatRepository = groupChatRepository;
  35. _loginContext = loginContext;
  36. _oftenContactRepository = oftenContactRepository;
  37. }
  38. /// <summary>
  39. /// 添加
  40. /// </summary>
  41. /// <param name="request"></param>
  42. /// <returns></returns>
  43. [HttpPost("add")]
  44. public async Task<bool> Insert(GroupChatUserInRequest request)
  45. {
  46. return await _groupChatUserRepository.InsertAsync(request);
  47. }
  48. /// <summary>
  49. /// 修改
  50. /// </summary>
  51. /// <param name="request"></param>
  52. /// <returns></returns>
  53. [HttpPost("update")]
  54. public async Task<bool> Update(GroupChatUserUpRequest request)
  55. {
  56. return await _groupChatUserRepository.UpdateAsync(request);
  57. }
  58. /// <summary>
  59. /// 根据群ID查询群
  60. /// </summary>
  61. /// <param name="request"></param>
  62. /// <returns></returns>
  63. [HttpPost("group-chat-user-search")]
  64. public async Task<GroupChatUserByGroupChatIdResultList> GetGroupChatUserByGroupChatId(
  65. GroupChatUserSearchRequest request)
  66. {
  67. var userId = _loginContext.AccountId;
  68. var groupChat = await _groupChatRepository.GetGroupChatByImIdAsync(request.GroupChatImId);
  69. if (groupChat == null)
  70. throw new BusinessException("群不存在!");
  71. var result = new GroupChatUserByGroupChatIdResultList
  72. {
  73. GroupChat = groupChat,
  74. Item = await _groupChatUserRepository.GetGroupChatUserByGroupChatIdAsync(request)
  75. };
  76. var query = Q.NewQuery();
  77. query.Where(nameof(Entity.GroupChatUser.UserId), _loginContext.AccountId);
  78. query.Where(nameof(Entity.GroupChatUser.GroupChatId), groupChat.Id);
  79. var groupChatUser = await _groupChatUserRepository.GetAsync(query);
  80. result.GroupChat.IsContacts = groupChatUser.IsContacts;
  81. //判断是否是管理员
  82. result.GroupChat.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId;
  83. //result.GroupChat.AvatarUrl = StringUtils.AddDomainMin(result.GroupChat.AvatarUrl);
  84. //result.GroupChat.QRCoder = StringUtils.AddDomain(result.GroupChat.QRCoder);
  85. result.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId;
  86. result.IsUser = result.Item.Any(n => n.UserId == userId);
  87. result.IsTop = await _oftenContactRepository.GetIsTopAsync(userId, groupChat.GroupChatImId);
  88. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest
  89. {
  90. UserId = userId,
  91. GroupChatId = groupChat.Id
  92. };
  93. result.IsDisturb = await _groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  94. return result;
  95. }
  96. /// <summary>
  97. /// 根据群GUID查询群
  98. /// </summary>
  99. /// <param name="guid"></param>
  100. /// <returns></returns>
  101. [HttpGet("{guid}")]
  102. public async Task<GroupChatUserByGroupChatIdResultList> GetGroupChatUserByGroupChatGuid(string guid)
  103. {
  104. var userId = _loginContext.AccountId;
  105. var groupChatUserSearchRequest = new GroupChatUserSearchRequest();
  106. var groupChat = await _groupChatRepository.GetGroupChatByGuidAsync(guid);
  107. if (groupChat == null)
  108. throw new BusinessException("群不存在!");
  109. groupChatUserSearchRequest.GroupChatImId = groupChat.GroupChatImId;
  110. var result = new GroupChatUserByGroupChatIdResultList
  111. {
  112. GroupChat = groupChat,
  113. Item = await _groupChatUserRepository.GetGroupChatUserByGroupChatIdAsync(groupChatUserSearchRequest)
  114. };
  115. //判断是否是管理员
  116. result.GroupChat.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId;
  117. result.GroupChat.AvatarUrl = StringUtils.AddDomainMin(result.GroupChat.AvatarUrl);
  118. result.GroupChat.QRCoder = StringUtils.AddDomain(result.GroupChat.QRCoder);
  119. result.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId;
  120. result.IsUser = result.Item.Any(n => n.UserId == userId);
  121. result.IsTop = await _oftenContactRepository.GetIsTopAsync(userId, groupChat.GroupChatImId);
  122. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest
  123. {
  124. UserId = userId,
  125. GroupChatId = groupChat.Id
  126. };
  127. result.IsDisturb = await _groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  128. return result;
  129. }
  130. /// <summary>
  131. /// 是否免打扰
  132. /// </summary>
  133. /// <param name="request"></param>
  134. /// <returns></returns>
  135. [HttpPost("up-is-disturb")]
  136. public async Task<bool> UpIsDisturb(GroupChatUserIsDisturbRequest request)
  137. {
  138. request.UserId = _loginContext.AccountId;
  139. return await _groupChatUserRepository.UpIsDisturbAsync(request);
  140. }
  141. /// <summary>
  142. /// 是否置顶
  143. /// </summary>
  144. /// <param name="request"></param>
  145. /// <returns></returns>
  146. [HttpPost("up-is-top")]
  147. public async Task<bool> UpIsTop(GroupChatUserIsTopRequest request)
  148. {
  149. request.UserId = _loginContext.AccountId;
  150. return await _groupChatUserRepository.UpIsTopAsync(request);
  151. }
  152. }
  153. }