|
|
|
@ -23,6 +23,8 @@ public static class ClientMgr
|
|
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, ChargerClient> Dictionary = new();
|
|
|
|
|
|
|
|
|
|
private static bool AutoChargeWorking { get; set; }
|
|
|
|
|
|
|
|
|
|
public static ChargerClient? GetBySn(string sn)
|
|
|
|
|
{
|
|
|
|
|
Dictionary.TryGetValue(sn, out var o);
|
|
|
|
@ -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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Log.Info("lack of effective elec price model detail");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|