Browse Source

Merge branch 'feature/task_245_rest' into dev

qinchaoyue 2 months ago
parent
commit
0929eee7e9

+ 9 - 7
src/Hotline.Api/config/appsettings.Development.json

@@ -67,9 +67,10 @@
         //"DbConnectionString": "PORT=50143;server=110.188.24.182;Database=callcenter_db;Uid=dev;Pwd=fengwo123!@#;"
     }
   },
-  "ConnectionStrings": {
-    "Hotline": "PORT=5432;DATABASE=hotline_dev;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;"
-  },
+    "ConnectionStrings": {
+        "Hotline": "PORT=5432;DATABASE=hotline_dev;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;",
+        "CAP": "PORT=5432;DATABASE=fwmq;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;Search Path=cap"
+    },
   "Cache": {
     "Host": "110.188.24.182",
     "Port": 50179,
@@ -117,10 +118,11 @@
     "DbConnectionString": "PORT=5432;DATABASE=fwmq;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;",
     "UseDashBoard": true,
     "RabbitMq": {
-      "UserName": "dev",
-      "Password": "123456",
-      "HostName": "110.188.24.182",
-      "VirtualHost": "fwt-master"
+        "UserName": "dev",
+        "Password": "123456",
+        "HostName": "110.188.24.182",
+        // "VirtualHost": "fwt-master"
+        "VirtualHost": "fwt-unittest"
     }
   },
   "FwClient": {

+ 2 - 1
src/Hotline.Application/Orders/OrderApplication.cs

@@ -3594,6 +3594,7 @@ public class OrderApplication : IOrderApplication, IScopeDependency
             OrgId = startStep.HandlerOrgId,
             OrgName = startStep.HandlerOrgName,
         };
+        _sessionContext.ChangeSession(startStep.HandlerId);
         var isAutoFillSummaryOpinion = bool.Parse(_systemSettingCacheManager
             .GetSetting(SettingConstants.IsAutoFillSummaryOpinion).SettingValue[0]);
 
@@ -4810,4 +4811,4 @@ public class OrderApplication : IOrderApplication, IScopeDependency
 
         return query;
     }
-}
+}

+ 12 - 7
src/Hotline/Authentications/ChangeSessionProvider.cs

@@ -18,19 +18,23 @@ using XF.Domain.Repository;
 namespace Hotline.Authentications;
 public class ChangeSessionProvider : IChangeSessionProvider, IScopeDependency
 {
-    private readonly IHttpContextAccessor _contextAccessor;
+    private readonly IServiceProvider _serviceProvider;
 
-    public ChangeSessionProvider(IHttpContextAccessor contextAccessor)
+    public ChangeSessionProvider(IServiceProvider serviceProvider)
     {
-        _contextAccessor = contextAccessor;
+        _serviceProvider = serviceProvider;
     }
 
-    public void ChangeSessionByUserId(string id, HttpContext httpContext)
+    public HttpContext ChangeSessionByUserId(string id, HttpContext httpContext)
     {
-        var userRepository = _contextAccessor.HttpContext.RequestServices.GetService<IRepository<User>>();
-        var accountRepository = _contextAccessor.HttpContext.RequestServices.GetService<IAccountRepository>();
+        if (httpContext == null) 
+        {
+            httpContext = new DefaultHttpContext();
+        }
+        var userRepository = _serviceProvider.GetService<IRepository<User>>();
+        var accountRepository = _serviceProvider.GetService<IAccountRepository>();
         var user = userRepository.Queryable().Where(m => m.Id == id).First();
-        if (user == null) return;
+        if (user == null) return null;
         var account = accountRepository.GetExtAsync(m => m.Id == user.Id, m => m.Includes(x => x.Roles)).GetAwaiter().GetResult();
 
         List<Claim> userClaims = [
@@ -48,5 +52,6 @@ public class ChangeSessionProvider : IChangeSessionProvider, IScopeDependency
             ];
         userClaims.AddRange(account.Roles.Select(d => new Claim(JwtClaimTypes.Role, d.Name)));
         httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(userClaims));
+        return httpContext;
     }
 }

