ソースを参照

新增佔用費流程

Jessica Tseng 2 年 前
コミット
238ef3ed12

+ 123 - 7
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -63,6 +63,45 @@ namespace EVCB_OCPP.WSServer.Message
 
     }
 
+    public class ID_GetOccupancyFee
+    {
+        public int ConnectorId { set; get; }
+
+        public string occupancySN { set; get; }
+
+    }
+
+    public class ID_GetOccupancyFeeResult
+    {
+        public string msgId { set; get; }
+        public int ConnectorId { set; get; }
+
+        public string occupancySN { set; get; }
+
+        public string chargeEndTime { set; get; }
+
+        public int occupancyDuration { set; get; }
+
+
+        public decimal occupancyFee { set; get; }
+
+
+    }
+
+    public class ID_OccupancyFeeResult
+    {
+        public string occupancySN { set; get; }
+
+        public string creditNo { set; get; }
+
+
+        public bool deductResult { set; get; }
+
+        public decimal amount { set; get; }
+
+        public string approvalNo { set; get; }
+
+    }
     internal partial class ProfileHandler
     {
         static private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
@@ -85,6 +124,7 @@ namespace EVCB_OCPP.WSServer.Message
                     case Actions.DataTransfer:
                         {
                             DataTransferRequest _request = request as DataTransferRequest;
+
                             var confirm = new DataTransferConfirmation() { status = DataTransferStatus.UnknownMessageId };
 
                             if (_request.messageId == "ID_CreditDeductResult")
@@ -156,6 +196,82 @@ namespace EVCB_OCPP.WSServer.Message
 
                                 confirm.status = DataTransferStatus.Accepted;
                             }
+                            if (_request.messageId == "ID_GetOccupancyFee")
+                            {
+
+                                var getOccupancyFee = JsonConvert.DeserializeObject<ID_GetOccupancyFee>(_request.data);
+                                ID_GetOccupancyFeeResult occupancyFeeResult = new ID_GetOccupancyFeeResult()
+                                {
+                                    msgId = _request.messageId,
+                                    ConnectorId = getOccupancyFee.ConnectorId,
+                                    occupancySN = getOccupancyFee.occupancySN
+                                };
+                                var report = new
+                                {
+                                    ChargeBoxId = session.ChargeBoxId,
+                                    occupancySN = getOccupancyFee.occupancySN
+
+                                };
+
+                                var response = await httpClient.Post(GlobalConfig.TCC_API_URL + "occupancy_payment", new Dictionary<string, string>()
+                                        {
+                                            { "PartnerId",session.CustomerId.ToString()}
+
+                                        }, report, GlobalConfig.TCC_SALTKEY);
+
+                                logger.Debug(JsonConvert.SerializeObject(response));
+
+                                var _httpResult = JsonConvert.DeserializeObject<CPOOuterResponse>(response.Response);
+
+                                if (!string.IsNullOrEmpty(_httpResult.Data))
+                                {
+                                    JObject jo = JObject.Parse(_httpResult.Data);
+                                    if (jo.ContainsKey("ChargeEndTime"))
+                                    {
+                                        occupancyFeeResult.chargeEndTime = jo["ChargeEndTime"].Value<string>();
+
+                                    }
+
+                                    if (jo.ContainsKey("OccupancyDuration"))
+                                    {
+                                        occupancyFeeResult.occupancyDuration = jo["OccupancyDuration"].Value<int>();
+                                    }
+
+
+                                    if (jo.ContainsKey("OccupancyFee"))
+                                    {
+                                        occupancyFeeResult.occupancyFee = jo["OccupancyFee"].Value<decimal>();
+                                    }
+                                }
+
+                                confirm.status = DataTransferStatus.Accepted;
+                                confirm.data = JsonConvert.SerializeObject(occupancyFeeResult);
+                            }
+                            if (_request.messageId == "ID_OccupancyFeeResult")
+                            {
+
+                                var occupancyFeeResult = JsonConvert.DeserializeObject<ID_OccupancyFeeResult>(_request.data);
+                                var report = new
+                                {
+                                    OccupancySN = occupancyFeeResult.occupancySN,
+                                    CreditNo = occupancyFeeResult.creditNo,
+                                    DeductResult = occupancyFeeResult.deductResult,
+                                    Amount = occupancyFeeResult.amount,
+                                    ApprovalNo = occupancyFeeResult.approvalNo
+
+                                };
+
+                                var response = await httpClient.Post(GlobalConfig.TCC_API_URL + "occupancyfee_result", new Dictionary<string, string>()
+                                        {
+                                            { "PartnerId",session.CustomerId.ToString()}
+
+                                        }, report, GlobalConfig.TCC_SALTKEY);
+
+                                logger.Debug(JsonConvert.SerializeObject(response));
+
+                                confirm.status = DataTransferStatus.Accepted;
+                                confirm.data = JsonConvert.SerializeObject(new { msgId = _request.messageId, occupancySN = occupancyFeeResult.occupancySN });
+                            }
                             result.Message = confirm;
                             result.Success = true;
                         }
