Эх сурвалжийг харах

1. CDFA 修改 費率改成單一時段或24小時時段 + 停車費
2.Trigger App.config 重新設定

Jessica Tseng 3 жил өмнө
parent
commit
4a3e9b9a45

+ 3 - 0
EVCB_OCPP.WSServer/Dto/ChargingPrice.cs

@@ -26,6 +26,9 @@ namespace EVCB_OCPP.WSServer.Dto
 
         public decimal PeriodEnergy { set; get; }
 
+        /// <summary>
+        /// 費率
+        /// </summary>
         public decimal Fee { set; get; }
     }
 }

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

@@ -23,9 +23,5 @@ namespace EVCB_OCPP.WSServer.Dto
         /// </summary>
         public string Currency { set; get; }
 
-        /// <summary>
-        /// 1:kwh 2:hr
-        /// </summary>
-        public int? BillingMethod { set; get; }
     }
 }

+ 88 - 44
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -1,4 +1,5 @@
-using EVCB_OCPP.Domain;
+using Dapper;
+using EVCB_OCPP.Domain;
 using EVCB_OCPP.Domain.Models.Database;
 using EVCB_OCPP.Packet.Features;
 using EVCB_OCPP.Packet.Messages;
@@ -12,6 +13,8 @@ using OCPPPackage.Profiles;
 using OCPPServer.Protocol;
 using System;
 using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
 using System.Data.Entity;
 using System.Data.SqlClient;
 using System.Diagnostics;
@@ -24,7 +27,7 @@ namespace EVCB_OCPP.WSServer.Message
     internal partial class ProfileHandler
     {
         static private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
-
+        string webConnectionString = ConfigurationManager.ConnectionStrings["WebDBContext"].ConnectionString;
 
         async internal Task<MessageResult> ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
         {
@@ -304,6 +307,20 @@ namespace EVCB_OCPP.WSServer.Message
                                 _idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
                             }
 
+                            string accountBalance = "0";
+                            if (session.CustomerId.ToString().ToUpper() == "10C7F5BD-C89A-4E2A-8611-B617E0B41A73")
+                            {
+                                using (SqlConnection conn = new SqlConnection(webConnectionString))
+                                {
+                                    var parameters = new DynamicParameters();
+                                    parameters.Add("@IdTag", _request.idTag, DbType.String, ParameterDirection.Input);
+                                    string strSql = "select parentIdTag from [dbo].[LocalListDetail]  where ListId = 27 and IdTag=@IdTag; ";
+                                    accountBalance = conn.ExecuteScalar<string>(strSql, parameters);
+
+                                }
+                            }
+
+
                             using (var db = new MainDBContext())
                             {
                                 var _CustomerId = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).Include(x => x.Customer).
@@ -326,7 +343,7 @@ namespace EVCB_OCPP.WSServer.Message
                                         CustomerId = _CustomerId,
                                         StartTime = _request.timestamp.ToUniversalTime(),
                                         ReservationId = _request.reservationId.HasValue ? _request.reservationId.Value : 0,
-                                        Fee = !session.IsBilling ? string.Empty : session.BillingMethod == 1 ? JsonConvert.SerializeObject(session.ChargingPrices) + "|" + session.Currency : session.HRPrice + "|" + session.Currency
+                                        Fee = !session.IsBilling ? string.Empty : JsonConvert.SerializeObject(session.ChargingPrices) + "|+" + accountBalance + "+" + "&" + session.ParkingFee + "&|" + session.Currency
 
                                     };
 
@@ -374,13 +391,13 @@ namespace EVCB_OCPP.WSServer.Message
                                 _idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
                             }
 
