xf 9 kuukautta sitten
vanhempi
commit
c2bf6edbbc

+ 1 - 1
src/Hotline/Caching/Services/UserCacheManager.cs

@@ -160,7 +160,7 @@ public class UserCacheManager : IUserCacheManager, IScopeDependency
     /// <returns></returns>
     public List<Work>? GetWorks()
     {
-        var works = _cacheWork.GetListByPrefix().ToList();
+        var works = _cacheWork.GetListByPrefix(Work.GetKeyPrefix(KeyMode.TelNo)).ToList();
         return works;
     }
 

+ 15 - 6
src/Hotline/Users/Work.cs

@@ -1,5 +1,6 @@
 using System.ComponentModel;
 using Hotline.Share.Enums.CallCenter;
+using Microsoft.EntityFrameworkCore.Metadata.Internal;
 using SqlSugar;
 using XF.Domain.Entities;
 using XF.Domain.Repository;
@@ -50,7 +51,7 @@ public class Work : CreationModificationEntity
 
     public string? StaffNo { get; set; }
 
-    public ETelModel? TelModel {get;set;}
+    public ETelModel? TelModel { get; set; }
 
     ///// <summary>
     ///// SignalR.ConnectionId
@@ -63,7 +64,7 @@ public class Work : CreationModificationEntity
 
     }
 
-    public Work(string userId, string name, string telId, string telNo, string? telPwd, string? description, string? queueId,string? staffNo, ETelModel? telModel)
+    public Work(string userId, string name, string telId, string telNo, string? telPwd, string? description, string? queueId, string? staffNo, ETelModel? telModel)
     {
         StartTime = DateTime.Now;
         UserId = userId;
@@ -97,8 +98,8 @@ public class Work : CreationModificationEntity
 
     public string GetKey(KeyMode keyMode) => keyMode switch
     {
-        KeyMode.UserId => $"WorkUserId-{UserId}",
-        KeyMode.TelNo => $"WorkTelNo-{TelNo}",
+        KeyMode.UserId => $"{GetKeyPrefix(KeyMode.UserId)}{UserId}",
+        KeyMode.TelNo => $"{GetKeyPrefix(KeyMode.TelNo)}{TelNo}",
         _ => throw new ArgumentOutOfRangeException(nameof(keyMode), keyMode, null)
     };
 
@@ -112,8 +113,16 @@ public class Work : CreationModificationEntity
     public static string GetKey(KeyMode keyMode, string? key) =>
     keyMode switch
     {
-        KeyMode.UserId => $"WorkUserId-{key}",
-        KeyMode.TelNo => $"WorkTelNo-{key}",
+        KeyMode.UserId => $"{GetKeyPrefix(KeyMode.UserId)}{key}",
+        KeyMode.TelNo => $"{GetKeyPrefix(KeyMode.TelNo)}{key}",
+        _ => throw new ArgumentOutOfRangeException(nameof(keyMode), keyMode, null)
+    };
+
+    public static string GetKeyPrefix(KeyMode keyMode) =>
+    keyMode switch
+    {
+        KeyMode.UserId => $"WorkUserId-",
+        KeyMode.TelNo => $"WorkTelNo-",
         _ => throw new ArgumentOutOfRangeException(nameof(keyMode), keyMode, null)
     };
 }

+ 1 - 1
src/XF.Domain/Cache/ITypedCache.cs

@@ -45,7 +45,7 @@ GetExpiration/GetExpirationAsync
         IDictionary<string, TValue> GetByPrefix();
         Task<IDictionary<string, TValue>> GetByPrefixAsync(CancellationToken cancellationToken);
 
-        IReadOnlyList<TValue> GetListByPrefix();
+        IReadOnlyList<TValue> GetListByPrefix(string? prefix = null);
         Task<IReadOnlyList<TValue>> GetListByPrefixAsync(CancellationToken cancellationToken);
 
         //void RemoveByPrefix(string prefix);

+ 2 - 2
src/XF.EasyCaching/DefaultTypedCache.cs

@@ -89,9 +89,9 @@ namespace XF.EasyCaching
             return cacheValueDic.ToDictionary(cacheValue => cacheValue.Key, cacheValue => cacheValue.Value.Value);
         }
 
-        public IReadOnlyList<TValue> GetListByPrefix()
+        public IReadOnlyList<TValue> GetListByPrefix(string? prefix = null)
         {
-            var cacheValueDic = _caching.GetByPrefix<TValue>(CreateRegion());
+            var cacheValueDic = _caching.GetByPrefix<TValue>(CreateRegion() + prefix);
             if (cacheValueDic == null) return new List<TValue>();
             return cacheValueDic.Values.Select(d => d.Value).ToList();
         }