|
@@ -11,7 +11,7 @@ using EVCB_OCPP.Packet.Features;
|
|
|
using EVCB_OCPP.Packet.Messages;
|
|
|
using EVCB_OCPP.Packet.Messages.Core;
|
|
|
using EVCB_OCPP.Packet.Messages.SubTypes;
|
|
|
-using EVCB_OCPP.WSServer.BusinessService;
|
|
|
+using EVCB_OCPP.WSServer.Service;
|
|
|
using EVCB_OCPP.WSServer.Dto;
|
|
|
using Newtonsoft.Json;
|
|
|
using OCPPPackage.Profiles;
|
|
@@ -73,21 +73,23 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
ConnectorErrorStauts _oldStatus = null;
|
|
|
using (var oldDB = new MainDBContext())
|
|
|
{
|
|
|
- if (_request.status == Packet.Messages.SubTypes.ChargePointStatus.Faulted)
|
|
|
+ _oldStatus = oldDB.ConnectorStatus.Where(x => x.ChargeBoxId == session.ChargeBoxId
|
|
|
+ && x.ConnectorId == _request.connectorId).Select(x => new ConnectorErrorStauts
|
|
|
+ {
|
|
|
+ Status = x.Status,
|
|
|
+ ChargePointErrorCodeId = x.ChargePointErrorCodeId,
|
|
|
+ ErrorInfo = x.ErrorInfo,
|
|
|
+ VendorId = x.VendorId,
|
|
|
+ VendorErrorCode = x.VendorErrorCode
|
|
|
+ }).FirstOrDefault();
|
|
|
+
|
|
|
+
|
|
|
+ if (_request.status != (ChargePointStatus)_oldStatus.Status || _request.status == ChargePointStatus.Faulted)
|
|
|
{
|
|
|
- _oldStatus = oldDB.ConnectorStatus.Where(x => x.ChargeBoxId == session.ChargeBoxId
|
|
|
- && x.ConnectorId == _request.connectorId).Select(x => new ConnectorErrorStauts
|
|
|
- {
|
|
|
- Status = x.Status,
|
|
|
- ChargePointErrorCodeId = x.ChargePointErrorCodeId,
|
|
|
- ErrorInfo = x.ErrorInfo,
|
|
|
- VendorId = x.VendorId,
|
|
|
- VendorErrorCode = x.VendorErrorCode
|
|
|
- }).FirstOrDefault();
|
|
|
+ removeIds = oldDB.ConnectorStatus.Where(x => x.ChargeBoxId == session.ChargeBoxId
|
|
|
+ && x.ConnectorId == _request.connectorId).Select(x => x.Id).ToList();
|
|
|
}
|
|
|
|
|
|
- removeIds = oldDB.ConnectorStatus.Where(x => x.ChargeBoxId == session.ChargeBoxId
|
|
|
- && x.ConnectorId == _request.connectorId).Select(x => x.Id).ToList();
|
|
|
}
|
|
|
|
|
|
using (var db = new MainDBContext())
|
|
@@ -135,6 +137,21 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (_request.status == Packet.Messages.SubTypes.ChargePointStatus.Faulted)
|
|
|
+ {
|
|
|
+ var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString(), false);
|
|
|
+ businessService.NotifyFaultStatus(new ErrorDetails()
|
|
|
+ {
|
|
|
+ ChargeBoxId = session.ChargeBoxId,
|
|
|
+ ConnectorId = _request.connectorId,
|
|
|
+ ErrorCode = _request.errorCode,
|
|
|
+ Info = _request.info,
|
|
|
+ OCcuredOn = _request.timestamp.Value,
|
|
|
+ VendorErrorCode = _request.vendorErrorCode,
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
var confirm = new StatusNotificationConfirmation() { };
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
@@ -214,7 +231,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
if (DateTime.Compare(DateTime.UtcNow.AddSeconds(-10), _request.timestamp.ToUniversalTime()) >= 0)
|
|
|
{
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString(), true);
|
|
|
- _idTagInfo = businessService.Authorize(_request.idTag);
|
|
|
+ _idTagInfo = businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -276,32 +293,10 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
StopTransactionRequest _request = request as StopTransactionRequest;
|
|
|
List<TransactionDataRecord> _TransactionDatas = new List<TransactionDataRecord>();
|
|
|
- if (_request.transactionData != null)
|
|
|
- {
|
|
|
- if (_request.transactionData.Count > 0)
|
|
|
- {
|
|
|
- foreach (var item in _request.transactionData)
|
|
|
- {
|
|
|
- foreach (var sampleVaule in item.sampledValue)
|
|
|
- {
|
|
|
- _TransactionDatas.Add(new TransactionDataRecord()
|
|
|
- {
|
|
|
- ChargeBoxId = session.ChargeBoxId,
|
|
|
- MeasuredOn = item.timestamp,
|
|
|
- TransactionId = _request.transactionId,
|
|
|
- ContextId = sampleVaule.context.HasValue ? (int)sampleVaule.context : 0,
|
|
|
- FormatId = sampleVaule.format.HasValue ? (int)sampleVaule.format : 0,
|
|
|
- LocationId = sampleVaule.location.HasValue ? (int)sampleVaule.location : 0,
|
|
|
- MeasurandId = sampleVaule.measurand.HasValue ? (int)sampleVaule.measurand : 0,
|
|
|
- PhaseId = sampleVaule.phase.HasValue ? (int)sampleVaule.phase : 0,
|
|
|
- UnitId = sampleVaule.unit.HasValue ? (int)sampleVaule.unit : 0,
|
|
|
- Value = sampleVaule.value
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ int _ConnectorId = 0;
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+ var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString(), true);
|
|
|
+ var _idTagInfo = businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
|
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
@@ -310,6 +305,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
if (transaction != null)
|
|
|
{
|
|
|
+ _ConnectorId = transaction.ConnectorId;
|
|
|
transaction.MeterStop = _request.meterStop;
|
|
|
transaction.StopTime = _request.timestamp;
|
|
|
transaction.StopReasonId = _request.reason.HasValue ? (int)_request.reason.Value : 0;
|
|
@@ -323,11 +319,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
db.SaveChanges();
|
|
|
var confirm = new StopTransactionConfirmation()
|
|
|
{
|
|
|
- idTagInfo = new Packet.Messages.SubTypes.IdTagInfo()
|
|
|
- {
|
|
|
-
|
|
|
- status = Packet.Messages.SubTypes.AuthorizationStatus.Accepted
|
|
|
- }
|
|
|
+ idTagInfo = _idTagInfo
|
|
|
|
|
|
};
|
|
|
result.Message = confirm;
|
|
@@ -339,6 +331,48 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (_request.transactionData != null)
|
|
|
+ {
|
|
|
+ if (_request.transactionData.Count > 0)
|
|
|
+ {
|
|
|
+ using (var _meterDb = new MeterValueDBContext())
|
|
|
+ {
|
|
|
+ foreach (var item in _request.transactionData)
|
|
|
+ {
|
|
|
+ foreach (var sampleVaule in item.sampledValue)
|
|
|
+ {
|
|
|
+ decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
+
|
|
|
+ string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
+ "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
+
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
+ {
|
|
|
+ new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
+ new SqlParameter("ConnectorId", (byte)_ConnectorId),
|
|
|
+ new SqlParameter("Value",value),
|
|
|
+ new SqlParameter("CreatedOn",item.timestamp),
|
|
|
+ new SqlParameter("ContextId",sampleVaule.context.HasValue ? (int)sampleVaule.context : 0),
|
|
|
+ new SqlParameter("FormatId",sampleVaule.format.HasValue ? (int)sampleVaule.format : 0),
|
|
|
+ new SqlParameter("MeasurandId",sampleVaule.measurand.HasValue ? (int)sampleVaule.measurand : 0),
|
|
|
+ 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),
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ _meterDb.Database.ExecuteSqlCommand(sp, parameter.ToArray());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
break;
|
|
|
case Actions.Authorize:
|
|
@@ -347,7 +381,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString(), true);
|
|
|
var confirm = new AuthorizeConfirmation()
|
|
|
{
|
|
|
- idTagInfo = businessService.Authorize(_request.idTag)
|
|
|
+ idTagInfo = businessService.Authorize(session.ChargeBoxId, _request.idTag)
|
|
|
};
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|