AdminVerifyInsetService.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using Datory;
  5. using GxPress.Common.Tools;
  6. using GxPress.Entity;
  7. using GxPress.EnumConst;
  8. using GxPress.Repository.Interface;
  9. using GxPress.Repository.Interface.AdminVerify;
  10. using GxPress.Repository.Interface.DepartmentUser;
  11. using GxPress.Request.App.AdminVerify;
  12. using GxPress.Request.App.Middle;
  13. using GxPress.Service.Interface.AdminVerify;
  14. using GxPress.Service.Interface.Middle;
  15. using GxPress.Repository.Interface.Friends;
  16. namespace GxPress.Service.Implement.AdminVerify
  17. {
  18. public class AdminVerifyInsetService : IAdminVerifyInsertService
  19. {
  20. private readonly IAdminVerifyRepository _adminVerifyRepository;
  21. private readonly IUserRepository _userRepository;
  22. private readonly IDepartmentRepository _departmentRepository;
  23. private readonly IMiddleService _middleService;
  24. private readonly IGroupRepository _groupRepository;
  25. private readonly IGroupChatRepository _groupChatRepository;
  26. private readonly IMiddleRepository _middleRepository;
  27. private readonly IGroupUserRepository _groupUserRepository;
  28. private readonly IDepartmentUserRepository departmentUserRepository;
  29. private readonly IFriendsRepository friendsRepository;
  30. public AdminVerifyInsetService(IAdminVerifyRepository adminVerifyRepository, IUserRepository userRepository,
  31. IDepartmentRepository departmentRepository, IMiddleService middleService, IGroupRepository groupRepository,
  32. IGroupChatRepository groupChatRepository, IMiddleRepository middleRepository, IGroupUserRepository groupUserRepository,
  33. IDepartmentUserRepository departmentUserRepository, IFriendsRepository friendsRepository)
  34. {
  35. _adminVerifyRepository = adminVerifyRepository;
  36. _userRepository = userRepository;
  37. _departmentRepository = departmentRepository;
  38. _groupRepository = groupRepository;
  39. _middleService = middleService;
  40. _groupChatRepository = groupChatRepository;
  41. _middleRepository = middleRepository;
  42. _groupUserRepository = groupUserRepository;
  43. this.departmentUserRepository = departmentUserRepository;
  44. this.friendsRepository = friendsRepository;
  45. }
  46. /// <summary>
  47. /// 添加成员
  48. /// </summary>
  49. /// <param name="request"></param>
  50. /// <returns></returns>
  51. public async Task<bool> InsertAsync(AdminVerifyInsertRequest request)
  52. {
  53. var adminVerifys = new List<Entity.AdminVerify>();
  54. //获取邀请人信息
  55. var userDto = await _userRepository.GetAsync(request.UserId);
  56. //获取员工所有信息
  57. var users = await _userRepository.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), request.UserIds));
  58. var departmentUsers = await departmentUserRepository.GetDepartmentUsersByUserIdsAsync(request.UserIds);
  59. var departments = await _departmentRepository.GetAllAsync(Q.WhereIn(nameof(Entity.Department.Id), departmentUsers.Select(n => n.DepartmentId)));
  60. //获取小组
  61. var group = await _groupRepository.GetAsync(request.SourceId);
  62. var ids = new List<GroupUserRoleTyeConst> { GroupUserRoleTyeConst.Admin, GroupUserRoleTyeConst.SuperAdmin };
  63. //创建人
  64. var groupUsers = await _groupUserRepository.GetAllAsync(Q.Where(nameof(GroupUser.GroupId), group.Id).WhereIn(nameof(GroupUser.GroupUserRoleId), ids));
  65. foreach (var userId in request.UserIds)
  66. {
  67. var adminVerify = new Entity.AdminVerify();
  68. var adminVerifyDto = new Entity.AdminVerify();
  69. //获取用户
  70. var user = users.FirstOrDefault(n => n.Id == userId);
  71. if (user == null)
  72. continue;
  73. var department = new Entity.Department();
  74. if (departmentUsers.FirstOrDefault(n => n.UserId == user.Id) != null)
  75. department = departments.FirstOrDefault(m => m.Id == departmentUsers.FirstOrDefault(n => n.UserId == user.Id).DepartmentId);
  76. //判断是否是小组成员
  77. if (request.VerifyType == GroupTypeConst.Group)
  78. {
  79. if (await _groupUserRepository.ExistsAsync(userId, request.SourceId))
  80. continue;
  81. }
  82. //申请
  83. if (request.SourceType == 1)
  84. {
  85. foreach (var groupUser in groupUsers)
  86. {
  87. //设置群主验证
  88. //await InsertMiddleVerify(groupUser.UserId);
  89. adminVerifyDto.AvatarUrl = StringUtils.RemoveDomain(user.AvatarUrl);
  90. adminVerifyDto.SourceName = group.Name;
  91. adminVerifyDto.Name = user.Name;
  92. adminVerifyDto.DisposeType = AdminVerifyTypeConst.UDispose.GetHashCode();
  93. adminVerifyDto.VerifyType = request.VerifyType;
  94. adminVerifyDto.AdminId = groupUser.UserId;
  95. adminVerifyDto.SourceType = request.SourceType;
  96. adminVerifyDto.SourceId = request.SourceId;
  97. adminVerifyDto.UserId = userId;
  98. adminVerifyDto.IsDelete = "";
  99. //获取部门
  100. adminVerifyDto.Remark = department.Name + "-" + user.Name;
  101. adminVerifyDto.Remark = request.Remark;
  102. adminVerifys.Add(adminVerifyDto);
  103. }
  104. }
  105. //邀请
  106. if (request.SourceType == 2)
  107. {
  108. adminVerify.AvatarUrl = StringUtils.RemoveDomain(userDto.AvatarUrl);
  109. adminVerify.Name = userDto.Name;
  110. adminVerify.DisposeType = AdminVerifyTypeConst.UDispose.GetHashCode();
  111. adminVerify.VerifyType = request.VerifyType;
  112. adminVerify.AdminId = userId;
  113. adminVerify.SourceType = request.SourceType;
  114. adminVerify.SourceId = request.SourceId;
  115. adminVerify.UserId = request.UserId;
  116. adminVerify.SourceName = group.Name;
  117. adminVerify.IsDelete = "";
  118. //获取部门
  119. adminVerify.Remark = department.Name + "-" + userDto.Name;
  120. adminVerifys.Add(adminVerify);
  121. }
  122. }
  123. await _adminVerifyRepository.InsertAsync(adminVerifys);
  124. return true;
  125. }
  126. /// <summary>
  127. /// 设置用户通知验证
  128. /// </summary>
  129. /// <param name="userId"></param>
  130. /// <returns></returns>
  131. private async Task InsertMiddleVerify(int userId)
  132. {
  133. var middle = await _middleRepository.GetMiddleAsync(Q
  134. .Where(nameof(Entity.Middle.Middle.AttributeValue), 3)
  135. .Where(nameof(Entity.Middle.Middle.UserId), userId));
  136. if (middle == null)
  137. {
  138. //添加验证信息
  139. var middleInsertTypeRequest = new MiddleInsertTypeRequest
  140. {
  141. AttributeValue = 3,
  142. FolderId = 0,
  143. FolderType = 1,
  144. MiddleId = 0,
  145. MiddleSonId = 0,
  146. UserId = userId
  147. };
  148. await _middleService.InsertAsync(middleInsertTypeRequest);
  149. }
  150. else if (middle.IsDelete)
  151. {
  152. middle.IsDelete = false;
  153. await _middleRepository.UpdateAsync(middle);
  154. }
  155. }
  156. }
  157. }