From 09e5635e174d3ee6e8b699f7d0d4f125d3e1c46f Mon Sep 17 00:00:00 2001
From: lixiaojun <1287241240@qq.com>
Date: 星期一, 06 五月 2024 09:47:26 +0800
Subject: [PATCH] 修复运行分析bug

---
 Yw.Server.Run/01-equipment/02-single/EquipmentRunAnalySingleJob.cs   |  108 +++++++++++---------------
 Yw.TopShelf.Run/Properties/PublishProfiles/FolderProfile.pubxml.user |    2 
 Yw.TopShelf.Run/Program.cs                                           |   19 ++++
 Yw.Server.Run/02-emws/02-single/EMWSRunAnalySingleJob.cs             |  110 +++++++++++---------------
 4 files changed, 110 insertions(+), 129 deletions(-)

diff --git a/Yw.Server.Run/01-equipment/02-single/EquipmentRunAnalySingleJob.cs b/Yw.Server.Run/01-equipment/02-single/EquipmentRunAnalySingleJob.cs
index 968ffa3..9e6db6d 100644
--- a/Yw.Server.Run/01-equipment/02-single/EquipmentRunAnalySingleJob.cs
+++ b/Yw.Server.Run/01-equipment/02-single/EquipmentRunAnalySingleJob.cs
@@ -100,8 +100,8 @@
                         ObjectID = configure.ObjectID,
                         DataTime = DateTime.Now,
                         RSa = Yw.Run.RunStatus.Shut,
-                        ContinueTime = configure.Frequency,
-                        TotalShutTime = configure.Frequency,
+                        ContinueTime = 0,
+                        TotalShutTime = 0,
                         TotalRunTime = 0,
                         BootTimes = 0,
                         AnalyStatus = Yw.Run.AnalyStatus.Normal,
@@ -112,33 +112,6 @@
                     if (lastRunRecord == null)
                     {
                         runRecord.AnalyInfo = "棣栨鍒嗘瀽";
-                        if (lastRecord == null)
-                        {
-                            runRecord.AnalyStatus = Yw.Run.AnalyStatus.Missing;
-                        }
-                        else
-                        {
-                            if (Yw.Monitor.DataStatus.HasError(lastRecord.DataStatus))
-                            {
-                                runRecord.AnalyStatus = Yw.Run.AnalyStatus.Abnormal;
-                            }
-                            else
-                            {
-                                if (int.TryParse(lastRecord.DataValue, out int intDataValue))
-                                {
-                                    if (intDataValue > Yw.Monitor.RunStatus.Shut)
-                                    {
-                                        runRecord.RSa = Yw.Run.RunStatus.Run;
-                                        runRecord.BootTimes += 1;
-                                        runRecord.TotalRunTime += configure.Frequency;
-                                    }
-                                }
-                                else
-                                {
-                                    runRecord.AnalyStatus = Yw.Run.AnalyStatus.Error;
-                                }
-                            }
-                        }
                     }
                     else
                     {
@@ -147,49 +120,60 @@
                         runRecord.TotalShutTime = lastRunRecord.TotalShutTime;
                         runRecord.TotalRunTime = lastRunRecord.TotalRunTime;
                         runRecord.BootTimes = lastRunRecord.BootTimes;
+                    }
 
