Parcourir la source

1. 可支援AC/DC 三種費率 以小時計費/多時段度數費率/單一度數費率
2. 轉送台泥電樁預授權狀態

Jessica Tseng il y a 3 ans
Parent
commit
6d8b692696

+ 5 - 6
EVCB_OCPP.WSServer/App.config

@@ -7,14 +7,13 @@
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
   </configSections>
    <connectionStrings>
-   <add name="ConnectionLogDBContext" connectionString="data source=172.1.2.187,1434\SQLEXPRESS2017;initial catalog=StandardOCPP_ConnectionLog;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
-   <add name="MainDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_Main;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
-   <add name="MeterValueDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_MeterValue;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
-   <add name="WebDBContext" connectionString="data source=172.1.2.187\SQLEXPRESS2017;initial catalog=StandardOCPP_Web;persist security info=True;user id=sa;password=Ph0930118811;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
-
+     <add name="ConnectionLogDBContext" connectionString="data source=172.1.2.216\SQLEXPRESS;initial catalog=StandardOCPP_ConnectionLog;;persist security info=True;user id=tccdev;password=tccdevtest;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
+     <add name="MainDBContext" connectionString="data source=172.1.2.216\SQLEXPRESS;initial catalog=StandardOCPP_Main;;persist security info=True;user id=tccdev;password=tccdevtest;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
+     <add name="MeterValueDBContext" connectionString="data source=172.1.2.216\SQLEXPRESS;initial catalog=StandardOCPP_MeterValue;;persist security info=True;user id=tccdev;password=tccdevtest;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
+     <add name="WebDBContext" connectionString="data source=172.1.2.216\SQLEXPRESS;initial catalog=StandardOCPP_Web;;persist security info=True;user id=tccdev;password=tccdevtest;MultipleActiveResultSets=True;App=EntityFramework; Max Pool Size=500" providerName="System.Data.SqlClient" />
    </connectionStrings>
   <appSettings>   
-     <add key="LocalAuthAPI" value="http://172.1.2.187/PortalApi/1" />
+     <add key="LocalAuthAPI" value="" />
     <add key="WSPort" value="2012" />
     <add key="WSSPort" value="2016" />  
   </appSettings>

+ 2 - 0
EVCB_OCPP.WSServer/Dto/ID_GetTxUserInfo.cs

