缓存设置

zw
smartwyy 6 months ago
parent 701daed9fe
commit 468e825396

@ -22,6 +22,8 @@ public static class ClientMgr
private static readonly ILog Log = LogManager.GetLogger(typeof(ClientMgr)); private static readonly ILog Log = LogManager.GetLogger(typeof(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)
{ {
@ -79,11 +81,15 @@ public static class ClientMgr
/// </summary> /// </summary>
public static void StartAutoChargeThread() public static void StartAutoChargeThread()
{ {
Thread thread = new Thread(AutoChargeThread) if (!AutoChargeWorking)
{ {
Name = @"auto-charge" Thread thread = new Thread(AutoChargeThread)
}; {
thread.Start(); Name = @"auto-charge"
};
thread.Start();
AutoChargeWorking = true;
}
} }
/// <summary> /// <summary>
/// ///
@ -99,31 +105,38 @@ public static class ClientMgr
while (true) while (true)
{ {
Thread.Sleep(1000 * 30); Thread.Sleep(1000 * 30);
DateTime now = DateTime.Now; try
ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.StartTime >= now && i.EndTime < now);
if (elecPriceModelVersion == null)
{ {
Log.Info("lack of effective elec price model"); DateTime now = DateTime.Now;
continue; ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.StartTime >= now && i.EndTime < now);
} if (elecPriceModelVersion == null)
{
Log.Info("lack of effective elec price model");
continue;
}
List<ElecPriceModelVersionDetail> elecPriceModelVersionDetails = elecPriceModelVersionDetailRepository.QueryListByClause(it => it.Version == elecPriceModelVersion.Version); List<ElecPriceModelVersionDetail> elecPriceModelVersionDetails = elecPriceModelVersionDetailRepository.QueryListByClause(it => it.Version == elecPriceModelVersion.Version);
ElecPriceModelVersionDetail? elecPriceModelVersionDetail = elecPriceModelVersionDetails.Where(i => i.StartHour <= now.Hour && i.StartMinute <= now.Minute ElecPriceModelVersionDetail? elecPriceModelVersionDetail = elecPriceModelVersionDetails.Where(i => i.StartHour <= now.Hour && i.StartMinute <= now.Minute
&& i.EndHour > now.Hour && && i.EndHour > now.Hour &&
i.EndMinute > now.Minute).FirstOrDefault(); i.EndMinute > now.Minute).FirstOrDefault();
if (elecPriceModelVersionDetail == null) if (elecPriceModelVersionDetail == null)
{ {
Log.Info("lack of effective elec price model detail"); Log.Info("lack of effective elec price model detail");
continue; continue;
} }
//int batteryCount = elecPriceModelVersionDetail.BatteryCount; //int batteryCount = elecPriceModelVersionDetail.BatteryCount;
foreach (KeyValuePair<string,ChargerClient> pair in Dictionary) foreach (KeyValuePair<string,ChargerClient> pair in Dictionary)
{
Result<bool> result = pair.Value.StartCharge();
Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}");
}
}
catch (Exception e)
{ {
Result<bool> result = pair.Value.StartCharge(); Log.Error("AutoChargeThread error", e);
Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}");
} }
} }
} }

@ -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