From e98a74040590b68c187f8b42cd7adfb931d3d936 Mon Sep 17 00:00:00 2001 From: lxw Date: Wed, 5 Jun 2024 11:10:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=90=AF=E5=81=9C=E9=A3=8E?= =?UTF-8?q?=E6=89=87=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/BusinessTask/AbstractTaskHandler.cs | 32 -------- Service/Execute/StationSoftMgr.cs | 4 +- .../MyTask/BatteryMoveTask.cs | 8 +- Service/MyTask/FanChangeTask.cs | 74 +++++++++++++++++++ .../MyTask/SwapOrderReportCloudTask.cs | 2 +- Service/Plc/Client/PlcMgr.cs | 2 + 6 files changed, 79 insertions(+), 43 deletions(-) delete mode 100644 Service/BusinessTask/AbstractTaskHandler.cs rename Service/{BusinessTask => }/MyTask/BatteryMoveTask.cs (91%) create mode 100644 Service/MyTask/FanChangeTask.cs rename Service/{BusinessTask => }/MyTask/SwapOrderReportCloudTask.cs (96%) diff --git a/Service/BusinessTask/AbstractTaskHandler.cs b/Service/BusinessTask/AbstractTaskHandler.cs deleted file mode 100644 index 113c9a7..0000000 --- a/Service/BusinessTask/AbstractTaskHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Service.BusinessTask; - -public abstract class AbstractTaskHandler -{ - private volatile bool _stopFlag = false; - - public void Start() - { - Thread thread = new Thread(Process); - thread.IsBackground = true; - thread.Name = Name(); - thread.Start(); - } - - private void Process() - { - while (!_stopFlag) - { - Handle(); - Thread.Sleep(Interval()); - } - } - - protected abstract int Interval(); - protected abstract void Handle(); - protected abstract string Name(); - - public void Stop() - { - _stopFlag = true; - } -} \ No newline at end of file diff --git a/Service/Execute/StationSoftMgr.cs b/Service/Execute/StationSoftMgr.cs index 0206095..630568b 100644 --- a/Service/Execute/StationSoftMgr.cs +++ b/Service/Execute/StationSoftMgr.cs @@ -1,6 +1,4 @@ -using Service.BusinessTask; -using Service.BusinessTask.MyTask; - + namespace Service.Execute { /// diff --git a/Service/BusinessTask/MyTask/BatteryMoveTask.cs b/Service/MyTask/BatteryMoveTask.cs similarity index 91% rename from Service/BusinessTask/MyTask/BatteryMoveTask.cs rename to Service/MyTask/BatteryMoveTask.cs index 1d6c126..2662d2e 100644 --- a/Service/BusinessTask/MyTask/BatteryMoveTask.cs +++ b/Service/MyTask/BatteryMoveTask.cs @@ -1,19 +1,13 @@ -using Autofac; -using Entity.Constant; using Entity.DbModel.Station; -using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.AutoTask; using HybirdFrameworkCore.Entity; using log4net; using Repository.Station; -using Service.Execute; -using Service.Execute.Api; -using Service.Execute.Model; using Service.Plc.Client; using Service.Station; -namespace Service.BusinessTask.MyTask; +namespace Service.MyTask; /// /// 电池移仓任务 diff --git a/Service/MyTask/FanChangeTask.cs b/Service/MyTask/FanChangeTask.cs new file mode 100644 index 0000000..82ba3be --- /dev/null +++ b/Service/MyTask/FanChangeTask.cs @@ -0,0 +1,74 @@ +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; +using HybirdFrameworkCore.AutoTask; +using HybirdFrameworkCore.Entity; +using log4net; +using Repository.Station; +using Service.Plc.Client; +using Service.Station; + +namespace Service.MyTask; + +/// +/// 电池充电是风扇启停 +/// +[Scope] +public class FanChangeTask : ITask +{ + private static readonly ILog Log = LogManager.GetLogger(typeof(FanChangeTask)); + + + public BinInfoRepository _binInfoRepository { get; set; } + + + private volatile bool _stop; + + + public string Name() + { + return "FanChangeTask"; + } + + public int Interval() + { + return 1000 * 3; + } + + /// 0:无状态 + /// 1000:已全部打开 + /// 1010:已全部关闭 + public void Handle() + { + try + { + int count = _binInfoRepository.GetCount(i => i.ChargeStatus == 1); + if (count > 0) + { + PlcMgr.AirBlowerControl(1000); + } + else + { + PlcMgr.AirBlowerControl(1010); + } + } + catch (Exception e) + { + Log.Error($" FanChangeTask err e={e}"); + } + } + + public bool Stoped() + { + return _stop; + } + + public void Stop() + { + _stop = true; + } + + public void ResetStop() + { + _stop = false; + } +} \ No newline at end of file diff --git a/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs b/Service/MyTask/SwapOrderReportCloudTask.cs similarity index 96% rename from Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs rename to Service/MyTask/SwapOrderReportCloudTask.cs index 1a978e2..a58f477 100644 --- a/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs +++ b/Service/MyTask/SwapOrderReportCloudTask.cs @@ -5,7 +5,7 @@ using log4net; using Repository.Station; using Service.Mgr; -namespace Service.BusinessTask.MyTask; +namespace Service.MyTask; /// /// 充电结束上报云平台task diff --git a/Service/Plc/Client/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs index 89b7edf..13a4272 100644 --- a/Service/Plc/Client/PlcMgr.cs +++ b/Service/Plc/Client/PlcMgr.cs @@ -76,6 +76,8 @@ public class PlcMgr return 0; } + + /// /// 是否远程模式