diff --git a/SlnMesnac.Business/PalletStowBusiness.cs b/SlnMesnac.Business/PalletStowBusiness.cs index 84622bc..b2c0005 100644 --- a/SlnMesnac.Business/PalletStowBusiness.cs +++ b/SlnMesnac.Business/PalletStowBusiness.cs @@ -50,15 +50,15 @@ namespace SlnMesnac.Business private readonly IRealPalletTaskService _realPalletTaskService; - private List _palletTasks; + - public PalletStowBusiness(ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IWmsInstockService msInstockService, IRealPalletTaskService realPalletTaskService, List palletTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) + public PalletStowBusiness(ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IWmsInstockService msInstockService, IRealPalletTaskService realPalletTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) { _mesProductPlanService = mesProductPlanService; _msInstockService = msInstockService; _realPalletTaskService = realPalletTaskService; - _palletTasks = palletTasks; + } @@ -140,7 +140,7 @@ namespace SlnMesnac.Business _realPalletTaskService.InsertPalletTask(new RealPalletTask() { PalletCode = epcStr,RecordTime = DateTime.Now }); - RefreshPalletTaskListEvent?.Invoke(_palletTasks); + // RefreshPalletTaskListEvent?.Invoke(_palletTasks); } catch (Exception e) @@ -154,7 +154,7 @@ namespace SlnMesnac.Business public void RemovePalletInfo(string palletCode) { _realPalletTaskService.RemovePalletTask(palletCode); - RefreshPalletTaskListEvent?.Invoke(_palletTasks); + // RefreshPalletTaskListEvent?.Invoke(_palletTasks); } } } diff --git a/SlnMesnac.Business/ProdCompletionBusiness.cs b/SlnMesnac.Business/ProdCompletionBusiness.cs index 5461b02..c6435bf 100644 --- a/SlnMesnac.Business/ProdCompletionBusiness.cs +++ b/SlnMesnac.Business/ProdCompletionBusiness.cs @@ -46,24 +46,20 @@ namespace SlnMesnac.Business { private readonly IMesProductPlanService _mesProductPlanService; - private readonly IRealBarCodeTaskService _barCodeTaskService; + private readonly IMesPrdBarCodeService _barCodeTaskService; - private List _barCodeTasks; + - public ProdCompletionBusiness(ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IRealBarCodeTaskService barCodeTaskService, List barCodeTasks,IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) + public ProdCompletionBusiness(ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IMesPrdBarCodeService barCodeTaskService, IServiceProvider serviceProvider) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) { _mesProductPlanService = mesProductPlanService; _barCodeTaskService = barCodeTaskService; - _barCodeTasks = barCodeTasks; + } - /// - /// 刷新条码队列 - /// - public delegate void RefreshBarCodeTaskList(List list); - public event RefreshBarCodeTaskList? RefreshBarCodeTaskListEvent; - + + public void Init() { DeviceOutPutHandle(); @@ -103,31 +99,31 @@ namespace SlnMesnac.Business plc.writeInt16ByAddress(GetPlcAddressByConfigKey("设备产出"), 0); //生成小包条码 string barCode = $"JYHB{(string.IsNullOrEmpty(productPlanDto.MaterialCode) ? "000000000" : productPlanDto.MaterialCode)}-000001"; - if (_barCodeTasks.Count > 0) - { - var info = _barCodeTasks.OrderByDescending(x => x.RecordTime).Where(x=>x.MaterialCode == productPlanDto.MaterialCode); - if(info.Count() > 0) - { - var task = info.FirstOrDefault(); + //if (_barCodeTasks.Count > 0) + //{ + // var info = _barCodeTasks.OrderByDescending(x => x.RecordTime).Where(x=>x.MaterialCode == productPlanDto.MaterialCode); + // if(info.Count() > 0) + // { + // var task = info.FirstOrDefault(); - ExtractNumber(task.BarCode, out int orFlag); + // ExtractNumber(task.BarCode, out int orFlag); - barCode = $"JYHB{(string.IsNullOrEmpty(productPlanDto.MaterialCode) ? "000000000" : productPlanDto.MaterialCode)}-{orFlag.ToString().PadLeft(6,'0')}"; - } - } + // barCode = $"JYHB{(string.IsNullOrEmpty(productPlanDto.MaterialCode) ? "000000000" : productPlanDto.MaterialCode)}-{orFlag.ToString().PadLeft(6,'0')}"; + // } + //} - RealBarCodeTask barCodeTask = new RealBarCodeTask() - { - BarCode = barCode, - PlanCode = productPlanDto.PlanCode, - MaterialCode = productPlanDto.MaterialCode, - RecordTime = DateTime.Now - }; - _barCodeTaskService.InsertBarCodeTask(barCodeTask); - - RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks); + //RealBarCodeTask barCodeTask = new RealBarCodeTask() + //{ + // BarCode = barCode, + // PlanCode = productPlanDto.PlanCode, + // MaterialCode = productPlanDto.MaterialCode, + // RecordTime = DateTime.Now + //}; + //_barCodeTaskService.InsertBarCodeTask(barCodeTask); + + //RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks); } catch (Exception ex) { @@ -157,11 +153,7 @@ namespace SlnMesnac.Business } } - public void RemoveBarCode(string barCode) - { - _barCodeTaskService.RemoveBarCodeTask(barCode); - RefreshBarCodeTaskListEvent?.Invoke(_barCodeTasks ); - } + //public void testPenCode() diff --git a/SlnMesnac.Business/ProdMgmtBusiness.cs b/SlnMesnac.Business/ProdMgmtBusiness.cs index 2b0483b..f289814 100644 --- a/SlnMesnac.Business/ProdMgmtBusiness.cs +++ b/SlnMesnac.Business/ProdMgmtBusiness.cs @@ -60,6 +60,8 @@ namespace SlnMesnac.Business public readonly IBasePalletInfoService _basePalletInfoService; + public readonly IMesPrdBarCodeService _mesPrdBarCodeService; + public readonly IBaseRealTaskService _baseRealTaskService; public readonly IWmsOutStockService _wmsOutStockService; @@ -67,26 +69,47 @@ namespace SlnMesnac.Business private readonly ConfigInfoBusiness _configInfoBusiness; - private List _palletTasks; + private ISqlSugarClient sqlSugarClient; private DebugConfig debugConfig = DebugConfig.Instance; - public ProdMgmtBusiness(ISqlSugarClient _sqlSugarClient, IWmsOutStockService wmsOutStockService, ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, List palletTasks, IServiceProvider serviceProvider, ConfigInfoBusiness configInfoBusiness) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) + public ProdMgmtBusiness(ISqlSugarClient _sqlSugarClient, IWmsOutStockService wmsOutStockService, ILogger logger, AppConfig appConfig, List plcFactories, List rfidFactories, IMesProductPlanService mesProductPlanService, IBasePalletInfoService basePalletInfoService, IBaseRealTaskService baseRealTaskService, IServiceProvider serviceProvider, ConfigInfoBusiness configInfoBusiness) : base(logger, appConfig, plcFactories, rfidFactories, serviceProvider) { - + sqlSugarClient = _sqlSugarClient; _wmsOutStockService = wmsOutStockService; _mesProductPlanService = mesProductPlanService; _basePalletInfoService = basePalletInfoService; _baseRealTaskService = baseRealTaskService; - _palletTasks = palletTasks; - _configInfoBusiness =configInfoBusiness; - // testTran(); + _mesPrdBarCodeService = serviceProvider.GetRequiredService(); + + _configInfoBusiness = configInfoBusiness; + } - public async void testTran() + public void TestTran() { + try + { + sqlSugarClient.AsTenant().BeginTran(); + BaseRealTask localPlan = _baseRealTaskService.GetExeTask(); + localPlan.Status = 2; + sqlSugarClient.AsTenant().GetConnection("local").Updateable(localPlan).ExecuteCommand(); + GenerateBarcode(10); + // throw new Exception("事务测试"); + sqlSugarClient.AsTenant().CommitTran(); + Console.WriteLine("提交事务"); + } + catch (Exception ex) + { + sqlSugarClient.AsTenant().RollbackTran(); + Console.WriteLine(ex.Message); + } + } + + private async void testRFID() + { //TcpClient tcpClient = new TcpClient(); //var waitClient = tcpClient.CreateWaitingClient(new WaitingOptions() @@ -350,38 +373,40 @@ namespace SlnMesnac.Business //} #endregion + if (prodPlan != null) + { + // 下发翻转信号 + plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), true); + Thread.Sleep(300); + plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), false); + + + sqlSugarClient.AsTenant().BeginTran(); + //1.完成本地计划 + if (localPlan != null) + { + localPlan.Status = 2; + localPlan.UpdateTime = DateTime.Now; + sqlSugarClient.AsTenant().GetConnection("local").Updateable(localPlan).ExecuteCommand(); + } + //2.生成小包条码 + GenerateBarcode(40); + //3.清空投料系统运行时间 + BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "拆包机系统运行时长").FirstOrDefault(); + configInfo.ConfigValue = "0"; + _configInfoBusiness.UpdateConfigInfo(configInfo); + + sqlSugarClient.AsTenant().CommitTran(); + } + } catch (Exception e) { - _logger.LogInformation($"投料校验异常:{e.Message}"); + sqlSugarClient.AsTenant().RollbackTran(); + _logger.LogInformation($"投料流程异常:{e.Message}"); Thread.Sleep(5000); - continue; - // TODO修改成传入本地计划查询出的mes计划 - // result = MatPutInValidTriggerEvent(2, prodPlan, string.Empty, $"投料校验异常:{e.Message},是否继续投料"); - } - if (prodPlan != null) - { - // 下发翻转信号 - plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), true); - Thread.Sleep(300); - plc.writeBoolByAddress(GetPlcAddressByConfigKey("设备投料"), false); - - #region 清空投料系统运行时间 - BaseConfigInfo configInfo = _configInfoBusiness.GetConfigInfos().Where(x => x.ConfigKey == "拆包机系统运行时长").FirstOrDefault(); - configInfo.ConfigValue = "0"; - _configInfoBusiness.UpdateConfigInfo(configInfo); - #endregion - - //在小包2楼绑定托盘时完成计划 - // PutInResutlHandle(prodPlan, result); - // 完成本地计划 - if (localPlan != null) - { - localPlan.Status = 2; - localPlan.UpdateTime = DateTime.Now; - _baseRealTaskService.Update(localPlan); - } + } Thread.Sleep(3000); @@ -474,6 +499,28 @@ namespace SlnMesnac.Business return result; } + + + /// + /// 投料后产生小包条码存储到数据库等待绑定 + /// + private void GenerateBarcode(int amount) + { + List list = new List(); + string baseDate = DateTime.Now.ToString("yyyyMMddHHmm"); // 当前日期和时间到分钟 + for (int i = 1; i <= amount; i++) + { + MesPrdBarcodeInfo record = new MesPrdBarcodeInfo(); + record = new MesPrdBarcodeInfo(); + record.PrdBarcodeInfo = baseDate + i.ToString("D3"); // 将序号格式化为三位数 + record.PrintFlag = "0"; + record.CreatTime = DateTime.Now; + list.Add(record); + } + sqlSugarClient.AsTenant().GetConnection("mes").Insertable(list).ExecuteCommand(); + } + + /// /// 更新生产计划 /// diff --git a/SlnMesnac.Business/base/BaseBusiness.cs b/SlnMesnac.Business/base/BaseBusiness.cs index d1552bd..812b9de 100644 --- a/SlnMesnac.Business/base/BaseBusiness.cs +++ b/SlnMesnac.Business/base/BaseBusiness.cs @@ -64,10 +64,8 @@ namespace SlnMesnac.Business.@base private IServiceProvider _serviceProvider; #region 本地缓存信息 - private List palletTasks; - - private List barCodeTasks; - + + private List baseConfigInfos; @@ -93,9 +91,7 @@ namespace SlnMesnac.Business.@base { baseConfigInfos = scope.ServiceProvider.GetRequiredService>(); - palletTasks = scope.ServiceProvider.GetRequiredService>(); - - barCodeTasks = scope.ServiceProvider.GetRequiredService>(); + } } @@ -219,50 +215,7 @@ namespace SlnMesnac.Business.@base } - /// - /// 通过托盘队列获取托盘信息 - /// - /// - /// - public string GetPalletInfoByTask() - { - try - { - if (palletTasks.Count == 0) - { - throw new ArgumentNullException("通过托盘队列获取托盘信息异常:托盘队列为空"); - } - - return palletTasks.OrderBy(x=>x.RecordTime).First().PalletCode; - } - catch (Exception ex) - { - throw new InvalidOperationException($"通过托盘队列获取托盘信息异常:{ex.Message}"); - } - } - - /// - /// 通过条码队列获取条码信息 - /// - /// - /// - public string GetBarCodeByTask() - { - try - { - if (barCodeTasks.Count == 0) - { - throw new ArgumentNullException("通过条码队列获取条码信息异常:托盘队列为空"); - } - - return barCodeTasks.OrderBy(x => x.RecordTime).First().BarCode; - } - catch (Exception ex) - { - throw new InvalidOperationException($"通过条码队列获取条码信息异常:{ex.Message}"); - } - } - + /// /// 根据configKey获取PLC地址 /// diff --git a/SlnMesnac.Extensions/SqlsugarSetup.cs b/SlnMesnac.Extensions/SqlsugarSetup.cs index 71d641b..5a5c1b7 100644 --- a/SlnMesnac.Extensions/SqlsugarSetup.cs +++ b/SlnMesnac.Extensions/SqlsugarSetup.cs @@ -83,25 +83,8 @@ namespace SlnMesnac.Extensions return info; }); - //缓存托盘队列 - services.AddSingleton>(x => - { - var service = x.GetService(); - - var info = service.Query(); - - return info; - }); - - //缓存条码队列 - services.AddSingleton>(x => - { - var service = x.GetService(); - - var info = service.Query(); - - return info; - }); + + } } } diff --git a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs index c9c8a01..1d969d5 100644 --- a/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs +++ b/SlnMesnac.WPF/Page/DevMonitorPage.xaml.cs @@ -126,18 +126,18 @@ namespace SlnMesnac.WPF.Page RefreshMagNet(); RefreshSpiral(); RefreshHot(); - RefreshUnPack(); - - App.Current.Dispatcher.BeginInvoke((Action)(() => - { - BagsAmountTxt.Text = _configInfoBusiness.GetConfigInfos().FirstOrDefault(x => x.ConfigKey == "包装袋余量").ConfigValue; - })); + RefreshUnPack(); } else { _logger.LogError($"设备监听启动失败;PLC连接失败!"); Thread.Sleep(1000 * 30); } + + App.Current.Dispatcher.BeginInvoke((Action)(() => + { + BagsAmountTxt.Text = _configInfoBusiness.GetConfigInfos().FirstOrDefault(x => x.ConfigKey == "包装袋余量").ConfigValue; + })); } catch (Exception ex) { @@ -161,48 +161,53 @@ namespace SlnMesnac.WPF.Page { try { - float cacheWeigh = plc.readFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("缓存区重量")); - recipeManageCache.BufferWeight = cacheWeigh; - if (recipeManageCache.RecipeMode == "自动模式") + if (plc != null) { - bool unPackStatus1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态")); - bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1状态")); - bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2状态")); - int signal1_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋状态")); - - if (signal1_1 == 1 && signal2 && signal3 && unPackStatus1) // 1.设备都已经启动 + float cacheWeigh = plc.readFloatByAddress(baseBusiness.GetPlcAddressByConfigKey("缓存区重量")); + recipeManageCache.BufferWeight = cacheWeigh; + if (recipeManageCache.RecipeMode == "自动模式") { - // 1.判断缓存区重量是否满足配方要求 - RecipeManage targetRecipe = null; - int result = JudgeCacheWeighIsOk(cacheWeigh, out targetRecipe); - switch (result) + bool unPackStatus1 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("拆包机系统运行状态")); + bool signal2 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋1状态")); + bool signal3 = plc.readBoolByAddress(baseBusiness.GetPlcAddressByConfigKey("螺旋2状态")); + int signal1_1 = plc.readByteByAddress(baseBusiness.GetPlcAddressByConfigKey("烘干机螺旋状态")); + + if (signal1_1 == 1 && signal2 && signal3 && unPackStatus1) // 1.设备都已经启动 { - case -1: - // TODO添加报警记录推送 - break; - case 0: break; - - case 1: - // 高切低 - HighToLowSpeed(targetRecipe); - break; - case 2: - // 低切高 - LowToHighSpeed(targetRecipe); - break; - default: break; - } + // 1.判断缓存区重量是否满足配方要求 + RecipeManage targetRecipe = null; + int result = JudgeCacheWeighIsOk(cacheWeigh, out targetRecipe); + switch (result) + { + case -1: + // TODO添加报警记录推送 + break; + case 0: break; + + case 1: + // 高切低 + HighToLowSpeed(targetRecipe); + break; + case 2: + // 低切高 + LowToHighSpeed(targetRecipe); + break; + default: break; + } + } } + } - Thread.Sleep(1000 * 10); + } catch (Exception ex) { _logger.LogError($"监测缓存区重量,动态调整配方频率StartAdjustRecipe异常:{ex.Message}"); } + Thread.Sleep(1000 * 10); } }); } diff --git a/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs b/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs index 2f7be61..afccf71 100644 --- a/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs @@ -49,18 +49,17 @@ namespace SlnMesnac.WPF.ViewModel DeletePalletCommand = new RelayCommand(DeletePallet); - DeleteBarCodeCommand = new RelayCommand (DeleteBarCode); + // DeleteBarCodeCommand = new RelayCommand (DeleteBarCode); - var palletTask = App.ServiceProvider.GetService>(); + - RefreshPalletTaskDataGrid(palletTask); + _palletStowBusiness.RefreshPalletTaskListEvent += RefreshPalletTaskDataGrid; - var barCodeTasks = App.ServiceProvider.GetService>(); - RefreshBarCodeTaskDataGrid(barCodeTasks); + - _prodCompletionBusiness.RefreshBarCodeTaskListEvent += RefreshBarCodeTaskDataGrid; + } #region 参数定义 @@ -79,9 +78,9 @@ namespace SlnMesnac.WPF.ViewModel /// /// 条码队列DataGrid /// - private ObservableCollection barCodeTaskDataGrid; + private ObservableCollection barCodeTaskDataGrid; - public ObservableCollection BarCodeTaskDataGrid + public ObservableCollection BarCodeTaskDataGrid { get { return barCodeTaskDataGrid; } set { barCodeTaskDataGrid = value; RaisePropertyChanged(() => BarCodeTaskDataGrid); } @@ -110,18 +109,18 @@ namespace SlnMesnac.WPF.ViewModel } } - /// - /// 刷新条码队列信息 - /// - /// - private void RefreshBarCodeTaskDataGrid(List barCodeTasks) - { - BarCodeTaskDataGrid = new ObservableCollection(); - foreach (var task in barCodeTasks) - { - BarCodeTaskDataGrid.Add(task); - } - } + ///// + ///// 刷新条码队列信息 + ///// + ///// + //private void RefreshBarCodeTaskDataGrid(List barCodeTasks) + //{ + // BarCodeTaskDataGrid = new ObservableCollection(); + // foreach (var task in barCodeTasks) + // { + // BarCodeTaskDataGrid.Add(task); + // } + //} /// /// 移除托盘队列信息 @@ -132,13 +131,13 @@ namespace SlnMesnac.WPF.ViewModel _palletStowBusiness.RemovePalletInfo(palletCode); } - /// - /// 移除小包条码队列信息 - /// - /// - private void DeleteBarCode(string barCode) - { - _prodCompletionBusiness.RemoveBarCode(barCode); - } + ///// + ///// 移除小包条码队列信息 + ///// + ///// + //private void DeleteBarCode(string barCode) + //{ + // _prodCompletionBusiness.RemoveBarCode(barCode); + //} } }