From 1c5b92ca67558312bd10d1597e38291260317ef0 Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 14 Aug 2024 17:10:53 +0800 Subject: [PATCH] =?UTF-8?q?add-=E5=AE=8C=E5=96=842=E6=A5=BC=E5=B0=8F?= =?UTF-8?q?=E5=8C=85=E4=BA=A7=E5=87=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/ProdCompletionBusiness.cs | 87 +++++++++++++++---- SlnMesnac.Business/ProdMgmtBusiness.cs | 3 +- SlnMesnac.Model/domain/MesPrdBarcodeInfo.cs | 9 +- SlnMesnac.Plc/Factory/SiemensFactory.cs | 30 ++++++- SlnMesnac.Plc/PlcAbsractFactory.cs | 8 ++ .../service/Impl/MesPrdBarCodeServiceImpl.cs | 2 +- SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs | 2 +- 7 files changed, 117 insertions(+), 24 deletions(-) diff --git a/SlnMesnac.Business/ProdCompletionBusiness.cs b/SlnMesnac.Business/ProdCompletionBusiness.cs index 5136666..a2ee039 100644 --- a/SlnMesnac.Business/ProdCompletionBusiness.cs +++ b/SlnMesnac.Business/ProdCompletionBusiness.cs @@ -11,6 +11,7 @@ using SlnMesnac.Rfid; using SqlSugar; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -49,6 +50,7 @@ namespace SlnMesnac.Business { private readonly IMesProductPlanService _mesProductPlanService; + private readonly IMesProductOrderService _mesProductOrderService; private readonly IMesPrdBarCodeService _barCodeTaskService; private readonly IMesBaseBarcodeInfoService _mesBaseBarcodeInfoService; public readonly IMesPrdBarCodeService _mesPrdBarCodeService; @@ -64,7 +66,7 @@ namespace SlnMesnac.Business _realPalletTaskService = serviceProvider.GetRequiredService(); _mesBaseBarcodeInfoService = serviceProvider.GetRequiredService(); _mesPrdBarCodeService = serviceProvider.GetRequiredService(); - + _mesProductOrderService = serviceProvider.GetRequiredService(); Init(); } @@ -113,7 +115,7 @@ namespace SlnMesnac.Business continue; } - if (!plc.readBoolByAddress(GetPlcAddressByConfigKey("2楼码垛出口到位信号"))) + if (plc.readByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"))!=1) { _logger.LogInformation("等待小包出口信号触发......"); Thread.Sleep(5000); @@ -150,21 +152,27 @@ namespace SlnMesnac.Business //TODO:没有计划的话,处理方式待定 throw new ArgumentException($"未获取到正在执行的生产计划"); } - + #region 开启事务 sqlSugarClient.AsTenant().BeginTran(); //1.生成大条码插入mes_barcode_info; string bigCode =GenerateBigBarcode(productPlanDto, epcStr); //2.40个小条码及大条码绑定托盘号,小条码绑定大条码 BindingBarCode(bigCode,epcStr); //3.更新mes_product_plan及mes_product_order表,更新已生产数量 + UpdatePlanInfoAndOrder(productPlanDto); - - + // 删除正在使用的数据库托盘号 + RealPalletTask realPallet = _realPalletTaskService.Query(x => x.PalletCode == epcStr).FirstOrDefault(); + if (realPallet != null) + { + sqlSugarClient.AsTenant().GetConnection("mes").Deleteable(realPallet).ExecuteCommand(); + } + // 写入PLC RFID号供调度使用 + plc.writeStringByAddress(GetPlcAddressByConfigKey("2楼码垛出口RFID条码地址"), epcStr); + plc.writeByteByAddress(GetPlcAddressByConfigKey("2楼小包出口到位信号"),2); + readRfidAmount = 0; sqlSugarClient.AsTenant().CommitTran(); - - plc.writeBoolByAddress(GetPlcAddressByConfigKey("2楼码垛出口到位信号"), false); - readRfidAmount = 0; - + #endregion } catch (Exception ex) { @@ -172,6 +180,8 @@ namespace SlnMesnac.Business // TODO:推送报警 _logger.LogError($"DeviceOutPutHandle异常:{ex.Message}"); } + + Thread.Sleep(1000 * 5); } } @@ -210,6 +220,7 @@ namespace SlnMesnac.Business mesBaseBarcodeInfo.updateTime = DateTime.Now; mesBaseBarcodeInfo.completeFlag = "1"; mesBaseBarcodeInfo.singleFlag = "0"; + // 改成spec mesBaseBarcodeInfo.barcodeSpec = productPlanDto.MaterialName; sqlSugarClient.AsTenant().GetConnection("mes").Insertable(mesBaseBarcodeInfo).ExecuteCommand(); return bigBarcode; @@ -225,26 +236,72 @@ namespace SlnMesnac.Business List list = _mesPrdBarCodeService.GetUseBarCodeList(); if(list==null || list.Count == 0) { - throw new Exception("托盘未找到可以绑定的小条码"); - }else if(list.Count > 40) + throw new InvalidOperationException("托盘未找到可以绑定的小条码"); + } + + if (list.Where(x => x.PrintFlag == "1").ToList().Count < 40) { - list = list.Take(40).ToList(); + // TODO推送低级别报警 } foreach (var item in list) { item.PalletInfoCode = epcStr; item.MesBarcodeInfo = bigBarcode; item.BindTime = DateTime.Now; + item.BindStatus = 1; } sqlSugarClient.AsTenant().GetConnection("mes").Updateable(list).ExecuteCommand(); } private void UpdatePlanInfoAndOrder(MesProductPlanDto productPlanDto) { + MesProductPlan productPlan = _mesProductPlanService.Query(x => x.PlanCode == productPlanDto.PlanCode).FirstOrDefault(); + if(productPlan == null) + { + throw new InvalidOperationException("未找到该生产计划!"); + } + MesProductOrder productOrder = _mesProductOrderService.Query(x => x.ProductOrderId == productPlan.ProductOrderId).FirstOrDefault(); + if (productPlan == null) + { + throw new InvalidOperationException("未找到该生产计划对应的生产工单!"); + } + #region 更新生产计划 + if (productPlan.CompleteAmount == 0) + { + productPlan.RealBeginTime = DateTime.Now; + } + productPlan.CompleteAmount++; + if(productPlan.CompleteAmount == productPlan.PlanAmount) + { + + productPlan.RealEndTime = DateTime.Now; + productPlan.PlanStatus = Model.enums.PlanStatusEnum.已完成; + } + productPlan.UpdateTime = DateTime.Now; + productPlan.UpdateBy = "SlnMesnac"; + sqlSugarClient.AsTenant().GetConnection("mes").Updateable(productPlan).ExecuteCommand(); + #endregion - } - + #region 更新生产工单 + + if (productOrder.CompleteAmount == 0) + { + + productOrder.RealBeginTime = DateTime.Now; + } + productOrder.CompleteAmount++; + if(productOrder.CompleteAmount== productOrder.PlanAmount) + { + + productOrder.RealEndTime = DateTime.Now; + productOrder.OrderStatus = "2"; + } + productOrder.UpdateTime = DateTime.Now; + productOrder.UpdateBy = "SlnMesnac"; + sqlSugarClient.AsTenant().GetConnection("mes").Updateable(productOrder).ExecuteCommand(); + #endregion + } @@ -303,7 +360,7 @@ namespace SlnMesnac.Business { RefreshMessage($"空托盘进入码垛位处理异常:{e.Message}"); } - Thread.Sleep(5000); + Thread.Sleep(1000*5); } } diff --git a/SlnMesnac.Business/ProdMgmtBusiness.cs b/SlnMesnac.Business/ProdMgmtBusiness.cs index 41b9654..94fce3e 100644 --- a/SlnMesnac.Business/ProdMgmtBusiness.cs +++ b/SlnMesnac.Business/ProdMgmtBusiness.cs @@ -95,7 +95,7 @@ namespace SlnMesnac.Business BaseRealTask localPlan = _baseRealTaskService.GetExeTask(); localPlan.Status = 2; sqlSugarClient.AsTenant().GetConnection("local").Updateable(localPlan).ExecuteCommand(); - GenerateBarcode(10); + GenerateBarcode(40); // throw new Exception("事务测试"); sqlSugarClient.AsTenant().CommitTran(); Console.WriteLine("提交事务"); @@ -515,6 +515,7 @@ namespace SlnMesnac.Business record.PrdBarcodeInfo = baseDate + i.ToString("D3"); // 将序号格式化为三位数 record.PrintFlag = "0"; record.CreatTime = DateTime.Now; + record.BindStatus = 0; list.Add(record); } sqlSugarClient.AsTenant().GetConnection("mes").Insertable(list).ExecuteCommand(); diff --git a/SlnMesnac.Model/domain/MesPrdBarcodeInfo.cs b/SlnMesnac.Model/domain/MesPrdBarcodeInfo.cs index 60b70f1..0d43461 100644 --- a/SlnMesnac.Model/domain/MesPrdBarcodeInfo.cs +++ b/SlnMesnac.Model/domain/MesPrdBarcodeInfo.cs @@ -78,10 +78,11 @@ namespace SlnMesnac.Model.domain [SugarColumn(ColumnName = "bind_time")] public DateTime? BindTime { get; set; } - - - - + /// + /// 绑定状态:0-未绑定;1-已绑定;2-弃用 + /// + [SugarColumn(ColumnName = "bind_status")] + public int? BindStatus { get; set; } } diff --git a/SlnMesnac.Plc/Factory/SiemensFactory.cs b/SlnMesnac.Plc/Factory/SiemensFactory.cs index 5129764..febdd40 100644 --- a/SlnMesnac.Plc/Factory/SiemensFactory.cs +++ b/SlnMesnac.Plc/Factory/SiemensFactory.cs @@ -260,6 +260,8 @@ namespace SlnMesnac.Plc.Factory } } + + /// /// 通过PLC地址读取float类型数据 /// @@ -350,13 +352,37 @@ namespace SlnMesnac.Plc.Factory OperateResult operateResult = s7.Write(address, (float)value); if (!operateResult.IsSuccess) { - throw new InvalidOperationException($"根据地址:{address};写入double数据失败:{operateResult.Message}"); + throw new InvalidOperationException($"根据地址:{address};写入Float数据失败:{operateResult.Message}"); } return operateResult.IsSuccess; } catch (Exception ex) { - throw new InvalidOperationException($"根据地址:{address};写入double数据异常:{ex.Message}"); + throw new InvalidOperationException($"根据地址:{address};写入Float数据异常:{ex.Message}"); + } + } + + + /// + /// 通过PLC地址写入Byte类型数据 + /// + /// + /// + /// + public override bool writeByteByAddress(string address,int value) + { + try + { + OperateResult operateResult = s7.Write(address,(byte)value); + if (!operateResult.IsSuccess) + { + throw new InvalidOperationException($"根据地址:{address};写入byte数据失败:{operateResult.Message}"); + } + return operateResult.IsSuccess; + } + catch (Exception ex) + { + throw new InvalidOperationException($"根据地址:{address};写入byte数据异常:{ex.Message}"); } } } diff --git a/SlnMesnac.Plc/PlcAbsractFactory.cs b/SlnMesnac.Plc/PlcAbsractFactory.cs index e76f8bf..16101c2 100644 --- a/SlnMesnac.Plc/PlcAbsractFactory.cs +++ b/SlnMesnac.Plc/PlcAbsractFactory.cs @@ -126,5 +126,13 @@ namespace SlnMesnac.Plc /// /// public abstract bool writeFloatByAddress(string address, int value); + + /// + /// 通过PLC地址写入Byte类型数据 + /// + /// + /// + /// + public abstract bool writeByteByAddress(string address, int value); } } \ No newline at end of file diff --git a/SlnMesnac.Repository/service/Impl/MesPrdBarCodeServiceImpl.cs b/SlnMesnac.Repository/service/Impl/MesPrdBarCodeServiceImpl.cs index 77aa330..c960160 100644 --- a/SlnMesnac.Repository/service/Impl/MesPrdBarCodeServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/MesPrdBarCodeServiceImpl.cs @@ -78,7 +78,7 @@ namespace SlnMesnac.Repository.service.Impl List list = null; try { - string sql = "select * from mes_prd_barcode_info where print_flag ='1' and pallet_info_code is null order by print_time limit 40;"; + string sql = "select * from mes_prd_barcode_info where bind_status =0 order by creat_time limit 40;"; list = _rep.Context.Ado.SqlQuery(sql); return list; }catch (Exception e) diff --git a/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs b/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs index 68f05f0..7647950 100644 --- a/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs @@ -278,7 +278,7 @@ namespace SlnMesnac.WPF.ViewModel if (info != null) { info.PlanStatus = PlanStatusEnum.已开始; - info.RealBeginTime = DateTime.Now; + info.PlanBeginTime = DateTime.Now; } _prodMgmtBusiness.UpdateProdPlan(info);