|
@@ -422,33 +422,33 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+
|
|
|
if (session.IsBilling)
|
|
|
- if (session.IsBilling)
|
|
|
+ {
|
|
|
+ using (var db = new MainDBContext())
|
|
|
{
|
|
|
- using (var db = new MainDBContext())
|
|
|
+ db.ServerMessage.Add(new ServerMessage()
|
|
|
{
|
|
|
- db.ServerMessage.Add(new ServerMessage()
|
|
|
- {
|
|
|
- ChargeBoxId = session.ChargeBoxId,
|
|
|
- CreatedBy = "Server",
|
|
|
- CreatedOn = DateTime.UtcNow,
|
|
|
- OutAction = Actions.DataTransfer.ToString(),
|
|
|
- OutRequest = JsonConvert.SerializeObject(
|
|
|
- new DataTransferRequest()
|
|
|
- {
|
|
|
- messageId = "ID_TxEnergy",
|
|
|
- vendorId = "Phihong Technology",
|
|
|
- data = JsonConvert.SerializeObject(new { txId = _request.transactionId, ConnectorId = _request.connectorId })
|
|
|
- },
|
|
|
- new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
- SerialNo = Guid.NewGuid().ToString(),
|
|
|
- InMessage = string.Empty
|
|
|
+ ChargeBoxId = session.ChargeBoxId,
|
|
|
+ CreatedBy = "Server",
|
|
|
+ CreatedOn = DateTime.UtcNow,
|
|
|
+ OutAction = Actions.DataTransfer.ToString(),
|
|
|
+ OutRequest = JsonConvert.SerializeObject(
|
|
|
+ new DataTransferRequest()
|
|
|
+ {
|
|
|
+ messageId = "ID_TxEnergy",
|
|
|
+ vendorId = "Phihong Technology",
|
|
|
+ data = JsonConvert.SerializeObject(new { txId = _request.transactionId, ConnectorId = _request.connectorId })
|
|
|
+ },
|
|
|
+ new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ SerialNo = Guid.NewGuid().ToString(),
|
|
|
+ InMessage = string.Empty
|
|
|
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
+ db.SaveChanges();
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|
|
@@ -476,6 +476,14 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
|
|
|
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);
|
|
@@ -588,33 +596,41 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
break;
|
|
|
case Actions.StopTransaction:
|
|
|
{
|
|
|
- StopTransactionRequest _request = request as StopTransactionRequest;
|
|
|
-
|
|
|
- int _ConnectorId = 0;
|
|
|
-
|
|
|
- var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
- var _idTagInfo = string.IsNullOrEmpty(_request.idTag) ? null : (_request.idTag == "Backend" ?
|
|
|
- new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted } : (await businessService.Authorize(session.ChargeBoxId, _request.idTag)).IdTagInfo);
|
|
|
-
|
|
|
+ StopTransactionRequest stopRequest = request as StopTransactionRequest;
|
|
|
+ IdTagInfo idTagInfo = null;
|
|
|
+ int connectorId = 0;
|
|
|
|
|
|
|
|
|
//特例****飛宏客戶旗下的電樁,若遇到Portal沒回應的狀況 ~允許充電
|
|
|
- if (session.CustomerId.ToString().ToUpper() == "8456AED9-6DD9-4BF3-A94C-9F5DCB9506F7" && _idTagInfo != null && _idTagInfo.status == AuthorizationStatus.ConcurrentTx)
|
|
|
+ if (session.CustomerId.ToString().ToUpper() == "8456AED9-6DD9-4BF3-A94C-9F5DCB9506F7" && idTagInfo != null && idTagInfo.status == AuthorizationStatus.ConcurrentTx)
|
|
|
{
|
|
|
- _idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
+ idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
- var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
|
|
|
+ var transaction = db.TransactionRecord.Where(x => x.Id == stopRequest.transactionId
|
|
|
&& x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
+
|
|
|
+ var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
+ idTagInfo = string.IsNullOrEmpty(stopRequest.idTag) ? null : (stopRequest.idTag == "Backend" ?
|
|
|
+ new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted } : (await businessService.Authorize(session.ChargeBoxId, stopRequest.idTag, transaction.ConnectorId)).IdTagInfo);
|
|
|
+
|
|
|
+
|
|
|
+ #region PnC 邏輯
|
|
|
+ if (!string.IsNullOrEmpty(stopRequest.idTag))
|
|
|
+ {
|
|
|
+ stopRequest.idTag = stopRequest.idTag.StartsWith("vid:") ? stopRequest.idTag.Replace("vid:", "") : stopRequest.idTag;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
|
|
|
#region 加入Transaction Start/StopSOC
|
|
|
- if (!session.IsAC && _request.transactionId > 0)
|
|
|
+ if (!session.IsAC && stopRequest.transactionId > 0)
|
|
|
{
|
|
|
var SearchTime = transaction.StartTime;
|
|
|
- var txStopTime = _request.timestamp;
|
|
|
+ var txStopTime = stopRequest.timestamp;
|
|
|
List<int> SOCCollection = new List<int>();
|
|
|
|
|
|
while (SearchTime.Date <= txStopTime.Date)
|
|
@@ -631,8 +647,9 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
transaction.StopSOC = SOCCollection.Count() == 0 ? "" : SOCCollection.Last().ToString("0");
|
|
|
}
|
|
|
#endregion
|
|
|
+
|
|
|
//遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
|
|
|
- if (_request.timestamp < new DateTime(2021, 11, 1))
|
|
|
+ if (stopRequest.timestamp < new DateTime(2021, 11, 1))
|
|
|
{
|
|
|
var confirm = new StopTransactionConfirmation()
|
|
|
{
|
|
@@ -653,7 +670,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
var confirm = new StopTransactionConfirmation()
|
|
|
{
|
|
|
- idTagInfo = _idTagInfo
|
|
|
+ idTagInfo = idTagInfo
|
|
|
|
|
|
};
|
|
|
|
|
@@ -665,23 +682,23 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- _ConnectorId = transaction.ConnectorId;
|
|
|
- transaction.MeterStop = _request.meterStop;
|
|
|
- transaction.StopTime = _request.timestamp.ToUniversalTime();
|
|
|
- transaction.StopReasonId = _request.reason.HasValue ? (int)_request.reason.Value : 0;
|
|
|
- transaction.StopReason = _request.reason.HasValue ? _request.reason.Value.ToString() : Reason.Local.ToString();
|
|
|
- transaction.StopIdTag = _request.idTag;
|
|
|
+ connectorId = transaction.ConnectorId;
|
|
|
+ transaction.MeterStop = stopRequest.meterStop;
|
|
|
+ transaction.StopTime = stopRequest.timestamp.ToUniversalTime();
|
|
|
+ transaction.StopReasonId = stopRequest.reason.HasValue ? (int)stopRequest.reason.Value : 0;
|
|
|
+ transaction.StopReason = stopRequest.reason.HasValue ? stopRequest.reason.Value.ToString() : Reason.Local.ToString();
|
|
|
+ transaction.StopIdTag = stopRequest.idTag;
|
|
|
transaction.Receipt = string.Empty;
|
|
|
transaction.Cost = session.IsBilling ? -1 : 0;
|
|
|
|
|
|
- if (_request.transactionData != null && _request.transactionData.Count > 0)
|
|
|
+ if (stopRequest.transactionData != null && stopRequest.transactionData.Count > 0)
|
|
|
{
|
|
|
- _request.transactionData[0].sampledValue.Add(new SampledValue()
|
|
|
+ stopRequest.transactionData[0].sampledValue.Add(new SampledValue()
|
|
|
{
|
|
|
context = ReadingContext.Transaction_End,
|
|
|
format = ValueFormat.Raw,
|
|
|
location = Location.Outlet,
|
|
|
- phase = _request.transactionData[0].sampledValue.Where(x => x.context.HasValue).Select(x => x.phase).FirstOrDefault(),
|
|
|
+ phase = stopRequest.transactionData[0].sampledValue.Where(x => x.context.HasValue).Select(x => x.phase).FirstOrDefault(),
|
|
|
unit = UnitOfMeasure.Wh,
|
|
|
measurand = Measurand.TotalEnergy,
|
|
|
value = decimal.Subtract(transaction.MeterStop, transaction.MeterStart).ToString()
|
|
@@ -703,7 +720,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
messageId = "ID_TxEnergy",
|
|
|
vendorId = "Phihong Technology",
|
|
|
- data = JsonConvert.SerializeObject(new { txId = _request.transactionId, ConnectorId = transaction.ConnectorId })
|
|
|
+ data = JsonConvert.SerializeObject(new { txId = stopRequest.transactionId, ConnectorId = transaction.ConnectorId })
|
|
|
},
|
|
|
new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
SerialNo = Guid.NewGuid().ToString(),
|
|
@@ -720,20 +737,20 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
else
|
|
|
{
|
|
|
|
|
|
- result.Exception = new Exception("Can't find transactionId " + _request.transactionId);
|
|
|
+ result.Exception = new Exception("Can't find transactionId " + stopRequest.transactionId);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#region Save MeterValue
|
|
|
|
|
|
- if (_request.transactionData != null)
|
|
|
+ if (stopRequest.transactionData != null)
|
|
|
{
|
|
|
- if (_request.transactionData.Count > 0)
|
|
|
+ if (stopRequest.transactionData.Count > 0)
|
|
|
{
|
|
|
using (var _meterDb = new MeterValueDBContext())
|
|
|
{
|
|
|
- foreach (var item in _request.transactionData)
|
|
|
+ foreach (var item in stopRequest.transactionData)
|
|
|
{
|
|
|
foreach (var sampleVaule in item.sampledValue)
|
|
|
{
|
|
@@ -746,7 +763,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
{
|
|
|
new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
- new SqlParameter("ConnectorId", (byte)_ConnectorId),
|
|
|
+ new SqlParameter("ConnectorId", (byte)connectorId),
|
|
|
new SqlParameter("Value",value),
|
|
|
new SqlParameter("CreatedOn",item.timestamp),
|
|
|
new SqlParameter("ContextId",sampleVaule.context.HasValue ? (int)sampleVaule.context : 0),
|
|
@@ -755,7 +772,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
new SqlParameter("PhaseId",sampleVaule.phase.HasValue ? (int)sampleVaule.phase : 0),
|
|
|
new SqlParameter("LocationId",sampleVaule.location.HasValue ? (int)sampleVaule.location : 0),
|
|
|
new SqlParameter("UnitId",sampleVaule.unit.HasValue ? (int)sampleVaule.unit : 0),
|
|
|
- new SqlParameter("TransactionId",_request.transactionId),
|
|
|
+ new SqlParameter("TransactionId",stopRequest.transactionId),
|
|
|
};
|
|
|
|
|
|
|
|
@@ -772,7 +789,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- result.Exception = new Exception("TransactionId " + _request.transactionId + " " + ex.Message);
|
|
|
+ result.Exception = new Exception("TransactionId " + stopRequest.transactionId + " " + ex.Message);
|
|
|
result.CallErrorMsg = "Reject Response Message";
|
|
|
result.Success = false;
|
|
|
// return result;
|