瀏覽代碼

1.加入拔槍通知
2.接收線上支付實際扣款金額

Jessica Tseng 2 年之前
父節點
當前提交
f66cfe6506

+ 67 - 6
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -8,6 +8,7 @@ using EVCB_OCPP.Packet.Messages.SubTypes;
 using EVCB_OCPP.WSServer.Dto;
 using EVCB_OCPP.WSServer.Service;
 using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using NLog;
 using OCPPPackage.Profiles;
 using OCPPServer.Protocol;
@@ -144,6 +145,13 @@ namespace EVCB_OCPP.WSServer.Message
                                     confirm.data = JsonConvert.SerializeObject(new { msgId = "ID_ReaderStatus", ConnectorId = preauth_status.ConnectorId });
                                 }
                             }
+                            if (_request.messageId == "ConnectorUnplugged")
+                            {
+                                JObject jo = JObject.Parse(_request.data);
+
+                                var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
+                                await businessService.NotifyConnectorUnplugged(session.ChargeBoxId, jo["txId"].Value<string>(), jo["timestamp"].Value<string>());
+                            }
                             result.Message = confirm;
                             result.Success = true;
                         }
@@ -710,7 +718,7 @@ namespace EVCB_OCPP.WSServer.Message
             return result;
         }
 
-        internal MessageResult ExecuteCoreConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
+        async internal Task<MessageResult> ExecuteCoreConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
         {
             MessageResult result = new MessageResult() { Success = true };
 
@@ -928,15 +936,70 @@ namespace EVCB_OCPP.WSServer.Message
                                                 tx.Cost = chargingCost + parkingCost;
                                             }
 
+
+                                            tx.StopTransactionReportedOn = DateTime.UtcNow;
                                             tx.Receipt = receipt;
                                             tx.UploadedtoTTIA = true;
                                             db.Configuration.AutoDetectChangesEnabled = false;
                                             db.Configuration.ValidateOnSaveEnabled = false;
                                             db.TransactionRecord.Attach(tx);
+                                            db.Entry(tx).Property(x => x.StopTransactionReportedOn).IsModified = true;
                                             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;
 
+                                            #region 同步發送充電結束通知
+                                            decimal? discountFee = null;//折扣金額
+                                            decimal? chargingAmount = null;//充電抵用金使用金額
+                                            decimal? actualFee = null;  //實際付款金額
+
+                                            var request = new
+                                            {
+                                                ChargeBoxId = tx.ChargeBoxId,
+                                                ConnectorId = tx.ConnectorId,
+                                                SessionId = tx.Id,
+                                                MeterStart = tx.MeterStart,
+                                                MeterStop = tx.MeterStop,
+                                                IdTag = tx.StartIdTag,
+                                                StartTime = tx.StartTime.ToString(GlobalConfig.UTC_DATETIMEFORMAT),
+                                                StopTime = tx.StopTime.ToString(GlobalConfig.UTC_DATETIMEFORMAT),
+                                                StopReason = tx.StopReasonId < 1 ? "Unknown" : (tx.StopReasonId > 12 ? "Unknown" : ((Reason)tx.StopReasonId).ToString()),
+                                                Receipt = tx.Receipt,
+                                                TotalCost = tx.Cost,
+                                                Fee = tx.Fee
+
+                                            };
+
+                                            var response = await httpClient.Post(GlobalConfig.TCC_API_URL + "completed_session", new Dictionary<string, string>()
+                                                {
+                                                    { "PartnerId",session.CustomerId.ToString()}
+
+                                                }, request, GlobalConfig.TCC_SALTKEY);
+
+                                            var _httpResult = JsonConvert.DeserializeObject<CPOOuterResponse>(response.Response);
+                                            if (!string.IsNullOrEmpty(_httpResult.Data))
+                                            {
+                                                JObject jo = JObject.Parse(_httpResult.Data);
+                                                if (jo.ContainsKey("discountAmount"))
+                                                {
+                                                    discountFee = jo["discountAmount"].Value<decimal>();
+
+                                                }
+
+                                                if (jo.ContainsKey("chargingAmount"))
+                                                {
+                                                    chargingAmount = jo["chargingAmount"].Value<decimal>();
+                                                }
+
+
+                                                if (jo.ContainsKey("actualAmount"))
+                                                {
+                                                    actualFee = jo["actualAmount"].Value<decimal>();
+                                                }
+                                            }
+                                            #endregion
+
+
                                             db.ServerMessage.Add(new ServerMessage()
                                             {
                                                 ChargeBoxId = session.ChargeBoxId,
@@ -954,17 +1017,15 @@ namespace EVCB_OCPP.WSServer.Message
                                                                     description = JsonConvert.SerializeObject(new
                                                                     {
                                                                         chargedEnergy = chargedEnergy,
-                                                                        chargingFee = chargingCost,
+                                                                        chargingFee = actualFee.HasValue ? actualFee : chargingCost,
                                                                         parkTime = (int)stoptime.Subtract(starttime).TotalSeconds,
                                                                         parkingFee = parkingCost,
                                                                         currency = currency,
-                                                                        couponPoint = 0,
                                                                         accountBalance = accountBalance - tx.Cost
-                                                                    })
+                                                                    }, GlobalConfig.JSONSERIALIZER_FORMAT)
                                                                 })
 