+                    var rsa = Yw.Run.RunStatus.Shut;
+                    if (lastRecord == null)
+                    {
+                        runRecord.AnalyStatus = Yw.Run.AnalyStatus.Missing;
+                    }
+                    else
+                    {
+                        if (Yw.Monitor.DataStatus.HasError(lastRecord.DataStatus))
+                        {
+                            runRecord.AnalyStatus = Yw.Run.AnalyStatus.Abnormal;
+                        }
+                        var enable_interrupt = Yw.Run.SysParas.EnableMonitorInterruptJudgement.GetPValue<bool?>();
+                        if (enable_interrupt.HasValue && enable_interrupt.Value)
+                        {
+                            if (monitor.IsInterrupt(lastRecord))
+                            {
+                                runRecord.AnalyStatus = Yw.Run.AnalyStatus.Interrupt;
+                            }
+                        }
+                        if (int.TryParse(lastRecord.DataValue, out int intDataValue))
+                        {
+                            rsa = intDataValue > Yw.Monitor.RunStatus.Shut ? Yw.Run.RunStatus.Run : Yw.Run.RunStatus.Shut;
+                        }
+                    }
+
+                    //鍙戠敓鏀瑰彉
+                    if (runRecord.RSa != rsa)
+                    {
                         if (EquipmentRunAnalyChangeTimesHelper.HasChanged(configure.ID, configure.ChangeTimes))
                         {
-                            runRecord.RSa = runRecord.RSa == Yw.Run.RunStatus.Run ? Yw.Run.RunStatus.Shut : Yw.Run.RunStatus.Run;
-                            runRecord.ContinueTime = configure.Frequency;
+                            runRecord.RSa = rsa;
+                            runRecord.ContinueTime = 0;
                             if (runRecord.RSa == Yw.Run.RunStatus.Run)
                             {
                                 runRecord.BootTimes += 1;
                             }
                         }
-                        else
-                        {
-                            runRecord.ContinueTime += configure.Frequency;
-                        }
+                    }
 
-                        if (runRecord.RSa == Yw.Run.RunStatus.Shut)
-                        {
-                            runRecord.TotalShutTime += configure.Frequency;
-                        }
-                        else
-                        {
-                            runRecord.TotalRunTime += configure.Frequency;
-                        }
+                    //鎸佺画鏃堕棿
+                    runRecord.ContinueTime += configure.Frequency;
 
-                        if (lastRecord == null)
-                        {
-                            runRecord.AnalyStatus = Yw.Run.AnalyStatus.Missing;
-                        }
-                        else
-                        {
-                            if (Yw.Monitor.DataStatus.HasError(lastRecord.DataStatus))
-                            {
-                                runRecord.AnalyStatus = Yw.Run.AnalyStatus.Abnormal;
-                            }
-                            var enable_interrupt = Yw.Run.SysParas.EnableMonitorInterruptJudgement.GetPValue<bool?>();
-                            if (enable_interrupt.HasValue && enable_interrupt.Value)
-                            {
-                                if (monitor.IsInterrupt(lastRecord))
-                                {
-                                    runRecord.AnalyStatus = Yw.Run.AnalyStatus.Interrupt;
-                                }
-                            }
-                        }
+                    //鎬诲叧鏈烘椂闂�
+                    if (runRecord.RSa == Yw.Run.RunStatus.Shut)
+                    {
+                        runRecord.TotalShutTime += configure.Frequency;
+                    }
+
+                    //鎬昏繍琛屾椂闂�
+                    if (runRecord.RSa == Yw.Run.RunStatus.Run)
+                    {
+                        runRecord.TotalRunTime += configure.Frequency;
                     }
 
                     #endregion
diff --git a/Yw.Server.Run/02-emws/02-single/EMWSRunAnalySingleJob.cs b/Yw.Server.Run/02-emws/02-single/EMWSRunAnalySingleJob.cs
index d0bb5d7..7f1ebbd 100644
--- a/Yw.Server.Run/02-emws/02-single/EMWSRunAnalySingleJob.cs
+++ b/Yw.Server.Run/02-emws/02-single/EMWSRunAnalySingleJob.cs
@@ -113,8 +113,8 @@
                         ObjectID = configure.ObjectID,
                         DataTime = DateTime.Now,
                         RSa = Yw.Run.RunStatus.Shut,
-                        ContinueTime = configure.Frequency,
-                        TotalShutTime = configure.Frequency,
+                        ContinueTime = 0,
+                        TotalShutTime = 0,
                         TotalRunTime = 0,
                         BootTimes = 0,
                         AnalyStatus = Yw.Run.AnalyStatus.Normal,