-
+                      
 
                             using (var db = new MainDBContext())
                             {
                                 var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
                                  && x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
-
+                              
                                 if (transaction != null)
                                 {
                                     _ConnectorId = transaction.ConnectorId;
@@ -576,18 +593,16 @@ namespace EVCB_OCPP.WSServer.Message
                                         if (feedto == null || string.IsNullOrEmpty(feedto.Fee)) return result;
                                         string currency = feedto.Fee.Substring(feedto.Fee.Length - 3);
                                         decimal sum = 0;
-                                        if (feedto.Fee.Length > 10)
+                                        // if (feedto.Fee.Length > 10)
                                         {
                                             chargingPrices = JsonConvert.DeserializeObject<List<ChargingPrice>>(feedto.Fee.Split('|')[0]);
                                             foreach (var item in txEnergy.PeriodEnergy)
                                             {
-                                                var periodEnergy = Math.Round(item.Value, 2, MidpointRounding.AwayFromZero);
                                                 string startTime = item.Key.Length == 1 ? "0" + item.Key + ":00" : item.Key + ":00";
                                                 decimal perfee = 0;
                                                 if (chargingPrices.Count == 1)
                                                 {
-
-                                                    perfee = Decimal.Multiply(periodEnergy, chargingPrices[0].Fee);
+                                                    perfee = Decimal.Multiply(item.Value, chargingPrices[0].Fee);
                                                     if (bill.Count == 0)
                                                     {
                                                         bill.Add(new ChargingBill()
@@ -597,22 +612,26 @@ namespace EVCB_OCPP.WSServer.Message
                                                             Fee = chargingPrices[0].Fee
                                                         });
                                                     }
-                                                    bill[0].PeriodEnergy += periodEnergy;
+                                                    bill[0].PeriodEnergy += item.Value;
+                                                    bill[0].PeriodEnergy = Math.Round(bill[0].PeriodEnergy, 3, MidpointRounding.AwayFromZero);
 
                                                 }
                                                 else
                                                 {
                                                     var price = chargingPrices.Where(x => x.StartTime == startTime).FirstOrDefault();
-                                                    perfee = Decimal.Multiply(periodEnergy, price.Fee);
+                                                    perfee = Decimal.Multiply(item.Value, price.Fee);
 
                                                     bill.Add(new ChargingBill()
                                                     {
                                                         StartTime = price.StartTime,
                                                         EndTime = price.EndTime,
-                                                        PeriodEnergy = periodEnergy,
-                                                        Fee = chargingPrices[0].Fee
+                                                        PeriodEnergy = Math.Round(item.Value, 3, MidpointRounding.AwayFromZero),
+                                                        Fee = price.Fee,
+
                                                     });
 
+
+
                                                 }
                                                 if (bill.Count > 0)
                                                 {
@@ -621,55 +640,58 @@ namespace EVCB_OCPP.WSServer.Message
 
                                                     if (bill.Count == 1)
                                                     {
+                                                        bill[0].PeriodEnergy = Math.Round(bill[0].PeriodEnergy, 3, MidpointRounding.AwayFromZero);
+                                                        bill[bill.Count - 1].Total = DollarRounding(Decimal.Multiply(bill[0].PeriodEnergy, bill[0].Fee), session.Currency);
                                                         sum = bill[bill.Count - 1].Total;
                                                     }
                                                 }
 
                                             }
                                         }
-                                        else
-                                        {
-                                      
-                                            // 以時計費
-                                            var fee = decimal.Parse(feedto.Fee.Split('|')[0]);
-
-                                            var totalHours = Math.Round(DateTime.UtcNow.Subtract(feedto.StartTime).TotalHours, 2, MidpointRounding.AwayFromZero);
-                                            sum = Decimal.Multiply((decimal)totalHours, fee);                                         
-                                            sum = DollarRounding(sum, session.Currency);
-                                            receipt = totalHours  + "hrs @ $" + fee + "/hr =" + sum;
-                                        }
-
-
-
 
                                         if (feedto.StopTime != GlobalConfig.DefaultNullTime)
                                         {
+                                            var gggg = feedto.Fee.Split('&')[1];
+                                            // 計算停車費
+                                            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)
                                             {
                                                 Console.WriteLine("Tx is empty");
                                                 return result;
                                             }
+                                            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("Energy:");
                                             while (startTime < tx.StopTime)
                                             {
                                                 if (bill.Count == 1)
                                                 {
                                                     confirmbill = bill;
-                                                    receipt = string.Format("{0} kWh @ ${1}/kWh={2}", bill[0].PeriodEnergy, bill[0].Fee, bill[0].Total);
+                                                    receipt += string.Format("| {0}~{1} @ ${2}/kWh=${3}", bill[0].StartTime, bill[0].EndTime, bill[0].Fee, bill[0].Total);
                                                     break;
                                                 }
                                                 if (bill.Count > 1)
                                                 {
+                                                  
                                                     confirmbill.Add(bill.Where(x => x.StartTime == startTime.ToString("HH:00")).FirstOrDefault());
                                                     if (confirmbill.Count == 24) break;
-                                                    if (confirmbill.Count > 1)
-                                                    {
-                                                        receipt += "|";
-                                                    }
-                                                    receipt += string.Format("{0}~{1} {2} kWh @ ${3}/kWh={4}", confirmbill[confirmbill.Count - 1].StartTime, confirmbill[confirmbill.Count - 1].EndTime,
-                                                        confirmbill[confirmbill.Count - 1].PeriodEnergy, bill[0].Fee, confirmbill[confirmbill.Count - 1].Total);
+                                                    //if (confirmbill.Count > 1)
+                                                    //{
+                                                    //    receipt += "|";
+                                                    //}
+                                                    receipt += string.Format("| {0}~{1} @ ${2}/kWh=${3}", confirmbill[confirmbill.Count - 1].StartTime, confirmbill[confirmbill.Count - 1].EndTime,
+                                                         confirmbill[confirmbill.Count - 1].Fee, confirmbill[confirmbill.Count - 1].Total);
 
 
 
@@ -677,20 +699,17 @@ namespace EVCB_OCPP.WSServer.Message
                                                 startTime = startTime.AddHours(1);
 
                                             }
-                                            if (bill.Count > 0)
-                                            {
-                                                confirmbill = confirmbill.Where(x => string.IsNullOrEmpty(x.StartTime) == false).ToList();
-                                            }
-
-                                            tx.Cost = sum;
-                                            tx.Receipt =  receipt;
 
+                                            receipt += string.Format("|Parking fee: | {0}~{1} @ ${2}/hr=${3}", feedto.StartTime.ToString("HH:mm"), feedto.StopTime.ToString("HH:mm"), fee, parkingCost);
+                                            tx.Cost = sum + parkingCost;
+                                            tx.Receipt = receipt;
+                                            tx.UploadedtoTTIA = true;
                                             db.Configuration.AutoDetectChangesEnabled = false;
                                             db.Configuration.ValidateOnSaveEnabled = false;
                                             db.TransactionRecord.Attach(tx);
                                             db.Entry(tx).Property(x => x.Cost).IsModified = true;
                                             db.Entry(tx).Property(x => x.Receipt).IsModified = true;
-
+                                            db.Entry(tx).Property(x => x.UploadedtoTTIA).IsModified = true;
 
                                             db.ServerMessage.Add(new ServerMessage()
                                             {
@@ -707,7 +726,7 @@ namespace EVCB_OCPP.WSServer.Message
                                                                 {
                                                                     txId = txEnergy.TxId,
                                                                     description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
-                                                                 "$0.00 {0}; Total Cost: ${1} {0}; Account Balance: $10.00 {0}", currency, sum)
+                                                                 "${2} {0}; Total Cost: ${3} {0}; Account Balance: ${4} {0}", currency, sum, parkingCost, tx.Cost, accountBalance - tx.Cost)
                                                                 })
 
                                                             },