@@ -525,7 +641,7 @@ namespace EVCB_OCPP.WSServer.Message
                                     var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
                                      && x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
 
-                                   // throw new Exception("123");
+                                    // throw new Exception("123");
                                     //遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
                                     if (_request.timestamp < new DateTime(2021, 11, 1))
                                     {
@@ -646,15 +762,15 @@ namespace EVCB_OCPP.WSServer.Message
                                     }
                                 }
                             }
-                            catch(Exception ex)
+                            catch (Exception ex)
                             {
-                                result.Exception = new Exception("TransactionId " + _request.transactionId+" "+ ex.Message);
+                                result.Exception = new Exception("TransactionId " + _request.transactionId + " " + ex.Message);
                                 result.CallErrorMsg = "Reject Response Message";
                                 result.Success = false;
-                               // return result;
+                                // return result;
                             }
 
-                           
+
 
 
                         }
@@ -858,8 +974,8 @@ namespace EVCB_OCPP.WSServer.Message
                                             chargingCost = DollarRounding(chargingCost, session.Currency);
                                         }
 
-                                        // 計算停車費
-                                        var parkingFee = decimal.Parse(feedto.Fee.Split('&')[1]);
+                                        // 計算停車費 台泥不適用此停車費模式
+                                        var parkingFee = 0;// 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;

+ 14 - 1
EVCB_OCPP.WSServer/Program.cs

@@ -1,15 +1,28 @@
 using Newtonsoft.Json;
 using System;
