GroupController.cs 9.2 KB

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