+ 9 - 3
src/XF.Domain/Authentications/DefaultSessionContext.cs

@@ -10,13 +10,14 @@ namespace XF.Domain.Authentications
 {
     public class DefaultSessionContext : ISessionContext, IScopeDependency
     {
-        private readonly HttpContext _context;
+        private HttpContext _context;
         private readonly IChangeSessionProvider _changeSessionProvider;
-        public DefaultSessionContext(IHttpContextAccessor httpContextAccessor)
+        private readonly IServiceProvider _serviceProvider;
+        public DefaultSessionContext(IHttpContextAccessor httpContextAccessor, IServiceProvider serviceProvider)
         {
+            _serviceProvider = serviceProvider;
             var httpContext = httpContextAccessor.HttpContext;
             if (httpContext is null)
-                //throw new ArgumentNullException(nameof(httpContext));
                 return;
 
             _context = httpContext;
@@ -76,6 +77,11 @@ namespace XF.Domain.Authentications
 
         public void ChangeSession(string id)
         {
+            if (_changeSessionProvider == null)
+            {
+                _context = _serviceProvider.GetService<IChangeSessionProvider>().ChangeSessionByUserId(id, _context);
+                return;
+            }
             _changeSessionProvider.ChangeSessionByUserId(id, _context);
         }
     }

+ 1 - 1
src/XF.Domain/Authentications/IChangeSessionProvider.cs

@@ -8,5 +8,5 @@ using System.Threading.Tasks;
 namespace XF.Domain.Authentications;
 public interface IChangeSessionProvider
 {
-    void ChangeSessionByUserId(string id, HttpContext httpContext);
+    HttpContext ChangeSessionByUserId(string id, HttpContext httpContext);
 }

+ 1 - 1
test/Hotline.Tests/Application/OrderSnapshotApplicationTest.cs

@@ -66,7 +66,7 @@ public class OrderSnapshotApplicationTest : TestBase
             .办理到网格员(SetZuoXi)
             .StepHandle(async order =>
             {
-                Thread.Sleep(30 * 1000);
+                Thread.Sleep(5 * 1000);
             }
             ).GetCreateResult();
         order.Id.ShouldNotBeNull();

+ 9 - 5
test/Hotline.Tests/Controller/TestSessionContext.cs

@@ -1,7 +1,9 @@
 using System.Security.Authentication;
 using System.Security.Claims;
+using Hotline.Authentications;
 using IdentityModel;
 using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
 using XF.Domain.Authentications;
 using XF.Domain.Dependency;
 
@@ -9,18 +11,20 @@ namespace Hotline.Tests.Controller;
 public class TestSessionContext : ISessionContext, IScopeDependency
 {
     private readonly IHttpContextAccessor _contextAccessor;
+    private readonly IChangeSessionProvider _changeSessionProvider;
     public TestSessionContext(IHttpContextAccessor httpContextAccessor)
     {
         _contextAccessor = httpContextAccessor;
-        //Roles = user.Claims.Where(d => d.Type == JwtClaimTypes.Role).Select(d => d.Value).ToArray();
+        if (httpContextAccessor.HttpContext == null) return;
+        if (_contextAccessor.HttpContext.Items.Any(m => m.Key == nameof(DefaultSessionContext))) return;
+        _contextAccessor.HttpContext.Items.Add(nameof(DefaultSessionContext), nameof(IChangeSessionProvider));
+        _changeSessionProvider = httpContextAccessor.HttpContext.RequestServices.GetService<IChangeSessionProvider>();
     }
-    private HttpContext _content = new DefaultHttpContext();
 
-    private HttpContext GetContext()
+    public void ChangeSession(string id)
     {
-        return _contextAccessor.HttpContext;
+        _changeSessionProvider.ChangeSessionByUserId(id, _contextAccessor.HttpContext);
     }
-    public HttpContext? HttpContext { get => GetContext(); set => _content = value; }
 
     public string? OpenId { get { return _contextAccessor.HttpContext.User.FindFirstValue(AppClaimTypes.OpenId); } init { } }
 

+ 9 - 0
test/Hotline.Tests/Domain/OrderVisitDomainServiceTest.cs

@@ -285,6 +285,15 @@ public class OrderVisitDomainServiceTest : TestBase
             new () {Name = "默认满意的规则", AppScope = "YiBin", ReplyRegular = "默认满意", VisitContent = "超过48小时自动回访", VisitState = EVisitState.Visited, SeatEvaluate = null,VoiceEvaluate = null,OrgProcessingResults=0, OrgHandledAttitude = 0 , VisitType = EVisitType.SmsVisit, SortOrder = 0},
             new () {Name = "对部门处理结果不满意的规则", AppScope = "YiBin", ReplyRegular = "2", VisitContent = "不满意", VisitState = EVisitState.SMSUnsatisfied, SeatEvaluate = null,VoiceEvaluate = null,OrgProcessingResults=2, OrgHandledAttitude = null , VisitType = null, SortOrder = 2},
             new () {Name = "用户回复的非1和2的规则", AppScope = "YiBin", ReplyRegular = "^(?!.*[12]).*$", VisitContent = "不满意", VisitState = EVisitState.SMSUnsatisfied, SeatEvaluate = null,VoiceEvaluate = null,OrgProcessingResults= null, OrgHandledAttitude = null , VisitType = null, SortOrder = 3, IsReplyToOrgVisitContent = true},
+
+            new () {Name = "非常满意的规则", AppScope = "LuZhou", ReplyRegular = "1", VisitContent = "非常满意", VisitState = EVisitState.Visited, SeatEvaluate = null,VoiceEvaluate = null,OrgProcessingResults=5, OrgHandledAttitude = 0, VisitType = EVisitType.SmsVisit, SortOrder = 1},
+            new () {Name = "满意的规则", AppScope = "LuZhou", ReplyRegular = "2", VisitContent = "满意", VisitState = EVisitState.Visited, SeatEvaluate = null,VoiceEvaluate = null,OrgProcessingResults=4, OrgHandledAttitude = 0 , VisitType = EVisitType.SmsVisit, SortOrder = 2},
+            new () {Name = "一般的规则", AppScope = "LuZhou", ReplyRegular = "3", VisitContent = "一般", VisitState = EVisitState.Visited, SeatEvaluate = null, VoiceEvaluate = null,OrgProcessingResults= 4, OrgHandledAttitude = 0 , VisitType = EVisitType.SmsVisit, SortOrder = 3},
+            new () {Name = "不满意的规则", AppScope = "LuZhou", ReplyRegular = "4", VisitContent = "不满意", VisitState = EVisitState.SMSUnsatisfied, SeatEvaluate = null,VoiceEvaluate = null,OrgProcessingResults=2, OrgHandledAttitude = 0 , VisitType = null, SortOrder = 4},
+            new () {Name = "非常不满意的规则", AppScope = "LuZhou", ReplyRegular = "5", VisitContent = "不满意", VisitState = EVisitState.SMSUnsatisfied, SeatEvaluate = null, VoiceEvaluate = null,OrgProcessingResults=2, OrgHandledAttitude = 0, VisitType = null, SortOrder = 5},
+            new () {Name = "默认满意的规则", AppScope = "LuZhou", ReplyRegular = "默认满意", VisitContent = "超过48小时自动回访", VisitState = EVisitState.Visited, SeatEvaluate = null, VoiceEvaluate = null,OrgProcessingResults=0, OrgHandledAttitude = 0, VisitType = EVisitType.SmsVisit, SortOrder = 0},
+            new () {Name = "用户回答非1,2,3,4,5的匹配规则", AppScope = "LuZhou", ReplyRegular = "^(?!.*[12345]).*$", VisitContent = "默认满意", VisitState = EVisitState.Visited, SeatEvaluate = null, VoiceEvaluate = null,OrgProcessingResults=0, OrgHandledAttitude = 0, VisitType = EVisitType.SmsVisit, SortOrder = 6},
+
             ];
 
         foreach (var item in entities)