diff --git a/.gitignore b/.gitignore index 11b55864..c1690b57 100644 --- a/.gitignore +++ b/.gitignore @@ -264,3 +264,4 @@ __pycache__/ /ZR.Admin.WebApi/wwwroot/2025/1213 /.gitignore /ZR.Admin.WebApi/wwwroot/Generatecode +/.trae diff --git a/ZR.Service/mes/qc/gp12/QcGp12Service.cs b/ZR.Service/mes/qc/gp12/QcGp12Service.cs index bb374ae2..1fa5e830 100644 --- a/ZR.Service/mes/qc/gp12/QcGp12Service.cs +++ b/ZR.Service/mes/qc/gp12/QcGp12Service.cs @@ -6,10 +6,12 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; 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; using ZR.Service.Utils; +using ZR.Service.mqtt; namespace ZR.Service.Business { @@ -19,6 +21,13 @@ namespace ZR.Service.Business [AppService(ServiceType = typeof(IQcGp12Service), ServiceLifetime = LifeTime.Transient)] public class QcGp12Service : BaseService, IQcGp12Service { + private readonly MqttService _mqttService; + + public QcGp12Service(MqttService mqttService) + { + _mqttService = mqttService; + } + public QcGp12LabelAnalysisDto AnalyzeLabelToDto(string label, int type) { QcGp12LabelAnalysisDto labelAnalysisDto = @@ -736,22 +745,35 @@ namespace ZR.Service.Business Context.Insertable(qcGp12Log).ExecuteCommand(); // 提交事务 Context.Ado.CommitTran(); + + // 发送mqtt消息通知打印抛光/打磨标签 + // 发送抛光标签打印消息 + if (qcGp12Workorder.PolishNumber > 0) + { + SendLabelPrintMqttMessage(qcGp12Workorder, 1, qcGp12Workorder.PolishNumber.Value); + } + // 发送打磨标签打印消息 + if (qcGp12Workorder.DamoNumber > 0) + { + SendLabelPrintMqttMessage(qcGp12Workorder, 2, qcGp12Workorder.DamoNumber.Value); + } + // 插入成品入库单 _ = Task.Run(() => { ProFinishedProductReceiptService proFinishedProductReceiptService = new ProFinishedProductReceiptService(); - + // 生成ReceiptNo:GP+日期YYYYMMDD+0001顺序递增 string today = nowTime.ToString("yyyyMMdd"); string receiptNoPrefix = $"GP{today}"; - + // 查询今天已存在的最大单号 var lastReceipt = Context .Queryable() .Where(it => it.ReceiptNo.StartsWith(receiptNoPrefix)) .OrderBy(it => it.ReceiptNo, OrderByType.Desc) .First(); - + string newReceiptNo; if (lastReceipt != null && !string.IsNullOrEmpty(lastReceipt.ReceiptNo)) { @@ -771,7 +793,7 @@ namespace ZR.Service.Business newReceiptNo = $"{receiptNoPrefix}0001"; } // 箱数 - int _packageCount = Context.Queryable().Where(it=>it.WorkOrder == qcGp12Workorder.WorkOrder).Where(it => it.LabelType == 1).Count(); + int _packageCount = Context.Queryable().Where(it => it.WorkOrder == qcGp12Workorder.WorkOrder).Where(it => it.LabelType == 1).Count(); // 工单号 MaterialUtils materialUtils = new MaterialUtils(); ResultionPackageCodeDto packageCodeDto = materialUtils.ResolutionPackage(qcGp12Workorder.Label); @@ -781,7 +803,8 @@ namespace ZR.Service.Business _workOrder = packageCodeDto.WorkoderID; } - ProFinishedProductReceipt newModel = new() { + ProFinishedProductReceipt newModel = new() + { ReceiptNo = newReceiptNo, SiteNo = qcGp12Workorder.SiteNo, WorkOrder = _workOrder, @@ -1002,5 +1025,55 @@ namespace ZR.Service.Business return Guid.NewGuid().ToString("N").Substring(0, 10); // Generate a 10-character unique ID } + /// + /// 发送标签打印MQTT消息 + /// + /// 工单信息 + /// 标签类型:1-抛光,2-打磨 + /// 数量 + private void SendLabelPrintMqttMessage(QcGp12ServiceWorkorder workorder, int labelType, int quantity) + { + try + { + if (quantity <= 0) + { + return; + } + + 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("Print/Label", message, MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce); + } + catch (Exception ex) + { + // 记录异常但不影响主流程 + Console.WriteLine($"发送标签打印MQTT消息失败: {ex.Message}"); + } + } + } }