|
@@ -19,6 +19,7 @@ using System.Data;
|
|
|
using System.Diagnostics;
|
|
|
using System.Globalization;
|
|
|
using SuperSocket.SocketBase;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
namespace EVCB_OCPP.WSServer.Message;
|
|
|
|
|
@@ -502,6 +503,16 @@ internal partial class ProfileHandler
|
|
|
t0 = timer.ElapsedMilliseconds;
|
|
|
|
|
|
var _idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
+
|
|
|
+ #region PnC 邏輯
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(_request.idTag))
|
|
|
+ {
|
|
|
+ _request.idTag = _request.idTag.StartsWith("vid:") ? _request.idTag.Replace("vid:", "") : _request.idTag;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
if (_request.idTag != "Backend")
|
|
|
{
|
|
|
var authorization_result = await businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
@@ -624,18 +635,36 @@ internal partial class ProfileHandler
|
|
|
break;
|
|
|
case Actions.StopTransaction:
|
|
|
{
|
|
|
+ StopTransactionRequest _request = request as StopTransactionRequest;
|
|
|
+
|
|
|
+ //遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
|
|
|
+ if (_request.timestamp < new DateTime(2021, 11, 1))
|
|
|
+ {
|
|
|
+ var confirm = new StopTransactionConfirmation()
|
|
|
+ {
|
|
|
+ idTagInfo = new IdTagInfo()
|
|
|
+ {
|
|
|
+ status = AuthorizationStatus.Invalid
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ result.Message = confirm;
|
|
|
+ result.Success = true;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
long getDateTimeTime, getServiceTime, getTagInfoTime, dbOpTime = 0, meterValueTime = 0;
|
|
|
var stopTrasactionTimer = Stopwatch.StartNew();
|
|
|
|
|
|
- StopTransactionRequest _request = request as StopTransactionRequest;
|
|
|
-
|
|
|
int _ConnectorId = 0;
|
|
|
-
|
|
|
var utcNow = DateTime.UtcNow;
|
|
|
+
|
|
|
getDateTimeTime = stopTrasactionTimer.ElapsedMilliseconds;
|
|
|
var businessService = await businessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
getServiceTime = stopTrasactionTimer.ElapsedMilliseconds;
|
|
|
|
|
|
+ TransactionRecord transaction;
|
|
|
+ transaction = await mainDbService.GetTransactionForStopTransaction(_request.transactionId, session.ChargeBoxId);
|
|
|
|
|
|
var _idTagInfo = string.IsNullOrEmpty(_request.idTag) ? null : (
|
|
|
_request.idTag == "Backend" ?
|
|
@@ -644,7 +673,7 @@ internal partial class ProfileHandler
|
|
|
expiryDate = utcNow.AddDays(1),
|
|
|
status = AuthorizationStatus.Accepted
|
|
|
} :
|
|
|
- (await businessService.Authorize(session.ChargeBoxId, _request.idTag)).IdTagInfo
|
|
|
+ (await businessService.Authorize(session.ChargeBoxId, _request.idTag, transaction?.ConnectorId)).IdTagInfo
|
|
|
);
|
|
|
getTagInfoTime = stopTrasactionTimer.ElapsedMilliseconds;
|
|
|
|
|
@@ -653,28 +682,16 @@ internal partial class ProfileHandler
|
|
|
{
|
|
|
_idTagInfo = new IdTagInfo() { expiryDate = utcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
}
|
|
|
- try
|
|
|
- {
|
|
|
- //遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
|
|
|
- if (_request.timestamp < new DateTime(2021, 11, 1))
|
|
|
- {
|
|
|
- var confirm = new StopTransactionConfirmation()
|
|
|
- {
|
|
|
- idTagInfo = new IdTagInfo()
|
|
|
- {
|
|
|
- status = AuthorizationStatus.Invalid
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
|
|
|
- result.Message = confirm;
|
|
|
- result.Success = true;
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- TransactionRecord transaction;
|
|
|
- transaction = await mainDbService.GetTransactionForStopTransaction(_request.transactionId, session.ChargeBoxId);
|
|
|
+ #region PnC 邏輯
|
|
|
+ if (!string.IsNullOrEmpty(_request.idTag))
|
|
|
+ {
|
|
|
+ _request.idTag = _request.idTag.StartsWith("vid:") ? _request.idTag.Replace("vid:", "") : _request.idTag;
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
|
|
|
+ try
|
|
|
+ {
|
|
|
if (transaction is null)
|
|
|
{
|
|
|
result.Exception = new Exception("Can't find transactionId " + _request.transactionId);
|
|
@@ -702,7 +719,8 @@ internal partial class ProfileHandler
|
|
|
await mainDbService.UpdateTransactionSOC(
|
|
|
transaction.Id,
|
|
|
startsoc: SOCCollection.Count == 0 ? "" : SOCCollection.First().ToString("0"),
|
|
|
- stopsoc: SOCCollection.Count == 0 ? "" : SOCCollection.Last().ToString("0");
|
|
|
+ stopsoc: SOCCollection.Count == 0 ? "" : SOCCollection.Last().ToString("0")
|
|
|
+ );
|
|
|
}
|
|
|
#endregion
|
|
|
|