From 3d1c151f32e6c15a101281c1f5a8e7788706ddf0 Mon Sep 17 00:00:00 2001 From: huangxianguo Date: Thu, 22 Aug 2024 15:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8F=82=E6=95=B0=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E7=9B=B8=E5=85=B3=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataExporter/ConfigService.cs | 51 +++++++ .../DataExporter/FormulaService.cs | 133 ++++++++++++++++++ .../DataExporter/SystemParamsService.cs | 106 ++++++++++++++ MasstransferExporter/Program.cs | 4 +- 4 files changed, 292 insertions(+), 2 deletions(-) create mode 100644 MasstransferExporter/DataExporter/ConfigService.cs diff --git a/MasstransferExporter/DataExporter/ConfigService.cs b/MasstransferExporter/DataExporter/ConfigService.cs new file mode 100644 index 0000000..6615651 --- /dev/null +++ b/MasstransferExporter/DataExporter/ConfigService.cs @@ -0,0 +1,51 @@ +using MasstransferCommon.Model.Constant; +using MasstransferCommon.Utils; +using MasstransferCommunicate.Mqtt.Client; +using MasstransferExporter.DataExporter.Model; +using Masuit.Tools; + +namespace MasstransferExporter.DataExporter; + +/// +/// 配置服务 +/// +public class ConfigService +{ + /// + /// 监听配置下发事件 + /// + public static async Task ListenConfigIssuedEvent() + { + await MessageQueueHelper.Subscribe(Topics.DownloadConfigData, HandleConfigIssuedEvent); + } + + + /// + /// 处理接收到的配置下发事件,根据配置类型执行不同的操作 + /// + /// + /// + private static void HandleConfigIssuedEvent(string topic, string payload) + { + if (payload.IsNullOrEmpty()) return; + + var data = JsonUtil.FromJson(payload); + + if (data.IsNullOrEmpty()) return; + + var type = data.Type; + switch (type) + { + case "system": + SystemParamsService.HandleSystemParamsIssuedEvent(data); + break; + case "formula": + { + var param = data.Param; + var formulaDto = JsonUtil.FromJson(JsonUtil.ToJson(param)); + FormulaService.HandleFormulaIssuedEvent(formulaDto); + break; + } + } + } +} \ No newline at end of file diff --git a/MasstransferExporter/DataExporter/FormulaService.cs b/MasstransferExporter/DataExporter/FormulaService.cs index b9f6956..ca8da78 100644 --- a/MasstransferExporter/DataExporter/FormulaService.cs +++ b/MasstransferExporter/DataExporter/FormulaService.cs @@ -4,6 +4,7 @@ using MasstransferCommunicate.Mqtt.Client; using MasstransferCore.Model.Entity; using MasstransferExporter.DataExporter.Model; using MasstransferInfrastructure.Database.Sqlite; +using Masuit.Tools; namespace MasstransferExporter.DataExporter; @@ -14,6 +15,133 @@ public class FormulaService { private static readonly SqliteHelper Db = SqliteHelper.GetInstance(); + + /// + /// 处理配方下发事件 + /// + public static void HandleFormulaIssuedEvent(FormulaDTO formulaDto) + { + if (formulaDto.IsNullOrEmpty() || formulaDto.Name.IsNullOrEmpty()) return; + + var name = formulaDto.Name; + + var formula = GetFormulaByName(name); + + if (formula.IsNullOrEmpty()) + { + // 当前不存在这个配方,则去创建这个配方 + formula = new Formula() + { + Name = name, + Code = formulaDto.Code, + Description = formulaDto.Description, + Selected = false, + }; + + Db.Insert(formula); + } + + // 插入其他的配方记录 + var formulaId = formula.Id; + + var algorithmParams = formulaDto.AlgorithmParams; + var altimetryParams = formulaDto.AltimetryParams; + var needleSetting = formulaDto.NeedleSetting; + var pcbSetting = formulaDto.PcbSetting; + var waferSetting = formulaDto.WaferSetting; + var jobSetting = formulaDto.JobSetting; + var axisPositionParams = formulaDto.AxisPositionParams; + var axisVariables = formulaDto.AxisVariables; + + if (algorithmParams != null) + { + var algorithmParamsByFormulaId = GetAlgorithmParamsByFormulaId(formulaId); + if (algorithmParamsByFormulaId != null) + { + algorithmParams.Id = algorithmParamsByFormulaId.Id; + } + + Db.SaveOrUpdate(algorithmParams); + } + + if (altimetryParams != null) + { + var altimetryParamsByFormulaId = GetAltimetryParamsByFormulaId(formulaId); + if (altimetryParamsByFormulaId != null) + { + altimetryParams.Id = altimetryParamsByFormulaId.Id; + } + + Db.SaveOrUpdate(altimetryParams); + } + + if (needleSetting != null) + { + var needleSettingByFormulaId = GetNeedleSettingByFormulaId(formulaId); + if (needleSettingByFormulaId != null) + { + needleSetting.Id = needleSettingByFormulaId.Id; + } + + Db.SaveOrUpdate(needleSetting); + } + + if (pcbSetting != null) + { + var pcbSettingByFormulaId = GetPcbSettingByFormulaId(formulaId); + if (pcbSettingByFormulaId != null) + { + pcbSetting.Id = pcbSettingByFormulaId.Id; + } + + Db.SaveOrUpdate(pcbSetting); + } + + if (waferSetting != null) + { + var waferSettingByFormulaId = GetWaferSettingByFormulaId(formulaId); + if (waferSettingByFormulaId != null) + { + waferSetting.Id = waferSettingByFormulaId.Id; + } + + Db.SaveOrUpdate(waferSetting); + } + + if (jobSetting != null) + { + var jobSettingByFormulaId = GetJobSettingByFormulaId(formulaId); + if (jobSettingByFormulaId != null) + { + jobSetting.Id = jobSettingByFormulaId.Id; + } + + Db.SaveOrUpdate(jobSetting); + } + + if (axisPositionParams != null) + { + var axisPositionParamsByFormulaId = GetAxisPositionParamsByFormulaId(formulaId); + if (axisPositionParamsByFormulaId != null) + { + axisPositionParams.Id = axisPositionParamsByFormulaId.Id; + } + + Db.SaveOrUpdate(axisPositionParams); + } + + if (axisVariables != null) + { + var axisVariablesByFormulaId = GetAxisVariablesByFormulaId(formulaId); + if (axisVariablesByFormulaId != null) + { + axisVariables.Id = axisVariablesByFormulaId.Id; + } + + Db.SaveOrUpdate(axisVariables); + } + } + /// /// 获取所有的配方列表 /// @@ -24,6 +152,11 @@ public class FormulaService return BeanUtil.CopyProperties(formulas); } + private static Formula GetFormulaByName(string name) + { + return Db.Query("select * from formulas where name = ?", name).FirstOrDefault(); + } + /// /// 获取当前已经启用的配方 /// diff --git a/MasstransferExporter/DataExporter/SystemParamsService.cs b/MasstransferExporter/DataExporter/SystemParamsService.cs index 9b775dc..a185d7a 100644 --- a/MasstransferExporter/DataExporter/SystemParamsService.cs +++ b/MasstransferExporter/DataExporter/SystemParamsService.cs @@ -1,7 +1,9 @@ using MasstransferCommon.Model.Constant; +using MasstransferCommon.Utils; using MasstransferCommunicate.Mqtt.Client; using MasstransferExporter.DataExporter.Model; using MasstransferInfrastructure.Database.Sqlite; +using Masuit.Tools; namespace MasstransferExporter.DataExporter; @@ -12,6 +14,110 @@ public class SystemParamsService { private static readonly SqliteHelper Db = SqliteHelper.GetInstance(); + + /// + /// 处理下发的系统配置参数 + /// + /// + public static void HandleSystemParamsIssuedEvent(ConfigData data) + { + if (data.IsNullOrEmpty()) return; + + var name = data.Name; + var param = JsonUtil.ToJson(data.Param); + switch (name) + { + case "相机配置": + var cameraParams = JsonUtil.FromJson(param); + if (cameraParams == null) break; + var cameraParamsFromDb = GetCameraParams(); + if (cameraParamsFromDb != null) + { + cameraParams.Id = cameraParamsFromDb.Id; + } + + Db.SaveOrUpdate(cameraParams); + break; + case "日志配置": + var logParams = JsonUtil.FromJson(param); + if (logParams == null) break; + var logParamsFromDb = GetLogParams(); + if (logParamsFromDb != null) + { + logParams.Id = logParamsFromDb.Id; + } + + Db.SaveOrUpdate(logParams); + break; + case "系统配置": + var systemParams = JsonUtil.FromJson(param); + if (systemParams == null) break; + var systemParamsFromDb = GetSystemParams(); + if (systemParamsFromDb != null) + { + systemParams.Id = systemParamsFromDb.Id; + } + + Db.SaveOrUpdate(systemParams); + break; + case "扫描器配置": + var scannerParams = JsonUtil.FromJson(param); + if (scannerParams == null) break; + var scannerParamsFromDb = GetScannerParams(); + if (scannerParamsFromDb != null) + { + scannerParams.Id = scannerParamsFromDb.Id; + } + + Db.SaveOrUpdate(scannerParams); + break; + case "MinIO配置": + var minioParams = JsonUtil.FromJson(param); + if (minioParams == null) break; + var minioParamsFromDb = GetMinioParams(); + if (minioParamsFromDb != null) + { + minioParams.Id = minioParamsFromDb.Id; + } + + Db.SaveOrUpdate(minioParams); + break; + case "MQTT配置": + var mqttParams = JsonUtil.FromJson(param); + if (mqttParams == null) break; + var mqttParamsFromDb = GetMqttConnectParams(); + if (mqttParamsFromDb != null) + { + mqttParams.Id = mqttParamsFromDb.Id; + } + + Db.SaveOrUpdate(mqttParams); + break; + case "基板拍照相机内参": + var waferCameraInternalParams = JsonUtil.FromJson(param); + if (waferCameraInternalParams == null) break; + var waferCameraInternalParamsFromDb = GetWaferParams(); + if (waferCameraInternalParamsFromDb != null) + { + waferCameraInternalParams.Id = waferCameraInternalParamsFromDb.Id; + } + + Db.SaveOrUpdate(waferCameraInternalParams); + break; + case "基板拍照相机外参": + var substrateCameraInternalParams = JsonUtil.FromJson(param); + if (substrateCameraInternalParams == null) break; + var substrateCameraInternalParamsFromDb = GetSubstrateParams(); + if (substrateCameraInternalParamsFromDb != null) + { + substrateCameraInternalParams.Id = substrateCameraInternalParamsFromDb.Id; + } + + Db.SaveOrUpdate(substrateCameraInternalParams); + break; + } + } + /// /// 系统参数上报 /// diff --git a/MasstransferExporter/Program.cs b/MasstransferExporter/Program.cs index 722aed3..bbd6049 100644 --- a/MasstransferExporter/Program.cs +++ b/MasstransferExporter/Program.cs @@ -13,9 +13,9 @@ class Program EnableTls = false }; - await MessageQueueHelper.InitConnect(options); + // await MessageQueueHelper.InitConnect(options); - CoordinateService.CoordinateExporter(); + await FormulaService.FormulaDataExporter(); Console.WriteLine("按任意键退出");