From 504216dfbd5f48483ae2bb5fc763f39de846321d Mon Sep 17 00:00:00 2001 From: huangxianguo Date: Tue, 10 Sep 2024 19:25:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=85=8D=E6=96=B9=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MasstransferCommon.Tests.csproj | 21 +++++++++++++++++++ .../Utils/JsonUtilTest.cs | 21 +++++++++++++++++++ MasstransferCommon/Utils/JsonUtil.cs | 1 + MasstransferExporter.sln | 10 ++++----- MasstransferExporter.sln.DotSettings.user | 8 +++++++ .../DataExporter/ConfigService.cs | 13 +++++++++--- .../DataExporter/FormulaService.cs | 2 +- .../DataExporter/Model/ConfigData.cs | 4 ++-- .../DataExporter/SystemParamsService.cs | 20 +++++++++--------- 9 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 MasstransferCommon.Tests/MasstransferCommon.Tests.csproj create mode 100644 MasstransferCommon.Tests/Utils/JsonUtilTest.cs diff --git a/MasstransferCommon.Tests/MasstransferCommon.Tests.csproj b/MasstransferCommon.Tests/MasstransferCommon.Tests.csproj new file mode 100644 index 0000000..4925776 --- /dev/null +++ b/MasstransferCommon.Tests/MasstransferCommon.Tests.csproj @@ -0,0 +1,21 @@ + + + + net7.0 + + false + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MasstransferCommon.Tests/Utils/JsonUtilTest.cs b/MasstransferCommon.Tests/Utils/JsonUtilTest.cs new file mode 100644 index 0000000..871ba5e --- /dev/null +++ b/MasstransferCommon.Tests/Utils/JsonUtilTest.cs @@ -0,0 +1,21 @@ +using System.IO; +using JetBrains.Annotations; +using MasstransferCommon.Utils; +using MasstransferExporter.DataExporter.Model; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace MasstransferCommon.Tests.Utils; + +[TestClass] +[TestSubject(typeof(JsonUtil))] +public class JsonUtilTest +{ + [TestMethod] + public void Test() + { + var json = File.ReadAllText("C:\\Users\\huangxianguo\\Desktop\\formula.json"); + + var dto = JsonUtil.FromJson(json); + Assert.IsNotNull(dto); + } +} \ No newline at end of file diff --git a/MasstransferCommon/Utils/JsonUtil.cs b/MasstransferCommon/Utils/JsonUtil.cs index 1c9da47..1db00a9 100644 --- a/MasstransferCommon/Utils/JsonUtil.cs +++ b/MasstransferCommon/Utils/JsonUtil.cs @@ -49,6 +49,7 @@ public class JsonUtil } catch (Exception e) { + Console.WriteLine(e); throw new ArgumentException($" 无效的json 字符串 {json} "); } } diff --git a/MasstransferExporter.sln b/MasstransferExporter.sln index bfee5fe..9309002 100644 --- a/MasstransferExporter.sln +++ b/MasstransferExporter.sln @@ -6,7 +6,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasstransferInfrastructure" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasstransferCommon", "MasstransferCommon\MasstransferCommon.csproj", "{66C6D73C-BADB-4E28-9C83-E701B019626D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject1", "TestProject1\TestProject1.csproj", "{D26C3A44-62AF-4ACC-B454-51E1098C2C86}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasstransferCommon.Tests", "MasstransferCommon.Tests\MasstransferCommon.Tests.csproj", "{DBEDC6E1-AEE6-47FA-A17A-2B412CE99C7C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -26,9 +26,9 @@ Global {66C6D73C-BADB-4E28-9C83-E701B019626D}.Debug|Any CPU.Build.0 = Debug|Any CPU {66C6D73C-BADB-4E28-9C83-E701B019626D}.Release|Any CPU.ActiveCfg = Release|Any CPU {66C6D73C-BADB-4E28-9C83-E701B019626D}.Release|Any CPU.Build.0 = Release|Any CPU - {D26C3A44-62AF-4ACC-B454-51E1098C2C86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D26C3A44-62AF-4ACC-B454-51E1098C2C86}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D26C3A44-62AF-4ACC-B454-51E1098C2C86}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D26C3A44-62AF-4ACC-B454-51E1098C2C86}.Release|Any CPU.Build.0 = Release|Any CPU + {DBEDC6E1-AEE6-47FA-A17A-2B412CE99C7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DBEDC6E1-AEE6-47FA-A17A-2B412CE99C7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DBEDC6E1-AEE6-47FA-A17A-2B412CE99C7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DBEDC6E1-AEE6-47FA-A17A-2B412CE99C7C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/MasstransferExporter.sln.DotSettings.user b/MasstransferExporter.sln.DotSettings.user index e69de29..e3bc613 100644 --- a/MasstransferExporter.sln.DotSettings.user +++ b/MasstransferExporter.sln.DotSettings.user @@ -0,0 +1,8 @@ + + MasstransferCommon.Tests + d6790ab7-33c2-4425-b2c9-51480cd1a852 + <SessionState ContinuousTestingMode="0" IsActive="True" Name="Test" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <TestAncestor> + <TestId>MSTest::DBEDC6E1-AEE6-47FA-A17A-2B412CE99C7C::net7.0::MasstransferCommon.Tests.Utils.JsonUtilTest.Test</TestId> + </TestAncestor> +</SessionState> \ No newline at end of file diff --git a/MasstransferExporter/DataExporter/ConfigService.cs b/MasstransferExporter/DataExporter/ConfigService.cs index 37745d5..92b0438 100644 --- a/MasstransferExporter/DataExporter/ConfigService.cs +++ b/MasstransferExporter/DataExporter/ConfigService.cs @@ -1,6 +1,8 @@ using MasstransferCommon.Atrributes; using MasstransferCommon.Events; +using MasstransferCommon.Model.Constant; using MasstransferCommon.Utils; +using MasstransferCommunicate.Mqtt.Client; using MasstransferExporter.DataExporter.Model; using Masuit.Tools; @@ -16,7 +18,7 @@ public class ConfigService : Instant /// private static async Task ListenConfigIssuedEvent(EventType type, bool start) { - // await MessageQueueHelper.Subscribe(Topics.DownloadConfigData, HandleConfigIssuedEvent); + await MessageQueueHelper.Subscribe(Topics.DownloadConfigData, HandleConfigIssuedEvent); } @@ -25,7 +27,7 @@ public class ConfigService : Instant /// /// /// - private static void HandleConfigIssuedEvent(string topic, ConfigData data) + private static void HandleConfigIssuedEvent(string topic, ConfigData data) { if (data.IsNullOrEmpty()) return; @@ -38,7 +40,12 @@ public class ConfigService : Instant case "FORMULA": { var param = data.Param; - var formulaDto = JsonUtil.FromJson(JsonUtil.ToJson(param)); + var formulaDto = JsonUtil.FromJson(param.ToString()); + if (formulaDto != null) + { + formulaDto.Name = data.Name; + } + FormulaService.HandleFormulaIssuedEvent(formulaDto); break; } diff --git a/MasstransferExporter/DataExporter/FormulaService.cs b/MasstransferExporter/DataExporter/FormulaService.cs index 1c8e58f..2c3bff6 100644 --- a/MasstransferExporter/DataExporter/FormulaService.cs +++ b/MasstransferExporter/DataExporter/FormulaService.cs @@ -263,7 +263,7 @@ public class FormulaService { var formulaDto = GetFormulaById(formula.Id); if (formulaDto == null) continue; - var data = new ConfigData() + var data = new ConfigData() { Name = formulaDto.Name, Param = formulaDto, diff --git a/MasstransferExporter/DataExporter/Model/ConfigData.cs b/MasstransferExporter/DataExporter/Model/ConfigData.cs index e18adb1..2bb1a28 100644 --- a/MasstransferExporter/DataExporter/Model/ConfigData.cs +++ b/MasstransferExporter/DataExporter/Model/ConfigData.cs @@ -5,11 +5,11 @@ namespace MasstransferExporter.DataExporter.Model; /// /// 配置数据 /// -public class ConfigData +public class ConfigData { [JsonProperty("name")] public string Name { get; set; } [JsonProperty("type")] public string Type { get; set; } - [JsonProperty("param")] public object Param { get; set; } + [JsonProperty("param")] public T? Param { get; set; } } \ No newline at end of file diff --git a/MasstransferExporter/DataExporter/SystemParamsService.cs b/MasstransferExporter/DataExporter/SystemParamsService.cs index 5459833..7bdff9e 100644 --- a/MasstransferExporter/DataExporter/SystemParamsService.cs +++ b/MasstransferExporter/DataExporter/SystemParamsService.cs @@ -19,12 +19,12 @@ public class SystemParamsService /// 处理下发的系统配置参数 /// /// - public static void HandleSystemParamsIssuedEvent(ConfigData data) + public static void HandleSystemParamsIssuedEvent(ConfigData data) { if (data.IsNullOrEmpty()) return; var name = data.Name; - var param = JsonUtil.ToJson(data.Param); + var param = data?.Param?.ToString(); switch (name) { case "相机配置": @@ -125,55 +125,55 @@ public class SystemParamsService { try { - var cameraParams = new ConfigData() + var cameraParams = new ConfigData() { Name = "相机配置", Param = GetCameraParams(), Type = "SYSTEM" }; - var substrateCameraInternalParams = new ConfigData() + var substrateCameraInternalParams = new ConfigData() { Name = "基板拍照相机内参", Param = GetSubstrateParams(), Type = "SYSTEM" }; - var waferCameraInternalParams = new ConfigData() + var waferCameraInternalParams = new ConfigData() { Name = "芯片拍照相机内参", Param = GetWaferParams(), Type = "SYSTEM" }; - var logParams = new ConfigData() + var logParams = new ConfigData() { Name = "日志配置", Param = GetLogParams(), Type = "SYSTEM" }; - var systemParams = new ConfigData() + var systemParams = new ConfigData() { Name = "系统配置", Param = GetSystemParams(), Type = "SYSTEM" }; - var scannerParams = new ConfigData() + var scannerParams = new ConfigData() { Name = "扫描器配置", Param = GetScannerParams(), Type = "SYSTEM" }; - var minioParams = new ConfigData() + var minioParams = new ConfigData() { Name = "MinIO配置", Param = GetMinioParams(), Type = "SYSTEM" }; - var mqttParams = new ConfigData() + var mqttParams = new ConfigData() { Name = "MQTT配置", Param = GetMqttConnectParams(),