@@ -718,6 +737,31 @@ namespace EVCB_OCPP.WSServer.Message
                                             }); ;
 
                                             db.SaveChanges();
+
+                                            using (SqlConnection conn = new SqlConnection(webConnectionString))
+                                            {
+
+                                                var parameters = new DynamicParameters();
+                                                parameters.Add("@IdTag", tx.StartIdTag, DbType.String, ParameterDirection.Input);
+                                                parameters.Add("@parentIdTag", accountBalance - tx.Cost, DbType.String, ParameterDirection.Input);
+                                                string strSql = "update [dbo].[LocalListDetail] set parentIdTag =@parentIdTag  where ListId = 27 and IdTag=@IdTag; ";
+                                                conn.Execute(strSql, parameters);
+
+                                            }
+
+                                            if (tx.CustomerId == Guid.Parse("10C7F5BD-C89A-4E2A-8611-B617E0B41A73"))
+                                            {
+                                                var mail_response = new OuterHttpClient().PostFormDataAsync("http://ocpp.phihong.com.tw/CDFA/" + tx.Id, new Dictionary<string, string>()
+                                                {
+                                                    { "email","2"},
+                                                    { "to","wonderj@phihongusa.com;jessica_tseng@phihong.com.tw"}
+
+                                               }, null);
+
+                                                Console.WriteLine(JsonConvert.SerializeObject(mail_response));
+
+                                            }
+
                                         }
                                         else
                                         {
@@ -1040,7 +1084,7 @@ namespace EVCB_OCPP.WSServer.Message
             }
             catch (Exception ex)
             {
-                logger.Debug("123 " + ex.ToString());
+                logger.Debug("123 " + action + " " + ex.ToString());
             }
 
 

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

