GroupController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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 IGroupCategoryRepository groupCategoryRepository;
  38. public GroupController(ILogger<GroupController> logger, IGroupRepository groupRepository,
  39. IGroupFolderRepository groupFolderRepository, IGroupUserRepository groupUserRepository,
  40. ILoginContext loginContext, IGroupService groupService, ITopicRepository topicRepository, ITopicService topicService, IGroupCategoryRepository groupCategoryRepository)
  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.groupCategoryRepository = groupCategoryRepository;
  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. request.UserId = _loginContext.AccountId;
  94. return await _groupService.DeleteAsync(request);
  95. }
  96. /// <summary>
  97. /// 退出小组
  98. /// </summary>
  99. /// <param name="groupId"></param>
  100. /// <returns></returns>
  101. [HttpDelete("{groupId}")]
  102. public async Task<bool> DeleteAsync(int groupId)
  103. {
  104. return await _groupService.DeleteAsync(_loginContext.AccountId, groupId);
  105. }
  106. /// <summary>
  107. /// 根据文件夹ID查询小组列表
  108. /// </summary>
  109. /// <param name="request"></param>
  110. /// <returns></returns>
  111. [HttpPost("find")]
  112. public async Task<PagedList<GroupUserFindResult>> FindGroupByGroupFolderId(GroupSearchRequest request)
  113. {
  114. request.UserId = _loginContext.AccountId;
  115. return await _groupService.FindGroupByGroupFolderIdAsync(request);
  116. }
  117. /// <summary>
  118. /// 获取小组详情
  119. /// </summary>
  120. /// <param name="request"></param>
  121. /// <returns></returns>
  122. [HttpPost("detail")]
  123. public async Task<GroupDetailResult> GroupDetailAsync(GroupDetailRequest request)
  124. {
  125. request.UserId = _loginContext.AccountId;
  126. return await _groupService.GroupDetailAsync(request);
  127. }
  128. /// <summary>
  129. /// 修改小组
  130. /// </summary>
  131. /// <param name="request"></param>
  132. /// <returns></returns>
  133. [HttpPost("update")]
  134. public async Task<bool> Update(GroupUpRequest request)
  135. {
  136. return await _groupRepository.UpdateAsync(request);
  137. }
  138. /// <summary>
  139. ///设置权限
  140. /// 1 超级管理员 2 管理员 3普通用户
  141. /// </summary>
  142. /// <param name="request"></param>
  143. /// <returns></returns>
  144. [HttpPost("update-user")]
  145. public async Task<bool> UpdateGroupUser(GroupUserUpRequest request)
  146. {
  147. return await _groupUserRepository.UpdateAsync(request);
  148. }
  149. /// <summary>
  150. /// 根据GroupId获取话题列表
  151. /// </summary>
  152. /// <param name="request"></param>
  153. /// <returns></returns>
  154. [HttpPost("search")]
  155. public async Task<PagedList<TopicListPageResult>> FindTopicByGroupId(TopicDetailListRequest request)
  156. {
  157. request.UserId = _loginContext.AccountId;
  158. return await _topicService.FindTopicByGroupIdAsync(request);
  159. }
  160. /// <summary>
  161. /// 加入是否管理员同意
  162. /// </summary>
  163. /// <param name="groupId"></param>
  164. /// <returns></returns>
  165. [HttpPut("set-admin/{groupId}")]
  166. public async Task<bool> SetGroupIsAdmin(int groupId)
  167. {
  168. return await _groupRepository.SetGroupIsAdminAsync(groupId);
  169. }
  170. /// <summary>
  171. /// 是否禁言
  172. /// </summary>
  173. /// <param name="groupId"></param>
  174. /// <returns></returns>
  175. [HttpPut("set-words/{groupId}")]
  176. public async Task<bool> SetGroupIsWords(int groupId)
  177. {
  178. return await _groupRepository.SetGroupIsWordsAsync(groupId);
  179. }
  180. /// <summary>
  181. /// 扫描二维码获取小组详情
  182. /// </summary>
  183. /// <param name="guId"></param>
  184. /// <returns></returns>
  185. [HttpGet("{guId}")]
  186. public async Task<GroupDetailResult> GroupDetailByGuId(string guId)
  187. {
  188. var userId = _loginContext.AccountId;
  189. return await _groupService.GroupDetailByGuIdAsync(guId, userId);
  190. }
  191. /// <summary>
  192. /// 设置用户是否免打扰
  193. /// </summary>
  194. /// <param name="groupId"></param>
  195. /// <returns></returns>
  196. [HttpPut("set-disturb/{groupId}")]
  197. public async Task<bool> SetIsUDisturbAsync(int groupId)
  198. {
  199. var userId = _loginContext.AccountId;
  200. return await _groupUserRepository.SetIsUDisturbAsync(groupId, userId);
  201. }
  202. /// <summary>
  203. /// 搜索小组成员
  204. /// </summary>
  205. /// <param name="request"></param>
  206. /// <returns></returns>
  207. [HttpPost("search-group-user")]
  208. public async Task<IEnumerable<GroupUserListResult>> SearchGroupUserAsync(TopicDetailListRequest request)
  209. {
  210. return await _groupRepository.SearchGroupUserAsync(request);
  211. }
  212. /// <summary>
  213. /// 根据广场类别查询小组
  214. /// </summary>
  215. /// <param name="categoryId"></param>
  216. /// <returns></returns>
  217. [HttpGet("category-list/{categoryId}")]
  218. public async Task<IEnumerable<SearchGroupDetailResult>> GetAllAsync(int categoryId)
  219. {
  220. return await _groupService.GetAllAsync(categoryId, _loginContext.AccountId);
  221. }
  222. /// <summary>
  223. /// 根据parendId获取小组广场
  224. /// </summary>
  225. /// <param name="parentId"></param>
  226. /// <returns></returns>
  227. [HttpGet("group-category/{parentId}")]
  228. [AllowAnonymous]
  229. public async Task<IEnumerable<GroupCategoryResult>> GetGroupCategoryAsync(int parentId)
  230. {
  231. return await groupCategoryRepository.GetAllAsync(parentId);
  232. }
  233. /// <summary>
  234. /// 或者最近使用的小组
  235. /// </summary>
  236. /// <returns></returns>
  237. [HttpGet("lately-group")]
  238. public async Task<IEnumerable<LatelyGroupDetailResult>> GetLatelyGroupDetailResultAsync()
  239. {
  240. return await _groupRepository.GetLatelyGroupDetailResultAsync(_loginContext.AccountId);
  241. }
  242. /// <summary>
  243. /// 小组转移
  244. /// </summary>
  245. /// <param name="request"></param>
  246. /// /// <returns></returns>
  247. [HttpPut("transfer")]
  248. public async Task<bool> SetGroupTransferAsync(GroupTransferReqeust request)
  249. {
  250. request.UserId = _loginContext.AccountId;
  251. return await _groupService.SetGroupTransferAsync(request);
  252. }
  253. /// <summary>
  254. /// /// 小组列表 搜索专用
  255. /// </summary>
  256. /// <returns></returns>
  257. [HttpGet("list")]
  258. public async Task<IEnumerable<UserGroupResult>> GetUserGroupListAsync()
  259. {
  260. return await _groupRepository.GetUserGroupListAsync(_loginContext.AccountId);
  261. }
  262. /// <summary>
  263. /// 小组广场搜索
  264. /// </summary>
  265. /// <param name="keyWord"></param>
  266. /// <returns></returns>
  267. [HttpGet("search")]
  268. public async Task<IEnumerable<SearchGroupDetailResult>> GetSearchGroupAsync([FromQuery] string keyWord)
  269. {
  270. return await _groupRepository.GetSearchGroupAsync(keyWord, _loginContext.AccountId);
  271. }
  272. }
  273. }