Sfoglia il codice sorgente

Merge branch 'test' of http://git.12345lm.cn/Fengwo/hotline into test

Dun.Jason 5 mesi fa
parent
commit
6a468b27f6

+ 0 - 9
src/Hotline.Application.Tests/Controller/OrderControllerTest.cs

@@ -74,15 +74,6 @@ public class OrderControllerTest : TestBase
             .办理到派单员()
             .办理到归档(SetPaiDanYuan)
             .GetCreateResult();
-        await _orderPublishEndWorkflowHandler.Handle(new EndWorkflowNotify(
-        new Hotline.FlowEngine.Workflows.Workflow
-        {
-            ModuleCode = WorkflowModuleConsts.OrderHandle,
-            ExternalId = order.Id
-        },
-        new Hotline.FlowEngine.Workflows.WorkflowTrace(),
-             new Share.Dtos.FlowEngine.BasicWorkflowDto()
-        ), new CancellationToken());
         var publish = await _orderPublishRepository.GetAsync(m => m.No == order.No);
         publish.ShouldNotBeNull(order.No);
     }

+ 20 - 0
src/Hotline.Application.Tests/Startup.cs

@@ -39,6 +39,7 @@ using Hotline.Application.Tests.Controller;
 using Hotline.Application.Tests.Infrastructure;
 using Hotline.Authentications;
 using Hotline.FlowEngine.Notifications;
+using Hotline.Application.Handlers.FlowEngine;
 
 namespace Hotline.Application.Tests;
 public class Startup
@@ -118,6 +119,7 @@ public class Startup
                         callCenterConfiguration.TianRun.Username,
                         callCenterConfiguration.TianRun.Password);
             services.RegisterMediatR(appConfiguration);
+            services.RegisterSignalR(configuration);
 
             // services.AddSenparcWeixinServices(configuration);
             AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(d => d.GetTypes())
@@ -182,6 +184,24 @@ public static class StartupHelper
         return services;
     }
 
+    /// <summary>
+    /// SignalR
+    /// </summary>
+    /// <param name="services"></param>
+    /// <param name="configuration"></param>
+    /// <returns></returns>
+    public static IServiceCollection RegisterSignalR(this IServiceCollection services, IConfiguration configuration)
+    {
+        var cacheConfig = configuration.GetRequiredSection("Cache").Get<CacheOptions>();
+        services.AddSignalR().AddStackExchangeRedis($"{cacheConfig.Host}:{cacheConfig.Port}", options =>
+        {
+            options.Configuration.ChannelPrefix = "Hotline:signalr:";
+            options.Configuration.Password = cacheConfig.Password;
+            options.Configuration.DefaultDatabase = cacheConfig.Database;
+        });
+        return services;
+    }
+
     public static IServiceCollection AddTestMq(this IServiceCollection services, IConfiguration configuration)
     {
         MqConfiguration mqConfiguration = configuration.GetSection("MqConfiguration").Get<MqConfiguration>();

+ 16 - 5
src/Hotline.Application/ExportWord/WordHelper.cs

@@ -1,6 +1,7 @@
 using DocumentFormat.OpenXml.Packaging;
 using DocumentFormat.OpenXml.Wordprocessing;
 using Hotline.Share.Dtos.ExportWord;
+using Hotline.Share.Tools;
 using HtmlToOpenXml;
 using OpenHtmlToPdf;
 
@@ -30,14 +31,24 @@ namespace Hotline.Application.ExportWord
                 mainPart.Document = new Document(new Body());
 
                 HtmlConverter converter = new HtmlConverter(mainPart);
-                var paragraphs = converter.Parse(htmlContent);
+                var validator = new HtmlImageValidator();
+                string validatedHtml = validator.ValidateAndReplaceImagesAsync(htmlContent);
+                try
+                {
+                    var paragraphs = converter.Parse(validatedHtml);
+
+                    foreach (var paragraph in paragraphs)
+                    {
+                        mainPart.Document.Body.Append(paragraph);
+                    }
 
-                foreach (var paragraph in paragraphs)
+                    mainPart.Document.Save();
+                }
+                catch (Exception e)
                 {
-                    mainPart.Document.Body.Append(paragraph);
+                    var msg = e.Message;
+                    // ignore
                 }
-
-                mainPart.Document.Save();
             }
 
             memoryStream.Position = 0;

