缓存设置

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 Dictionary<string, ChargerClient> Dictionary = new();
private static bool AutoChargeWorking { get; set; }
public static ChargerClient? GetBySn(string sn)
{
@ -79,11 +81,15 @@ public static class ClientMgr
/// </summary>
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;
}
}
/// <summary>
///
@ -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<ElecPriceModelVersionDetail> 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<ElecPriceModelVersionDetail> 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<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.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}");
Log.Error("AutoChargeThread error", e);
}
}
}

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

Loading…
Cancel
Save