From 04237b6b7c5fb17f20417c26dc09b2389f1316d3 Mon Sep 17 00:00:00 2001 From: liuwf Date: Tue, 2 Jan 2024 12:33:06 +0800 Subject: [PATCH] change. --- .../Business/CollectionFoamMachine.cs | 28 ++++++++++++++----- .../ViewModels/FoamMachinesPageViewModel.cs | 5 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs b/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs index 07943210..63892959 100644 --- a/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs +++ b/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs @@ -4,7 +4,7 @@ using Admin.Core.Model; using Aucma.Core.BoxFoam.Models; using Aucma.Core.BoxFoam.ViewModels; using Aucma.Core.HwPLc; - +using Microsoft.Extensions.DependencyInjection; using NetTaste; using NPOI.Util; using System; @@ -50,6 +50,10 @@ namespace Aucma.Core.BoxFoam.Business // 系统参数 Dictionary systemKeys = new Dictionary(); Semaphore semaphore = new Semaphore(1, 1); + + private readonly IBoxLastShotRecordServices? _lastShotRecordServices = App.ServiceProvider.GetService(); + + public CollectionFoamMachine() { startCollect(); @@ -77,19 +81,29 @@ namespace Aucma.Core.BoxFoam.Business ReadGunData(obj, "DB50.1460", gunKeys,"B2"); //A2枪数据 RefreshSystemDataDelegateEvent?.Invoke(systemKeys); RefreshGunDataDelegateEvent?.Invoke(gunKeys); + + foreach (KeyValuePair kvPair in gunKeys) { + //程序启动缓存没数据查数据库 if (!tempKeys.ContainsKey(kvPair.Key)) - { + { + BoxLastShotRecord record = _lastShotRecordServices.Query(x => x.System == kvPair.Value.System && x.ProductLineCode == kvPair.Value.ProductLineCode && x.GunCode == kvPair.Value.GunCode).OrderByDescending(x => x.CreateTime).FirstOrDefault(); + if (record == null) { + // 数据库也没数据 + int a = _lastShotRecordServices.AddAsync(kvPair.Value).Result; RefreshLastShotDataDelegateEvent?.Invoke(kvPair.Value); - + continue; + } + tempKeys.Add(kvPair.Key, record); } - // 关枪时间不同 - else if(!kvPair.Value.MixpistOff.Equals(tempKeys[kvPair.Key].MixpistOff)) + if (!kvPair.Value.MixpistOff.Equals(tempKeys[kvPair.Key].MixpistOff)) { + int b=_lastShotRecordServices.AddAsync(kvPair.Value).Result; RefreshLastShotDataDelegateEvent?.Invoke(kvPair.Value); } - + + } } @@ -190,7 +204,7 @@ namespace Aucma.Core.BoxFoam.Business BoxLastShotRecord lastShotRecord = new BoxLastShotRecord(); lastShotRecord.System = gunCode.Substring(1, 1); lastShotRecord.GunCode = gunCode; - lastShotRecord.ProductLineCode = ""; + lastShotRecord.ProductLineCode = "CX_02"; lastShotRecord.PolTemp = byteToFloat(info.Skip(0).Take(4).ToArray()).ToString(); lastShotRecord.PolHp = byteToFloat(info.Skip(4).Take(4).ToArray()).ToString(); diff --git a/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs index 32ae720b..389c4c2a 100644 --- a/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs @@ -27,7 +27,7 @@ namespace Aucma.Core.BoxFoam.ViewModels CollectionFoamMachine.RefreshGunDataDelegateEvent += RefreshGunData; CollectionFoamMachine.RefreshSystemDataDelegateEvent += RefreshSystemData; _boxLastShotRecordServices = App.ServiceProvider.GetService(); - + LoadData(); //Task.WaitAll(LoadData()); } @@ -215,7 +215,7 @@ namespace Aucma.Core.BoxFoam.ViewModels int i = 1; var list = await _boxLastShotRecordServices.QueryAsync(); if (list == null) return; - list.OrderByDescending(d => d.CreateTime).Take(50); + list.OrderByDescending(d => d.CreateTime).Take(30); foreach (var item in list) { string system = string.Empty; @@ -239,6 +239,7 @@ namespace Aucma.Core.BoxFoam.ViewModels model.IsoInjectiontemperature = item.IsoTemp; model.LastTime = item.CreateTime; model.Createtime = item.CreateTime; + model.StationNumber = item.PourNu; LastShotRecordDataGrid.Insert(0,model); } }));