|
@@ -62,15 +62,15 @@ public class OnlineLogDbService
|
|
|
private GroupSingleHandler<EVSEOnlineRecord> insertOnlineLogHandler;
|
|
|
private GroupSingleHandler<EVSEOnlineRecord> updateOnlineLogHandler;
|
|
|
|
|
|
- internal Task UpdateOnlineLog(long rowId, DateTime offlineTime)
|
|
|
+ internal Task UpdateOnlineLog(string chargeBoxId, DateTime offlineTime)
|
|
|
{
|
|
|
- return updateOnlineLogHandler.HandleAsync(new EVSEOnlineRecord() { Id = rowId, OfflineTime = offlineTime });
|
|
|
+ return updateOnlineLogHandler.HandleAsync(new EVSEOnlineRecord() { ChargeBoxId = chargeBoxId, OfflineTime = offlineTime });
|
|
|
//return UpdateOnlineLogDapper(rowId, offlineTime);
|
|
|
}
|
|
|
|
|
|
- internal Task InsertOnlineLog(string chargeBoxId, DateTime heartbeatUpdatedOn)
|
|
|
+ internal Task InsertOnlineLog(string chargeBoxId, DateTime onlineTime)
|
|
|
{
|
|
|
- return insertOnlineLogHandler.HandleAsync(new EVSEOnlineRecord() { ChargeBoxId = chargeBoxId, OnlineTime = heartbeatUpdatedOn });
|
|
|
+ return insertOnlineLogHandler.HandleAsync(new EVSEOnlineRecord() { ChargeBoxId = chargeBoxId, OnlineTime = onlineTime });
|
|
|
//return InsertOnlineLogDapper(chargeBoxId, heartbeatUpdatedOn);
|
|
|
}
|
|
|
|
|
@@ -102,14 +102,24 @@ public class OnlineLogDbService
|
|
|
|
|
|
private async Task BundleUpdateWithDapper(IEnumerable<EVSEOnlineRecord> records)
|
|
|
{
|
|
|
- string sqlString = "UPDATE dbo.EVSEOnlineRecord SET OfflineTime=@OfflineTime WHERE Id=@Id";
|
|
|
+ string sqlString = """
|
|
|
+ UPDATE dbo.EVSEOnlineRecord
|
|
|
+ SET OfflineTime=@OfflineTime
|
|
|
+ WHERE Id = (
|
|
|
+ SELECT TOP(1) Id
|
|
|
+ FROM dbo.EVSEOnlineRecord
|
|
|
+ WHERE ChargeBoxId = @ChargeBoxId
|
|
|
+ ORDER BY OnlineTime DESC
|
|
|
+ )
|
|
|
+ """;
|
|
|
|
|
|
using var dbConn = await connectionFactory.CreateAsync();
|
|
|
foreach (var record in records)
|
|
|
{
|
|
|
var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@ChargeBoxId", record.ChargeBoxId, System.Data.DbType.String, System.Data.ParameterDirection.Input, 36);
|
|
|
parameters.Add("@OfflineTime", record.OfflineTime, System.Data.DbType.DateTime);
|
|
|
- parameters.Add("@Id", record.Id, System.Data.DbType.Int64);
|
|
|
+ //parameters.Add("@Id", record.Id, System.Data.DbType.Int64);
|
|
|
await dbConn.ExecuteAsync(sqlString, parameters);
|
|
|
}
|
|
|
}
|