+ 43 - 0
src/Hotline.Share/Tools/HtmlImageValidator.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace Hotline.Share.Tools;
+public class HtmlImageValidator
+{
+    private readonly HttpClient _httpClient = new HttpClient();
+
+    public string ValidateAndReplaceImagesAsync(string htmlContent)
+    {
+        string pattern = "<img[^>]+src=\"([^\"]+)\"[^>]*>";
+        var matches = Regex.Matches(htmlContent, pattern);
+
+        foreach (Match match in matches)
+        {
+            string imageUrl = match.Groups[1].Value;
+            if (!IsImageAccessible(imageUrl))
+            {
+                // 将无效链接替换为空白或占位符
+                htmlContent = htmlContent.Replace(imageUrl, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAIAAABLixI0AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAEXRFWHRTb2Z0d2FyZQBTbmlwYXN0ZV0Xzt0AAALiSURBVDiNrZLLaxNRFMZPJneapJ2kHdOIbdJa6cO4GFoDVmwXBbU7QVwIIrqT+gfooms3irioIIJLwY3QhRtxEVpapEgFJ9FUsXnQWtLnmEyTTmYm84qLG27GNJZW/Rju4rtnfve79xzH1NSU/3gnHEWlYj4SiXAcV+ejrlPhofNjR2J9XpwVRTGRSPT397vd7hpLLeu5onF4kAuZADA8PJxKpWKxGMdxDMPgLepIieziOC4QCPA8L0nSQSwXMvEHALqu/wnX19cXDAZ5nhcEAQAQ2dB1naZpAAixDpZxYVOUzKxI4y28Soplx/X29vp8vnQ6rWkaIiC8nvB7WKZWyjJOxYStnG5PVyqVotGonZjP55PJZC0XTdMh1mEHYXmcJg5FjuSGRvbfN5NaQuR2IdbBMs79RSRaLVelGb+GXWpZr+by+9D+RNUiVZVkh25YAEAjSjcsGlGyUqZRfd+qrK2cIsmNe1o2EHksTLSvWJiLSJG4Z9VjqjrsJP/9rNaJPRZAZc0EAMus/AuI8VKR0cH/kIth3N1sBexz31CKIe0aGwDQ4mTpitfT5K4r8LfRAx0IcxD83hGCWJcTy8XoqjJPzEBTmGu9FmwZ9NEB7JzsZDpba381yCUoK3HxzYr8Xq8UKGgmfk5bmxOedkvnTvvGg+6z4Z52OyiTydSzNtXkws6LbS1OQbMdRLSqzP/UMk/GXjK22RYl82M8XWMpmrquxnjxlaB9b0gBAAtkxhmaHH3E2EgbBfixodTueEjQUPulO5F7bW4/MZOb5ezOHu4JAgDLrOxaa3Fx+mDQSMfVm9xdAlJVdW7lg0PvocGLHQoAirqwlH8raMkDQONdt+0gAHjGP3idfvgtP0McJKkFUZlNl2YbUjDoxsD9K+HrxNlVc5MzE5KZBYDl0rtWV/uZpssAgJLZRdncBsPTEORt8d0ambjQdZE4XzNfni88lg2FAj8AyKB8yk0bAd2hVn4BVP1hWBpYCWkAAAAASUVORK5CYII=");
+            }
+        }
+
+        return htmlContent;
+    }
+
+    private bool IsImageAccessible(string url)
+    {
+        try
+        {
+            var response = _httpClient.GetAsync(url).GetAwaiter().GetResult();
+            return response.IsSuccessStatusCode;
+        }
+        catch
+        {
+            return false;
+        }
+    }
+}

+ 3 - 1
src/Hotline/Orders/OrderDomainService.cs

@@ -85,7 +85,8 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
         Publisher publisher,
         IRepository<OrderVisitDetail> orderVisitDetailRepository,
         IRepository<WorkflowStep> workflowStepRepository,
-        ISystemLogRepository systemLogRepository)
+        ISystemLogRepository systemLogRepository,
+        IOptionsSnapshot<AppConfiguration> appOptions)
     {
         _orderRepository = orderRepository;
         _orderRedoRepository = orderRedoRepository;
@@ -109,6 +110,7 @@ public class OrderDomainService : IOrderDomainService, IScopeDependency
         _orderVisitDetailRepository = orderVisitDetailRepository;
         _workflowStepRepository = workflowStepRepository;
         _systemLogRepository = systemLogRepository;
+        _appOptions = appOptions;
     }
 
     /// <summary>