Browse Source

1. 調整Log
2. StopTransaction/StartTransaction 回調加入ReservationId

Jessica Tseng 2 years ago
parent
commit
32e039476b

+ 2 - 2
EVCB_OCPP.TaskScheduler/Jobs/CheckEVSEOnlineJob.cs

@@ -37,7 +37,7 @@ namespace EVCB_OCPP.TaskScheduler.Jobs
 
         public async Task Execute(IJobExecutionContext context)
         {
-            logger.Debug(this.ToString() + " :Starting........");
+           // logger.Debug(this.ToString() + " :Starting........");
 
 
             List<EVSECurrentStatus> _EVSEs = GetEVSEs();
@@ -222,7 +222,7 @@ namespace EVCB_OCPP.TaskScheduler.Jobs
             await UpdateOnlineRecords(updateData, insertData);
 
 
-            logger.Debug(this.ToString() + " :Finished........");
+          //  logger.Debug(this.ToString() + " :Finished........");
 
         }
 

+ 2 - 1
EVCB_OCPP.TaskScheduler/Jobs/StopTransacionReportJob.cs

@@ -22,7 +22,7 @@ namespace EVCB_OCPP.TaskScheduler.Jobs
 
         public async Task Execute(IJobExecutionContext context)
         {
-            await Console.Out.WriteLineAsync(this.ToString() + " :Starting........");
+            logger.Info(this.ToString() + " :Starting........");
 
             List<Task> tList = new List<Task>();
 
@@ -39,6 +39,7 @@ namespace EVCB_OCPP.TaskScheduler.Jobs
 
             Task.WaitAll(tList.ToArray());
 
+            logger.Info(this.ToString() + " :Finished........");
             await Console.Out.WriteLineAsync(this.ToString() + " :Finished........");
         }
 

+ 17 - 16
EVCB_OCPP.TaskScheduler/Services/CommonCustomerService.cs

@@ -150,17 +150,11 @@ namespace EVCB_OCPP.TaskScheduler.Services
 
                         _dbService.ReportStartTx(sendBack);
 
-
-
-
-
-
-
                     }
                 }
                 catch (Exception ex)
                 {
-                    Console.WriteLine("Assigned_StartTransactionCallbackTask Exception: " + ex.GetBaseException().ToString());
+                    logger.Error("Assigned_StartTransactionCallbackTask Exception: " + ex.GetBaseException().ToString());
                 }
 
                 ChargeRecordCallCounter++;
@@ -170,8 +164,8 @@ namespace EVCB_OCPP.TaskScheduler.Services
         }
 
         async public Task ReportStopTransaction()
-        {         
-            
+        {
+
             var items = _dbService.GetNeedReportSession(customerId, false, 1000);
 
             Stopwatch watch = new Stopwatch();
@@ -200,12 +194,17 @@ namespace EVCB_OCPP.TaskScheduler.Services
             }
             while (ChargeRecordCallCounter != groupTasks.Count)
             {
+                if (watch.ElapsedMilliseconds / 1000 > 300)
+                {
+                    logger.Error(customerId + " ReportStopTransaction Lock "+ ChargeRecordCallCounter+" "+ groupTasks.Count);
+                    break;
+                }
                 await Task.Delay(10);
             }
 
             watch.Stop();
 
-            Console.WriteLine("ReportStopTransaction Task(" + items.Count() + ") : It takes  " + watch.ElapsedMilliseconds / 1000 + " Seconds");
+            logger.Debug("ReportStopTransaction Task(" + items.Count() + ") : It takes  " + watch.ElapsedMilliseconds / 1000 + " Seconds");
 
         }
 
@@ -228,11 +227,11 @@ namespace EVCB_OCPP.TaskScheduler.Services
                         Parallel.ForEach(reportlst, po, async (r) =>
                         {
 
-                            if(!string.IsNullOrEmpty(r.Fee) && string.IsNullOrEmpty(r.Receipt))
+                            if (!string.IsNullOrEmpty(r.Fee) && string.IsNullOrEmpty(r.Receipt))
                             {
                                 //如果有計費但還沒結算 不回報給客戶
                                 completecounter++;
-                               
+
                             }
                             else
                             {
@@ -247,6 +246,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
                                     StartTime = r.StartTime.ToString(DefaultSetting.UTC_DATETIMEFORMAT),
                                     StopTime = r.StopTime.ToString(DefaultSetting.UTC_DATETIMEFORMAT),
                                     StopReason = r.StopReasonId < 1 ? "Unknown" : (r.StopReasonId > 12 ? "Unknown" : ((Reason)r.StopReasonId).ToString()),
+                                    ReservationId=r.ReservationId,
                                     Receipt = r.Receipt,
                                     TotalCost = r.Cost,
                                     Fee = r.Fee
@@ -273,13 +273,14 @@ namespace EVCB_OCPP.TaskScheduler.Services
                                     completecounter++;
                                 }
                             }
-                           
+
 
                         });
 
                         while (completecounter != reportlst.Count)
                         {
-                            await Task.Delay(10);
+                            logger.Debug(completecounter + "       " + reportlst.Count);
+                            await Task.Delay(10000);
                         }
 
                         _dbService.ReportStopTx(sendBack);
@@ -294,7 +295,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
                 }
                 catch (Exception ex)
                 {
-                    Console.WriteLine("Assigned_StartTransactionCallbackTask Exception: " + ex.GetBaseException().ToString());
+                    logger.Error("Assigned_StartTransactionCallbackTask Exception: " + ex.GetBaseException().ToString());
                 }
 
                 ChargeRecordCallCounter++;
@@ -420,7 +421,7 @@ namespace EVCB_OCPP.TaskScheduler.Services
                 }
                 catch (Exception ex)
                 {
-                    Console.WriteLine("Assigned_ReportExecutionofRemoteCommandTask Exception: " + ex.GetBaseException().ToString());
+                    logger.Debug("Assigned_ReportExecutionofRemoteCommandTask Exception: " + ex.GetBaseException().ToString());
                 }
 
                 ChargeRecordCallCounter++;

+ 3 - 3
EVCB_OCPP.TaskScheduler/Services/DatabaseService.cs

@@ -143,17 +143,17 @@ namespace EVCB_OCPP.TaskScheduler.Services
                     // 20220211 revised
                     if (isgoing)
                     {
-                        sqlString = "SELECT Top(" + size + ") Id, 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,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,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' ";
                         }
                     }