|
@@ -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
|
|
|
|