@@ -35,4 +35,4 @@ using System.Runtime.InteropServices;
 [assembly: AssemblyVersion("0.1.0.0")]
 [assembly: AssemblyFileVersion("0.1.0.0")]
 
-[assembly: AssemblyInformationalVersion("2081228")]
+[assembly: AssemblyInformationalVersion("aeab43f")]

+ 4 - 4
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -1248,7 +1248,7 @@ namespace EVCB_OCPP.WSServer
 
                     }
 
-                    await Task.Delay(1000);
+                    await Task.Delay(500);
 
                 }
                 catch (Exception ex)
@@ -1404,7 +1404,7 @@ namespace EVCB_OCPP.WSServer
             {
                 var parameters = new DynamicParameters();
                 parameters.Add("@MachineId", client.MachineId, DbType.String, ParameterDirection.Input);
-                string displayPricestrSql = " SELECT  [FeeName],[Currency],[Fee],[BillingMethod]  FROM[StationMachine]  left join [dbo].[Station]" +
+                string displayPricestrSql = " SELECT  [FeeName],[Currency],[Fee]  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 ; ";
@@ -1414,7 +1414,7 @@ namespace EVCB_OCPP.WSServer
                 {
                     return string.Empty;
                 }
-                client.BillingMethod = stationPrice.BillingMethod;
+              
                 var chargingPriceResult = await conn.QueryAsync<ChargingPrice>(strSql, parameters);
                 client.ChargingPrices = chargingPriceResult.ToList();
                 if (string.IsNullOrEmpty(client.ChargingPrices[0].StartTime))
@@ -1423,7 +1423,7 @@ namespace EVCB_OCPP.WSServer
                 }
                 displayPriceText = stationPrice.FeeName;
                 client.Currency = stationPrice.Currency;
-                client.HRPrice = stationPrice.Fee;
+                client.ParkingFee = stationPrice.Fee;
                 client.IsBilling = true;
             }
 

+ 3 - 6
EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs

@@ -37,19 +37,16 @@ namespace OCPPServer.Protocol
         public string DisplayPrice { set; get; }
 
         /// <summary>
-        /// 以小時計費
+        /// 停車費率 以小時計費
         /// </summary>
-        public decimal HRPrice { set; get; }
+        public decimal ParkingFee { set; get; }
 
         /// <summary>
         /// 電樁是否計費
         /// </summary>
         public bool IsBilling { set; get; }
 
-        /// <summary>
-        /// 1:以度數計費 2:以小時計費
-        /// </summary>
-        public int? BillingMethod { set; get; }
+       
 
         public string CustomerName { get; set; }
 

+ 4 - 4
TestTool.RemoteTriggerAPP/App.config

@@ -35,16 +35,16 @@
   <applicationSettings>
     <TestTool.RemoteTriggerAPP.Properties.Settings>
       <setting name="UpdateFWPreUrl" serializeAs="String">
-        <value>http://test.evsocket.phihong.com.cn:9001/</value>
+        <value>http://ocpp.phihong.com.tw:5002/</value>
       </setting>
       <setting name="FTPUpdateFWPreUrl" serializeAs="String">
-        <value>ftp://testocpp:testocpp@test.evsocket.phihong.com.cn/</value>
+        <value>ftp://testocpp:testocpp@ocpp.phihong.com.tw/</value>
       </setting>
       <setting name="GetDiagnosticsPreUrl" serializeAs="String">
-        <value>http://ocpp.phihong.com.tw:9003/api/v1/file/</value>
+        <value>http://ocpp.phihong.com.tw:5000/api/v1/file/</value>
       </setting>
       <setting name="FTPGetDiagnosticsPreUrl" serializeAs="String">
-        <value>ftp://evseocpp:evseocpp@test.evsocket.phihong.com.cn/</value>
+        <value>ftp://evseocpp:evseocpp@ocpp.phihong.com.tw/</value>
       </setting>
     </TestTool.RemoteTriggerAPP.Properties.Settings>
   </applicationSettings>