dss 2 anni fa
parent
commit
2d5f51a679

+ 1 - 1
src/CallCenter/Caches/IUserCacheManager.cs

@@ -52,7 +52,7 @@ namespace CallCenter.Caches
         /// <returns></returns>
         List<Work> GetWorks();
 
-        void AddOrUpdateWorksCache(List<Work> list);
+        void AddWorksCache(Work work);
 
         void RemoveCallCache(string id);
     }

+ 10 - 4
src/CallCenter/Caches/UserCacheManager.cs

@@ -63,7 +63,7 @@ public class UserCacheManager : IUserCacheManager, IScopeDependency
     /// 查询所有在工作的记录
     /// </summary>
     /// <returns></returns>
-    public List<Work> GetWorks()
+    public List<Work>? GetWorks()
     {
         var works = _cacheWorks.GetOrAdd(WorkKey, k =>
         {
@@ -73,9 +73,15 @@ public class UserCacheManager : IUserCacheManager, IScopeDependency
         return works;
     }
 
-    public void AddOrUpdateWorksCache(List<Work> list)
+    public void AddWorksCache(Work work)
     {
-        _cacheWorks.AddOrUpdate(WorkKey, list);
+        var list = GetWorks();
+        if (list == null)
+        {
+            list = new List<Work>();
+        }
+        list.Add(work);
+        _cacheWorks.Add(WorkKey, list);
     }
 
 
@@ -88,7 +94,7 @@ public class UserCacheManager : IUserCacheManager, IScopeDependency
             if (model!=null)
             {
                 list.Remove(model);
-                AddOrUpdateWorksCache(list);
+                _cacheWorks.AddOrUpdate(WorkKey, list);
             }
         }
     }

+ 7 - 1
src/CallCenter/Users/UserDomainService.cs

@@ -60,6 +60,9 @@ namespace CallCenter.Users
 
             var work = new Work(userId, user.Name, tel.Id, tel.No);
             await _workRepository.AddAsync(work, cancellationToken);
+
+            //更新work缓存
+            _userCacheManager.AddWorksCache(work);
             //_userCacheManager.RemoveCallCache(work.Id);
             if (!string.IsNullOrEmpty(user.StaffNo))
                 await _deviceManager.UpdateStaffNoAsync(tel.No, user.StaffNo, tel.LineId, cancellationToken);
@@ -86,7 +89,10 @@ namespace CallCenter.Users
             await _deviceManager.UpdateStaffNoAsync(work.TelNo, string.Empty, tel.LineId, cancellationToken);
             _cacheWork.Remove(work.GetKey(KeyMode.UserId));
             _cacheWork.Remove(work.GetKey(KeyMode.TelNo));
-            //_userCacheManager.RemoveCallCache(work.Id);
+
+            //更新work缓存
+            _userCacheManager.RemoveCallCache(work.Id);
+
             //foreach (var group in tel.Groups)
             //{
             //    await _deviceManager.ModifyGroupExtAsync(group.No, tel.No, group.Voice, false, cancellationToken);