|
@@ -14,198 +14,198 @@ using System.Threading.Tasks;
|
|
|
using MachineOperateRecord = EVCB_OCPP.TaskScheduler.Models.MachineOperateRecord;
|
|
|
using Transaction = EVCB_OCPP.TaskScheduler.Models.Transaction;
|
|
|
|
|
|
-namespace EVCB_OCPP.TaskScheduler.Services
|
|
|
+namespace EVCB_OCPP.TaskScheduler.Services;
|
|
|
+
|
|
|
+public class DatabaseService
|
|
|
{
|
|
|
- public class DatabaseService
|
|
|
+ private readonly ILogger logger;
|
|
|
+ private readonly SqlConnectionFactory<Domain.MainDBContext> mainDbConnectionFactory;
|
|
|
+ //private readonly SqlConnectionFactory<OnlineLogDBContext> onlineLogDbConnectionFactory;
|
|
|
+ private readonly SqlConnectionFactory<WebDBConetext> webDbConnectionFactory;
|
|
|
+
|
|
|
+ //private readonly string mainDBConnectString;
|
|
|
+ //private readonly string onlineDBConnectString;
|
|
|
+
|
|
|
+ public DatabaseService(
|
|
|
+ ILogger<DatabaseService> logger,
|
|
|
+ SqlConnectionFactory<Domain.MainDBContext> mainDbConnectionFactory,
|
|
|
+ SqlConnectionFactory<OnlineLogDBContext> onlineLogDbConnectionFactory,
|
|
|
+ SqlConnectionFactory<WebDBConetext> webDbConnectionFactory)
|
|
|
{
|
|
|
- private readonly ILogger logger;
|
|
|
- private readonly SqlConnectionFactory<Domain.MainDBContext> mainDbConnectionFactory;
|
|
|
- //private readonly SqlConnectionFactory<OnlineLogDBContext> onlineLogDbConnectionFactory;
|
|
|
- private readonly SqlConnectionFactory<WebDBConetext> webDbConnectionFactory;
|
|
|
+ this.logger = logger;
|
|
|
+ this.mainDbConnectionFactory = mainDbConnectionFactory;
|
|
|
+ //this.onlineLogDbConnectionFactory = onlineLogDbConnectionFactory;
|
|
|
+ this.webDbConnectionFactory = webDbConnectionFactory;
|
|
|
|
|
|
- //private readonly string mainDBConnectString;
|
|
|
- //private readonly string onlineDBConnectString;
|
|
|
+ //mainDBConnectString = configuration.GetConnectionString("MainDBContext");
|
|
|
+ //onlineDBConnectString = configuration.GetConnectionString("OnlineLogDBContext");
|
|
|
+ }
|
|
|
|
|
|
- public DatabaseService(
|
|
|
- ILogger<DatabaseService> logger,
|
|
|
- SqlConnectionFactory<Domain.MainDBContext> mainDbConnectionFactory,
|
|
|
- SqlConnectionFactory<OnlineLogDBContext> onlineLogDbConnectionFactory,
|
|
|
- SqlConnectionFactory<WebDBConetext> webDbConnectionFactory)
|
|
|
+ internal async Task<string> GetCustomerName(Guid customerId)
|
|
|
+ {
|
|
|
+ string name = string.Empty;
|
|
|
+ try
|
|
|
{
|
|
|
- this.logger = logger;
|
|
|
- this.mainDbConnectionFactory = mainDbConnectionFactory;
|
|
|
- //this.onlineLogDbConnectionFactory = onlineLogDbConnectionFactory;
|
|
|
- this.webDbConnectionFactory = webDbConnectionFactory;
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ {
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@Id", customerId, DbType.Guid);
|
|
|
+ name = await dbConn.QueryFirstOrDefaultAsync<string>("SELECT Name FROM [dbo].[Customer] where Id=@Id ", parameters);
|
|
|
+ }
|
|
|
|
|
|
- //mainDBConnectString = configuration.GetConnectionString("MainDBContext");
|
|
|
- //onlineDBConnectString = configuration.GetConnectionString("OnlineLogDBContext");
|
|
|
}
|
|
|
-
|
|
|
- internal async Task<string> GetCustomerName(Guid customerId)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- string name = string.Empty;
|
|
|
- try
|
|
|
- {
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@Id", customerId, DbType.Guid);
|
|
|
- name = await dbConn.QueryFirstOrDefaultAsync<string>("SELECT Name FROM [dbo].[Customer] where Id=@Id ", parameters);
|
|
|
- }
|
|
|
+ logger.LogError("Query Data Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ internal async Task<bool> IsCallParterAPI(Guid customerId)
|
|
|
+ {
|
|
|
+ bool result = false;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- logger.LogError("Query Data Error " + ex.ToString());
|
|
|
+ //dbConn.Open();
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@Id", customerId, DbType.Guid);
|
|
|
+ result = await dbConn.ExecuteScalarAsync<bool>("SELECT count(*) FROM [dbo].[Customer] where Id=@Id and CallPartnerApiOnSchedule=1 ", parameters);
|
|
|
}
|
|
|
|
|
|
- return name;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- internal async Task<bool> IsCallParterAPI(Guid customerId)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- bool result = false;
|
|
|
- try
|
|
|
- {
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- //dbConn.Open();
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@Id", customerId, DbType.Guid);
|
|
|
- result = await dbConn.ExecuteScalarAsync<bool>("SELECT count(*) FROM [dbo].[Customer] where Id=@Id and CallPartnerApiOnSchedule=1 ", parameters);
|
|
|
- }
|
|
|
+ logger.LogError("Query Data Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("Query Data Error " + ex.ToString());
|
|
|
- }
|
|
|
+ return result;
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
+ internal async Task<CustomerConnectionDto> GetAPIConnectionInfo(Guid partnerId)
|
|
|
+ {
|
|
|
+ CustomerConnectionDto result = new CustomerConnectionDto();
|
|
|
+ string key = string.Empty;
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@Id", partnerId, DbType.Guid, ParameterDirection.Input);
|
|
|
+ using (SqlConnection conn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ {
|
|
|
+ string strSql = "Select Name, ApiKey, ApiUrl from [dbo].[Customer] where Id=@Id; ";
|
|
|
+ result = await conn.QueryFirstOrDefaultAsync<CustomerConnectionDto>(strSql, parameters);
|
|
|
}
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- internal async Task<CustomerConnectionDto> GetAPIConnectionInfo(Guid partnerId)
|
|
|
+ internal async Task<List<Guid>> GetCallParterAPICustomers()
|
|
|
+ {
|
|
|
+ List<Guid> result = new List<Guid>();
|
|
|
+ try
|
|
|
{
|
|
|
- CustomerConnectionDto result = new CustomerConnectionDto();
|
|
|
- string key = string.Empty;
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@Id", partnerId, DbType.Guid, ParameterDirection.Input);
|
|
|
- using (SqlConnection conn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- string strSql = "Select Name, ApiKey, ApiUrl from [dbo].[Customer] where Id=@Id; ";
|
|
|
- result = await conn.QueryFirstOrDefaultAsync<CustomerConnectionDto>(strSql, parameters);
|
|
|
+ //dbConn.Open();
|
|
|
+ result = (await dbConn.QueryAsync<Guid>("SELECT Id FROM [dbo].[Customer] where CallPartnerApiOnSchedule=1")).ToList();
|
|
|
}
|
|
|
- return result;
|
|
|
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("Query Data Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- internal async Task<List<Guid>> GetCallParterAPICustomers()
|
|
|
+ internal async Task<List<Guid>> GetNotifyStopTransactionCustomers()
|
|
|
+ {
|
|
|
+ List<Guid> result = new List<Guid>();
|
|
|
+ try
|
|
|
{
|
|
|
- List<Guid> result = new List<Guid>();
|
|
|
- try
|
|
|
- {
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- //dbConn.Open();
|
|
|
- result = (await dbConn.QueryAsync<Guid>("SELECT Id FROM [dbo].[Customer] where CallPartnerApiOnSchedule=1")).ToList();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- logger.LogError("Query Data Error " + ex.ToString());
|
|
|
+ //dbConn.Open();
|
|
|
+ result = (await dbConn.QueryAsync<Guid>("SELECT Id FROM [dbo].[Customer] where CallPartnerApiOnSchedule=1 and InstantStopTxReport=0")).ToList();
|
|
|
}
|
|
|
|
|
|
- return result;
|
|
|
}
|
|
|
-
|
|
|
- internal async Task<List<Guid>> GetNotifyStopTransactionCustomers()
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- List<Guid> result = new List<Guid>();
|
|
|
- try
|
|
|
- {
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- //dbConn.Open();
|
|
|
- result = (await dbConn.QueryAsync<Guid>("SELECT Id FROM [dbo].[Customer] where CallPartnerApiOnSchedule=1 and InstantStopTxReport=0")).ToList();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("Query Data Error " + ex.ToString());
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
+ logger.LogError("Query Data Error " + ex.ToString());
|
|
|
}
|
|
|
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- internal async Task<List<Transaction>> GetNeedReportSession(Guid customerId, bool isgoing, int size)
|
|
|
+ internal async Task<List<Transaction>> GetNeedReportSession(Guid customerId, bool isgoing, int size)
|
|
|
+ {
|
|
|
+ List<Transaction> result = new List<Transaction>();
|
|
|
+ try
|
|
|
{
|
|
|
- List<Transaction> result = new List<Transaction>();
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- //dbConn.Open();
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@CustomerId", customerId, DbType.Guid);
|
|
|
- string sqlString = string.Empty;
|
|
|
+ //dbConn.Open();
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@CustomerId", customerId, DbType.Guid);
|
|
|
+ string sqlString = string.Empty;
|
|
|
|
|
|
- // 20220211 revised
|
|
|
- if (isgoing)
|
|
|
- {
|
|
|
- sqlString = $"""
|
|
|
- SELECT Top({size}) Id,ReservationId, ChargeBoxId,ConnectorId,StartTime,MeterStart,StartIdTag
|
|
|
+ // 20220211 revised
|
|
|
+ if (isgoing)
|
|
|
+ {
|
|
|
+ sqlString = $"""
|
|
|
+ SELECT Top({size}) Id,ReservationId, ChargeBoxId,ConnectorId,StartTime,MeterStart,StartIdTag
|
|
|
FROM [dbo].[TransactionRecord]
|
|
|
WHERE CustomerId=@CustomerId and StopTime='1991/1/1' and StartTransactionReportedOn='1991/1/1'
|
|
|
""";
|
|
|
- }
|
|
|
- else
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (customerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
|
|
|
{
|
|
|
- if (customerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
|
|
|
- {
|
|
|
- sqlString = $"""
|
|
|
- SELECT Top({size}) Id,ReservationId,ChargeBoxId,ConnectorId,StartTime,StopTime,MeterStart,MeterStop,StartIdTag ,StopReasonId,Receipt,Cost,Fee
|
|
|
+ sqlString = $"""
|
|
|
+ SELECT Top({size}) Id,ReservationId,ChargeBoxId,ConnectorId,StartTime,StopTime,MeterStart,MeterStop,StartIdTag ,StopReasonId,Receipt,Cost,Fee
|
|
|
FROM [dbo].[TransactionRecord]
|
|
|
WHERE CustomerId=@CustomerId and StopTime!='1991/1/1' and StopTransactionReportedOn='1991/1/1' and BillingDone=1
|
|
|
""";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- sqlString = $"""
|
|
|
- SELECT Top({size}) Id,ReservationId,ChargeBoxId,ConnectorId,StartTime,StopTime,MeterStart,MeterStop,StartIdTag ,StopReasonId,Receipt,Cost,Fee
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sqlString = $"""
|
|
|
+ SELECT Top({size}) Id,ReservationId,ChargeBoxId,ConnectorId,StartTime,StopTime,MeterStart,MeterStop,StartIdTag ,StopReasonId,Receipt,Cost,Fee
|
|
|
FROM [dbo].[TransactionRecord]
|
|
|
WHERE CustomerId=@CustomerId and StopTime!='1991/1/1' and StopTransactionReportedOn='1991/1/1'
|
|
|
""";
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
- result = (await dbConn.QueryAsync<Transaction>(sqlString, parameters)).ToList();
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("Query Data Error " + ex.ToString());
|
|
|
+ result = (await dbConn.QueryAsync<Transaction>(sqlString, parameters)).ToList();
|
|
|
}
|
|
|
|
|
|
- return result;
|
|
|
}
|
|
|
-
|
|
|
- internal async Task<List<Transaction>> GetNeedReportStartTransactionSession(int size = 1000)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- //string sqlString = $"""
|
|
|
- // SELECT Top({size}) Id, CustomerId,ReservationId, ChargeBoxId,ConnectorId,StartTime,MeterStart,StartIdTag
|
|
|
- // FROM [dbo].[TransactionRecord]
|
|
|
- // WHERE StopTime='1991/1/1' and StartTransactionReportedOn='1991/1/1'
|
|
|
- // """;
|
|
|
- string sqlString = $"""
|
|
|
- WITH CTE AS (
|
|
|
+ logger.LogError("Query Data Error " + ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ internal async Task<List<Transaction>> GetNeedReportStartTransactionSession(int size = 1000)
|
|
|
+ {
|
|
|
+ //string sqlString = $"""
|
|
|
+ // SELECT Top({size}) Id, CustomerId,ReservationId, ChargeBoxId,ConnectorId,StartTime,MeterStart,StartIdTag
|
|
|
+ // FROM [dbo].[TransactionRecord]
|
|
|
+ // WHERE StopTime='1991/1/1' and StartTransactionReportedOn='1991/1/1'
|
|
|
+ // """;
|
|
|
+ string sqlString = $"""
|
|
|
+ WITH CTE AS (
|
|
|
SELECT Id, CustomerId,ReservationId, ChargeBoxId,ConnectorId,StartTime,MeterStart,StartIdTag
|
|
|
, ROW_NUMBER() OVER (PARTITION BY CustomerId ORDER BY Id desc) AS RowNum
|
|
|
FROM [dbo].[TransactionRecord]
|
|
@@ -216,19 +216,19 @@ namespace EVCB_OCPP.TaskScheduler.Services
|
|
|
WHERE RowNum < {size};
|
|
|
""";
|
|
|
|
|
|
- using var dbConn = await mainDbConnectionFactory.CreateAsync();
|
|
|
- return (await dbConn.QueryAsync<Transaction>(sqlString)).ToList();
|
|
|
- }
|
|
|
-
|
|
|
- internal async Task<List<Transaction>> GetNeedReportStopTransactionSession(int size = 1000)
|
|
|
- {
|
|
|
- //string sqlString = $"""
|
|
|
- // SELECT Top({size}) Id,ReservationId,ChargeBoxId,ConnectorId,StartTime,StopTime,MeterStart,MeterStop,StartIdTag ,StopReasonId,Receipt,Cost,Fee
|
|
|
- // FROM [dbo].[TransactionRecord]
|
|
|
- // WHERE StopTime!='1991/1/1' and StopTransactionReportedOn='1991/1/1'
|
|
|
- // """;
|
|
|
- string sqlString = $"""
|
|
|
- WITH CTE AS (
|
|
|
+ using var dbConn = await mainDbConnectionFactory.CreateAsync();
|
|
|
+ return (await dbConn.QueryAsync<Transaction>(sqlString)).ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ internal async Task<List<Transaction>> GetNeedReportStopTransactionSession(int size = 1000)
|
|
|
+ {
|
|
|
+ //string sqlString = $"""
|
|
|
+ // SELECT Top({size}) Id,ReservationId,ChargeBoxId,ConnectorId,StartTime,StopTime,MeterStart,MeterStop,StartIdTag ,StopReasonId,Receipt,Cost,Fee
|
|
|
+ // FROM [dbo].[TransactionRecord]
|
|
|
+ // WHERE StopTime!='1991/1/1' and StopTransactionReportedOn='1991/1/1'
|
|
|
+ // """;
|
|
|
+ string sqlString = $"""
|
|
|
+ WITH CTE AS (
|
|
|
SELECT Id,CustomerId,ReservationId,ChargeBoxId,ConnectorId,StartTime,StopTime,MeterStart,MeterStop,StartIdTag ,StopReasonId,Receipt,Cost,Fee
|
|
|
, ROW_NUMBER() OVER (PARTITION BY CustomerId ORDER BY Id desc) AS RowNum
|
|
|
FROM [dbo].[TransactionRecord]
|
|
@@ -239,349 +239,348 @@ namespace EVCB_OCPP.TaskScheduler.Services
|
|
|
WHERE RowNum < {size};
|
|
|
""";
|
|
|
|
|
|
- using var dbConn = await mainDbConnectionFactory.CreateAsync();
|
|
|
- return (await dbConn.QueryAsync<Transaction>(sqlString)).ToList();
|
|
|
- }
|
|
|
+ using var dbConn = await mainDbConnectionFactory.CreateAsync();
|
|
|
+ return (await dbConn.QueryAsync<Transaction>(sqlString)).ToList();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- internal async Task<List<MachineOperateRecord>> GetNeedReportExecution(Guid customerId, int size)
|
|
|
+ internal async Task<List<MachineOperateRecord>> GetNeedReportExecution(Guid customerId, int size)
|
|
|
+ {
|
|
|
+ List<MachineOperateRecord> result = new List<MachineOperateRecord>();
|
|
|
+ try
|
|
|
{
|
|
|
- List<MachineOperateRecord> result = new List<MachineOperateRecord>();
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- //dbConn.Open();
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@CustomerId", customerId, DbType.Guid);
|
|
|
- string sqlString = string.Empty;
|
|
|
+ //dbConn.Open();
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@CustomerId", customerId, DbType.Guid);
|
|
|
+ string sqlString = string.Empty;
|
|
|
|
|
|
- sqlString = $"""
|
|
|
- SELECT Top({size}) Machine.CustomerId, record.Id, record.ChargeBoxId,record.Action,record.SerialNo,record.Status,record.EVSE_Value,record.EVSE_Status
|
|
|
+ sqlString = $"""
|
|
|
+ SELECT Top({size}) Machine.CustomerId, record.Id, record.ChargeBoxId,record.Action,record.SerialNo,record.Status,record.EVSE_Value,record.EVSE_Status
|
|
|
FROM [dbo].[MachineOperateRecord] record
|
|
|
left join[dbo].[Machine] on record.ChargeBoxId = Machine.ChargeBoxId
|
|
|
WHERE Machine.CustomerId =@CustomerId and Status!= 0 and RequestType = 1 and ReportedOn = '1991/01/01'
|
|
|
""";
|
|
|
- result = (await dbConn.QueryAsync<MachineOperateRecord>(sqlString, parameters)).ToList();
|
|
|
- }
|
|
|
+ result = (await dbConn.QueryAsync<MachineOperateRecord>(sqlString, parameters)).ToList();
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("GetNeedReportExecution Error " + ex.ToString());
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- internal async Task ReportStartTx(Dictionary<int, TransactionResponse> reportResults)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
+ logger.LogError("GetNeedReportExecution Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- foreach (var kv in reportResults)
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@Id", kv.Key, DbType.Int32, ParameterDirection.Input);
|
|
|
- parameters.Add("@StartTransactionReportedOn", kv.Value.StartTransactionReportedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
- parameters.Add("@ErrorMsg", kv.Value.ErrorMsg, DbType.String, ParameterDirection.Input, -1);
|
|
|
- await Policy.Handle<Exception>()
|
|
|
- .WaitAndRetryForeverAsync((cnt) => TimeSpan.FromSeconds(5))
|
|
|
- .ExecuteAsync(() => dbConn.ExecuteAsync("UPDATE [dbo].[TransactionRecord] set StartTransactionReportedOn=@StartTransactionReportedOn, ErrorMsg=@ErrorMsg where Id=@Id", parameters));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("ReportStartTx Error " + ex.ToString());
|
|
|
- }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- }
|
|
|
+ internal async Task ReportStartTx(Dictionary<int, TransactionResponse> reportResults)
|
|
|
+ {
|
|
|
|
|
|
- internal async Task ReportStopTx(Dictionary<int, TransactionResponse> reportResults)
|
|
|
+ try
|
|
|
{
|
|
|
-
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- using (var trans = await dbConn.BeginTransactionAsync())
|
|
|
+ foreach (var kv in reportResults)
|
|
|
{
|
|
|
- //dbConn.Open();
|
|
|
-
|
|
|
- foreach (var kv in reportResults)
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@Id", kv.Key, DbType.Int32, ParameterDirection.Input);
|
|
|
- parameters.Add("@StopTransactionReportedOn", kv.Value.StopTransactionReportedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
- parameters.Add("@ErrorMsg", kv.Value.ErrorMsg, DbType.String, ParameterDirection.Input, -1);
|
|
|
- await dbConn.ExecuteAsync("UPDATE [dbo].[TransactionRecord] set StopTransactionReportedOn=@StopTransactionReportedOn, ErrorMsg=@ErrorMsg where Id=@Id", parameters, trans);
|
|
|
- //await trans.ExecuteAsync("UPDATE [dbo].[TransactionRecord] set StopTransactionReportedOn=@StopTransactionReportedOn, ErrorMsg=@ErrorMsg where Id=@Id", parameters);
|
|
|
- }
|
|
|
-
|
|
|
- await trans.CommitAsync();
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@Id", kv.Key, DbType.Int32, ParameterDirection.Input);
|
|
|
+ parameters.Add("@StartTransactionReportedOn", kv.Value.StartTransactionReportedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
+ parameters.Add("@ErrorMsg", kv.Value.ErrorMsg, DbType.String, ParameterDirection.Input, -1);
|
|
|
+ await Policy.Handle<Exception>()
|
|
|
+ .WaitAndRetryForeverAsync((cnt) => TimeSpan.FromSeconds(5))
|
|
|
+ .ExecuteAsync(() => dbConn.ExecuteAsync("UPDATE [dbo].[TransactionRecord] set StartTransactionReportedOn=@StartTransactionReportedOn, ErrorMsg=@ErrorMsg where Id=@Id", parameters));
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("ReportStopTx Error " + ex.ToString());
|
|
|
- }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("ReportStartTx Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
+ internal async Task ReportStopTx(Dictionary<int, TransactionResponse> reportResults)
|
|
|
+ {
|
|
|
|
|
|
- internal async Task TurntoTimeoutMachineOperateCommands(int intervalSeconds)
|
|
|
+ try
|
|
|
{
|
|
|
-
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ using (var trans = await dbConn.BeginTransactionAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ //dbConn.Open();
|
|
|
+
|
|
|
+ foreach (var kv in reportResults)
|
|
|
{
|
|
|
- //dbConn.Open();
|
|
|
- await dbConn.ExecuteAsync("CheckUnCommitMachineOperateCommand", new { @TimeoutIntervalSeconds = intervalSeconds }, null, null, commandType: CommandType.StoredProcedure);
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@Id", kv.Key, DbType.Int32, ParameterDirection.Input);
|
|
|
+ parameters.Add("@StopTransactionReportedOn", kv.Value.StopTransactionReportedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
+ parameters.Add("@ErrorMsg", kv.Value.ErrorMsg, DbType.String, ParameterDirection.Input, -1);
|
|
|
+ await dbConn.ExecuteAsync("UPDATE [dbo].[TransactionRecord] set StopTransactionReportedOn=@StopTransactionReportedOn, ErrorMsg=@ErrorMsg where Id=@Id", parameters, trans);
|
|
|
+ //await trans.ExecuteAsync("UPDATE [dbo].[TransactionRecord] set StopTransactionReportedOn=@StopTransactionReportedOn, ErrorMsg=@ErrorMsg where Id=@Id", parameters);
|
|
|
}
|
|
|
|
|
|
+ await trans.CommitAsync();
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("TurntoTimeoutMachineOperateCommands Error " + ex.ToString());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- internal async Task ReportExecution(Dictionary<int, BasicResponse> reportResults)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- using (var trans = await dbConn.BeginTransactionAsync())
|
|
|
- {
|
|
|
- //dbConn.Open();
|
|
|
+ logger.LogError("ReportStopTx Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
- foreach (var kv in reportResults)
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@Id", kv.Key, DbType.Int32, ParameterDirection.Input);
|
|
|
- parameters.Add("@ReportedOn", kv.Value.ReportedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
|
|
|
- await dbConn.ExecuteAsync("UPDATE [dbo].[MachineOperateRecord] set ReportedOn=@ReportedOn where Id=@Id", parameters, trans);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- await trans.CommitAsync();
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
+
|
|
|
+ internal async Task TurntoTimeoutMachineOperateCommands(int intervalSeconds)
|
|
|
+ {
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- logger.LogError("ReportExecution Error " + ex.ToString());
|
|
|
+ //dbConn.Open();
|
|
|
+ await dbConn.ExecuteAsync("CheckUnCommitMachineOperateCommand", new { @TimeoutIntervalSeconds = intervalSeconds }, null, null, commandType: CommandType.StoredProcedure);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("TurntoTimeoutMachineOperateCommands Error " + ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
- internal async Task<List<CustomerInfoDto>> GetCustomerInfos()
|
|
|
+ internal async Task ReportExecution(Dictionary<int, BasicResponse> reportResults)
|
|
|
+ {
|
|
|
+ try
|
|
|
{
|
|
|
- List<CustomerInfoDto> result = new List<CustomerInfoDto>();
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ using (var trans = await dbConn.BeginTransactionAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ //dbConn.Open();
|
|
|
+
|
|
|
+ foreach (var kv in reportResults)
|
|
|
{
|
|
|
- result = (await dbConn.QueryAsync<CustomerInfoDto>("SELECT Id , Name FROM [dbo].[Customer] where IsShow =1 "))
|
|
|
- .ToList();
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@Id", kv.Key, DbType.Int32, ParameterDirection.Input);
|
|
|
+ parameters.Add("@ReportedOn", kv.Value.ReportedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
+
|
|
|
+ await dbConn.ExecuteAsync("UPDATE [dbo].[MachineOperateRecord] set ReportedOn=@ReportedOn where Id=@Id", parameters, trans);
|
|
|
}
|
|
|
|
|
|
+ await trans.CommitAsync();
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("ReportExecution Error " + ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ internal async Task<List<CustomerInfoDto>> GetCustomerInfos()
|
|
|
+ {
|
|
|
+ List<CustomerInfoDto> result = new List<CustomerInfoDto>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- logger.LogError("GetCustomerInfos Error " + ex.ToString());
|
|
|
+ result = (await dbConn.QueryAsync<CustomerInfoDto>("SELECT Id , Name FROM [dbo].[Customer] where IsShow =1 "))
|
|
|
+ .ToList();
|
|
|
}
|
|
|
|
|
|
- //add PHT Electric Avenue
|
|
|
-
|
|
|
- return result;
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("GetCustomerInfos Error " + ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //add PHT Electric Avenue
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- internal async Task<List<ChargerAmountDto>> GetChargerAmount(bool connected)
|
|
|
+ internal async Task<List<ChargerAmountDto>> GetChargerAmount(bool connected)
|
|
|
+ {
|
|
|
+ List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
+ try
|
|
|
{
|
|
|
- List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ if (connected)
|
|
|
{
|
|
|
- if (connected)
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
- var quertResult = await dbConn.QueryAsync<ChargerAmountDto>("""
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
+ var quertResult = await dbConn.QueryAsync<ChargerAmountDto>("""
|
|
|
SELECT count(ChargeBoxId) as Charger_Count , Customer.Name as CustomerName FROM [dbo].[Machine]
|
|
|
inner join Customer on Customer.id =[Machine].CustomerId
|
|
|
WHERE IsDelete=0 and HeartbeatUpdatedOn>=@HeartbeatUpdatedOn
|
|
|
group by CustomerId,Customer.Name
|
|
|
""", parameters);
|
|
|
- result = quertResult.ToList();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var queryResult = await dbConn.QueryAsync<ChargerAmountDto>("""
|
|
|
+ result = quertResult.ToList();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var queryResult = await dbConn.QueryAsync<ChargerAmountDto>("""
|
|
|
SELECT count(ChargeBoxId) as Charger_Count , Customer.Name as CustomerName FROM [dbo].[Machine]
|
|
|
inner join Customer on Customer.id =[Machine].CustomerId
|
|
|
where IsDelete=0
|
|
|
group by CustomerId,Customer.Name
|
|
|
""");
|
|
|
- result = queryResult.ToList();
|
|
|
- }
|
|
|
-
|
|
|
+ result = queryResult.ToList();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("GetChargerAmount Error " + ex.ToString());
|
|
|
- }
|
|
|
-
|
|
|
- //add PHT Electric Avenue
|
|
|
|
|
|
- return result;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("GetChargerAmount Error " + ex.ToString());
|
|
|
}
|
|
|
|
|
|
- internal async Task<List<ChargerAmountDto>> GetConnectorAmount()
|
|
|
+ //add PHT Electric Avenue
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ internal async Task<List<ChargerAmountDto>> GetConnectorAmount()
|
|
|
+ {
|
|
|
+ List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
+ try
|
|
|
{
|
|
|
- List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
- var queryResult = await dbConn.QueryAsync<ChargerAmountDto>("""
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
+ var queryResult = await dbConn.QueryAsync<ChargerAmountDto>("""
|
|
|
SELECT sum(GunAmt) as Charger_Count , Customer.Name as CustomerName FROM [dbo].[Machine]
|
|
|
inner join Customer on Customer.id =[Machine].CustomerId
|
|
|
where IsDelete=0 and HeartbeatUpdatedOn>=@HeartbeatUpdatedOn
|
|
|
group by CustomerId,Customer.Name
|
|
|
""", parameters);
|
|
|
- result = queryResult.ToList();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("GetConnectorAmount Error " + ex.ToString());
|
|
|
+ result = queryResult.ToList();
|
|
|
}
|
|
|
|
|
|
- //add PHT Electric Avenue
|
|
|
-
|
|
|
- return result;
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("GetConnectorAmount Error " + ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //add PHT Electric Avenue
|
|
|
|
|
|
- internal async Task<List<ChargerAmountDto>> GetPHTChargerAmount(bool connected, bool inner)
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ internal async Task<List<ChargerAmountDto>> GetPHTChargerAmount(bool connected, bool inner)
|
|
|
+ {
|
|
|
+ List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
+ try
|
|
|
{
|
|
|
- List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
- try
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
{
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ if (connected)
|
|
|
{
|
|
|
- if (connected)
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
- var requestResult = await dbConn.QueryAsync<ChargerAmountDto>($"""
|
|
|
- SELECT count(ChargeBoxId) as Charger_Count , Customer.Name as CustomerName
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
+ var requestResult = await dbConn.QueryAsync<ChargerAmountDto>($"""
|
|
|
+ SELECT count(ChargeBoxId) as Charger_Count , Customer.Name as CustomerName
|
|
|
FROM [dbo].[Machine]
|
|
|
inner join Customer on Customer.id =[Machine].CustomerId
|
|
|
where IsDelete=0 and Customer.Name='PHT'
|
|
|
{(inner ? "and [ChargePointVendor]!='Electric Avenue'" : "and [ChargePointVendor]='Electric Avenue'")}
|
|
|
and HeartbeatUpdatedOn>=@HeartbeatUpdatedOn group by CustomerId,Customer.Name
|
|
|
""", parameters);
|
|
|
- result = requestResult.ToList();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var requestResult = await dbConn.QueryAsync<ChargerAmountDto>($"""
|
|
|
- SELECT count(ChargeBoxId) as Charger_Count , Customer.Name as CustomerName
|
|
|
+ result = requestResult.ToList();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var requestResult = await dbConn.QueryAsync<ChargerAmountDto>($"""
|
|
|
+ SELECT count(ChargeBoxId) as Charger_Count , Customer.Name as CustomerName
|
|
|
FROM [dbo].[Machine]
|
|
|
inner join Customer on Customer.id =[Machine].CustomerId where IsDelete=0
|
|
|
{(inner ? "and [ChargePointVendor]!='Electric Avenue'" : "and [ChargePointVendor]='Electric Avenue'")}
|
|
|
and Customer.Name='PHT' group by CustomerId,Customer.Name
|
|
|
""");
|
|
|
- result = requestResult.ToList();
|
|
|
- }
|
|
|
-
|
|
|
+ result = requestResult.ToList();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("GetChargerAmount Error " + ex.ToString());
|
|
|
- }
|
|
|
-
|
|
|
- //add PHT Electric Avenue
|
|
|
|
|
|
- return result;
|
|
|
}
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("GetChargerAmount Error " + ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ //add PHT Electric Avenue
|
|
|
|
|
|
- internal async Task<List<ChargerAmountDto>> GetPHTConnectorAmount(bool inner)
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ internal async Task<List<ChargerAmountDto>> GetPHTConnectorAmount(bool inner)
|
|
|
+ {
|
|
|
+ List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
+ try
|
|
|
{
|
|
|
- List<ChargerAmountDto> result = new List<ChargerAmountDto>();
|
|
|
- try
|
|
|
- {
|
|
|
- using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
- var queryResult = await dbConn.QueryAsync<ChargerAmountDto>($"""
|
|
|
- SELECT sum(GunAmt) as Charger_Count , Customer.Name as CustomerName FROM [dbo].[Machine]
|
|
|
- inner join Customer on Customer.id =[Machine].CustomerId where IsDelete=0 and Customer.Name='PHT'
|
|
|
- {(inner ? "and [ChargePointVendor]!='Electric Avenue'" : "and [ChargePointVendor]='Electric Avenue'")}
|
|
|
- and HeartbeatUpdatedOn>=@HeartbeatUpdatedOn group by CustomerId,Customer.Name
|
|
|
- """, parameters);
|
|
|
- result = queryResult.ToList();
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("GetConnectorAmount Error " + ex.ToString());
|
|
|
+ using (var dbConn = await mainDbConnectionFactory.CreateAsync())
|
|
|
+ {
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@HeartbeatUpdatedOn", new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), DbType.DateTime, ParameterDirection.Input);
|
|
|
+ var queryResult = await dbConn.QueryAsync<ChargerAmountDto>($"""
|
|
|
+ SELECT sum(GunAmt) as Charger_Count , Customer.Name as CustomerName FROM [dbo].[Machine]
|
|
|
+ inner join Customer on Customer.id =[Machine].CustomerId where IsDelete=0 and Customer.Name='PHT'
|
|
|
+ {(inner ? "and [ChargePointVendor]!='Electric Avenue'" : "and [ChargePointVendor]='Electric Avenue'")}
|
|
|
+ and HeartbeatUpdatedOn>=@HeartbeatUpdatedOn group by CustomerId,Customer.Name
|
|
|
+ """, parameters);
|
|
|
+ result = queryResult.ToList();
|
|
|
}
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("GetConnectorAmount Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
- //add PHT Electric Avenue
|
|
|
+ //add PHT Electric Avenue
|
|
|
|
|
|
- return result;
|
|
|
- }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- internal async Task SaveConnectionStatistics(List<ConnectionStatistics> connectionStatistics)
|
|
|
+ internal async Task SaveConnectionStatistics(List<ConnectionStatistics> connectionStatistics)
|
|
|
+ {
|
|
|
+ try
|
|
|
{
|
|
|
- try
|
|
|
+ using (var dbConn = await webDbConnectionFactory.CreateAsync())
|
|
|
+ using (var trans = await dbConn.BeginTransactionAsync())
|
|
|
{
|
|
|
- using (var dbConn = await webDbConnectionFactory.CreateAsync())
|
|
|
- using (var trans = await dbConn.BeginTransactionAsync())
|
|
|
+ foreach (var connection in connectionStatistics)
|
|
|
{
|
|
|
- foreach (var connection in connectionStatistics)
|
|
|
- {
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@CustomerName", connection.CustomerName, DbType.String, ParameterDirection.Input);
|
|
|
- parameters.Add("@StationName", connection.StationName, DbType.String, ParameterDirection.Input);
|
|
|
- parameters.Add("@StoragedChargerAmount", connection.StoragedChargerAmount, DbType.Int32, ParameterDirection.Input);
|
|
|
- parameters.Add("@UsedChargerAmount", connection.UsedChargerAmount, DbType.Int32, ParameterDirection.Input);
|
|
|
- parameters.Add("@UsedConnectorAmount", connection.UsedConnectorAmount, DbType.Int32, ParameterDirection.Input);
|
|
|
- parameters.Add("@CreatedOn", connection.CreatedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
-
|
|
|
- await dbConn.ExecuteAsync("""
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@CustomerName", connection.CustomerName, DbType.String, ParameterDirection.Input);
|
|
|
+ parameters.Add("@StationName", connection.StationName, DbType.String, ParameterDirection.Input);
|
|
|
+ parameters.Add("@StoragedChargerAmount", connection.StoragedChargerAmount, DbType.Int32, ParameterDirection.Input);
|
|
|
+ parameters.Add("@UsedChargerAmount", connection.UsedChargerAmount, DbType.Int32, ParameterDirection.Input);
|
|
|
+ parameters.Add("@UsedConnectorAmount", connection.UsedConnectorAmount, DbType.Int32, ParameterDirection.Input);
|
|
|
+ parameters.Add("@CreatedOn", connection.CreatedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
+
|
|
|
+ await dbConn.ExecuteAsync("""
|
|
|
INSERT INTO [dbo].[ConnectionStatistics]
|
|
|
([CustomerName],[StationName],[StoragedChargerAmount],[UsedChargerAmount],[UsedConnectorAmount],[CreatedOn])
|
|
|
VALUES(@CustomerName,@StationName,@StoragedChargerAmount,@UsedChargerAmount,@UsedConnectorAmount,@CreatedOn)
|
|
|
""", parameters);
|
|
|
- }
|
|
|
-
|
|
|
- await trans.CommitAsync();
|
|
|
}
|
|
|
+
|
|
|
+ await trans.CommitAsync();
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- logger.LogError("ReportStartTx Error " + ex.ToString());
|
|
|
- }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ logger.LogError("ReportStartTx Error " + ex.ToString());
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
}
|