@@ -125,33 +125,6 @@
                     if (lastRunRecord == null)
                     {
                         runRecord.AnalyInfo = "棣栨鍒嗘瀽";
-                        if (lastRecord == null)
-                        {
-                            runRecord.AnalyStatus = Yw.Run.AnalyStatus.Missing;
-                        }
-                        else
-                        {
-                            if (Yw.Monitor.DataStatus.HasError(lastRecord.DataStatus))
-                            {
-                                runRecord.AnalyStatus = Yw.Run.AnalyStatus.Abnormal;
-                            }
-                            else
-                            {
-                                if (int.TryParse(lastRecord.DataValue, out int intDataValue))
-                                {
-                                    if (intDataValue > Yw.Monitor.RunStatus.Shut)
-                                    {
-                                        runRecord.RSa = Yw.Run.RunStatus.Run;
-                                        runRecord.BootTimes += 1;
-                                        runRecord.TotalRunTime += configure.Frequency;
-                                    }
-                                }
-                                else
-                                {
-                                    runRecord.AnalyStatus = Yw.Run.AnalyStatus.Error;
-                                }
-                            }
-                        }
                     }
                     else
                     {
@@ -160,49 +133,60 @@
                         runRecord.TotalShutTime = lastRunRecord.TotalShutTime;
                         runRecord.TotalRunTime = lastRunRecord.TotalRunTime;
                         runRecord.BootTimes = lastRunRecord.BootTimes;
+                    }
 
-                        if (EMWSRunAnalyChangeTimesHelper.HasChanged(configure.ID, configure.ChangeTimes))
+                    var rsa = Yw.Run.RunStatus.Shut;
+                    if (lastRecord == null)
+                    {
+                        runRecord.AnalyStatus = Yw.Run.AnalyStatus.Missing;
+                    }
+                    else
+                    {
+                        if (Yw.Monitor.DataStatus.HasError(lastRecord.DataStatus))
                         {
-                            runRecord.RSa = runRecord.RSa == Yw.Run.RunStatus.Run ? Yw.Run.RunStatus.Shut : Yw.Run.RunStatus.Run;
-                            runRecord.ContinueTime = configure.Frequency;
+                            runRecord.AnalyStatus = Yw.Run.AnalyStatus.Abnormal;
+                        }
+                        var enable_interrupt = Yw.Run.SysParas.EnableMonitorInterruptJudgement.GetPValue<bool?>();
+                        if (enable_interrupt.HasValue && enable_interrupt.Value)
+                        {
+                            if (monitor.IsInterrupt(lastRecord))
+                            {
+                                runRecord.AnalyStatus = Yw.Run.AnalyStatus.Interrupt;
+                            }
+                        }
+                        if (int.TryParse(lastRecord.DataValue, out int intDataValue))
+                        {
+                            rsa = intDataValue > Yw.Monitor.RunStatus.Shut ? Yw.Run.RunStatus.Run : Yw.Run.RunStatus.Shut;
+                        }
+                    }
+
+                    //鍙戠敓鏀瑰彉
+                    if (runRecord.RSa != rsa)
+                    {
+                        if (EquipmentRunAnalyChangeTimesHelper.HasChanged(configure.ID, configure.ChangeTimes))
+                        {
+                            runRecord.RSa = rsa;
+                            runRecord.ContinueTime = 0;
                             if (runRecord.RSa == Yw.Run.RunStatus.Run)
                             {
                                 runRecord.BootTimes += 1;
                             }
                         }
-                        else
-                        {
-                            runRecord.ContinueTime += configure.Frequency;
-                        }
+                    }
 
-                        if (runRecord.RSa == Yw.Run.RunStatus.Shut)
-                        {
-                            runRecord.TotalShutTime += configure.Frequency;
-                        }
-                        else
-                        {
-                            runRecord.TotalRunTime += configure.Frequency;
-                        }
+                    //鎸佺画鏃堕棿
+                    runRecord.ContinueTime += configure.Frequency;
 
