|
@@ -166,6 +166,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
break;
|
|
|
case Actions.BootNotification:
|
|
|
{
|
|
|
+ Debug.WriteLine(DateTime.UtcNow);
|
|
|
if (session.CustomerId == Guid.Empty)
|
|
|
{
|
|
|
result.Message = new BootNotificationConfirmation() { currentTime = DateTime.UtcNow, interval = 5, status = RegistrationStatus.Pending };
|
|
@@ -192,16 +193,23 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
|
|
|
|
|
|
- // var configVaule = db.MachineConfiguration.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.HeartbeatInterval)
|
|
|
- // .Select(x => x.ConfigureSetting).FirstOrDefault();
|
|
|
+ var configVaule = db.MachineConfiguration.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.HeartbeatInterval)
|
|
|
+ .Select(x => x.ConfigureSetting).FirstOrDefault();
|
|
|
|
|
|
- // if (configVaule != null)
|
|
|
- // {
|
|
|
- // int.TryParse(configVaule, out heartbeat_interval);
|
|
|
- // }
|
|
|
+ if (configVaule != null)
|
|
|
+ {
|
|
|
+ int.TryParse(configVaule, out heartbeat_interval);
|
|
|
}
|
|
|
- var confirm = new BootNotificationConfirmation() { currentTime = DateTime.UtcNow, interval = heartbeat_interval, status = Packet.Messages.SubTypes.RegistrationStatus.Accepted };
|
|
|
- result.Message = confirm;
|
|
|
+ }
|
|
|
+ if (session.IsPending == true)
|
|
|
+ {
|
|
|
+ session.IsPending = false;
|
|
|
+ }
|
|
|
+ if (session.IsPending == null)
|
|
|
+ {
|
|
|
+ session.IsPending = true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
result.Success = true;
|
|
@@ -495,6 +503,8 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
+ db.Database.Log = Console.Write;
|
|
|
+
|
|
|
var _CustomerId = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).Include(x => x.Customer).
|
|
|
Select(x => x.CustomerId).FirstOrDefault();
|
|
|
|
|
@@ -572,129 +582,130 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
_idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
}
|
|
|
-
|
|
|
- using (var db = new MainDBContext())
|
|
|
+ try
|
|
|
{
|
|
|
- var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
|
|
|
- && x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
|
|
|
- if (_request.timestamp < new DateTime(2021, 11, 1))
|
|
|
+ using (var db = new MainDBContext())
|
|
|
{
|
|
|
- var confirm = new StopTransactionConfirmation()
|
|
|
- {
|
|
|
- idTagInfo = new IdTagInfo()
|
|
|
- {
|
|
|
- status = AuthorizationStatus.Invalid
|
|
|
- }
|
|
|
+ var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
|
|
|
+ && x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
|
|
|
- };
|
|
|
|
|
|
- result.Message = confirm;
|
|
|
- result.Success = true;
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- if (transaction != null)
|
|
|
- {
|
|
|
- var confirm = new StopTransactionConfirmation()
|
|
|
+ //遠傳太久以前的停止充電 直接拒絕 避免電樁持續重送~~~~~~~
|
|
|
+ if (_request.timestamp < new DateTime(2021, 11, 1))
|
|
|
{
|
|
|
- idTagInfo = _idTagInfo
|
|
|
+ var confirm = new StopTransactionConfirmation()
|
|
|
+ {
|
|
|
+ idTagInfo = new IdTagInfo()
|
|
|
+ {
|
|
|
+ status = AuthorizationStatus.Invalid
|
|
|
+ }
|
|
|
|
|
|
- };
|
|
|
+ };
|
|
|
|
|
|
- //Avoid rewrite transaction data
|
|
|
- if (transaction.StopTime != GlobalConfig.DefaultNullTime)
|
|
|
- {
|
|
|
result.Message = confirm;
|
|
|
result.Success = true;
|
|
|
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;
|
|
|
- transaction.Receipt = string.Empty;
|
|
|
- transaction.Cost = session.IsBilling ? -1 : 0;
|
|
|
|
|
|
- if (_request.transactionData != null && _request.transactionData.Count > 0)
|
|
|
+ if (transaction != null)
|
|
|
{
|
|
|
- _request.transactionData[0].sampledValue.Add(new SampledValue()
|
|
|
+ var confirm = new StopTransactionConfirmation()
|
|
|
{
|
|
|
- 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(),
|
|
|
- unit = UnitOfMeasure.Wh,
|
|
|
- measurand = Measurand.TotalEnergy,
|
|
|
- value = decimal.Subtract(transaction.MeterStop, transaction.MeterStart).ToString()
|
|
|
- });
|
|
|
- }
|
|
|
+ idTagInfo = _idTagInfo
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- await db.SaveChangesAsync();
|
|
|
+ //Avoid rewrite transaction data
|
|
|
+ if (transaction.StopTime != GlobalConfig.DefaultNullTime)
|
|
|
+ {
|
|
|
+ result.Message = confirm;
|
|
|
+ result.Success = true;
|
|
|
+ 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;
|
|
|
+ transaction.Receipt = string.Empty;
|
|
|
+ transaction.Cost = session.IsBilling ? -1 : 0;
|
|
|
|
|
|
- if (session.IsBilling)
|
|
|
- {
|
|
|
- db.ServerMessage.Add(new ServerMessage()
|
|
|
+ if (_request.transactionData != null && _request.transactionData.Count > 0)
|
|
|
{
|
|
|
- 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 = transaction.ConnectorId })
|
|
|
- },
|
|
|
- new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
- SerialNo = Guid.NewGuid().ToString(),
|
|
|
- InMessage = string.Empty
|
|
|
+ _request.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(),
|
|
|
+ unit = UnitOfMeasure.Wh,
|
|
|
+ measurand = Measurand.TotalEnergy,
|
|
|
+ value = decimal.Subtract(transaction.MeterStop, transaction.MeterStart).ToString()
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- });
|
|
|
|
|
|
- db.SaveChanges();
|
|
|
- }
|
|
|
+ await db.SaveChangesAsync();
|
|
|
|
|
|
- result.Message = confirm;
|
|
|
- result.Success = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
|
|
|
- result.Exception = new Exception("Can't find transactionId " + _request.transactionId);
|
|
|
+ if (session.IsBilling)
|
|
|
+ {
|
|
|
+ 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 = transaction.ConnectorId })
|
|
|
+ },
|
|
|
+ new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
+ SerialNo = Guid.NewGuid().ToString(),
|
|
|
+ InMessage = string.Empty
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ db.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+ result.Message = confirm;
|
|
|
+ result.Success = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ result.Exception = new Exception("Can't find transactionId " + _request.transactionId);
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- #region Save MeterValue
|
|
|
+ #region Save MeterValue
|
|
|
|
|
|
- if (_request.transactionData != null)
|
|
|
- {
|
|
|
- if (_request.transactionData.Count > 0)
|
|
|
+ if (_request.transactionData != null)
|
|
|
{
|
|
|
- using (var _meterDb = new MeterValueDBContext())
|
|
|
+ if (_request.transactionData.Count > 0)
|
|
|
{
|
|
|
- foreach (var item in _request.transactionData)
|
|
|
+ using (var _meterDb = new MeterValueDBContext())
|
|
|
{
|
|
|
- foreach (var sampleVaule in item.sampledValue)
|
|
|
+ foreach (var item in _request.transactionData)
|
|
|
{
|
|
|
- decimal value = Convert.ToDecimal(sampleVaule.value);
|
|
|
+ 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";
|
|
|
+ string sp = "[dbo].[uspInsertMeterValueRecord] @ChargeBoxId," +
|
|
|
+ "@ConnectorId,@Value,@CreatedOn,@ContextId,@FormatId,@MeasurandId,@PhaseId,@LocationId,@UnitId,@TransactionId";
|
|
|
|
|
|
- List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
+ List<SqlParameter> parameter = new List<SqlParameter>
|
|
|
{
|
|
|
new SqlParameter("ChargeBoxId",session.ChargeBoxId),
|
|
|
new SqlParameter("ConnectorId", (byte)_ConnectorId),
|
|
@@ -710,17 +721,24 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
};
|
|
|
|
|
|
|
|
|
- _meterDb.Database.ExecuteSqlCommand(sp, parameter.ToArray());
|
|
|
+ _meterDb.Database.ExecuteSqlCommand(sp, parameter.ToArray());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ result.Exception = new Exception("TransactionId " + _request.transactionId + " " + ex.Message);
|
|
|
+ result.CallErrorMsg = "Reject Response Message";
|
|
|
+ result.Success = false;
|
|
|
+ // return result;
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case Actions.Authorize:
|
|
@@ -1001,25 +1019,14 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
}
|
|
|
|
|
|
- if (session.CustomerId == new Guid("009E603C-79CD-4620-A2B8-D9349C0E8AD8"))
|
|
|
- {
|
|
|
- chargingCost = confirmbill.Count > 0 ? confirmbill.Sum(x => x.Total) : chargingCost;
|
|
|
- chargingCost = chargedEnergy == 0 ? 0 : (chargingCost + parkingCost < 1 ? 1 : chargingCost); //台泥最低一元
|
|
|
- receipt += string.Format("|Total Energy Fee : ${0}", chargingCost);
|
|
|
+ chargingCost = confirmbill.Count > 0 ? confirmbill.Sum(x => x.Total) : chargingCost;
|
|
|
+ receipt += string.Format("|Total Energy Fee : ${0}", chargingCost);
|
|
|
|
|
|
- receipt += string.Format("|Parking Fee: | {0} - {1} @ ${2}/hr=${3}", feedto.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")),
|
|
|
- feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), parkingFee, parkingCost);
|
|
|
- tx.Cost = chargingCost + parkingCost;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- chargingCost = confirmbill.Count > 0 ? confirmbill.Sum(x => x.Total) : chargingCost;
|
|
|
- receipt += string.Format("|Total Energy Fee : ${0}", chargingCost);
|
|
|
+ receipt += string.Format("|Parking Fee: | {0} - {1}: | {2} @ ${3}/hr= ${4}", feedto.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")),
|
|
|
+ feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), (totalHours / 1 >= 1) ? string.Format("{0} hours {1} minutes", (int)totalHours / 1, ((totalHours % 1) * 60).ToString("0.0")) : string.Format("{0} minutes", ((totalHours % 1) * 60).ToString("0.0")), parkingFee, parkingCost);
|
|
|
+ receipt += string.Format("|Stop Reason: {0}", tx.StopReason);
|
|
|
|
|
|
- receipt += string.Format("|Parking Fee: | {0} - {1} @ ${2}/hr=${3}", feedto.StartTime.ToString("hh:mm tt", new CultureInfo("en-us")),
|
|
|
- feedto.StopTime.ToString("hh:mm tt", new CultureInfo("en-us")), parkingFee, parkingCost);
|
|
|
- tx.Cost = chargingCost + parkingCost;
|
|
|
- }
|
|
|
+ tx.Cost = chargingCost + parkingCost;
|
|
|
|
|
|
|
|
|
if (customerInfo != null && customerInfo.InstantStopTxReport)
|
|
@@ -1041,7 +1048,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
Fee = tx.Fee
|
|
|
|
|
|
};
|
|
|
-
|
|
|
+ logger.Debug("completed_session " + JsonConvert.SerializeObject(request));
|
|
|
var response = await httpClient.Post(customerInfo.ApiUrl + "completed_session", new Dictionary<string, string>()
|
|
|
{
|
|
|
{ "PartnerId",session.CustomerId.ToString()}
|
|
@@ -1049,6 +1056,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}, request, customerInfo.ApiKey);
|
|
|
|
|
|
var _httpResult = JsonConvert.DeserializeObject<CPOOuterResponse>(response.Response);
|
|
|
+ logger.Debug("completed_session Response" + response.Response);
|
|
|
JObject jo = JObject.Parse(_httpResult.Data);
|
|
|
if (jo.ContainsKey("CouponPoint"))
|
|
|
{
|