WebGroupController.cs 8.9 KB

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