Browse Source

1. Modify customId when retrieving the configuration with the key "CentralChargeBoxId"/"ChargeBoxId"

Jessica Tseng 7 months ago
parent
commit
ece7eee5af

+ 14 - 9
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -1573,12 +1573,9 @@ internal partial class ProfileHandler
 
 						try
 						{
-							GetConfigurationConfirmation _confirm = confirm as GetConfigurationConfirmation;
-							//  GetConfigurationRequest _request = _confirm.GetRequest() as GetConfigurationRequest;
-
-							List<Task> updateTasks = new List<Task>();
+							GetConfigurationConfirmation _confirm = confirm as GetConfigurationConfirmation;							
                             List<MachineConfigurations> configure = await mainDbService.GetMachineConfiguration(session.ChargeBoxId);
-
+							string customId = string.Empty;
                             if (_confirm.configurationKey != null)
                             {
                                 foreach (var item in _confirm.configurationKey)
@@ -1591,8 +1588,12 @@ internal partial class ProfileHandler
 
                                     var foundConfig = configure.Find(x => x.ConfigureName == item.key);
                                     var updateValue = string.IsNullOrEmpty(item.value) ? string.Empty : item.value;
+									if (item.key == "CentralChargeBoxId" || item.key == "ChargeBoxId")
+									{
+										customId = item.value;
+									}
 
-                                    if (foundConfig == null)
+									if (foundConfig == null)
                                     {
                                         await mainDbService.AddMachineConfiguration(session.ChargeBoxId, item.key, updateValue, item.IsReadOnly);
                                     }
@@ -1606,7 +1607,7 @@ internal partial class ProfileHandler
                                         if (foundConfig.ConfigureName == "SecurityProfile")
                                         {
                                             oldValue = foundConfig.ConfigureSetting;
-                                        }
+                                        }										
 
                                         await mainDbService.UpdateMachineConfiguration(session.ChargeBoxId, item.key, updateValue, item.IsReadOnly);
                                     }
@@ -1641,11 +1642,15 @@ internal partial class ProfileHandler
 									operation.EvseStatus = 1;
 									operation.EvseValue = JsonConvert.SerializeObject(_confirm.configurationKey, Formatting.None);
 
-								}
-
+								}								
 								await db.SaveChangesAsync();
 
 							}
+							if (!string.IsNullOrEmpty(customId))
+							{
+								await mainDbService.UpdateCustomId(customId, session.ChargeBoxId);
+							}
+
 						}
 						catch (Exception ex)
 						{

+ 25 - 1
EVCB_OCPP.WSServer/Service/DbService/MainDbService.cs

@@ -63,6 +63,7 @@ public interface IMainDbService
 
     Task<Dictionary<string, decimal>> GetTransactionPeriodEnergy(int transactionId);
 
+    Task<bool> UpdateCustomId(string customId, string chargeboxId);
 
 }
 
@@ -454,7 +455,30 @@ public class MainDbService : IMainDbService
         return UpdateHeartBeatsDapper(machineIds);
     }
 
-    public async Task UpdateMachineConnectionType(string chargeBoxId, int connectionType)
+	public async Task<bool> UpdateCustomId(string customId,string chargeboxId)
+	{
+		using var conn = await sqlConnectionFactory.CreateAsync();
+		try
+		{
+			var parameters = new DynamicParameters();
+			parameters.Add("@ChargeBoxId", chargeboxId, size: 50);
+			parameters.Add("@CustomId", customId, size: 25);
+			var resultCnt = await conn.ExecuteAsync("""
+                UPDATE Machine
+                SET CustomId = @CustomId
+                WHERE ChargeBoxId = @ChargeBoxId
+                """, parameters);
+		}
+		catch (Exception e)
+		{
+			logger.LogError(e.Message);
+			logger.LogCritical("UpdateCustomId update fail");
+			return false;
+		}
+		return true;
+	}
+
+	public async Task UpdateMachineConnectionType(string chargeBoxId, int connectionType)
     {
         using var semaphoreWrapper = await startupSemaphore.GetToken();
         using var db = await contextFactory.CreateDbContextAsync();