Robert 1 жил өмнө
parent
commit
6786ac566d

+ 1 - 1
EVCB_OCPP.WSServer/Jobs/StationConfigPollingJob.cs

@@ -39,7 +39,7 @@ namespace EVCB_OCPP.WSServer.Jobs
 
                 var stationId = evseStationPair[chargboxId];
                 var configs = stationEvseConfigs[stationId];
-                await protalServer.CheckandUpdateConfig(chargboxId, configs);
+                await protalServer.ComparenUpdateConfig(chargboxId, configs);
             }
         }
     }

+ 1 - 0
EVCB_OCPP.WSServer/Message/BasicMessageHandler.cs

@@ -88,6 +88,7 @@ namespace EVCB_OCPP.WSServer.Message
             }
             return msg;
         }
+
         static internal string GenerateConfirmationofOCPP20(string uniqueId, EVCB_OCPP20.Packet.Messages.IConfirmation confirmation)
         {
             string msg = string.Empty;

+ 41 - 14
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -1019,9 +1019,12 @@ namespace EVCB_OCPP.WSServer
             var displayPriceText = await webDbService.SetDefaultFee(session);
             UpdateClientDisplayPrice(session.ChargeBoxId, displayPriceText);
 
-            sendTask = async () => await messageService.SendChangeConfigurationRequest(
-                session.ChargeBoxId, key: "DefaultPrice", value: displayPriceText);
-            await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
+            if (!string.IsNullOrEmpty(displayPriceText))
+            {
+                sendTask = async () => await messageService.SendChangeConfigurationRequest(
+                    session.ChargeBoxId, key: "DefaultPrice", value: displayPriceText);
+                await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
+            }
 
             if (session.CustomerId == new Guid("298918C0-6BB5-421A-88CC-4922F918E85E") || session.CustomerId == new Guid("9E6BFDCC-09FB-4DAB-A428-43FE507600A3"))
             {
@@ -1035,12 +1038,7 @@ namespace EVCB_OCPP.WSServer
                     session.ChargeBoxId, key: "StopTransactionOnInvalidId", value: "True");
             }
 
-            sendTask = async () => await messageService.SendGetEVSEConfigureRequest(session.ChargeBoxId);
-            response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
-            if (response.Success && response.Message is GetConfigurationConfirmation confirmation)
-            {
-                await CheckandUpdateConfig(session.ChargeBoxId, confirmation.configurationKey.ToDictionary(x => x.key, x => x.value));
-            }
+            await GetnChecknUpdateConfig(session.ChargeBoxId, session.DisconnetCancellationToken);
 
             sendTask = async () => await messageService.SendDataTransferRequest(
                 session.ChargeBoxId,
@@ -1050,19 +1048,48 @@ namespace EVCB_OCPP.WSServer
             await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, session.DisconnetCancellationToken);
         }
 
-        internal async Task CheckandUpdateConfig(string chargeBoxId, Dictionary<string,string> currentConfigs, CancellationToken token = default)
+        internal async Task GetnChecknUpdateConfig(string chargeBoxId, CancellationToken token = default)
         {
-            List<KeyValuePair<string, string>> configs = await webDbService.GetCustomerStationEvseConfig(chargeBoxId);
+            MessageResult response = await GetEvseCurrentConfig(chargeBoxId, token);
+            if (!response.Success || response.Message is not GetConfigurationConfirmation confirmation)
+            {
+                return;
+            }
+
+            Dictionary<string,string> configs = await GetEvseDBCurrentConfig(chargeBoxId, token);
             if (configs == null)
             {
                 logger.LogInformation("{0} get station config failed", chargeBoxId);
                 return;
             }
 
-            foreach(var config in configs)
+            await ComparenUpdateConfig(chargeBoxId, 
+                evseCurrentConfigs: confirmation.configurationKey.ToDictionary(x => x.key, x => x.value), 
+                evseDbConfigs: configs, 
+                token);
+        }
+
+        private async Task<MessageResult> GetEvseCurrentConfig(string chargeBoxId, CancellationToken token = default)
+        {
+            var sendTask = async () => await messageService.SendGetEVSEConfigureRequest(chargeBoxId);
+            var response = await confirmWaitingMessageSerevice.SendAndWaitUntilResultAsync(sendTask, token);
+            return response;
+        }
+
+        private Task<Dictionary<string, string>> GetEvseDBCurrentConfig(string chargeBoxId, CancellationToken token = default)
+        {
+            return webDbService.GetCustomerStationEvseConfig(chargeBoxId, token);
+        }
+
+        internal async Task ComparenUpdateConfig(string chargeBoxId, 
+            Dictionary<string,string> evseCurrentConfigs,
+            Dictionary<string, string> evseDbConfigs,
+            CancellationToken token = default)
+        {
+            foreach(var config in evseDbConfigs)
             {
-                if (currentConfigs.Keys.Contains(config.Key) &&
-                    currentConfigs[config.Key] == config.Value)
+                if (evseCurrentConfigs.Keys.Contains(config.Key) &&
+                    evseCurrentConfigs[config.Key] == config.Value)
                 {
                     continue;
                 }

+ 7 - 18
EVCB_OCPP.WSServer/Service/DbService/WebDbService.cs

@@ -128,31 +128,20 @@ public class WebDbService
         return displayPriceText;
     }
 
-    internal async Task<List<KeyValuePair<string, string>>> GetCustomerStationEvseConfig(string chargeBoxId)
+    internal async Task<Dictionary<string, string>> GetCustomerStationEvseConfig(string chargeBoxId, CancellationToken token = default)
     {
-        string getStationStrSql = """
-                SELECT [StationId] 
+        string strSql = """
+                SELECT [ConfigureName], [ConfigureSetting]
                 FROM [dbo].[StationMachine]
-                where [ChargeBoxId] = @ChargeBoxId;
-                """;
-        string getConfigStrSql = """
-                SELECT [ConfigureName],[ConfigureSetting]
-                FROM [dbo].[StationMachineConfig]
-                where [StationId] = @StationId;
+                INNER Join [dbo].[StationMachineConfig] on [dbo].[StationMachine].StationId = [dbo].[StationMachineConfig].StationId
+                WHERE [ChargeBoxId] = @ChargeBoxId
                 """;
 
         using SqlConnection conn = await webDbConnectionFactory.CreateAsync();
         DynamicParameters parameters = new DynamicParameters();
         parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 25);
-        int stationId = await conn.QueryFirstOrDefaultAsync<int>(getStationStrSql, parameters);
-        if (stationId == default)
-        {
-            return null;
-        }
-        parameters = new DynamicParameters();
-        parameters.Add("@StationId", stationId, DbType.Int32, ParameterDirection.Input);
-        var configs = await conn.QueryAsync<StationMachineConfig>(getConfigStrSql, parameters);
-        return configs.Select(x => new KeyValuePair<string, string>(x.ConfigureName, x.ConfigureSetting)).ToList();
+        var configs = await conn.QueryAsync<StationMachineConfig>(new CommandDefinition(strSql, parameters: parameters, cancellationToken: token));
+        return configs.ToDictionary(x=>x.ConfigureName, x=>x.ConfigureSetting);
     }
 
     internal async Task<Dictionary<string, int>> GetEvseStationPair(List<string> chargeboxIds)