From d4613ab8931c0260d8b8033febbbf81489fd3cfa Mon Sep 17 00:00:00 2001 From: git_rabbit Date: Fri, 23 Jan 2026 11:48:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=89=93=E5=8D=B0=E5=8A=9F=E8=83=BD=E5=B9=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4MQTT=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将ProFinishedProductReceiptService中的_receiptLogService改为局部变量 - 统一GP12和后道标签打印的MQTT主题格式 - 调整标签打印名称以更准确反映业务场景 - 在后道服务中新增标签打印MQTT消息发送功能 --- .../pro/ProFinishedProductReceiptService.cs | 3 +- ZR.Service/mes/qc/backend/QcBackEndService.cs | 70 ++++++++++++++++++- ZR.Service/mes/qc/gp12/QcGp12Service.cs | 6 +- 3 files changed, 73 insertions(+), 6 deletions(-) diff --git a/ZR.Service/mes/pro/ProFinishedProductReceiptService.cs b/ZR.Service/mes/pro/ProFinishedProductReceiptService.cs index 30c0147f..d716ba89 100644 --- a/ZR.Service/mes/pro/ProFinishedProductReceiptService.cs +++ b/ZR.Service/mes/pro/ProFinishedProductReceiptService.cs @@ -18,7 +18,6 @@ namespace ZR.Service.Business [AppService(ServiceType = typeof(IProFinishedProductReceiptService), ServiceLifetime = LifeTime.Transient)] public class ProFinishedProductReceiptService : BaseService, IProFinishedProductReceiptService { - private readonly IProFinishedProductReceiptLogService _receiptLogService; /// /// 查询MES成品入库单主表(含产品信息及标签打印状态)列表 @@ -61,7 +60,7 @@ namespace ZR.Service.Business /// public ProFinishedProductReceipt AddProFinishedProductReceipt(ProFinishedProductReceipt model) { - + ProFinishedProductReceiptLogService _receiptLogService = new (); try { diff --git a/ZR.Service/mes/qc/backend/QcBackEndService.cs b/ZR.Service/mes/qc/backend/QcBackEndService.cs index c8c8eccd..24883b57 100644 --- a/ZR.Service/mes/qc/backend/QcBackEndService.cs +++ b/ZR.Service/mes/qc/backend/QcBackEndService.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using ZR.Common.MqttHelper; using ZR.Model.Business; using ZR.Model.Dto; +using ZR.Model.MES.qc.DTO; using ZR.Model.MES.wms; using ZR.Model.MES.wms.Dto; using ZR.Service.Business.IBusinessService; @@ -25,11 +26,13 @@ namespace ZR.Service.Business { private readonly MqttService _mqttService; // 注入MqttService private readonly ILogger _logger; + private readonly IProFinishedProductReceiptService _proFinishedProductReceiptService; - public QcBackEndService(MqttService mqttService, ILogger logger) + public QcBackEndService(MqttService mqttService, ILogger logger, IProFinishedProductReceiptService proFinishedProductReceiptService) { _mqttService = mqttService; _logger = logger; + _proFinishedProductReceiptService = proFinishedProductReceiptService; } public QcBackEndLabelAnalysisDto AnalyzeLabelToDto(string label, int type) @@ -1237,6 +1240,19 @@ namespace ZR.Service.Business Context.Insertable(qcBackEndLog).ExecuteCommand(); // 提交事务 Context.Ado.CommitTran(); + + // 发送mqtt消息通知打印抛光/打磨标签 + // 发送抛光标签打印消息 + if (qcBackEndWorkorder.PolishNumber > 0) + { + SendLabelPrintMqttMessage(qcBackEndWorkorder, 1, qcBackEndWorkorder.PolishNumber.Value); + } + // 发送打磨标签打印消息 + if (qcBackEndWorkorder.DamoNumber > 0) + { + SendLabelPrintMqttMessage(qcBackEndWorkorder, 2, qcBackEndWorkorder.DamoNumber.Value); + } + // 插入成品入库单 _ = Task.Run(() => { @@ -1519,6 +1535,58 @@ namespace ZR.Service.Business return Guid.NewGuid().ToString("N").Substring(0, 10); // Generate a 10-character unique ID } + /// + /// 发送标签打印MQTT消息 + /// + /// 工单信息 + /// 标签类型:1-抛光,2-打磨 + /// 数量 + private void SendLabelPrintMqttMessage(QcBackEndServiceWorkorder workorder, int labelType, int quantity) + { + try + { + if (quantity <= 0) + { + return; + } + + string mqttTopic = "shgg_mes/backEnd/label_print/print/PGDM"; + string labelCode = labelType == 1 ? "Type=DeNoPG" : "Type=DeNoDM"; + string path = labelType == 1 ? "D:\\RIZO\\label\\抛光送货单.btw" : "D:\\RIZO\\label\\打磨送货单.btw"; + string name = labelType == 1 ? "后道抛光送货单标签打印" : "后道打磨送货单标签打印"; + + var printDto = new PrintDeliveryNoteDto + { + Path = path, + SiteNo = workorder.SiteNo, + Name = name, + PartNumber = workorder.PartNumber, + Description = workorder.Description, + Color = workorder.Color, + Specification = workorder.Specification, + WorkOrder = workorder.WorkOrder, + PackageCode = workorder.WorkOrder, + Team = workorder.Team, + Sort = 1, + ProductionTime = workorder.WorkOrder, + BatchCode = workorder.WorkOrder, + PackageNum = quantity, + LabelCode = $"{labelCode}^ItemNumber={workorder.PartNumber}^Order={workorder.WorkOrder}^Qty={quantity}", + LabelType = 1, + CreatedTime = DateTime.Now.ToString() + }; + + string message = JsonSerializer.Serialize(printDto); + _mqttService.PublishAsync(mqttTopic, message, MqttQualityOfServiceLevel.AtLeastOnce); + _logger.LogInformation($"发送后道标签打印MQTT消息成功: {mqttTopic}"); + } + catch (Exception ex) + { + // 记录异常但不影响主流程 + _logger.LogError(ex, "发送后道标签打印MQTT消息失败"); + } + } + /// /// 打印特殊包装标签 /// diff --git a/ZR.Service/mes/qc/gp12/QcGp12Service.cs b/ZR.Service/mes/qc/gp12/QcGp12Service.cs index 1fa5e830..b743e33b 100644 --- a/ZR.Service/mes/qc/gp12/QcGp12Service.cs +++ b/ZR.Service/mes/qc/gp12/QcGp12Service.cs @@ -1039,10 +1039,10 @@ namespace ZR.Service.Business { return; } - + string mqttTopic = $"shgg_mes/gp12/label_print/print/PGDM"; string labelCode = labelType == 1 ? "Type=DeNoPG" : "Type=DeNoDM"; string path = labelType == 1 ? "D:\\RIZO\\label\\抛光送货单.btw" : "D:\\RIZO\\label\\打磨送货单.btw"; - string name = labelType == 1 ? "包装抛光送货单标签打印" : "包装打磨送货单标签打印"; + string name = labelType == 1 ? "GP12抛光送货单标签打印" : "GP12打磨送货单标签打印"; var printDto = new PrintDeliveryNoteDto { @@ -1066,7 +1066,7 @@ namespace ZR.Service.Business }; string message = JsonSerializer.Serialize(printDto); - _mqttService.PublishAsync("Print/Label", message, MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce); + _mqttService.PublishAsync(mqttTopic, message, MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce); } catch (Exception ex) {