-                                                            },
-                                                            new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
+                                                            }, GlobalConfig.JSONSERIALIZER_FORMAT),
                                                 SerialNo = Guid.NewGuid().ToString(),
                                                 InMessage = string.Empty
 

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

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

+ 3 - 3
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -886,7 +886,7 @@ namespace EVCB_OCPP.WSServer
                                         {
                                             ChargeBoxId = session.ChargeBoxId,
                                             CreatedBy = "Server",
-                                            CreatedOn = DateTime.UtcNow,
+                                            CreatedOn = DateTime.UtcNow.AddMinutes(1),
                                             OutAction = Actions.DataTransfer.ToString(),
                                             OutRequest = JsonConvert.SerializeObject(
                                                     new DataTransferRequest()
@@ -1035,7 +1035,7 @@ namespace EVCB_OCPP.WSServer
             }
         }
 
-        private void ProcessConfirmationMessage(MessageResult analysisResult, ClientData session, Actions action)
+        async private void ProcessConfirmationMessage(MessageResult analysisResult, ClientData session, Actions action)
         {
 
             BasicMessageHandler msgAnalyser = new BasicMessageHandler();
@@ -1047,7 +1047,7 @@ namespace EVCB_OCPP.WSServer
                 {
                     case "Core":
                         {
-                            confirmResult = profileHandler.ExecuteCoreConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
+                            confirmResult = await profileHandler.ExecuteCoreConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
                         }
                         break;
                     case "FirmwareManagement":

+ 1 - 1
EVCB_OCPP.WSServer/Service/BusinessServiceFactory.cs

@@ -14,7 +14,7 @@ namespace EVCB_OCPP.WSServer.Service
 
         Task NotifyFaultStatus(ErrorDetails details);
 
-        Task NotifyConnectorUnplugged(string chargeBoxId,string data);
+        Task NotifyConnectorUnplugged(string chargeBoxId,string transactionId,string timestamp);
 
     }
 

+ 1 - 1
EVCB_OCPP.WSServer/Service/LocalBusinessService.cs

@@ -78,7 +78,7 @@ namespace EVCB_OCPP.WSServer.Service
 
         }
 
-        async public Task NotifyConnectorUnplugged(string chargeBoxId, string data)
+        async public Task NotifyConnectorUnplugged(string chargeBoxId, string transactionId, string timestamp)
         {
             await Task.Delay(10);
         }

+ 3 - 3
EVCB_OCPP.WSServer/Service/OuterBusinessService.cs

@@ -150,13 +150,13 @@ namespace EVCB_OCPP.WSServer.Service
 
         }
 
-        async public Task NotifyConnectorUnplugged(string chargeBoxId, string data)
+        async public Task NotifyConnectorUnplugged(string chargeBoxId, string transactionId, string timestamp)
         {
             try
             {
-                JObject jo = JObject.Parse(data);
+                JObject jo = JObject.Parse(transactionId);
 
-                var details = new { ChargeBoxId = chargeBoxId, SessionId = jo["idTx"].Value<Int32>(), Timestamp = jo["timestamp"].Value<DateTime>() };
+                var details = new { ChargeBoxId = chargeBoxId, SessionId = transactionId, Timestamp = timestamp };
                 if (signMaterial.CallsThirdParty)
                 {
                     var response = await httpClient.Post(signMaterial.APIUrl + "connectorunplugged", new Dictionary<string, string>()