From 1cfbfec6444226e26eb6f1027ceed2cdcdcd64c0 Mon Sep 17 00:00:00 2001 From: wenjy Date: Mon, 8 Jan 2024 16:18:56 +0800 Subject: [PATCH] =?UTF-8?q?add=20-=20=E6=96=B0=E7=AE=B1=E4=BD=93=E5=8F=91?= =?UTF-8?q?=E6=B3=A1=E6=B7=BB=E5=8A=A0=E7=8F=AD=E7=BB=84=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/TeamSwitchBusiness.cs | 288 ++++++++++++++++++ .../ViewModels/MainWindowViewModel.cs | 5 + 2 files changed, 293 insertions(+) create mode 100644 Aucma.Core.BoxFoam/Business/TeamSwitchBusiness.cs diff --git a/Aucma.Core.BoxFoam/Business/TeamSwitchBusiness.cs b/Aucma.Core.BoxFoam/Business/TeamSwitchBusiness.cs new file mode 100644 index 00000000..0e46dbec --- /dev/null +++ b/Aucma.Core.BoxFoam/Business/TeamSwitchBusiness.cs @@ -0,0 +1,288 @@ +using Admin.Core.IService; +using Admin.Core.Model; +using Aucma.Core.HwPLc; +using log4net; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Timers; + +namespace Aucma.Core.BoxFoam.Business +{ + /// + /// 班组信息切换 + /// + public class TeamSwitchBusiness + { + private readonly log4net.ILog log = LogManager.GetLogger(typeof(TeamSwitchBusiness)); + + private readonly IBoxFoamPlanServices _boxFoamPlanServices; + private readonly IBoxFoamDataServices _oldBoxFoamDataServices; + private readonly IBoxFoamDataRecordServices _boxFoamDataRecordServices; + public TeamSwitchBusiness() + { + _boxFoamPlanServices = App.ServiceProvider.GetService(); + + _oldBoxFoamDataServices = App.ServiceProvider.GetService(); + + _boxFoamDataRecordServices = App.ServiceProvider.GetService(); + } + + public void Init() + { + + DayShiftInfoCut(); + NightShiftInfoCut(); + } + + /// + /// 白班信息切换 + /// + private void DayShiftInfoCut() + { + DateTime now = DateTime.Now; + + DateTime scheduledTime = new DateTime(now.Year, now.Month, now.Day, 08, 00, 00); + + if (now > scheduledTime) + { + scheduledTime = scheduledTime.AddDays(1); + } + TimeSpan timeToGo = scheduledTime - now; + int dueTime = (int)timeToGo.TotalMilliseconds; + + System.Timers.Timer timer = new System.Timers.Timer(); + timer.Elapsed += DayShiftTimerCallback; + timer.AutoReset = true; + timer.Interval = dueTime; + timer.Start(); + } + + private void DayShiftTimerCallback(object sender, ElapsedEventArgs e) + { + Console.WriteLine("切换为白班!"); + + UpdateShiftInfo(1); + + #region 重新定义Timer,进行第二天执行 + DateTime now = DateTime.Now; + + DateTime scheduledTime = new DateTime(now.Year, now.Month, now.Day, 08, 00, 00); + + if (now > scheduledTime) + { + scheduledTime = scheduledTime.AddDays(1); + } + + TimeSpan timeToGo = scheduledTime - now; + int dueTime = (int)timeToGo.TotalMilliseconds; + + System.Timers.Timer timer = (System.Timers.Timer)sender; + timer.Elapsed += DayShiftTimerCallback; + timer.AutoReset = true; + timer.Interval = dueTime; + timer.Start(); + #endregion + } + + /// + /// 夜班班组切换 + /// + private void NightShiftInfoCut() + { + DateTime now = DateTime.Now; + + DateTime scheduledTime = new DateTime(now.Year, now.Month, now.Day, 20, 00, 00); + + if (now > scheduledTime) + { + scheduledTime = scheduledTime.AddDays(1); + } + TimeSpan timeToGo = scheduledTime - now; + int dueTime = (int)timeToGo.TotalMilliseconds; + + System.Timers.Timer timer = new System.Timers.Timer(); + timer.Elapsed += NightShiftTimerCallback; + timer.AutoReset = true; + timer.Interval = dueTime; + timer.Start(); + } + + private void NightShiftTimerCallback(object sender, ElapsedEventArgs e) + { + Console.WriteLine("切换为夜班!"); + + UpdateShiftInfo(2); + + #region 重新定义Timer,进行第二天执行 + DateTime now = DateTime.Now; + + DateTime scheduledTime = new DateTime(now.Year, now.Month, now.Day, 20, 00, 00); + + if (now > scheduledTime) + { + scheduledTime = scheduledTime.AddDays(1); + } + + TimeSpan timeToGo = scheduledTime - now; + int dueTime = (int)timeToGo.TotalMilliseconds; + + System.Timers.Timer timer = (System.Timers.Timer)sender; + timer.Elapsed += NightShiftTimerCallback; + timer.AutoReset = true; + timer.Interval = dueTime; + timer.Start(); + #endregion + } + + /// + /// 班组切换 + /// + /// 班组类型:1-白班;2-夜班 + private void UpdateShiftInfo(int shiftType) + { + log.Warn($"{(shiftType == 1 ? "白班" : "夜班")}班组切换,开始处理切换逻辑"); + try + { + //下发PLC清空产量信号 + #region 清空PLC产量,新线暂时未清除产量,如需清除可将注释取消 + //var obj1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); + //if (obj1 != null) + //{ + // if (obj1.plc.IsConnected) + // { + // var flag = obj1.plc.WriteInt16("M216", "1");//换班 数据清空 + // log.Warn($"班组切换清空A区产量数据:{(flag == true ? "成功" : "失败")}"); + // } + //} + //var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); + //if (obj2 != null) + //{ + // if (obj2.plc.IsConnected) + // { + // bool flag = obj2.plc.WriteInt16("M216", "1");//换班 数据清空 + // log.Warn($"班组切换清空B区产量数据:{(flag == true ? "成功" : "失败")}"); + // } + //} + //var obj3 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3")); + //if (obj3 != null) + //{ + // if (obj3.plc.IsConnected) + // { + // var flag = obj3.plc.WriteInt16("M216", "1");//换班 数据清空 + // log.Warn($"班组切换清空C区产量数据:{(flag == true ? "成功" : "失败")}"); + // } + //} + //var obj4 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc4")); + //if (obj4 != null) + //{ + // if (obj4.plc.IsConnected) + // { + // var flag = obj4.plc.WriteInt16("M216", "1");//换班 数据清空 + // log.Warn($"班组切换清空D区产量数据:{(flag == true ? "成功" : "失败")}"); + // } + //} + #endregion + + //小时统计报表数据存至记录表,清空小时统计报表 + + var hourDataList = _oldBoxFoamDataServices.Query(x => x.ProductLineCode == "CX_02" && x.StationCode == "1005"); + List hourRecordList = new List(); + if (hourDataList != null) + { + foreach (var item in hourDataList) + { + BoxFoamDataRecord hourRecord = new BoxFoamDataRecord(); + hourRecord.OrderCode = item.OrderCode; + hourRecord.ProductLineCode = item.ProductLineCode; + hourRecord.Fixturestatus = item.Production; + hourRecord.CuringTimeSettingValue = item.CuringTimeSettingValue; + hourRecord.ActualValue = item.ActualValue; + hourRecord.AnHour = item.AnHour; + hourRecord.TwoHour = item.TwoHour; + hourRecord.ThreeHour = item.ThreeHour; + hourRecord.FourHour = item.FourHour; + hourRecord.FiveHour = item.FiveHour; + hourRecord.SixHour = item.SixHour; + hourRecord.SevenHour = item.SevenHour; + hourRecord.EightHour = item.EightHour; + hourRecord.NineHour = item.NineHour; + hourRecord.TenHour = item.TenHour; + hourRecord.ElevenHour = item.ElevenHour; + hourRecord.TwelveHour = item.TwelveHour; + hourRecord.BoxFixturesideplate = item.BoxFixturesideplate; + hourRecord.BoxClosebetatemperature = item.BoxClosebetatemperature; + hourRecord.BoxBeat = item.BoxBeat; + hourRecord.CreateTime = DateTime.Now; + hourRecordList.Add(hourRecord); + + bool deleteFlag = _oldBoxFoamDataServices.DeleteAsync(item).Result; + if (deleteFlag) + { + log.Warn($"{item.Fixtureboxtype}:小时数据清除成功"); + } + else + { + log.Warn($"{item.Fixtureboxtype}:小时数据清除失败"); + } + } + } + int addFlag = _boxFoamDataRecordServices.AddAsync(hourRecordList).Result; + if (addFlag > 0) + { + log.Warn("班组切换小时数据记录保存成功"); + } + else + { + log.Warn("班组切换小时数据记录保存失败"); + } + //当班计划,班组计划设为0 + var planInfoList = _boxFoamPlanServices.QueryAsync(x => x.ProductLineCode == "CX_02" && x.StationCode == "1005").Result; + + if (planInfoList != null) + { + foreach (var plan in planInfoList) + { + if (plan.PlanAmount > plan.CompleteAmount) + { + plan.PlanAmount = plan.PlanAmount - plan.CompleteAmount; + plan.CompleteAmount = 0; + plan.ShiftType = 1; + + int saveFlag = _boxFoamPlanServices.AddAsync(plan).Result; + if (saveFlag > 0) + { + log.Warn($"计划:{plan.OrderCode},剩余计划:{plan.PlanAmount},未完成进行顺延,执行成功"); + } + else + { + log.Warn($"计划:{plan.OrderCode},剩余计划:{plan.PlanAmount},未完成进行顺延,执行失败"); + } + } + else + { + plan.ShiftType = 0; + + bool updateFlag = _boxFoamPlanServices.UpdateAsync(plan).Result; + if (updateFlag) + { + log.Warn($"计划:{plan.OrderCode},班组切换标识更新成功"); + } + else + { + log.Warn($"计划:{plan.OrderCode},班组切换标识更新失败"); + } + } + } + } + } + catch (Exception ex) + { + log.Warn($"{(shiftType == 1 ? "白班" : "夜班")}班组切换,切换逻辑处理异常:{ex.Message}"); + } + } + } +} diff --git a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs index 411e44fb..e494d270 100644 --- a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs @@ -28,6 +28,8 @@ namespace Aucma.Core.BoxFoam.ViewModels MonitorPageView monitorPage = new MonitorPageView();//任务监控 FoamMachinesPageView foamMachinesPageView = new FoamMachinesPageView(); + + public MainWindowViewModel() { UserContent = firstPage; @@ -35,6 +37,9 @@ namespace Aucma.Core.BoxFoam.ViewModels { init(); }); + + TeamSwitchBusiness teamSwitchBusiness = new TeamSwitchBusiness(); + teamSwitchBusiness.Init(); } public Task init()