Pārlūkot izejas kodu

add main commit
Commit 24183186: 1.新增 iso15118 hardcode 回覆,提供電樁測試使用
2.加入 SetDefaultFee Exception catch

Robert 1 gadu atpakaļ
vecāks
revīzija
914f9cffa3

+ 16 - 0
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -190,6 +190,22 @@ internal partial class ProfileHandler
                             confirm.status = DataTransferStatus.Accepted;
                             confirm.data = JsonConvert.SerializeObject(new { txId = jo["txId"].Value<int>(), msgId = _request.messageId });
                         }
+
+                        if (_request.messageId == "Authorize")
+                        {
+                            string iso15118_token = string.Empty;
+                            JObject jo = JObject.Parse(_request.data);
+                            if (jo.ContainsKey("idToken"))
+                            {
+                                iso15118_token = jo["idToken"].Value<string>();
+
+                            }
+
+                            confirm.status = DataTransferStatus.Accepted;
+                            confirm.data = JsonConvert.SerializeObject(new { certificateStatus = iso15118_token == "12345678901234" ? "Accepted" : "CertificateExpired", idTokenInfo = new { status = iso15118_token == "12345678901234" ? "Accepted" : "Invalid" } });
+
+
+                        }
                         result.Message = confirm;
                         result.Success = true;
                     }

+ 48 - 40
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -1229,56 +1229,64 @@ namespace EVCB_OCPP.WSServer
 
             if (string.IsNullOrEmpty(client.ChargeBoxId)) return displayPriceText;
 
-            using (SqlConnection conn = new SqlConnection(webConnectionString))
+            try
             {
-                var parameters = new DynamicParameters();
-                parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input, 36);
-                string displayPricestrSql = "";
-                string strSql = "";
 
-                if (client.IsAC)
+                using (SqlConnection conn = new SqlConnection(webConnectionString))
                 {
-                    displayPricestrSql = "   SELECT  [AC_BillingMethod] as BillingMethod,[AC_FeeName] as FeeName,[AC_Fee] as ChargingFeebyHour" +
-                "  ,[AC_ParkingFee] as ParkingFee, [Currency]  FROM[StationMachine]  left join[dbo].[Station]" +
-                "  on[StationMachine].StationId = Station.[Id]  where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
+                    var parameters = new DynamicParameters();
+                    parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input, 36);
+                    string displayPricestrSql = "";
+                    string strSql = "";
 
-                    strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee]  FROM[StationMachine]  left join [dbo].[StationFee]" +
-                   " on[StationMachine].StationId = StationFee.StationId  where StationMachine.MachineId =@MachineId and StationFee.IsAC=1; ";
-                }
-                else
-                {
-                    displayPricestrSql = "   SELECT  [DC_BillingMethod] as BillingMethod,[DC_FeeName] as FeeName,[DC_Fee] as ChargingFeebyHour" +
-               "  ,[DC_ParkingFee] as ParkingFee, [Currency]  FROM[StationMachine]  left join[dbo].[Station]" +
-               "  on[StationMachine].StationId = Station.[Id]  where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
+                    if (client.IsAC)
+                    {
+                        displayPricestrSql = "   SELECT  [AC_BillingMethod] as BillingMethod,[AC_FeeName] as FeeName,[AC_Fee] as ChargingFeebyHour" +
+                    "  ,[AC_ParkingFee] as ParkingFee, [Currency]  FROM[StationMachine]  left join[dbo].[Station]" +
+                    "  on[StationMachine].StationId = Station.[Id]  where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
 
-                    strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee]  FROM[StationMachine]  left join [dbo].[StationFee]" +
-                   " on[StationMachine].StationId = StationFee.StationId  where StationMachine.MachineId =@MachineId and StationFee.IsAC=0; ";
+                        strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee]  FROM[StationMachine]  left join [dbo].[StationFee]" +
+                       " on[StationMachine].StationId = StationFee.StationId  where StationMachine.MachineId =@MachineId and StationFee.IsAC=1; ";
+                    }
+                    else
+                    {
+                        displayPricestrSql = "   SELECT  [DC_BillingMethod] as BillingMethod,[DC_FeeName] as FeeName,[DC_Fee] as ChargingFeebyHour" +
+                   "  ,[DC_ParkingFee] as ParkingFee, [Currency]  FROM[StationMachine]  left join[dbo].[Station]" +
+                   "  on[StationMachine].StationId = Station.[Id]  where StationMachine.MachineId=@MachineId and Station.IsBilling=1; ";
 
-                }
-                //var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
-                var result = await conn.QueryFirstOrDefaultAsync<StationFee>(displayPricestrSql, parameters);
-                if (result == default)
-                {
-                    return string.Empty;
-                }
-                var stationPrice = result;//.First();
+                        strSql = " SELECT CAST( [StartTime] as varchar(5)) StartTime,CAST( [EndTime] as varchar(5)) EndTime,[Fee]  FROM[StationMachine]  left join [dbo].[StationFee]" +
+                       " on[StationMachine].StationId = StationFee.StationId  where StationMachine.MachineId =@MachineId and StationFee.IsAC=0; ";
 
-                if (stationPrice.BillingMethod == 1)
-                {
-                    var chargingPriceResult = await conn.QueryAsync<ChargingPrice>(strSql, parameters);
-                    client.ChargingPrices = chargingPriceResult.ToList();
-                    if (string.IsNullOrEmpty(client.ChargingPrices[0].StartTime))
+                    }
+                    //var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
+                    var result = await conn.QueryFirstOrDefaultAsync<StationFee>(displayPricestrSql, parameters);
+                    if (result == default)
                     {
-                        client.ChargingPrices = new List<ChargingPrice>();
+                        return string.Empty;
                     }
-                }
+                    var stationPrice = result;//.First();
 
-                displayPriceText = stationPrice.FeeName;
-                client.BillingMethod = stationPrice.BillingMethod;
-                client.Currency = stationPrice.Currency;
-                client.ChargingFeebyHour = stationPrice.ChargingFeebyHour;
-                client.ParkingFee = stationPrice.ParkingFee;
-                client.IsBilling = true;
+                    if (stationPrice.BillingMethod == 1)
+                    {
+                        var chargingPriceResult = await conn.QueryAsync<ChargingPrice>(strSql, parameters);
+                        client.ChargingPrices = chargingPriceResult.ToList();
+                        if (string.IsNullOrEmpty(client.ChargingPrices[0].StartTime))
+                        {
+                            client.ChargingPrices = new List<ChargingPrice>();
+                        }
+                    }
+
+                    displayPriceText = stationPrice.FeeName;
+                    client.BillingMethod = stationPrice.BillingMethod;
+                    client.Currency = stationPrice.Currency;
+                    client.ChargingFeebyHour = stationPrice.ChargingFeebyHour;
+                    client.ParkingFee = stationPrice.ParkingFee;
+                    client.IsBilling = true;
+                }
+            }
+            catch (Exception ex)
+            {
+                logger.Error("SetDefaultFee", ex.ToString());
             }
 
             return displayPriceText;