Эх сурвалжийг харах

update string builder / change to async await

Robert 1 жил өмнө
parent
commit
5ccbe363e5

+ 25 - 10
EVCB_OCPP.TaskScheduler/Services/DatabaseService.cs

@@ -44,7 +44,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
             string name = string.Empty;
             try
             {
-                using (var dbConn = mainDbConnectionFactory.Create())
+                using (var dbConn = await mainDbConnectionFactory.CreateAsync())
                 {
                     var parameters = new DynamicParameters();
                     parameters.Add("@Id", customerId, DbType.Guid);
@@ -66,7 +66,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
             bool result = false;
             try
             {
-                using (var dbConn = mainDbConnectionFactory.Create())
+                using (var dbConn = await mainDbConnectionFactory.CreateAsync())
                 {
                     //dbConn.Open();
                     var parameters = new DynamicParameters();
@@ -147,7 +147,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
             List<Transaction> result = new List<Transaction>();
             try
             {
-                using (var dbConn = mainDbConnectionFactory.Create())
+                using (var dbConn = await mainDbConnectionFactory.CreateAsync())
                 {
                     //dbConn.Open();
                     var parameters = new DynamicParameters();
@@ -157,17 +157,29 @@ namespace EVCB_OCPP.TaskScheduler.Services
                     // 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' ";
+                        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
                     {
                         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 FROM [dbo].[TransactionRecord] where CustomerId=@CustomerId and StopTime!='1991/1/1' and StopTransactionReportedOn='1991/1/1' and  BillingDone=1";
+                            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 FROM [dbo].[TransactionRecord] where CustomerId=@CustomerId and StopTime!='1991/1/1' and StopTransactionReportedOn='1991/1/1' ";
+                            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' 
+                                """;
                         }
                     }
 
@@ -195,9 +207,12 @@ namespace EVCB_OCPP.TaskScheduler.Services
                     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 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'";
+                    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();
                 }
             }
@@ -274,7 +289,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
 
             try
             {
-                using (var dbConn = mainDbConnectionFactory.Create())
+                using (var dbConn = await mainDbConnectionFactory.CreateAsync())
                 {
                     //dbConn.Open();
                     await dbConn.ExecuteAsync("CheckUnCommitMachineOperateCommand", new { @TimeoutIntervalSeconds = intervalSeconds }, null, null, commandType: CommandType.StoredProcedure);