@@ -8,6 +8,8 @@ namespace EVCB_OCPP.WSServer.Dto
 {
     public class ID_GetTxUserInfo
     {
+        public string VEMData { set; get; }
+
         public string TxId { set; get; }
 
         public Guid? SerialNo { set; get; }

+ 10 - 0
EVCB_OCPP.WSServer/Dto/StationFee.cs

@@ -8,6 +8,11 @@ namespace EVCB_OCPP.WSServer.Dto
 {
     public class StationFee
     {
+        /// <summary>
+        /// 收費方式 1: 以度計費 2:以小時計費
+        /// </summary>
+        public int BillingMethod { set; get; }
+
         /// <summary>
         /// 電樁顯示用費率 
         /// </summary>
@@ -23,5 +28,10 @@ namespace EVCB_OCPP.WSServer.Dto
         /// </summary>
         public string Currency { set; get; }
 
+        /// <summary>
+        /// 充電費率 以小時計費
+        /// </summary>
+        public decimal ChargingFeebyHour { set; get; }
+
     }
 }

+ 73 - 65
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -121,26 +121,26 @@ namespace EVCB_OCPP.WSServer.Message
                             {
                                 if (session.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
                                 {
-                                    //var preauth_status = JsonConvert.DeserializeObject<ID_ReaderStatus>(_request.data);
-                                    //var report = new
-                                    //{
-                                    //    ChargeBoxId = session.ChargeBoxId,
-                                    //    ConnectorId = preauth_status.ConnectorId,
-                                    //    CreditNo = preauth_status.creditNo,
-                                    //    readerStatus = preauth_status.readerStatus,
-                                    //    SerialNo = preauth_status.SerialNo,
-                                    //    ApprovalNo = preauth_status.VEMData,
-                                    //    Timestamp = preauth_status.Timestamp                                    
-
-                                    //};
-
-                                    //var response = await httpClient.Post(GlobalConfig.TCC_API_URL + "preauth_status", new Dictionary<string, string>()
-                                    //    {
-                                    //        { "PartnerId",session.CustomerId.ToString()}
-
-                                    //    }, report, GlobalConfig.TCC_SALTKEY);
-
-                                    //logger.Debug(JsonConvert.SerializeObject(response));
+                                    var preauth_status = JsonConvert.DeserializeObject<ID_ReaderStatus>(_request.data);
+                                    var report = new
+                                    {
+                                        ChargeBoxId = session.ChargeBoxId,
+                                        ConnectorId = preauth_status.ConnectorId,
+                                        CreditNo = preauth_status.creditNo,
+                                        ReaderStatus = preauth_status.readerStatus,
+                                        SerialNo = preauth_status.SerialNo,
+                                        VEMData = preauth_status.VEMData,
+                                        Timestamp = preauth_status.Timestamp
+
+                                    };
+
+                                    var response = await httpClient.Post(GlobalConfig.TCC_API_URL + "preauth_status", new Dictionary<string, string>()
+                                        {
+                                            { "PartnerId",session.CustomerId.ToString()}
+
+                                        }, report, GlobalConfig.TCC_SALTKEY);
+
+
                                     confirm.status = DataTransferStatus.Accepted;
                                 }
                             }
@@ -483,11 +483,11 @@ namespace EVCB_OCPP.WSServer.Message
                                         MeterStart = _request.meterStart,
                                         CustomerId = _CustomerId,
                                         StartTime = _request.timestamp.ToUniversalTime(),
-                                        ReservationId = _request.reservationId.HasValue ? _request.reservationId.Value : 0,
-                                        Fee = !session.IsBilling ? string.Empty : JsonConvert.SerializeObject(session.ChargingPrices) + "|+" + accountBalance + "+" + "&" + session.ParkingFee + "&|" + session.Currency
-
+                                        ReservationId = _request.reservationId.HasValue ? _request.reservationId.Value : 0,                                    
                                     };
 
+                                    _newTransaction.Fee = !session.IsBilling ? string.Empty : session.BillingMethod == 1 ? JsonConvert.SerializeObject(session.ChargingPrices) : session.ChargingFeebyHour.ToString();
+                                    _newTransaction.Fee += !session.IsBilling ? string.Empty :"|+" + accountBalance + "+" + "&" + session.ParkingFee + "&|" + session.Currency;
                                     db.TransactionRecord.Add(_newTransaction);
 
                                     db.SaveChanges();
@@ -751,11 +751,11 @@ namespace EVCB_OCPP.WSServer.Message
                                         List<ChargingPrice> chargingPrices = new List<ChargingPrice>();
                                         var txEnergy = JsonConvert.DeserializeObject<TransactionEnergy>(_confirm.data);
                                         var feedto = db.TransactionRecord.Where(x => x.Id == txEnergy.TxId).Select(x => new { Id = x.Id, ConnectorId = x.ConnectorId, Fee = x.Fee, StopTime = x.StopTime, StartTime = x.StartTime }).FirstOrDefault();
-
+                                        decimal chargedEnergy = 0m;
                                         if (feedto == null || string.IsNullOrEmpty(feedto.Fee)) return result;
                                         string currency = feedto.Fee.Substring(feedto.Fee.Length - 3);
                                         decimal chargingCost = 0;
-                                        if (feedto.Fee.Length > 10)
+                                        if (feedto.Fee.Length > 58)
                                         {
                                             chargingPrices = JsonConvert.DeserializeObject<List<ChargingPrice>>(feedto.Fee.Split('|')[0]);
                                             foreach (var item in txEnergy.PeriodEnergy)
@@ -766,6 +766,7 @@ namespace EVCB_OCPP.WSServer.Message
 
                                                 //小數點無條件捨去到第4位
                                                 var periodEnergy = (decimal)((int)Decimal.Multiply(item.Value, 10000) / (double)10000);
+                                                chargedEnergy += periodEnergy;
                                                 if (chargingPrices.Count == 1)
                                                 {
                                                     perfee = Decimal.Multiply(periodEnergy, chargingPrices[0].Fee);
@@ -810,20 +811,34 @@ namespace EVCB_OCPP.WSServer.Message
                                                 }
                                             }
                                         }
+                                        else
+                                        {
+                                            //以小時計費
+                                            foreach (var item in txEnergy.PeriodEnergy)
+                                            {  //小數點無條件捨去到第4位
+                                                var periodEnergy = (decimal)((int)Decimal.Multiply(item.Value, 10000) / (double)10000);
+                                                chargedEnergy += periodEnergy;
+                                            }
+
+                                            var fee = decimal.Parse(feedto.Fee.Split('|')[0]);
+                                            var charging_stoptime = feedto.StopTime == GlobalConfig.DefaultNullTime ? DateTime.Parse(DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm")) : DateTime.Parse(feedto.StopTime.ToString("yyyy/MM/dd HH:mm"));
+                                            var charging_starttime = DateTime.Parse(feedto.StartTime.ToString("yyyy/MM/dd HH:mm"));
+                                            chargingCost = Decimal.Multiply((decimal)charging_stoptime.Subtract(charging_starttime).TotalHours, fee);
+                                            chargingCost = DollarRounding(chargingCost, session.Currency);
+                                        }
+
+                                        // 計算停車費
+                                        var parkingFee = decimal.Parse(feedto.Fee.Split('&')[1]);
+                                        var stoptime = feedto.StopTime==GlobalConfig.DefaultNullTime ? DateTime.Parse(DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm")) : DateTime.Parse(feedto.StopTime.ToString("yyyy/MM/dd HH:mm"));
+                                        var starttime = DateTime.Parse(feedto.StartTime.ToString("yyyy/MM/dd HH:mm"));
+                                        var totalHours = stoptime.Subtract(starttime).TotalHours;
+                                        var parkingCost = Decimal.Multiply((decimal)totalHours, parkingFee);
+                                        parkingCost = DollarRounding(parkingCost, session.Currency);
 
                                         if (feedto.StopTime != GlobalConfig.DefaultNullTime)
                                         {
-
-                                            // 計算停車費
-                                            var fee = decimal.Parse(feedto.Fee.Split('&')[1]);
                                             decimal accountBalance = 0;
-                                            var stoptime = DateTime.Parse(feedto.StopTime.ToString("yyyy/MM/dd HH:mm"));
-                                            var starttime = DateTime.Parse(feedto.StartTime.ToString("yyyy/MM/dd HH:mm"));
                                             decimal.TryParse(feedto.Fee.Split('+')[1], out accountBalance);
-                                            var totalHours = stoptime.Subtract(starttime).TotalHours;
-                                            var parkingCost = Decimal.Multiply((decimal)totalHours, fee);
-                                            parkingCost = DollarRounding(parkingCost, session.Currency);
-
 
                                             var tx = db.TransactionRecord.Where(x => x.Id == txEnergy.TxId).FirstOrDefault();
                                             if (tx == null)
@@ -834,15 +849,23 @@ namespace EVCB_OCPP.WSServer.Message
                                             if (tx.UploadedtoTTIA) return result;
                                             var startTime = new DateTime(tx.StartTime.Year, tx.StartTime.Month, tx.StartTime.Day, tx.StartTime.Hour, 0, 0);
                                             List<ChargingBill> confirmbill = new List<ChargingBill>();
-                                            receipt = string.Format("({0} )Energy:", bill.Sum(x => x.PeriodEnergy));
-
+                                            receipt = string.Format("({0} )Energy:", chargedEnergy);
 
                                             while (startTime < tx.StopTime)
                                             {
                                                 if (bill.Count == 1)
                                                 {
                                                     confirmbill = bill;
-                                                    receipt += string.Format("| {0} - {1}:| {2} kWh @ ${3}/kWh=${4}", tx.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")), confirmbill[0].PeriodEnergy.ToString("0.0000"), tx.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), bill[0].Fee, bill[0].Total);
+                                                    receipt += string.Format("| {0} - {1}:| {2} kWh @ ${3}/kWh=${4}", tx.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")), tx.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")),
+                                                        confirmbill[0].PeriodEnergy.ToString("0.0000"), bill[0].Fee, bill[0].Total);
+
+                                                    break;
+                                                }
+                                                if (bill.Count == 0)
+                                                {
+                                                    receipt += string.Format("| {0} - {1} @ ${2}/hr=${3}", feedto.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")),
+                                                       feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), feedto.Fee.Split('|')[0], chargingCost);
+
                                                     break;
                                                 }
                                                 if (bill.Count > 1)
@@ -879,24 +902,21 @@ namespace EVCB_OCPP.WSServer.Message
 
                                             if (session.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
                                             {
-                                                // if (confirmbill.Count > 1)
-                                                {
-                                                    chargingCost = confirmbill.Sum(x => x.Total);
-                                                    chargingCost = confirmbill.Sum(x => x.PeriodEnergy) == 0 ? 0 : (chargingCost + parkingCost < 1 ? 1 : chargingCost);  //台泥最低一元
-                                                    receipt += string.Format("|Total Energy Fee : ${0}", chargingCost);
-                                                }
+                                                chargingCost = confirmbill.Count > 0 ? confirmbill.Sum(x => x.Total) : chargingCost;
+                                                chargingCost = chargedEnergy == 0 ? 0 : (chargingCost + parkingCost < 1 ? 1 : chargingCost);  //台泥最低一元
+                                                receipt += string.Format("|Total Energy Fee : ${0}", chargingCost);
+
                                                 receipt += string.Format("|Parking Fee: | {0} - {1} @ ${2}/hr=${3}", feedto.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")),
-                                                feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), fee, parkingCost);
+                                                feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), parkingFee, parkingCost);
                                                 tx.Cost = chargingCost + parkingCost;
                                             }
                                             else
                                             {
-                                                if (confirmbill.Count > 1)
-                                                {
-                                                    receipt += string.Format("|Total Energy Fee : ${0}", confirmbill.Sum(x => x.Total));
-                                                }
+                                                chargingCost = confirmbill.Count > 0 ? confirmbill.Sum(x => x.Total) : chargingCost;
+                                                receipt += string.Format("|Total Energy Fee : ${0}", chargingCost);
+
                                                 receipt += string.Format("|Parking Fee: | {0} - {1} @ ${2}/hr=${3}", feedto.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")),
-                                                feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), fee, parkingCost);
+                                                feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), parkingFee, parkingCost);
                                                 tx.Cost = chargingCost + parkingCost;
                                             }
 
