diff --git a/Service/Charger/Client/ClientMgr.cs b/Service/Charger/Client/ClientMgr.cs index 55600a5..9f0e681 100644 --- a/Service/Charger/Client/ClientMgr.cs +++ b/Service/Charger/Client/ClientMgr.cs @@ -22,6 +22,8 @@ public static class ClientMgr private static readonly ILog Log = LogManager.GetLogger(typeof(ClientMgr)); private static readonly Dictionary Dictionary = new(); + + private static bool AutoChargeWorking { get; set; } public static ChargerClient? GetBySn(string sn) { @@ -79,11 +81,15 @@ public static class ClientMgr /// public static void StartAutoChargeThread() { - Thread thread = new Thread(AutoChargeThread) + if (!AutoChargeWorking) { - Name = @"auto-charge" - }; - thread.Start(); + Thread thread = new Thread(AutoChargeThread) + { + Name = @"auto-charge" + }; + thread.Start(); + AutoChargeWorking = true; + } } /// /// @@ -99,31 +105,38 @@ public static class ClientMgr while (true) { Thread.Sleep(1000 * 30); - DateTime now = DateTime.Now; - ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.StartTime >= now && i.EndTime < now); - if (elecPriceModelVersion == null) + try { - Log.Info("lack of effective elec price model"); - continue; - } + DateTime now = DateTime.Now; + ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.StartTime >= now && i.EndTime < now); + if (elecPriceModelVersion == null) + { + Log.Info("lack of effective elec price model"); + continue; + } - List elecPriceModelVersionDetails = elecPriceModelVersionDetailRepository.QueryListByClause(it => it.Version == elecPriceModelVersion.Version); - ElecPriceModelVersionDetail? elecPriceModelVersionDetail = elecPriceModelVersionDetails.Where(i => i.StartHour <= now.Hour && i.StartMinute <= now.Minute - && i.EndHour > now.Hour && - i.EndMinute > now.Minute).FirstOrDefault(); - if (elecPriceModelVersionDetail == null) - { - Log.Info("lack of effective elec price model detail"); - continue; - } + List elecPriceModelVersionDetails = elecPriceModelVersionDetailRepository.QueryListByClause(it => it.Version == elecPriceModelVersion.Version); + ElecPriceModelVersionDetail? elecPriceModelVersionDetail = elecPriceModelVersionDetails.Where(i => i.StartHour <= now.Hour && i.StartMinute <= now.Minute + && i.EndHour > now.Hour && + i.EndMinute > now.Minute).FirstOrDefault(); + if (elecPriceModelVersionDetail == null) + { + Log.Info("lack of effective elec price model detail"); + continue; + } - //int batteryCount = elecPriceModelVersionDetail.BatteryCount; + //int batteryCount = elecPriceModelVersionDetail.BatteryCount; - foreach (KeyValuePair pair in Dictionary) + foreach (KeyValuePair pair in Dictionary) + { + Result result = pair.Value.StartCharge(); + Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}"); + } + } + catch (Exception e) { - Result result = pair.Value.StartCharge(); - Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}"); + Log.Error("AutoChargeThread error", e); } } } diff --git a/Service/System/SysConfigService.cs b/Service/System/SysConfigService.cs index 82c73b6..94318bf 100644 --- a/Service/System/SysConfigService.cs +++ b/Service/System/SysConfigService.cs @@ -201,6 +201,7 @@ namespace Service.System string newValue = Convert.ToString(value); Dictionary.AddOrUpdate(key, newValue, (s, s1) => newValue); + redisHelper.SetKeyValueStr(key, newValue); SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]); if (sysConfig == null) diff --git a/WinFormStarter/bin/Debug/net6.0-windows/Microsoft.Extensions.DependencyInjection.dll b/WinFormStarter/bin/Debug/net6.0-windows/Microsoft.Extensions.DependencyInjection.dll index 97525f7..6fe031c 100644 Binary files a/WinFormStarter/bin/Debug/net6.0-windows/Microsoft.Extensions.DependencyInjection.dll and b/WinFormStarter/bin/Debug/net6.0-windows/Microsoft.Extensions.DependencyInjection.dll differ