GroupController.cs 10 KB

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