@@ -925,7 +945,7 @@ namespace EVCB_OCPP.WSServer.Message
                                                                     txId = txEnergy.TxId,
                                                                     description = JsonConvert.SerializeObject(new
                                                                     {
-                                                                        chargedEnergy = bill.Sum(x => x.PeriodEnergy),
+                                                                        chargedEnergy = chargedEnergy,
                                                                         chargingFee = chargingCost,
                                                                         parkTime = (int)stoptime.Subtract(starttime).TotalSeconds,
                                                                         parkingFee = parkingCost,
@@ -994,17 +1014,6 @@ namespace EVCB_OCPP.WSServer.Message
                                         }
                                         else
                                         {
-
-                                            // 計算停車費
-                                            var fee = decimal.Parse(feedto.Fee.Split('&')[1]);
-                                            decimal accountBalance = 0;
-                                            var stoptime = DateTime.Parse(DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm"));
-                                            var starttime = DateTime.Parse(feedto.StartTime.ToString("yyyy/MM/dd HH:mm"));
-                                            decimal.TryParse(feedto.Fee.Split('+')[1], out accountBalance);
-                                            var totalHours = stoptime.Subtract(starttime).TotalHours;
-                                            var parkingCost = Decimal.Multiply((decimal)totalHours, fee);
-                                            parkingCost = DollarRounding(parkingCost, session.Currency);
-
                                             db.ServerMessage.Add(new ServerMessage()
                                             {
                                                 ChargeBoxId = session.ChargeBoxId,
@@ -1019,11 +1028,9 @@ namespace EVCB_OCPP.WSServer.Message
                                                      data = JsonConvert.SerializeObject(new
                                                      {
                                                          txId = txEnergy.TxId,
-                                                         //description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
-                                                         //"${2} {0}; Total Cost: ${3} {0}; Account Balance: $0.00 {0}", currency, sum, parkingCost, sum + parkingCost),
                                                          description = JsonConvert.SerializeObject(new
                                                          {
-                                                             chargedEnergy = bill.Sum(x => x.PeriodEnergy),
+                                                             chargedEnergy = chargedEnergy,
                                                              chargingFee = chargingCost,
                                                              parkTime = (int)stoptime.Subtract(starttime).TotalSeconds,
                                                              parkingFee = parkingCost,
@@ -1083,7 +1090,8 @@ namespace EVCB_OCPP.WSServer.Message
                                             ConnectorId = txUserInfo.ConnectorId,
                                             SessionId = txUserInfo.TxId,
                                             SerialNo = txUserInfo.SerialNo,
-                                            StartTime = txUserInfo.StartTime.ToString(GlobalConfig.UTC_DATETIMEFORMAT)
+                                            StartTime = txUserInfo.StartTime.ToString(GlobalConfig.UTC_DATETIMEFORMAT),
+                                            VEMData = txUserInfo.VEMData
                                         };
 
                                         var response = httpClient.Post(GlobalConfig.TCC_API_URL + "start_session", new Dictionary<string, string>()

+ 4 - 4
EVCB_OCPP.WSServer/Properties/AssemblyInfo.cs

@@ -31,8 +31,8 @@ using System.Runtime.InteropServices;
 //
 // 您可以指定所有的值,或將組建編號或修訂編號設為預設值
 // 指定為預設值: 
-// [assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyFileVersion("1.0.2.0")]
+// [assembly: AssemblyVersion("1.0.3.0")]
+[assembly: AssemblyVersion("1.0.3.0")]
+[assembly: AssemblyFileVersion("1.0.3.0")]
 
-[assembly: AssemblyInformationalVersion("2771388")]
+[assembly: AssemblyInformationalVersion("0d7e6f6")]

+ 101 - 69
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -452,8 +452,6 @@ namespace EVCB_OCPP.WSServer
                         RemoveClient(_removeClient);
                     }
 
-                    session.IsCheckIn = true;
-
                     clientDic.Add(session.ChargeBoxId, session);
                     session.m_ReceiveData += new ClientData.OCPPClientDataEventHandler<ClientData, String>(ReceivedMessage);
                     // logger.Debug("------------New " + (session == null ? "Oops" : session.ChargeBoxId));
@@ -758,16 +756,9 @@ namespace EVCB_OCPP.WSServer
                                 {
                                     if (((BootNotificationConfirmation)replyResult.Message).status == Packet.Messages.SubTypes.RegistrationStatus.Accepted)
                                     {
-                                        using (var db = new MainDBContext())
-                                        {
-                                            var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
-                                            if (machine != null)
-                                            {
-                                                machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
-                                                db.SaveChanges();
-                                            }
-                                        }
+                                        session.IsCheckIn = true;
 
+                                      
                                         CheckVersion(session.ChargeBoxId);
                                         CheckEVSEConfigure(session.ChargeBoxId);
 
@@ -871,6 +862,20 @@ namespace EVCB_OCPP.WSServer
                                     }
                                     else
                                     {
+                                        using (var db = new MainDBContext())
+                                        {
+                                            var machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
+                                            if (machine != null)
+                                            {
+                                                if (machine.ConnectorType.Contains("6") || machine.ConnectorType.Contains("7") || machine.ConnectorType.Contains("8") || machine.ConnectorType.Contains("9"))
+                                                {
+                                                    session.IsAC = false;
+                                                }
+                                                machine.ConnectionType = session.Origin.Contains("https") ? 2 : 1;
+                                                db.SaveChanges();
+                                            }
+                                        }
+
                                         await SetDefaultFee(session);
                                     }
                                 }
@@ -1818,77 +1823,104 @@ namespace EVCB_OCPP.WSServer
             {
                 var parameters = new DynamicParameters();
                 parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input);
-                string displayPricestrSql = " SELECT  [FeeName],[Currency],[ParkingFee]  FROM[StationMachine]  left join [dbo].[Station]" +
+                string displayPricestrSql = "";
+                string strSql = "";
+                logger.Debug(client.MachineId + " " + client.IsAC);
+                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=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; ";
-                string 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 ; ";
+
+                    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; ";
+
+                }
                 var result = await conn.QueryAsync<StationFee>(displayPricestrSql, parameters);
-                var stationPrice = result.FirstOrDefault();
+                var stationPrice = result.First();
                 if (stationPrice == null)
                 {
                     return string.Empty;
                 }
-
-                var chargingPriceResult = await conn.QueryAsync<ChargingPrice>(strSql, parameters);
-                client.ChargingPrices = chargingPriceResult.ToList();
-                if (string.IsNullOrEmpty(client.ChargingPrices[0].StartTime))
+                if (stationPrice.BillingMethod == 1)
                 {
-                    client.ChargingPrices = new List<ChargingPrice>();
+                    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;
 
-
-                if (client.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
-                {
-                    if (displayPriceText.StartsWith("AC") || displayPriceText.StartsWith("DC"))
-                    {
-
-                        if (client.ChargeBoxId.StartsWith("D"))
-                        {
-
-                            var unitWords = displayPriceText.Split(';').ToList();
-                            int dcIndex = unitWords.FindIndex(x => x.Contains("DC"));
-                            displayPriceText = unitWords[dcIndex].Replace("DC:", "");
-                            var priceText = displayPriceText.Split('$')[1].TrimStart(' ').Split('/')[0]; ;
-                            var dc_UnitPrice = int.Parse(priceText);
-                            client.ChargingPrices = new List<ChargingPrice>()
-                          {
-                              new ChargingPrice()
-                              {
-                                   EndTime="23:59",
-                                   StartTime="00:00",
-                                   Fee=dc_UnitPrice
-                              }
-                          };
-
-
-                        }
-                        else
-                        {
-                            var unitWords = displayPriceText.Split(';').ToList();
-                            int dcIndex = unitWords.FindIndex(x => x.Contains("AC"));
-                            displayPriceText = unitWords[dcIndex].Replace("AC:", "");
-                            var priceText = displayPriceText.Split('$')[1].TrimStart(' ').Split('/')[0]; ;
-                            var ac_UnitPrice = int.Parse(priceText);
-                            client.ChargingPrices = new List<ChargingPrice>()
-                          {
-                              new ChargingPrice()
-                              {
-                                   EndTime="23:59",
-                                   StartTime="00:00",
-                                   Fee=ac_UnitPrice
-                              }
-                          };
-                            Console.WriteLine("Chargeboxid=>" + client.ChargeBoxId);
-                        }
-
-
-                    }
-
-                }
+                logger.Debug(string.Format("displayPriceText:{0}\r\n client.BillingMethod:{1}\r\n client.Currency:{2}\r\nclient.ChargingFeebyHour:{3}\r\nclient.ParkingFee:{4}\r\n",
+                   displayPriceText, client.BillingMethod, client.Currency, client.ChargingFeebyHour, client.ParkingFee));
+
+                //    if (client.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
+                //    {
+                //        if (displayPriceText.StartsWith("AC") || displayPriceText.StartsWith("DC"))
+                //        {
+
+                //            if (client.ChargeBoxId.StartsWith("D"))
+                //            {
+
+                //                var unitWords = displayPriceText.Split(';').ToList();
+                //                int dcIndex = unitWords.FindIndex(x => x.Contains("DC"));
+                //                displayPriceText = unitWords[dcIndex].Replace("DC:", "");
+                //                var priceText = displayPriceText.Split('$')[1].TrimStart(' ').Split('/')[0]; ;
+                //                var dc_UnitPrice = int.Parse(priceText);
+                //                client.ChargingPrices = new List<ChargingPrice>()
+                //              {
+                //                  new ChargingPrice()
+                //                  {
+                //                       EndTime="23:59",
+                //                       StartTime="00:00",
+                //                       Fee=dc_UnitPrice
+                //                  }
+                //              };
+
+
+                //            }
+                //            else
+                //            {
+                //                var unitWords = displayPriceText.Split(';').ToList();
+                //                int dcIndex = unitWords.FindIndex(x => x.Contains("AC"));
+                //                displayPriceText = unitWords[dcIndex].Replace("AC:", "");
+                //                var priceText = displayPriceText.Split('$')[1].TrimStart(' ').Split('/')[0]; ;
+                //                var ac_UnitPrice = int.Parse(priceText);
+                //                client.ChargingPrices = new List<ChargingPrice>()
+                //              {
+                //                  new ChargingPrice()
+                //                  {
+                //                       EndTime="23:59",
+                //                       StartTime="00:00",
+                //                       Fee=ac_UnitPrice
+                //                  }
+                //              };
+                //                Console.WriteLine("Chargeboxid=>" + client.ChargeBoxId);
+                //            }
+
+
+                //        }
+
+                //    }
             }
 
             return displayPriceText;

+ 19 - 2
EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs

@@ -29,6 +29,11 @@ namespace OCPPServer.Protocol
 
         public bool ResetSecurityProfile { set; get; }
 
+
+        public bool IsAC { set; get; }
+
+        #region Billing
+
         public List<ChargingPrice> ChargingPrices { set; get; }
 
         /// <summary>
@@ -36,6 +41,11 @@ namespace OCPPServer.Protocol
         /// </summary>
         public string DisplayPrice { set; get; }
 
+        /// <summary>
+        /// 充電費率 以小時計費
+        /// </summary>
+        public decimal ChargingFeebyHour { set; get; }
+
         /// <summary>
         /// 停車費率 以小時計費
         /// </summary>
@@ -46,15 +56,21 @@ namespace OCPPServer.Protocol
         /// </summary>
         public bool IsBilling { set; get; }
 
+        /// <summary>
+        /// 收費方式 1: 以度計費 2:以小時計費
+        /// </summary>
+        public int BillingMethod { set; get; }
        
 
-        public string CustomerName { get; set; }
-
         /// <summary>
         /// 電樁適用幣別
         /// </summary>
         public string Currency { get; internal set; }
 
+        #endregion
+
+        public string CustomerName { get; set; }
+
 
         public string StationName { set; get; }
 
@@ -67,6 +83,7 @@ namespace OCPPServer.Protocol
 
         public ClientData()
         {
+            IsAC = true;
             IsPending = false;
             IsCheckIn = false;
             ChargeBoxId = SessionID;