|
@@ -56,6 +56,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
var _machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
_machine.ChargeBoxSerialNumber = string.IsNullOrEmpty(_request.chargeBoxSerialNumber) ? string.Empty : _request.chargeBoxSerialNumber;
|
|
|
+ _machine.ChargePointSerialNumber = string.IsNullOrEmpty(_request.chargePointSerialNumber) ? string.Empty : _request.chargePointSerialNumber;
|
|
|
_machine.ChargePointModel = string.IsNullOrEmpty(_request.chargePointModel) ? string.Empty : _request.chargePointModel;
|
|
|
_machine.ChargePointVendor = string.IsNullOrEmpty(_request.chargePointVendor) ? string.Empty : _request.chargePointVendor;
|
|
|
_machine.FW_CurrentVersion = string.IsNullOrEmpty(_request.firmwareVersion) ? string.Empty : _request.firmwareVersion;
|
|
@@ -66,6 +67,8 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
|
+ logger.Error(string.Format("{0} ChargeBoxSerialNumber:{1} ", session.ChargeBoxId, _request.chargePointSerialNumber));
|
|
|
+
|
|
|
var configVaule = db.MachineConfiguration.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.HeartbeatInterval)
|
|
|
.Select(x => x.ConfigureSetting).FirstOrDefault();
|
|
|
|
|
@@ -207,6 +210,10 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
case Actions.MeterValues:
|
|
|
{
|
|
|
MeterValuesRequest _request = request as MeterValuesRequest;
|
|
|
+ string feeText = session.FeeDescription.Split(';')[1].Replace(" Current Rate: $", "").Split(' ')[0];
|
|
|
+
|
|
|
+ decimal fee = decimal.Parse(feeText);
|
|
|
+ decimal energy_kwh = 0;
|
|
|
|
|
|
if (_request.meterValue.Count > 0)
|
|
|
{
|
|
@@ -219,6 +226,11 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
|
|
|
+ if (sampleVaule.context == ReadingContext.Sample_Periodic && sampleVaule.measurand == Measurand.Energy_Active_Import_Interval)
|
|
|
+ {
|
|
|
+ energy_kwh = sampleVaule.unit == UnitOfMeasure.Wh ? Decimal.Divide(value, 1000) : value;
|
|
|
+ }
|
|
|
+
|
|
|
string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
"@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
|
|
@@ -249,6 +261,52 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (energy_kwh > 0)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // ************等Alston 可以使用在打開這個功能 ~ 電樁畫面上目前不會顯示
|
|
|
+ //using (var db = new MainDBContext())
|
|
|
+ //{
|
|
|
+ // db.ServerMessage.Add(new ServerMessage()
|
|
|
+ // {
|
|
|
+ // ChargeBoxId = session.ChargeBoxId,
|
|
|
+ // CreatedBy = "Server",
|
|
|
+ // CreatedOn = DateTime.Now,
|
|
|
+ // OutAction = Actions.DataTransfer.ToString(),
|
|
|
+ // OutRequest = JsonConvert.SerializeObject(
|
|
|
+ // new DataTransferRequest()
|
|
|
+ // {
|
|
|
+ // messageId = "RunningCost",
|
|
|
+ // vendorId = "Phihong Technology",
|
|
|
+ // data = JsonConvert.SerializeObject(new
|
|
|
+ // {
|
|
|
+ // txId = _request.transactionId,
|
|
|
+ // description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
+ // "$0.00 {0}; Total Cost: ${1} {0}; Account Balance: $155.05 {0}", session.Currency,
|
|
|
+ // Decimal.Multiply(energy_kwh, fee))
|
|
|
+ // })
|
|
|
+
|
|
|
+ // },
|
|
|
+ // new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ // SerialNo = Guid.NewGuid().ToString(),
|
|
|
+ // InMessage = string.Empty
|
|
|
+
|
|
|
+ // }); ;
|
|
|
+
|
|
|
+ // db.SaveChanges();
|
|
|
+
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ Console.WriteLine(string.Format("{0} :{1}", session.ChargeBoxId + " RunningCost", ex.Message));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
var confirm = new MeterValuesConfirmation() { };
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
@@ -263,9 +321,12 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
int _transactionId = -1;
|
|
|
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
- //var _idTagInfo = new IdTagInfo() { status = AuthorizationStatus.Accepted };
|
|
|
var _idTagInfo = _request.idTag == "Backend" ? new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted } : await businessService.Authorize(session.ChargeBoxId, _request.idTag);
|
|
|
-
|
|
|
+ //特例****飛宏客戶旗下的電樁,若遇到Portal沒回應的狀況 ~允許充電
|
|
|
+ if (session.CustomerId.ToString().ToUpper() == "8456AED9-6DD9-4BF3-A94C-9F5DCB9506F7" && _idTagInfo.status == AuthorizationStatus.ConcurrentTx)
|
|
|
+ {
|
|
|
+ _idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
+ }
|
|
|
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
@@ -289,7 +350,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
CustomerId = _CustomerId,
|
|
|
StartTime = _request.timestamp,
|
|
|
ReservationId = _request.reservationId.HasValue ? _request.reservationId.Value : 0,
|
|
|
-
|
|
|
+ Fee = session.FeeDescription
|
|
|
|
|
|
};
|
|
|
|
|
@@ -298,14 +359,14 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
db.SaveChanges();
|
|
|
|
|
|
_transactionId = _newTransaction.Id;
|
|
|
- Console.WriteLine("***************************************************** ");
|
|
|
- Console.WriteLine(string.Format("{0} :TransactionId {1} ", session.ChargeBoxId, _newTransaction.Id));
|
|
|
- Console.WriteLine("***************************************************** ");
|
|
|
+ logger.Info("***************************************************** ");
|
|
|
+ logger.Info(string.Format("{0} :TransactionId {1} ", session.ChargeBoxId, _newTransaction.Id));
|
|
|
+ logger.Info("***************************************************** ");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_transactionId = _existedTx.Id;
|
|
|
- Console.WriteLine("Duplication ***************************************************** " + _existedTx.Id);
|
|
|
+ logger.Error("Duplication ***************************************************** " + _existedTx.Id);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -329,8 +390,13 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
|
|
|
+ //特例****飛宏客戶旗下的電樁,若遇到Portal沒回應的狀況 ~允許充電
|
|
|
+ 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));
|
|
|
|
|
|
- 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));
|
|
|
+ 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 };
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -341,11 +407,44 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
if (transaction != null)
|
|
|
{
|
|
|
+ decimal energy_kwh = decimal.Subtract(_request.meterStop, transaction.MeterStart);
|
|
|
+
|
|
|
+ energy_kwh = decimal.Divide(energy_kwh, 1000);
|
|
|
+ string feeText = transaction.Fee.Split(';')[1].Replace(" Current Rate: $", "").Split(' ')[0];
|
|
|
+ decimal fee = decimal.Parse(feeText);
|
|
|
+ decimal cost = Decimal.Multiply(energy_kwh, (decimal)fee);
|
|
|
+ if (session.Currency == "USD" || session.Currency == "EUR")
|
|
|
+ {
|
|
|
+ //0.4867
|
|
|
+ if ((int)(cost * 100) < cost * 100)
|
|
|
+ {
|
|
|
+ cost = Decimal.Add(cost, (decimal)0.01);//0.4967
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ cost = Decimal.Parse(cost.ToString("0.00"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if ((int)(cost) < cost )
|
|
|
+ {
|
|
|
+ cost = Decimal.Add(cost, (decimal)1);
|
|
|
+ }
|
|
|
+
|
|
|
+ cost = Decimal.Parse(cost.ToString("0"));
|
|
|
+ }
|
|
|
+ string receipt = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
+ "$0.00 {0}; Total Cost: ${1} {0}; Account Balance: $4555 {0}", session.Currency,
|
|
|
+ cost);
|
|
|
+
|
|
|
+
|
|
|
_ConnectorId = transaction.ConnectorId;
|
|
|
transaction.MeterStop = _request.meterStop;
|
|
|
transaction.StopTime = _request.timestamp;
|
|
|
transaction.StopReasonId = _request.reason.HasValue ? (int)_request.reason.Value : 0;
|
|
|
transaction.StopIdTag = _request.idTag;
|
|
|
+ transaction.Receipt = receipt;
|
|
|
+ transaction.Cost = cost;
|
|
|
|
|
|
if (_TransactionDatas.Count > 0)
|
|
|
{
|
|
@@ -358,6 +457,39 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
idTagInfo = _idTagInfo
|
|
|
|
|
|
};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (energy_kwh > 0)
|
|
|
+ {
|
|
|
+ db.ServerMessage.Add(new ServerMessage()
|
|
|
+ {
|
|
|
+ ChargeBoxId = session.ChargeBoxId,
|
|
|
+ CreatedBy = "Server",
|
|
|
+ CreatedOn = DateTime.Now,
|
|
|
+ OutAction = Actions.DataTransfer.ToString(),
|
|
|
+ OutRequest = JsonConvert.SerializeObject(
|
|
|
+ new DataTransferRequest()
|
|
|
+ {
|
|
|
+ messageId = "FinalCost",
|
|
|
+ vendorId = "Phihong Technology",
|
|
|
+ data = JsonConvert.SerializeObject(new
|
|
|
+ {
|
|
|
+ txId = _request.transactionId,
|
|
|
+ description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
+ "$0.00 {0}; Total Cost: ${1} {0}; Account Balance: $4555 {0}", session.Currency,
|
|
|
+ energy_kwh, Decimal.Multiply(energy_kwh, (decimal)fee))
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ SerialNo = Guid.NewGuid().ToString(),
|
|
|
+ InMessage = string.Empty
|
|
|
+
|
|
|
+ }); ;
|
|
|
+
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
|
}
|
|
@@ -415,12 +547,17 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
AuthorizeRequest _request = request as AuthorizeRequest;
|
|
|
|
|
|
-
|
|
|
+ //特例****飛宏客戶旗下的電樁,若遇到Portal沒回應的狀況 ~允許充電
|
|
|
var businessService = BusinessServiceFactory.CreateBusinessService(session.CustomerId.ToString());
|
|
|
var confirm = new AuthorizeConfirmation()
|
|
|
{
|
|
|
idTagInfo = _request.idTag == "Backend" ? new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted } : await businessService.Authorize(session.ChargeBoxId, _request.idTag)
|
|
|
};
|
|
|
+
|
|
|
+ if (session.CustomerId.ToString().ToUpper() == "8456AED9-6DD9-4BF3-A94C-9F5DCB9506F7" && confirm.idTagInfo.status == AuthorizationStatus.ConcurrentTx)
|
|
|
+ {
|
|
|
+ confirm.idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
+ }
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
|
}
|