|
@@ -31,7 +31,7 @@ public class OnlineLogDbService
|
|
|
throw new Exception($"{nameof(InitUpdateOnlineLogHandler)} should only called once");
|
|
|
}
|
|
|
|
|
|
- updateOnlineLogHandler = new GroupSingleHandler<EVSEOnlineRecord>(
|
|
|
+ updateOnlineLogHandler = new GroupHandler<EVSEOnlineRecord>(
|
|
|
//BulkInsertWithBulkCopy,
|
|
|
BundleUpdateWithDapper,
|
|
|
//loggerFactory.CreateLogger("InsertMeterValueHandler")
|
|
@@ -47,7 +47,7 @@ public class OnlineLogDbService
|
|
|
throw new Exception($"{nameof(InitInsertOnlineLogHandler)} should only called once");
|
|
|
}
|
|
|
|
|
|
- insertOnlineLogHandler = new GroupSingleHandler<EVSEOnlineRecord>(
|
|
|
+ insertOnlineLogHandler = new GroupHandler<EVSEOnlineRecord>(
|
|
|
//BulkInsertWithBulkCopy,
|
|
|
BundleInsertWithDapper,
|
|
|
//loggerFactory.CreateLogger("InsertMeterValueHandler")
|
|
@@ -59,8 +59,8 @@ public class OnlineLogDbService
|
|
|
private readonly SqlConnectionFactory<OnlineLogDBContext> connectionFactory;
|
|
|
private readonly ILogger<OnlineLogDbService> logger;
|
|
|
|
|
|
- private GroupSingleHandler<EVSEOnlineRecord> insertOnlineLogHandler;
|
|
|
- private GroupSingleHandler<EVSEOnlineRecord> updateOnlineLogHandler;
|
|
|
+ private GroupHandler<EVSEOnlineRecord> insertOnlineLogHandler;
|
|
|
+ private GroupHandler<EVSEOnlineRecord> updateOnlineLogHandler;
|
|
|
|
|
|
internal Task UpdateOnlineLog(string chargeBoxId, DateTime offlineTime)
|
|
|
{
|
|
@@ -100,8 +100,11 @@ public class OnlineLogDbService
|
|
|
await dbConn.ExecuteAsync(sqlString, parameters);
|
|
|
}
|
|
|
|
|
|
- private async Task BundleUpdateWithDapper(IEnumerable<EVSEOnlineRecord> records)
|
|
|
+ private async Task<BundleHandlerResult<EVSEOnlineRecord>> BundleUpdateWithDapper(IEnumerable<EVSEOnlineRecord> records)
|
|
|
{
|
|
|
+ List<EVSEOnlineRecord> comtpetedRecords = new();
|
|
|
+ Exception exception = null;
|
|
|
+
|
|
|
string sqlString = """
|
|
|
UPDATE dbo.EVSEOnlineRecord
|
|
|
SET OfflineTime=@OfflineTime
|
|
@@ -113,32 +116,57 @@ public class OnlineLogDbService
|
|
|
)
|
|
|
""";
|
|
|
|
|
|
- using var dbConn = await connectionFactory.CreateAsync();
|
|
|
- foreach (var record in records)
|
|
|
+ try
|
|
|
{
|
|
|
- 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);
|
|
|
- await dbConn.ExecuteAsync(sqlString, parameters);
|
|
|
+ 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);
|
|
|
+ await dbConn.ExecuteAsync(sqlString, parameters);
|
|
|
+ comtpetedRecords.Add(record);
|
|
|
+ }
|
|
|
}
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ exception = e;
|
|
|
+ }
|
|
|
+
|
|
|
+ return new BundleHandlerResult<EVSEOnlineRecord>(comtpetedRecords, exception);
|
|
|
}
|
|
|
|
|
|
- private async Task BundleInsertWithDapper(IEnumerable<EVSEOnlineRecord> records)
|
|
|
+ private async Task<BundleHandlerResult<EVSEOnlineRecord>> BundleInsertWithDapper(IEnumerable<EVSEOnlineRecord> records)
|
|
|
{
|
|
|
+ List<EVSEOnlineRecord> completedDatas = new();
|
|
|
+ Exception exception = null;
|
|
|
+
|
|
|
string sqlString = """
|
|
|
INSERT INTO dbo.EVSEOnlineRecord ("ChargeBoxId","OnlineTime","OfflineTime")
|
|
|
VALUES( @ChargeBoxId, @OnlineTime, @OfflineTime);
|
|
|
""";
|
|
|
-
|
|
|
- using var dbConn = await connectionFactory.CreateAsync();
|
|
|
- foreach (var record in records)
|
|
|
+ try
|
|
|
{
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@ChargeBoxId", record.ChargeBoxId, System.Data.DbType.String, System.Data.ParameterDirection.Input, 36);
|
|
|
- parameters.Add("@OnlineTime", record.OnlineTime, System.Data.DbType.DateTime);
|
|
|
- parameters.Add("@OfflineTime", DefaultSetting.DefaultNullTime, System.Data.DbType.DateTime);
|
|
|
- await dbConn.ExecuteAsync(sqlString, parameters);
|
|
|
+ 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("@OnlineTime", record.OnlineTime, System.Data.DbType.DateTime);
|
|
|
+ parameters.Add("@OfflineTime", DefaultSetting.DefaultNullTime, System.Data.DbType.DateTime);
|
|
|
+ await dbConn.ExecuteAsync(sqlString, parameters);
|
|
|
+ completedDatas.Add(record);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ logger.LogError(e.Message);
|
|
|
+ logger.LogError(e.StackTrace);
|
|
|
+
|
|
|
+ exception = e;
|
|
|
}
|
|
|
+
|
|
|
+ return new BundleHandlerResult<EVSEOnlineRecord>(completedDatas, exception);
|
|
|
}
|
|
|
}
|