AdminVerifyInsetService.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. namespace GxPress.Service.Implement.AdminVerify
  16. {
  17. public class AdminVerifyInsetService : IAdminVerifyInsertService
  18. {
  19. private readonly IAdminVerifyRepository _adminVerifyRepository;
  20. private readonly IUserRepository _userRepository;
  21. private readonly IDepartmentRepository _departmentRepository;
  22. private readonly IMiddleService _middleService;
  23. private readonly IGroupRepository _groupRepository;
  24. private readonly IGroupChatRepository _groupChatRepository;
  25. private readonly IMiddleRepository _middleRepository;
  26. private readonly IGroupUserRepository _groupUserRepository;
  27. private readonly IDepartmentUserRepository departmentUserRepository;
  28. public AdminVerifyInsetService(IAdminVerifyRepository adminVerifyRepository, IUserRepository userRepository,
  29. IDepartmentRepository departmentRepository, IMiddleService middleService, IGroupRepository groupRepository,
  30. IGroupChatRepository groupChatRepository, IMiddleRepository middleRepository, IGroupUserRepository groupUserRepository, IDepartmentUserRepository departmentUserRepository)
  31. {
  32. _adminVerifyRepository = adminVerifyRepository;
  33. _userRepository = userRepository;
  34. _departmentRepository = departmentRepository;
  35. _groupRepository = groupRepository;
  36. _middleService = middleService;
  37. _groupChatRepository = groupChatRepository;
  38. _middleRepository = middleRepository;
  39. _groupUserRepository = groupUserRepository;
  40. this.departmentUserRepository = departmentUserRepository;
  41. }
  42. /// <summary>
  43. /// 添加成员
  44. /// </summary>
  45. /// <param name="request"></param>
  46. /// <returns></returns>
  47. public async Task<bool> InsertAsync(AdminVerifyInsertRequest request)
  48. {
  49. var adminVerifys = new List<Entity.AdminVerify>();
  50. //获取邀请人信息
  51. var userDto = await _userRepository.GetAsync(request.UserId);
  52. //获取员工所有信息
  53. var users = await _userRepository.GetAllAsync(Q.WhereIn(nameof(Entity.User.Id), request.UserIds));
  54. var departmentUsers = await departmentUserRepository.GetDepartmentUsersByUserIdsAsync(request.UserIds);
  55. var departments = await _departmentRepository.GetAllAsync(Q.WhereIn(nameof(Entity.Department.Id), departmentUsers.Select(n => n.DepartmentId)));
  56. foreach (var userId in request.UserIds)
  57. {
  58. var adminVerify = new Entity.AdminVerify();
  59. var adminVerifyDto = new Entity.AdminVerify();
  60. //获取用户
  61. var user = users.FirstOrDefault(n => n.Id == userId);
  62. if (user == null)
  63. continue;
  64. var department = new Entity.Department();
  65. if (departmentUsers.FirstOrDefault(n => n.UserId == user.Id) != null)
  66. {
  67. department = departments.FirstOrDefault(m => m.Id == departmentUsers.FirstOrDefault(n => n.UserId == user.Id).DepartmentId);
  68. }
  69. var group = await _groupRepository.GetAsync(request.SourceId);
  70. //查询是否存在
  71. adminVerify = await _adminVerifyRepository.GetAsync(Q.Where(nameof(Entity.AdminVerify.AdminId), userId).Where(nameof(Entity.AdminVerify.SourceType), request.SourceType).Where(nameof(Entity.AdminVerify.SourceId), group.Id).WhereIn(nameof(Entity.AdminVerify.DisposeType), new List<int> { 0, 1 }));
  72. if (adminVerify != null)
  73. continue;
  74. adminVerify = new Entity.AdminVerify();
  75. //申请
  76. if (request.SourceType == 1)
  77. {
  78. var ids = new List<int> { GroupUserRoleTyeConst.Admin.GetHashCode(), GroupUserRoleTyeConst.SuperAdmin.GetHashCode() };
  79. //创建人
  80. var groupUsers = await _groupUserRepository.GetAllAsync(Q.Where(nameof(GroupUser.GroupId), group.Id).WhereIn(nameof(GroupUser.GroupUserRoleId), ids));
  81. foreach (var groupUser in groupUsers)
  82. {
  83. //设置群主验证
  84. await InsertMiddleVerify(groupUser.UserId);
  85. adminVerifyDto.AvatarUrl = StringUtils.RemoveDomain(user.AvatarUrl);
  86. adminVerifyDto.SourceName = group.Name;
  87. adminVerifyDto.Name = user.Name;
  88. adminVerifyDto.DisposeType = AdminVerifyTypeConst.UDispose.GetHashCode();
  89. adminVerifyDto.VerifyType = request.VerifyType;
  90. adminVerifyDto.AdminId = groupUser.UserId;
  91. adminVerifyDto.SourceType = request.SourceType;
  92. adminVerifyDto.SourceId = request.SourceId;
  93. adminVerifyDto.UserId = userId;
  94. adminVerifyDto.IsDelete = "";
  95. //获取部门
  96. adminVerifyDto.Remark = department.Name + "-" + user.Name;
  97. //await _adminVerifyRepository.InsertAsync(adminVerifyDto);
  98. adminVerifys.Add(adminVerifyDto);
  99. }
  100. }
  101. //邀请
  102. if (request.SourceType == 2)
  103. {
  104. //await _adminVerifyRepository.InsertAsync(adminVerifyDto);
  105. adminVerifys.Add(adminVerifyDto);
  106. adminVerify.AvatarUrl = StringUtils.RemoveDomain(userDto.AvatarUrl);
  107. adminVerify.Name = userDto.Name;
  108. adminVerify.DisposeType = AdminVerifyTypeConst.UDispose.GetHashCode();
  109. adminVerify.VerifyType = request.VerifyType;
  110. adminVerify.AdminId = userId;
  111. adminVerify.SourceType = request.SourceType;
  112. adminVerify.SourceId = request.SourceId;
  113. adminVerify.UserId = request.UserId;
  114. adminVerify.SourceName = group.Name;
  115. adminVerify.IsDelete = "";
  116. //获取部门
  117. adminVerify.Remark = department.Name + "-" + userDto.Name;
  118. //await _adminVerifyRepository.InsertAsync(adminVerify);
  119. adminVerifys.Add(adminVerify);
  120. await InsertMiddleVerify(userId);
  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. }