+using System.Collections.Generic;
 using System.Net.Http;
 using System.Threading.Tasks;
 
 namespace EVCB_OCPP.WSServer
 {
-   
+
     class Program
     {
         static void Main(string[] args)
         {
+
+            Dictionary<long, long> dictionary = new Dictionary<long, long>()
+            {
+                {  DateTimeOffset.Now.AddDays(-3).ToUnixTimeSeconds(),  DateTimeOffset.Now.ToUnixTimeSeconds()},
+                {  DateTimeOffset.Now.AddDays(-2).ToUnixTimeSeconds(),  DateTimeOffset.Now.ToUnixTimeSeconds()},
+                {  DateTimeOffset.Now.AddDays(-1).ToUnixTimeSeconds(),  DateTimeOffset.Now.ToUnixTimeSeconds()}
+
+             };
+
+          var ttt=   JsonConvert.SerializeObject(dictionary);
+
+
             Console.WriteLine("====================================================================================================");
             Console.WriteLine("====================================================================================================");
             Console.WriteLine("==                                                                                                ==");

+ 61 - 17
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -1746,29 +1746,73 @@ namespace EVCB_OCPP.WSServer
                             {
 
                                 string displayPriceText = await SetDefaultFee(session);
-                                if (!string.IsNullOrEmpty(displayPriceText) && displayPriceText != session.DisplayPrice)
+                                if (!string.IsNullOrEmpty(displayPriceText))
                                 {
-                                    clientDic[item.Key].DisplayPrice = displayPriceText;
+                                    if (displayPriceText.StartsWith(";"))
+                                        return;
+                                    bool changeChargingPrice = false;
+                                    bool changeParkingPrice = false;
+                                    var displayPrices = displayPriceText.Split(';');
+                                    if (displayPrices[0] != session.DisplayChargingPrice)
+                                    {
+                                        changeChargingPrice = true;
+                                        clientDic[item.Key].DisplayChargingPrice = displayPrices[0];
+                                    }
+
+                                    if (displayPrices[1] != session.DisplayParkingPrice)
+                                    {
+                                        changeParkingPrice = true;
+                                        clientDic[item.Key].DisplayParkingPrice = displayPrices[1];
+                                    }
 
                                     using (var db = new MainDBContext())
                                     {
-                                        db.ServerMessage.Add(new ServerMessage()
+                                        if (changeChargingPrice)
                                         {
-                                            ChargeBoxId = session.ChargeBoxId,
-                                            CreatedBy = "Server",
-                                            CreatedOn = DateTime.UtcNow,
-                                            OutAction = Actions.ChangeConfiguration.ToString(),
-                                            OutRequest = JsonConvert.SerializeObject(
-                                                    new ChangeConfigurationRequest()
+                                            db.ServerMessage.Add(new ServerMessage()
+                                            {
+                                                ChargeBoxId = session.ChargeBoxId,
+                                                CreatedBy = "Server",
+                                                CreatedOn = DateTime.UtcNow,
+                                                OutAction = Actions.ChangeConfiguration.ToString(),
+                                                OutRequest = JsonConvert.SerializeObject(
+                                                   new ChangeConfigurationRequest()
+                                                   {
+                                                       key = "DefaultPrice",
+                                                       value = clientDic[item.Key].DisplayChargingPrice
+                                                   },
+                                                   new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
+                                                SerialNo = Guid.NewGuid().ToString(),
+                                                InMessage = string.Empty
+
+                                            }); ;
+                                        }
+                                        if (changeParkingPrice)
+                                        {
+                                            db.ServerMessage.Add(new ServerMessage()
+                                            {
+                                                ChargeBoxId = session.ChargeBoxId,
+                                                CreatedBy = "Server",
+                                                CreatedOn = DateTime.UtcNow,
+                                                OutAction = Actions.DataTransfer.ToString(),
+                                                OutRequest = JsonConvert.SerializeObject(
+                                                new DataTransferRequest()
+                                                {
+                                                    messageId = "ID_SetOccupancyPrice",
+                                                    vendorId = "Phihong Technology",
+                                                    data = JsonConvert.SerializeObject(new
                                                     {
-                                                        key = "DefaultPrice",
-                                                        value = clientDic[item.Key].DisplayPrice
-                                                    },
-                                                    new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
-                                            SerialNo = Guid.NewGuid().ToString(),
-                                            InMessage = string.Empty
+                                                        price = session.DisplayParkingPrice
+
+                                                    })
 
-                                        }); ;
+                                                },
+                                                new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
+                                                SerialNo = Guid.NewGuid().ToString(),
+                                                InMessage = string.Empty
+
+                                            });
+                                        }
 
                                         if (session.CustomerId == new Guid("10C7F5BD-C89A-4E2A-8611-B617E0B41A73"))
                                         {
@@ -1879,7 +1923,7 @@ namespace EVCB_OCPP.WSServer
                         }
                     }
 
-                    displayPriceText = stationPrice.FeeName;
+                    displayPriceText = string.Format("{0};{1} {2}/min", stationPrice.FeeName, stationPrice.ParkingFee, client.Currency);
                     client.BillingMethod = stationPrice.BillingMethod;
                     client.Currency = stationPrice.Currency;
                     client.ChargingFeebyHour = stationPrice.ChargingFeebyHour;

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

@@ -37,9 +37,14 @@ namespace OCPPServer.Protocol
         public List<ChargingPrice> ChargingPrices { set; get; }
 
         /// <summary>
-        /// 電樁顯示費率
+        /// 電樁顯示充電費率
         /// </summary>
-        public string DisplayPrice { set; get; }
+        public string DisplayChargingPrice { set; get; }
+
+        /// <summary>
+        /// 電樁占用費顯示費率
+        /// </summary>
+        public string DisplayParkingPrice { set; get; }
 
         /// <summary>
         /// 充電費率 以小時計費

BIN
SocketCommon/bin/Release/SuperSocket.Common.dll


BIN
SuperWebSocket/bin/Debug/SuperWebSocket.dll


BIN
SuperWebSocket/bin/Debug/SuperWebSocket.pdb