GroupController.cs 11 KB

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