缓存设置

zw
smartwyy 6 months ago
parent 701daed9fe
commit 468e825396

@ -23,6 +23,8 @@ public static class ClientMgr
private static readonly Dictionary<string, ChargerClient> Dictionary = new(); private static readonly Dictionary<string, ChargerClient> Dictionary = new();
private static bool AutoChargeWorking { get; set; }
public static ChargerClient? GetBySn(string sn) public static ChargerClient? GetBySn(string sn)
{ {
Dictionary.TryGetValue(sn, out var o); Dictionary.TryGetValue(sn, out var o);
@ -78,12 +80,16 @@ public static class ClientMgr
/// ///
/// </summary> /// </summary>
public static void StartAutoChargeThread() public static void StartAutoChargeThread()
{
if (!AutoChargeWorking)
{ {
Thread thread = new Thread(AutoChargeThread) Thread thread = new Thread(AutoChargeThread)
{ {
Name = @"auto-charge" Name = @"auto-charge"
}; };
thread.Start(); thread.Start();
AutoChargeWorking = true;
}
} }
/// <summary> /// <summary>
/// ///
@ -99,6 +105,8 @@ public static class ClientMgr
while (true) while (true)
{ {
Thread.Sleep(1000 * 30); Thread.Sleep(1000 * 30);
try
{
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.StartTime >= now && i.EndTime < now); ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.StartTime >= now && i.EndTime < now);
if (elecPriceModelVersion == null) if (elecPriceModelVersion == null)
@ -126,6 +134,11 @@ public static class ClientMgr
Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}"); Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}");
} }
} }
catch (Exception e)
{
Log.Error("AutoChargeThread error", e);
}
}
} }
private static void ConnClient(EquipNetInfo netInfo) private static void ConnClient(EquipNetInfo netInfo)

@ -201,6 +201,7 @@ namespace Service.System
string newValue = Convert.ToString(value); string newValue = Convert.ToString(value);
Dictionary.AddOrUpdate(key, newValue, (s, s1) => newValue); Dictionary.AddOrUpdate(key, newValue, (s, s1) => newValue);
redisHelper.SetKeyValueStr(key, newValue);
SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]); SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]);
if (sysConfig == null) if (sysConfig == null)

Loading…
Cancel
Save