lihao лет назад: 4
Родитель
Сommit
b89d4684da

+ 2 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/OftenContactRepository.cs

@@ -281,7 +281,7 @@ namespace GxPress.Repository.Implement
         {
             return await _repository.GetAllAsync<int>(Q.Select(nameof(OftenContact.ContactUserId)).Where(nameof(OftenContact.UserId), userId).Where(nameof(OftenContact.ChatType), 1));
         }
-        public async Task<IEnumerable<OftenContactInfo>> GetContactInfosAsync(OftenContactSearchRequest request)
+        public async Task<List<OftenContactInfo>> GetContactInfosAsync(OftenContactSearchRequest request)
         {
             var sql =
                $"select a.*,b.* from tede_middle a left join tede_often_contact b on a.MiddleId=b.Id where a.FolderType=10 and a.UserId={request.UserId} and a.ParentId={request.IndividualGroupId} and a.IsDelete=0 order by a. IsTop desc,a.LastModifiedDate desc";
@@ -297,7 +297,7 @@ namespace GxPress.Repository.Implement
                             oftenContactInfo.ContactUserId = oftenContact == null ? "" : oftenContact.ContactUserId;
                             return oftenContactInfo;
                         }, splitOn: "Id,Id");
-            return result;
+            return result.ToList();
         }
 
         public async Task<IEnumerable<OftenContactInfo>> GetContactInfoAllAsync(OftenContactSearchRequest request)

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/IOftenContactRepository.cs

@@ -79,7 +79,7 @@ namespace GxPress.Repository.Interface
 
         Task<int> InsertAsync(Entity.OftenContact oftenContact);
 
-        Task<IEnumerable<OftenContactInfo>> GetContactInfosAsync(OftenContactSearchRequest request);
+        Task<List<OftenContactInfo>> GetContactInfosAsync(OftenContactSearchRequest request);
         Task<Entity.OftenContact> GetAsync(SqlKata.Query query);
         Task<IEnumerable<Entity.OftenContact>> GetAllAsync(SqlKata.Query query);
         /// <summary>

+ 21 - 14
gx_api/GxPress/Service/GxPress.Service.Implement/OftenContact/OftenContactService.Get.cs

@@ -22,32 +22,39 @@ namespace GxPress.Service.Implement.OftenContact
             //获取文件夹数据
             var result = new List<OftenContactInfo>();
             var data = await _repository.GetContactInfosAsync(request);
-            foreach (var oftenContact in data)
+
+            for (int i = 0; i < data.Count; i++)
             {
-                if (oftenContact.ChatType == 1)
+                if (data[i].ChatType == 1)
                 {
-                    var user = await _userRepository.GetAsync(int.Parse(oftenContact.ContactUserId));
+                    var user = await _userRepository.GetAsync(int.Parse(data[i].ContactUserId));
                     if (user == null)
+                    {
+                        data.Remove(data[i]);
                         continue;
-                    oftenContact.Name = user.Name;
-                    oftenContact.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
-                    oftenContact.ImId = user.ImId;
-                    oftenContact.ToUserId = user.Id;
+                    }
+                    data[i].Name = user.Name;
+                    data[i].AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
+                    data[i].ImId = user.ImId;
+                    data[i].ToUserId = user.Id;
                 }
 
-                if (oftenContact.ChatType == 2)
+                if (data[i].ChatType == 2)
                 {
                     var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
-                        oftenContact.ContactUserId));
+                        data[i].ContactUserId));
                     if (groupChat == null)
+                    {
+                        data.Remove(data[i]);
                         continue;
-                    oftenContact.Name = groupChat.Name;
-                    oftenContact.AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
-                    oftenContact.ImId = groupChat.GroupChatImId;
+                    }
+                    data[i].Name = groupChat.Name;
+                    data[i].AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
+                    data[i].ImId = groupChat.GroupChatImId;
                     var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
                     groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
-                    groupChatUserIsDisturbRequest.UserId = oftenContact.UserId;
-                    oftenContact.IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
+                    groupChatUserIsDisturbRequest.UserId = data[i].UserId;
+                    data[i].IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
                 }
             }
             result = data.ToList();