AdminVerifyInsetService.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. //获取小组
  57. var group = await _groupRepository.GetAsync(request.SourceId);
  58. var ids = new List<int> { GroupUserRoleTyeConst.Admin.GetHashCode(), GroupUserRoleTyeConst.SuperAdmin.GetHashCode() };
  59. //创建人
  60. var groupUsers = await _groupUserRepository.GetAllAsync(Q.Where(nameof(GroupUser.GroupId), group.Id).WhereIn(nameof(GroupUser.GroupUserRoleId), ids));
  61. foreach (var userId in request.UserIds)
  62. {
  63. var adminVerify = new Entity.AdminVerify();
  64. var adminVerifyDto = new Entity.AdminVerify();
  65. //获取用户
  66. var user = users.FirstOrDefault(n => n.Id == userId);
  67. if (user == null)
  68. continue;
  69. var department = new Entity.Department();
  70. if (departmentUsers.FirstOrDefault(n => n.UserId == user.Id) != null)
  71. {
  72. department = departments.FirstOrDefault(m => m.Id == departmentUsers.FirstOrDefault(n => n.UserId == user.Id).DepartmentId);
  73. }
  74. var query = Q.NewQuery();
  75. query.Where(nameof(Entity.AdminVerify.AdminId), userId);
  76. query.Where(nameof(Entity.AdminVerify.SourceType), request.SourceType);
  77. query.Where(nameof(Entity.AdminVerify.SourceId), group.Id);
  78. query.WhereIn(nameof(Entity.AdminVerify.DisposeType), new List<int> { 0, 1 });
  79. //查询是否存在
  80. adminVerify = await _adminVerifyRepository.GetAsync(query);
  81. if (adminVerify != null)
  82. continue;
  83. adminVerify = new Entity.AdminVerify();
  84. //申请
  85. if (request.SourceType == 1)
  86. {
  87. foreach (var groupUser in groupUsers)
  88. {
  89. //设置群主验证
  90. //await InsertMiddleVerify(groupUser.UserId);
  91. adminVerifyDto.AvatarUrl = StringUtils.RemoveDomain(user.AvatarUrl);
  92. adminVerifyDto.SourceName = group.Name;
  93. adminVerifyDto.Name = user.Name;
  94. adminVerifyDto.DisposeType = AdminVerifyTypeConst.UDispose.GetHashCode();
  95. adminVerifyDto.VerifyType = request.VerifyType;
  96. adminVerifyDto.AdminId = groupUser.UserId;
  97. adminVerifyDto.SourceType = request.SourceType;
  98. adminVerifyDto.SourceId = request.SourceId;
  99. adminVerifyDto.UserId = userId;
  100. adminVerifyDto.IsDelete = "";
  101. //获取部门
  102. adminVerifyDto.Remark = department.Name + "-" + user.Name;
  103. adminVerifyDto.Remark = request.Remark;
  104. //await _adminVerifyRepository.InsertAsync(adminVerifyDto);
  105. adminVerifys.Add(adminVerifyDto);
  106. }
  107. }
  108. //邀请
  109. if (request.SourceType == 2)
  110. {
  111. //await _adminVerifyRepository.InsertAsync(adminVerifyDto);
  112. adminVerifys.Add(adminVerifyDto);
  113. adminVerify.AvatarUrl = StringUtils.RemoveDomain(userDto.AvatarUrl);
  114. adminVerify.Name = userDto.Name;
  115. adminVerify.DisposeType = AdminVerifyTypeConst.UDispose.GetHashCode();
  116. adminVerify.VerifyType = request.VerifyType;
  117. adminVerify.AdminId = userId;
  118. adminVerify.SourceType = request.SourceType;
  119. adminVerify.SourceId = request.SourceId;
  120. adminVerify.UserId = request.UserId;
  121. adminVerify.SourceName = group.Name;
  122. adminVerify.IsDelete = "";
  123. //获取部门
  124. adminVerify.Remark = department.Name + "-" + userDto.Name;
  125. //await _adminVerifyRepository.InsertAsync(adminVerify);
  126. adminVerifys.Add(adminVerify);
  127. //await InsertMiddleVerify(userId);
  128. }
  129. }
  130. await _adminVerifyRepository.InsertAsync(adminVerifys);
  131. return true;
  132. }
  133. /// <summary>
  134. /// 设置用户通知验证
  135. /// </summary>
  136. /// <param name="userId"></param>
  137. /// <returns></returns>
  138. private async Task InsertMiddleVerify(int userId)
  139. {
  140. var middle = await _middleRepository.GetMiddleAsync(Q
  141. .Where(nameof(Entity.Middle.Middle.AttributeValue), 3)
  142. .Where(nameof(Entity.Middle.Middle.UserId), userId));
  143. if (middle == null)
  144. {
  145. //添加验证信息
  146. var middleInsertTypeRequest = new MiddleInsertTypeRequest
  147. {
  148. AttributeValue = 3,
  149. FolderId = 0,
  150. FolderType = 1,
  151. MiddleId = 0,
  152. MiddleSonId = 0,
  153. UserId = userId
  154. };
  155. await _middleService.InsertAsync(middleInsertTypeRequest);
  156. }
  157. else if (middle.IsDelete)
  158. {
  159. middle.IsDelete = false;
  160. await _middleRepository.UpdateAsync(middle);
  161. }
  162. }
  163. }
  164. }