-                        if (lastRecord == null)
-                        {
-                            runRecord.AnalyStatus = Yw.Run.AnalyStatus.Missing;
-                        }
-                        else
-                        {
-                            if (Yw.Monitor.DataStatus.HasError(lastRecord.DataStatus))
-                            {
-                                runRecord.AnalyStatus = Yw.Run.AnalyStatus.Abnormal;
-                            }
-                            var enable_interrupt = Yw.Run.SysParas.EnableMonitorInterruptJudgement.GetPValue<bool?>();
-                            if (enable_interrupt.HasValue && enable_interrupt.Value)
-                            {
-                                if (monitor.IsInterrupt(lastRecord))
-                                {
-                                    runRecord.AnalyStatus = Yw.Run.AnalyStatus.Interrupt;
-                                }
-                            }
-                        }
+                    //鎬诲叧鏈烘椂闂�
+                    if (runRecord.RSa == Yw.Run.RunStatus.Shut)
+                    {
+                        runRecord.TotalShutTime += configure.Frequency;
+                    }
+
+                    //鎬昏繍琛屾椂闂�
+                    if (runRecord.RSa == Yw.Run.RunStatus.Run)
+                    {
+                        runRecord.TotalRunTime += configure.Frequency;
                     }
 
                     #endregion
diff --git a/Yw.TopShelf.Run/Program.cs b/Yw.TopShelf.Run/Program.cs
index 27684c3..782ace5 100644
--- a/Yw.TopShelf.Run/Program.cs
+++ b/Yw.TopShelf.Run/Program.cs
@@ -16,13 +16,26 @@
 
 
 //SMI
+//HostFactory.Run(x =>
+//{
+//    x.Service<Service>();
+//    x.RunAsLocalSystem();
+//    x.SetDescription("鏅烘収娉电珯Core鐗堣繍琛屽垎鏋愮▼搴�(SMI)");
+//    x.SetDisplayName("IStation.Core.Server.Run.SMI");
+//    x.SetServiceName("IStation.Core.Server.Run.SMI");
+//    x.EnableServiceRecovery(r => r.RestartService(TimeSpan.FromSeconds(120)));
+//    x.StartAutomatically();
+//});
+
+
+//PHM
 HostFactory.Run(x =>
 {
     x.Service<Service>();
     x.RunAsLocalSystem();
-    x.SetDescription("鏅烘収娉电珯Core鐗堣繍琛屽垎鏋愮▼搴�(SMI)");
-    x.SetDisplayName("IStation.Core.Server.Run.SMI");
-    x.SetServiceName("IStation.Core.Server.Run.SMI");
+    x.SetDescription("鏅烘収娉电珯Core鐗堣繍琛屽垎鏋愮▼搴�(PHM)");
+    x.SetDisplayName("IStation.Core.Server.Run.PHM");
+    x.SetServiceName("IStation.Core.Server.Run.PHM");
     x.EnableServiceRecovery(r => r.RestartService(TimeSpan.FromSeconds(120)));
     x.StartAutomatically();
 });
diff --git a/Yw.TopShelf.Run/Properties/PublishProfiles/FolderProfile.pubxml.user b/Yw.TopShelf.Run/Properties/PublishProfiles/FolderProfile.pubxml.user
index 0e17420..1b4ca99 100644
--- a/Yw.TopShelf.Run/Properties/PublishProfiles/FolderProfile.pubxml.user
+++ b/Yw.TopShelf.Run/Properties/PublishProfiles/FolderProfile.pubxml.user
@@ -4,7 +4,7 @@
 -->
 <Project>
   <PropertyGroup>
-    <History>True|2024-04-26T05:38:39.5183442Z;False|2024-04-26T13:36:48.1771029+08:00;True|2024-04-04T16:12:48.6153997+08:00;</History>
+    <History>True|2024-05-04T13:41:10.0872570Z;True|2024-04-26T13:38:39.5183442+08:00;False|2024-04-26T13:36:48.1771029+08:00;True|2024-04-04T16:12:48.6153997+08:00;</History>
     <LastFailureDetails />
   </PropertyGroup>
 </Project>
\ No newline at end of file

--
Gitblit v1.9.3