WebGroupController.cs 10 KB

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