From 2e5c1123229e6e4e61eff49e389bdbd27502557b Mon Sep 17 00:00:00 2001 From: liuwf Date: Mon, 11 Dec 2023 16:09:57 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E7=8A=B6=E6=80=81=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E8=B0=83=E5=BA=A6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Admin.Core.Tasks/Admin.Core.Tasks.csproj | 1 + .../QuartzNet/Jobs/Job_AllState_Quartz.cs | 67 ++++++++++++++++ Aucma.Core.CodeBinding/Startup.cs | 7 +- .../ViewModels/MainWindowViewModel.cs | 80 +++++-------------- Aucma.Core.CodeBinding/appsettings.json | 6 +- 5 files changed, 93 insertions(+), 68 deletions(-) create mode 100644 Admin.Core.Tasks/QuartzNet/Jobs/Job_AllState_Quartz.cs diff --git a/Admin.Core.Tasks/Admin.Core.Tasks.csproj b/Admin.Core.Tasks/Admin.Core.Tasks.csproj index 7f26dc15..4575ef40 100644 --- a/Admin.Core.Tasks/Admin.Core.Tasks.csproj +++ b/Admin.Core.Tasks/Admin.Core.Tasks.csproj @@ -13,6 +13,7 @@ + diff --git a/Admin.Core.Tasks/QuartzNet/Jobs/Job_AllState_Quartz.cs b/Admin.Core.Tasks/QuartzNet/Jobs/Job_AllState_Quartz.cs new file mode 100644 index 00000000..2e128a96 --- /dev/null +++ b/Admin.Core.Tasks/QuartzNet/Jobs/Job_AllState_Quartz.cs @@ -0,0 +1,67 @@ +using Admin.Core.Common; +using Admin.Core.IService; +using Admin.Core.IService.ISys; +using Admin.Core.Model; +using Admin.Core.Service; +using Aucma.Core.PLc; +using Aucma.Core.Scanner; +using log4net; +using NetTaste; +using NPOI.SS.Formula.Functions; +using Quartz; +using System; +using System.Linq; +using System.Threading.Tasks; + +/// +///plc,数据库,扫码器状态刷新 +/// +namespace Admin.Core.Tasks +{ + public class Job_AllState_Quartz : JobBase, IJob + { + public delegate Task RefreshCodeBindingState(bool mesState, bool plcState, bool scanner1, bool scanner2); + public static event RefreshCodeBindingState RefreshCodeBindingStateEvent; + + private readonly IBaseServices baseServices; + public Job_AllState_Quartz(ISysTasksQzService SysTasksQzService, ISysJobLogService sysJobLogService,IBaseBomInfoServices baseBomInfoServices) + { + _SysTasksQzService = SysTasksQzService; + _sysJobLogService = sysJobLogService; + baseServices = baseBomInfoServices; + + + } + public async Task Execute(IJobExecutionContext context) + { + await ExecuteJob(context, async () => await Run()); + } + + #region plc,数据库,扫码器状态刷新 + public Task Run() + { + bool mesState; + bool plcState; + bool scanner1; + bool scanner2; + mesState = baseServices.GetConnectionState(); + var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); + if (obj != null && obj.plc.IsConnected) + { + plcState = true; + } + else + { + plcState = false; + } + string ip1 = Appsettings.app("Middleware", "Scanner1", "Ip"); + string ip2 = Appsettings.app("Middleware", "Scanner2", "Ip"); + scanner1 = MvCodeHelper.ConnectionStatus(ip1); + scanner2 = MvCodeHelper.ConnectionStatus(ip2); + //条码绑定上位机状态刷新 + RefreshCodeBindingStateEvent(mesState,plcState,scanner1,scanner2); + return Task.FromResult(0); + #endregion + } + } +} diff --git a/Aucma.Core.CodeBinding/Startup.cs b/Aucma.Core.CodeBinding/Startup.cs index 94d66e37..7d817c66 100644 --- a/Aucma.Core.CodeBinding/Startup.cs +++ b/Aucma.Core.CodeBinding/Startup.cs @@ -66,7 +66,7 @@ namespace Aucma.Core.CodeBinding services.AddScannerSetup(); // - // services.AddJobSetup(); + services.AddJobSetup(); //PLC services.AddPlcSetup(); //ֱ֧ȫ :֧ System.Text.Encoding.GetEncoding("GB2312") System.Text.Encoding.GetEncoding("GB18030") @@ -89,7 +89,7 @@ namespace Aucma.Core.CodeBinding /// /// /// - public void Configure(IApplicationBuilder app, IScannerService scannerService, IRunPlcService runPlcService) // ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter + public void Configure(IApplicationBuilder app, IScannerService scannerService, IRunPlcService runPlcService, ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter) // ISysTasksQzService tasksQzService, ISchedulerCenter schedulerCenter { // ʹþ̬ļ app.UseStaticFiles(); @@ -98,9 +98,10 @@ namespace Aucma.Core.CodeBinding //ɨ app.UseScannerMildd(scannerService); // QuartzNetJobȷ - // app.UseQuartzJobMildd(tasksQzService, schedulerCenter); + app.UseQuartzJobMildd(tasksQzService, schedulerCenter); //PLC app.UsePlcMildd(runPlcService); + } #region ע diff --git a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs index fc5dbf13..59cc27cc 100644 --- a/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.CodeBinding/ViewModels/MainWindowViewModel.cs @@ -18,6 +18,8 @@ using Admin.Core.IService; using Admin.Core.Service; using Microsoft.Extensions.DependencyInjection; using Admin.Core.Model; +using Admin.Core.Tasks; +using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData; namespace Aucma.Core.CodeBinding.ViewModels { @@ -38,23 +40,10 @@ namespace Aucma.Core.CodeBinding.ViewModels { UserContent = firstPage; + Job_AllState_Quartz.RefreshCodeBindingStateEvent += RefreshStatus; - MesDbState(false); - PlcState(true); - Scanner1State(true); - Scanner2State(true); - init(); } - public void init() - { - // 设备状态刷新定时器 - System.Timers.Timer timer = new System.Timers.Timer(1000 * 5); - timer.Elapsed += new System.Timers.ElapsedEventHandler(RefreshStatus); - timer.AutoReset = true; - timer.Enabled = true; - timer.Start(); - } #region 设备状态刷新 /// @@ -62,48 +51,15 @@ namespace Aucma.Core.CodeBinding.ViewModels /// /// /// - public void RefreshStatus(object sender, System.Timers.ElapsedEventArgs e) - { - RefreshMesDb(); - RefreshPlc(); - RefreshScanner(); - - } - /// - /// 数据库状态刷新 - /// - /// - /// - public void RefreshMesDb() - { - MesDbState(true); - } - - - /// - /// plc状态刷新 - /// - /// - /// - public void RefreshPlc() + public Task RefreshStatus(bool mesState,bool plcState,bool scanner1,bool scanner2) { - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); - if (obj != null) - { - if (obj.plc.IsConnected) - { - PlcState(true); - } - else - { - PlcState(false); - } - } - else - { - PlcState(false); - } + MesDbState(mesState); + PlcState(plcState); + Scanner1State(scanner1); + Scanner2State(scanner2); + return Task.CompletedTask; } + /// /// 扫码器状态刷新 /// @@ -264,13 +220,13 @@ namespace Aucma.Core.CodeBinding.ViewModels { if (type) { - MesDbUIStatusWb = "MES数据库连接成功"; + MesDbUIStatusWb = "MES数据库"; MesDbUIColor = "Green"; MesUIIcon = "Assets/Images/Green.png"; } else { - MesDbUIStatusWb = "MES数据库异常"; + MesDbUIStatusWb = "MES数据库"; MesDbUIColor = "Red"; MesUIIcon = "Assets/Images/Red.png"; } @@ -317,13 +273,13 @@ namespace Aucma.Core.CodeBinding.ViewModels { if (type) { - PlcUIStatusWb = "PLC连接成功"; + PlcUIStatusWb = "PLC状态"; PlcUIColor = "Green"; PlcUIIcon = "Assets/Images/Green.png"; } else { - PlcUIStatusWb = "PLC状态异常"; + PlcUIStatusWb = "PLC状态"; PlcUIColor = "Red"; PlcUIIcon = "Assets/Images/Red.png"; } @@ -376,13 +332,13 @@ namespace Aucma.Core.CodeBinding.ViewModels { if (type) { - Scanner1UIStatusWb = "扫码器1连接成功"; + Scanner1UIStatusWb = "扫码器1状态"; Scanner1UIColor = "Green"; Scanner1UIIcon = "Assets/Images/Green.png"; } else { - Scanner1UIStatusWb = "扫码器1状态异常"; + Scanner1UIStatusWb = "扫码器1状态"; Scanner1UIColor = "Red"; Scanner1UIIcon = "Assets/Images/Red.png"; } @@ -435,13 +391,13 @@ namespace Aucma.Core.CodeBinding.ViewModels { if (type) { - Scanner2UIStatusWb = "扫码器2连接成功"; + Scanner2UIStatusWb = "扫码器2状态"; Scanner2UIColor = "Green"; Scanner2UIIcon = "Assets/Images/Green.png"; } else { - Scanner2UIStatusWb = "扫码器2状态异常"; + Scanner2UIStatusWb = "扫码器2状态"; Scanner2UIColor = "Red"; Scanner2UIIcon = "Assets/Images/Red.png"; } diff --git a/Aucma.Core.CodeBinding/appsettings.json b/Aucma.Core.CodeBinding/appsettings.json index 5d51ac7f..d495c94e 100644 --- a/Aucma.Core.CodeBinding/appsettings.json +++ b/Aucma.Core.CodeBinding/appsettings.json @@ -101,13 +101,13 @@ "JobGroup": "DEFAULT", "Cron": "*/1 * * * * ?", "AssemblyName": "Admin.Core.Tasks", - "ClassName": "Job_Admin_Quartz", + "ClassName": "Job_AllState_Quartz", "Remark": "执行任务调度系统", "RunTimes": 3881, "BeginTime": "2023-04-23 11:08:50.000", - "EndTime": "2023-08-06 16:45:30.000", + "EndTime": "2080-12-01 16:45:30.000", "TriggerType": 1, - "IntervalSecond": 1, + "IntervalSecond": 5, "CycleRunTimes": 1, "IsStart": true, "JobParams": null,