WebGroupController.cs 11 KB

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