|
@@ -1,4 +1,5 @@
|
|
|
-using EVCB_OCPP.Domain;
|
|
|
+using Dapper;
|
|
|
+using EVCB_OCPP.Domain;
|
|
|
using EVCB_OCPP.Domain.Models.Database;
|
|
|
using EVCB_OCPP.Packet.Features;
|
|
|
using EVCB_OCPP.Packet.Messages;
|
|
@@ -12,6 +13,8 @@ using OCPPPackage.Profiles;
|
|
|
using OCPPServer.Protocol;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Configuration;
|
|
|
+using System.Data;
|
|
|
using System.Data.Entity;
|
|
|
using System.Data.SqlClient;
|
|
|
using System.Diagnostics;
|
|
@@ -24,7 +27,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
internal partial class ProfileHandler
|
|
|
{
|
|
|
static private ILogger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
-
|
|
|
+ string webConnectionString = ConfigurationManager.ConnectionStrings["WebDBContext"].ConnectionString;
|
|
|
|
|
|
async internal Task<MessageResult> ExecuteCoreRequest(Actions action, ClientData session, IRequest request)
|
|
|
{
|
|
@@ -304,6 +307,20 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
_idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
}
|
|
|
|
|
|
+ string accountBalance = "0";
|
|
|
+ if (session.CustomerId.ToString().ToUpper() == "10C7F5BD-C89A-4E2A-8611-B617E0B41A73")
|
|
|
+ {
|
|
|
+ using (SqlConnection conn = new SqlConnection(webConnectionString))
|
|
|
+ {
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@IdTag", _request.idTag, DbType.String, ParameterDirection.Input);
|
|
|
+ string strSql = "select parentIdTag from [dbo].[LocalListDetail] where ListId = 27 and IdTag=@IdTag; ";
|
|
|
+ accountBalance = conn.ExecuteScalar<string>(strSql, parameters);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
var _CustomerId = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).Include(x => x.Customer).
|
|
@@ -326,7 +343,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
CustomerId = _CustomerId,
|
|
|
StartTime = _request.timestamp.ToUniversalTime(),
|
|
|
ReservationId = _request.reservationId.HasValue ? _request.reservationId.Value : 0,
|
|
|
- Fee = !session.IsBilling ? string.Empty : session.BillingMethod == 1 ? JsonConvert.SerializeObject(session.ChargingPrices) + "|" + session.Currency : session.HRPrice + "|" + session.Currency
|
|
|
+ Fee = !session.IsBilling ? string.Empty : JsonConvert.SerializeObject(session.ChargingPrices) + "|+" + accountBalance + "+" + "&" + session.ParkingFee + "&|" + session.Currency
|
|
|
|
|
|
};
|
|
|
|
|
@@ -374,13 +391,13 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
_idTagInfo = new IdTagInfo() { expiryDate = DateTime.UtcNow.AddDays(1), status = AuthorizationStatus.Accepted };
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
var transaction = db.TransactionRecord.Where(x => x.Id == _request.transactionId
|
|
|
&& x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
-
|
|
|
+
|
|
|
if (transaction != null)
|
|
|
{
|
|
|
_ConnectorId = transaction.ConnectorId;
|
|
@@ -576,18 +593,16 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
if (feedto == null || string.IsNullOrEmpty(feedto.Fee)) return result;
|
|
|
string currency = feedto.Fee.Substring(feedto.Fee.Length - 3);
|
|
|
decimal sum = 0;
|
|
|
- if (feedto.Fee.Length > 10)
|
|
|
+ // if (feedto.Fee.Length > 10)
|
|
|
{
|
|
|
chargingPrices = JsonConvert.DeserializeObject<List<ChargingPrice>>(feedto.Fee.Split('|')[0]);
|
|
|
foreach (var item in txEnergy.PeriodEnergy)
|
|
|
{
|
|
|
- var periodEnergy = Math.Round(item.Value, 2, MidpointRounding.AwayFromZero);
|
|
|
string startTime = item.Key.Length == 1 ? "0" + item.Key + ":00" : item.Key + ":00";
|
|
|
decimal perfee = 0;
|
|
|
if (chargingPrices.Count == 1)
|
|
|
{
|
|
|
-
|
|
|
- perfee = Decimal.Multiply(periodEnergy, chargingPrices[0].Fee);
|
|
|
+ perfee = Decimal.Multiply(item.Value, chargingPrices[0].Fee);
|
|
|
if (bill.Count == 0)
|
|
|
{
|
|
|
bill.Add(new ChargingBill()
|
|
@@ -597,22 +612,26 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
Fee = chargingPrices[0].Fee
|
|
|
});
|
|
|
}
|
|
|
- bill[0].PeriodEnergy += periodEnergy;
|
|
|
+ bill[0].PeriodEnergy += item.Value;
|
|
|
+ bill[0].PeriodEnergy = Math.Round(bill[0].PeriodEnergy, 3, MidpointRounding.AwayFromZero);
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var price = chargingPrices.Where(x => x.StartTime == startTime).FirstOrDefault();
|
|
|
- perfee = Decimal.Multiply(periodEnergy, price.Fee);
|
|
|
+ perfee = Decimal.Multiply(item.Value, price.Fee);
|
|
|
|
|
|
bill.Add(new ChargingBill()
|
|
|
{
|
|
|
StartTime = price.StartTime,
|
|
|
EndTime = price.EndTime,
|
|
|
- PeriodEnergy = periodEnergy,
|
|
|
- Fee = chargingPrices[0].Fee
|
|
|
+ PeriodEnergy = Math.Round(item.Value, 3, MidpointRounding.AwayFromZero),
|
|
|
+ Fee = price.Fee,
|
|
|
+
|
|
|
});
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
if (bill.Count > 0)
|
|
|
{
|
|
@@ -621,55 +640,58 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
|
|
|
if (bill.Count == 1)
|
|
|
{
|
|
|
+ bill[0].PeriodEnergy = Math.Round(bill[0].PeriodEnergy, 3, MidpointRounding.AwayFromZero);
|
|
|
+ bill[bill.Count - 1].Total = DollarRounding(Decimal.Multiply(bill[0].PeriodEnergy, bill[0].Fee), session.Currency);
|
|
|
sum = bill[bill.Count - 1].Total;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- // 以時計費
|
|
|
- var fee = decimal.Parse(feedto.Fee.Split('|')[0]);
|
|
|
-
|
|
|
- var totalHours = Math.Round(DateTime.UtcNow.Subtract(feedto.StartTime).TotalHours, 2, MidpointRounding.AwayFromZero);
|
|
|
- sum = Decimal.Multiply((decimal)totalHours, fee);
|
|
|
- sum = DollarRounding(sum, session.Currency);
|
|
|
- receipt = totalHours + "hrs @ $" + fee + "/hr =" + sum;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
if (feedto.StopTime != GlobalConfig.DefaultNullTime)
|
|
|
{
|
|
|
+ var gggg = feedto.Fee.Split('&')[1];
|
|
|
+ // 計算停車費
|
|
|
+ var fee = decimal.Parse(feedto.Fee.Split('&')[1]);
|
|
|
+ decimal accountBalance = 0;
|
|
|
+ var stoptime = DateTime.Parse(feedto.StopTime.ToString("yyyy/MM/dd HH:mm"));
|
|
|
+ var starttime = DateTime.Parse(feedto.StartTime.ToString("yyyy/MM/dd HH:mm"));
|
|
|
+ decimal.TryParse(feedto.Fee.Split('+')[1], out accountBalance);
|
|
|
+ var totalHours = stoptime.Subtract(starttime).TotalHours;
|
|
|
+ var parkingCost = Decimal.Multiply((decimal)totalHours, fee);
|
|
|
+ parkingCost = DollarRounding(parkingCost, session.Currency);
|
|
|
+
|
|
|
+
|
|
|
var tx = db.TransactionRecord.Where(x => x.Id == txEnergy.TxId).FirstOrDefault();
|
|
|
if (tx == null)
|
|
|
{
|
|
|
Console.WriteLine("Tx is empty");
|
|
|
return result;
|
|
|
}
|
|
|
+ if (tx.UploadedtoTTIA) return result;
|
|
|
var startTime = new DateTime(tx.StartTime.Year, tx.StartTime.Month, tx.StartTime.Day, tx.StartTime.Hour, 0, 0);
|
|
|
List<ChargingBill> confirmbill = new List<ChargingBill>();
|
|
|
+ receipt = string.Format("Energy:");
|
|
|
while (startTime < tx.StopTime)
|
|
|
{
|
|
|
if (bill.Count == 1)
|
|
|
{
|
|
|
confirmbill = bill;
|
|
|
- receipt = string.Format("{0} kWh @ ${1}/kWh={2}", bill[0].PeriodEnergy, bill[0].Fee, bill[0].Total);
|
|
|
+ receipt += string.Format("| {0}~{1} @ ${2}/kWh=${3}", bill[0].StartTime, bill[0].EndTime, bill[0].Fee, bill[0].Total);
|
|
|
break;
|
|
|
}
|
|
|
if (bill.Count > 1)
|
|
|
{
|
|
|
+
|
|
|
confirmbill.Add(bill.Where(x => x.StartTime == startTime.ToString("HH:00")).FirstOrDefault());
|
|
|
if (confirmbill.Count == 24) break;
|
|
|
- if (confirmbill.Count > 1)
|
|
|
- {
|
|
|
- receipt += "|";
|
|
|
- }
|
|
|
- receipt += string.Format("{0}~{1} {2} kWh @ ${3}/kWh={4}", confirmbill[confirmbill.Count - 1].StartTime, confirmbill[confirmbill.Count - 1].EndTime,
|
|
|
- confirmbill[confirmbill.Count - 1].PeriodEnergy, bill[0].Fee, confirmbill[confirmbill.Count - 1].Total);
|
|
|
+ //if (confirmbill.Count > 1)
|
|
|
+ //{
|
|
|
+ // receipt += "|";
|
|
|
+ //}
|
|
|
+ receipt += string.Format("| {0}~{1} @ ${2}/kWh=${3}", confirmbill[confirmbill.Count - 1].StartTime, confirmbill[confirmbill.Count - 1].EndTime,
|
|
|
+ confirmbill[confirmbill.Count - 1].Fee, confirmbill[confirmbill.Count - 1].Total);
|
|
|
|
|
|
|
|
|
|
|
@@ -677,20 +699,17 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
startTime = startTime.AddHours(1);
|
|
|
|
|
|
}
|
|
|
- if (bill.Count > 0)
|
|
|
- {
|
|
|
- confirmbill = confirmbill.Where(x => string.IsNullOrEmpty(x.StartTime) == false).ToList();
|
|
|
- }
|
|
|
-
|
|
|
- tx.Cost = sum;
|
|
|
- tx.Receipt = receipt;
|
|
|
|
|
|
+ receipt += string.Format("|Parking fee: | {0}~{1} @ ${2}/hr=${3}", feedto.StartTime.ToString("HH:mm"), feedto.StopTime.ToString("HH:mm"), fee, parkingCost);
|
|
|
+ tx.Cost = sum + parkingCost;
|
|
|
+ tx.Receipt = receipt;
|
|
|
+ tx.UploadedtoTTIA = true;
|
|
|
db.Configuration.AutoDetectChangesEnabled = false;
|
|
|
db.Configuration.ValidateOnSaveEnabled = false;
|
|
|
db.TransactionRecord.Attach(tx);
|
|
|
db.Entry(tx).Property(x => x.Cost).IsModified = true;
|
|
|
db.Entry(tx).Property(x => x.Receipt).IsModified = true;
|
|
|
-
|
|
|
+ db.Entry(tx).Property(x => x.UploadedtoTTIA).IsModified = true;
|
|
|
|
|
|
db.ServerMessage.Add(new ServerMessage()
|
|
|
{
|
|
@@ -707,7 +726,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
{
|
|
|
txId = txEnergy.TxId,
|
|
|
description = string.Format("Connection Fee: $0.00 {0}; Session Fee: ${1} {0}; Occupancy Fee: " +
|
|
|
- "$0.00 {0}; Total Cost: ${1} {0}; Account Balance: $10.00 {0}", currency, sum)
|
|
|
+ "${2} {0}; Total Cost: ${3} {0}; Account Balance: ${4} {0}", currency, sum, parkingCost, tx.Cost, accountBalance - tx.Cost)
|
|
|
})
|
|
|
|
|
|
},
|
|
@@ -718,6 +737,31 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}); ;
|
|
|
|
|
|
db.SaveChanges();
|
|
|
+
|
|
|
+ using (SqlConnection conn = new SqlConnection(webConnectionString))
|
|
|
+ {
|
|
|
+
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@IdTag", tx.StartIdTag, DbType.String, ParameterDirection.Input);
|
|
|
+ parameters.Add("@parentIdTag", accountBalance - tx.Cost, DbType.String, ParameterDirection.Input);
|
|
|
+ string strSql = "update [dbo].[LocalListDetail] set parentIdTag =@parentIdTag where ListId = 27 and IdTag=@IdTag; ";
|
|
|
+ conn.Execute(strSql, parameters);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tx.CustomerId == Guid.Parse("10C7F5BD-C89A-4E2A-8611-B617E0B41A73"))
|
|
|
+ {
|
|
|
+ var mail_response = new OuterHttpClient().PostFormDataAsync("http://ocpp.phihong.com.tw/CDFA/" + tx.Id, new Dictionary<string, string>()
|
|
|
+ {
|
|
|
+ { "email","2"},
|
|
|
+ { "to","wonderj@phihongusa.com;jessica_tseng@phihong.com.tw"}
|
|
|
+
|
|
|
+ }, null);
|
|
|
+
|
|
|
+ Console.WriteLine(JsonConvert.SerializeObject(mail_response));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1040,7 +1084,7 @@ namespace EVCB_OCPP.WSServer.Message
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- logger.Debug("123 " + ex.ToString());
|
|
|
+ logger.Debug("123 " + action + " " + ex.ToString());
|
|
|
}
|
|
|
|
|
|
|