GroupController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. using Microsoft.Extensions.Logging;
  21. namespace GxPress.Api.AppControllers
  22. {
  23. /// <summary>
  24. /// 小组
  25. /// </summary>
  26. [Route("api/app/group")]
  27. [ApiController]
  28. [Authorize]
  29. public class GroupController : ControllerBase
  30. {
  31. private readonly ILogger<GroupController> _logger;
  32. private readonly IGroupRepository _groupRepository;
  33. private readonly IGroupUserRepository _groupUserRepository;
  34. private readonly IGroupFolderRepository _groupFolderRepository;
  35. private readonly IGroupService _groupService;
  36. private readonly ILoginContext _loginContext;
  37. private readonly ITopicRepository _topicRepository;
  38. private readonly ITopicService _topicService;
  39. private readonly IGroupCategoryRepository groupCategoryRepository;
  40. private readonly IUserGroupCategoryRepository userGroupCategoryRepository;
  41. private readonly IGroupCategoryService groupCategoryService;
  42. public GroupController(ILogger<GroupController> logger, IGroupRepository groupRepository,
  43. IGroupFolderRepository groupFolderRepository, IGroupUserRepository groupUserRepository,
  44. ILoginContext loginContext, IGroupService groupService, ITopicRepository topicRepository,
  45. ITopicService topicService, IGroupCategoryRepository groupCategoryRepository,
  46. IUserGroupCategoryRepository userGroupCategoryRepository, IGroupCategoryService groupCategoryService)
  47. {
  48. _logger = logger;
  49. _groupFolderRepository = groupFolderRepository;
  50. _groupRepository = groupRepository;
  51. _groupUserRepository = groupUserRepository;
  52. _loginContext = loginContext;
  53. _groupService = groupService;
  54. _topicRepository = topicRepository;
  55. _topicService = topicService;
  56. this.groupCategoryRepository = groupCategoryRepository;
  57. this.userGroupCategoryRepository = userGroupCategoryRepository;
  58. this.groupCategoryService = groupCategoryService;
  59. }
  60. /// <summary>
  61. /// 新建小组
  62. /// </summary>
  63. /// <param name="request"></param>
  64. /// <returns></returns>
  65. [HttpPut("insert")]
  66. public async Task<GroupDetailResult> Insert(GroupInRequest request)
  67. {
  68. request.UserId = _loginContext.AccountId;
  69. var result = await _groupService.InsertGroup(request);
  70. //插入小组用户
  71. if (result.Id > 0 && request.UserIds.Count > 0)
  72. {
  73. var groupUserInRequest = new GroupUserInRequest();
  74. groupUserInRequest.UserId = request.UserId;
  75. groupUserInRequest.UserIds = request.UserIds;
  76. groupUserInRequest.SourceType = 2;
  77. groupUserInRequest.GroupId = result.Id;
  78. await _groupService.InsertsAsync(groupUserInRequest);
  79. }
  80. return result;
  81. }
  82. /// <summary>
  83. /// 添加小组成员
  84. /// </summary>
  85. /// <param name="request"></param>
  86. /// <returns></returns>
  87. [HttpPost("insert-user")]
  88. public async Task<AppResult<object>> AddGroupUser(GroupUserInRequest request)
  89. {
  90. request.UserId = _loginContext.AccountId;
  91. return await _groupService.InsertsAsync(request);
  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. request.UserId = _loginContext.AccountId;
  102. return await _groupService.DeleteAsync(request);
  103. }
  104. /// <summary>
  105. /// 退出小组
  106. /// </summary>
  107. /// <param name="groupId"></param>
  108. /// <returns></returns>
  109. [HttpDelete("{groupId}")]
  110. public async Task<bool> DeleteAsync(int groupId)
  111. {
  112. return await _groupService.DeleteAsync(_loginContext.AccountId, groupId);
  113. }
  114. /// <summary>
  115. /// 根据文件夹ID查询小组列表
  116. /// </summary>
  117. /// <param name="request"></param>
  118. /// <returns></returns>
  119. [HttpPost("find")]
  120. public async Task<PagedList<GroupUserFindResult>> FindGroupByGroupFolderId(GroupSearchRequest request)
  121. {
  122. request.UserId = _loginContext.AccountId;
  123. return await _groupService.FindGroupByGroupFolderIdAsync(request);
  124. }
  125. /// <summary>
  126. /// 获取小组详情
  127. /// </summary>
  128. /// <param name="request"></param>
  129. /// <returns></returns>
  130. [HttpPost("detail")]
  131. public async Task<GroupDetailResult> GroupDetailAsync(GroupDetailRequest request)
  132. {
  133. request.UserId = _loginContext.AccountId;
  134. return await _groupService.GroupDetailAsync(request);
  135. }
  136. /// <summary>
  137. /// 修改小组
  138. /// </summary>
  139. /// <param name="request"></param>
  140. /// <returns></returns>
  141. [HttpPost("update")]
  142. public async Task<bool> Update(GroupUpRequest request)
  143. {
  144. return await _groupRepository.UpdateAsync(request);
  145. }
  146. /// <summary>
  147. /// 是否添加到通讯录
  148. /// </summary>
  149. /// <param name="groupId"></param>
  150. /// <returns></returns>
  151. [HttpPut("contacts/{groupId}")]
  152. public async Task<bool> UpdateContactsAsync(int groupId)
  153. {
  154. return await _groupRepository.UpdateContactsAsync(groupId, _loginContext.AccountId);
  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. /// <param name="categoryId"></param>
  234. /// <returns></returns>
  235. [HttpGet("category-list/{categoryId}")]
  236. public async Task<IEnumerable<SearchGroupDetailResult>> GetAllAsync(int categoryId)
  237. {
  238. return await _groupService.GetAllAsync(categoryId, _loginContext.AccountId);
  239. }
  240. /// <summary>
  241. /// 根据parendId获取小组广场
  242. /// </summary>
  243. /// <param name="parentId"></param>
  244. /// <returns></returns>
  245. [HttpGet("group-category/{parentId}")]
  246. [AllowAnonymous]
  247. public async Task<IEnumerable<GroupCategoryResult>> GetGroupCategoryAsync(int parentId)
  248. {
  249. return await groupCategoryService.GetGroupCategoryAsync(parentId, _loginContext.AccountId);
  250. }
  251. /// <summary>
  252. /// 或者最近使用的小组
  253. /// </summary>
  254. /// <returns></returns>
  255. [HttpGet("lately-group")]
  256. public async Task<IEnumerable<LatelyGroupDetailResult>> GetLatelyGroupDetailResultAsync()
  257. {
  258. return await _groupRepository.GetLatelyGroupDetailResultAsync(_loginContext.AccountId);
  259. }
  260. /// <summary>
  261. /// 小组转移
  262. /// </summary>
  263. /// <param name="request"></param>
  264. /// /// <returns></returns>
  265. [HttpPut("transfer")]
  266. public async Task<bool> SetGroupTransferAsync(GroupTransferReqeust request)
  267. {
  268. request.UserId = _loginContext.AccountId;
  269. return await _groupService.SetGroupTransferAsync(request);
  270. }
  271. /// <summary>
  272. /// /// 小组列表 搜索专用
  273. /// </summary>
  274. /// <returns></returns>
  275. [HttpGet("list")]
  276. public async Task<IEnumerable<UserGroupResult>> GetUserGroupListAsync()
  277. {
  278. return await _groupRepository.GetUserGroupListAsync(_loginContext.AccountId);
  279. }
  280. /// <summary>
  281. /// 小组广场搜索
  282. /// </summary>
  283. /// <param name="keyWord"></param>
  284. /// <returns></returns>
  285. [HttpGet("search")]
  286. public async Task<IEnumerable<SearchGroupDetailResult>> GetSearchGroupAsync([FromQuery] string keyWord)
  287. {
  288. return await _groupRepository.GetSearchGroupAsync(keyWord, _loginContext.AccountId);
  289. }
  290. /// <summary>
  291. /// 添加小组广场用户排序
  292. /// </summary>
  293. /// <param name="request"></param>
  294. /// <returns></returns>
  295. [HttpPost("user-group-category")]
  296. public async Task<bool> InsertAsync(IEnumerable<Entity.tede2.Group.UserGroupCategory> request)
  297. {
  298. return await userGroupCategoryRepository.InsertAsync(request, _loginContext.AccountId);
  299. }
  300. }
  301. }