WebGroupController.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Common.Page;
  5. using GxPress.Repository.Interface;
  6. using GxPress.Repository.Interface.Group;
  7. using GxPress.Request.AddressBookGroup;
  8. using GxPress.Request.App.Group;
  9. using GxPress.Request.App.GroupUser;
  10. using GxPress.Request.App.Topic;
  11. using GxPress.Result.AddressBook;
  12. using GxPress.Result.App.Group;
  13. using GxPress.Result.App.GroupUser;
  14. using GxPress.Result.App.Topic;
  15. using GxPress.Result.Web;
  16. using GxPress.Service.Interface.Group;
  17. using GxPress.Service.Interface.Topic;
  18. using Microsoft.AspNetCore.Authorization;
  19. using Microsoft.AspNetCore.Mvc;
  20. namespace GxPress.Api.WebControllers
  21. {
  22. /// <summary>
  23. /// 导航数据
  24. /// </summary>
  25. [Route("api/web/group")]
  26. [ApiController]
  27. [Authorize]
  28. public class WebGroupController : Controller
  29. {
  30. private readonly IGroupRepository _groupRepository;
  31. private readonly IGroupUserRepository _groupUserRepository;
  32. private readonly IGroupFolderRepository _groupFolderRepository;
  33. private readonly IGroupService _groupService;
  34. private readonly ILoginContext _loginContext;
  35. private readonly ITopicRepository _topicRepository;
  36. private readonly ITopicService _topicService;
  37. private readonly IGroupCategroyRepository groupCategroyRepository;
  38. public WebGroupController(IGroupRepository groupRepository,
  39. IGroupFolderRepository groupFolderRepository, IGroupUserRepository groupUserRepository,
  40. ILoginContext loginContext, IGroupService groupService, ITopicRepository topicRepository, ITopicService topicService, IGroupCategroyRepository groupCategroyRepository)
  41. {
  42. _groupFolderRepository = groupFolderRepository;
  43. _groupRepository = groupRepository;
  44. _groupUserRepository = groupUserRepository;
  45. _loginContext = loginContext;
  46. _groupService = groupService;
  47. _topicRepository = topicRepository;
  48. _topicService = topicService;
  49. this.groupCategroyRepository = groupCategroyRepository;
  50. }
  51. /// <summary>
  52. /// 新建小组
  53. /// </summary>
  54. /// <param name="request"></param>
  55. /// <returns></returns>
  56. [HttpPut("insert")]
  57. public async Task<GroupDetailResult> Insert(GroupInRequest request)
  58. {
  59. request.UserId = _loginContext.AccountId;
  60. var result = await _groupService.InsertGroup(request);
  61. //插入小组用户
  62. if (result.Id > 0 && request.UserIds.Count > 0)
  63. {
  64. var groupUserInRequest = new GroupUserInRequest();
  65. groupUserInRequest.UserId = request.UserId;
  66. groupUserInRequest.UserIds = request.UserIds;
  67. groupUserInRequest.SourceType = 2;
  68. groupUserInRequest.GroupId = result.Id;
  69. await _groupService.InsertsAsync(groupUserInRequest);
  70. }
  71. return result;
  72. }
  73. /// <summary>
  74. /// 根据广场类别查询小组
  75. /// </summary>
  76. /// <param name="categoryId"></param>
  77. /// <returns></returns>
  78. [HttpGet("category-list/{categoryId}")]
  79. public async Task<IEnumerable<Entity.Group>> GetAllAsync(int categoryId)
  80. {
  81. return await _groupService.GetAllAsync(categoryId);
  82. }
  83. /// <summary>
  84. /// 根据parendId获取
  85. /// </summary>
  86. /// <param name="parentId"></param>
  87. /// <returns></returns>
  88. [HttpGet("group-category/{parentId}")]
  89. [AllowAnonymous]
  90. public async Task<IEnumerable<GroupCategoryResult>> GetGroupCategoryAsync(int parentId)
  91. {
  92. return await groupCategroyRepository.GetAllAsync(parentId);
  93. }
  94. /// <summary>
  95. /// 删除小组成员
  96. /// </summary>
  97. /// <param name="request"></param>
  98. /// <returns></returns>
  99. [HttpPost("delete-user")]
  100. public async Task<bool> DeleteGroupUser(GroupUserDeRequest request)
  101. {
  102. return await _groupService.DeleteAsync(request);
  103. }
  104. /// <summary>
  105. /// 退出小组
  106. /// </summary>
  107. /// <param name="groupId"></param>
  108. /// <returns></returns>
  109. [HttpDelete("{groupId}")]
  110. public async Task<bool> DeleteAsync(int groupId)
  111. {
  112. return await _groupService.DeleteAsync(_loginContext.AccountId, groupId);
  113. }
  114. /// <summary>
  115. /// 根据文件夹ID查询小组列表
  116. /// </summary>
  117. /// <param name="request"></param>
  118. /// <returns></returns>
  119. [HttpPost("find")]
  120. public async Task<PagedList<GroupUserFindResult>> FindGroupByGroupFolderId(GroupSearchRequest request)
  121. {
  122. request.UserId = _loginContext.AccountId;
  123. return await _groupService.FindGroupByGroupFolderIdAsync(request);
  124. }
  125. /// <summary>
  126. /// 获取小组详情
  127. /// </summary>
  128. /// <param name="request"></param>
  129. /// <returns></returns>
  130. [HttpPost("detail")]
  131. public async Task<GroupDetailResult> GroupDetailAsync(GroupDetailRequest request)
  132. {
  133. request.UserId = _loginContext.AccountId;
  134. return await _groupService.GroupDetailAsync(request);
  135. }
  136. /// <summary>
  137. /// 修改小组
  138. /// </summary>
  139. /// <param name="request"></param>
  140. /// <returns></returns>
  141. [HttpPost("update")]
  142. public async Task<bool> Update(GroupUpRequest request)
  143. {
  144. return await _groupRepository.UpdateAsync(request);
  145. }
  146. /// <summary>
  147. ///设置权限
  148. /// 1 超级管理员 2 管理员 3普通用户
  149. /// </summary>
  150. /// <param name="request"></param>
  151. /// <returns></returns>
  152. [HttpPost("update-user")]
  153. public async Task<bool> UpdateGroupUser(GroupUserUpRequest request)
  154. {
  155. return await _groupUserRepository.UpdateAsync(request);
  156. }
  157. /// <summary>
  158. /// 根据GroupId获取话题列表
  159. /// </summary>
  160. /// <param name="request"></param>
  161. /// <returns></returns>
  162. [HttpPost("search")]
  163. public async Task<PagedList<TopicListPageResult>> FindTopicByGroupId(TopicDetailListRequest request)
  164. {
  165. request.UserId = _loginContext.AccountId;
  166. return await _topicService.FindTopicByGroupIdAsync(request);
  167. }
  168. /// <summary>
  169. /// 加入是否管理员同意
  170. /// </summary>
  171. /// <param name="groupId"></param>
  172. /// <returns></returns>
  173. [HttpPut("set-admin/{groupId}")]
  174. public async Task<bool> SetGroupIsAdmin(int groupId)
  175. {
  176. return await _groupRepository.SetGroupIsAdminAsync(groupId);
  177. }
  178. /// <summary>
  179. /// 是否禁言
  180. /// </summary>
  181. /// <param name="groupId"></param>
  182. /// <returns></returns>
  183. [HttpPut("set-words/{groupId}")]
  184. public async Task<bool> SetGroupIsWords(int groupId)
  185. {
  186. return await _groupRepository.SetGroupIsWordsAsync(groupId);
  187. }
  188. /// <summary>
  189. /// 扫描二维码获取小组详情
  190. /// </summary>
  191. /// <param name="guId"></param>
  192. /// <returns></returns>
  193. [HttpGet("{guId}")]
  194. public async Task<GroupDetailResult> GroupDetailByGuId(string guId)
  195. {
  196. var userId = _loginContext.AccountId;
  197. return await _groupService.GroupDetailByGuIdAsync(guId, userId);
  198. }
  199. /// <summary>
  200. /// 设置用户是否免打扰
  201. /// </summary>
  202. /// <param name="groupId"></param>
  203. /// <returns></returns>
  204. [HttpPut("set-disturb/{groupId}")]
  205. public async Task<bool> SetIsUDisturbAsync(int groupId)
  206. {
  207. var userId = _loginContext.AccountId;
  208. return await _groupUserRepository.SetIsUDisturbAsync(groupId, userId);
  209. }
  210. /// <summary>
  211. /// 搜索小组成员
  212. /// </summary>
  213. /// <param name="request"></param>
  214. /// <returns></returns>
  215. [HttpPost("search-group-user")]
  216. public async Task<IEnumerable<GroupUserListResult>> SearchGroupUserAsync(TopicDetailListRequest request)
  217. {
  218. return await _groupRepository.SearchGroupUserAsync(request);
  219. }
  220. /// <summary>
  221. /// 用户小组列表
  222. /// </summary>
  223. /// <param name="userId"></param>
  224. /// <returns></returns>
  225. [HttpGet("list/{userId}")]
  226. public async Task<IEnumerable<UserGroupList>> GetAllByUserIdAsync(int userId)
  227. {
  228. return await _groupRepository.GetAllByUserIdAsync(userId);
  229. }
  230. }
  231. }