|
@@ -35,6 +35,8 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
parameters.Add("@LastUpdatedTime", lastUpdatedOn, DbType.DateTime, ParameterDirection.Output);
|
|
|
conn.Execute("GetBasicInfoLastUpdatedTimeById", parameters, commandType: System.Data.CommandType.StoredProcedure);
|
|
|
lastUpdatedOn = DateTime.SpecifyKind(parameters.Get<DateTime>("@LastUpdatedTime"), DateTimeKind.Utc);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return lastUpdatedOn;
|
|
@@ -118,7 +120,7 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
FaultMessage = ((ChargePointErrorCode)_RefConnector.ChargePointErrorCodeId).ToString() + (string.IsNullOrEmpty(_RefConnector.VendorErrorCode) ? "" : "-" + _RefConnector.VendorErrorCode)
|
|
|
|
|
|
});
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
return _machine == null ? null : cp;
|
|
|
}
|
|
@@ -293,30 +295,45 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
return existed;
|
|
|
}
|
|
|
|
|
|
- public TransasctionData GetActiveSessionInfo(string chargeBoxId, List<Measurand> requiredMeasurands, string sessionId = "", string idTag = "")
|
|
|
+ public List<TransasctionData> GetActiveSessionInfo(string chargeBoxId, List<Measurand> requiredMeasurands, string sessionId = "", string idTag = "")
|
|
|
{
|
|
|
List<ConnectorMeterValue> meterValues = new List<ConnectorMeterValue>();
|
|
|
ConnectorMeterValueModel meterModel = null;
|
|
|
- TransasctionData transactionData = null;
|
|
|
- if (string.IsNullOrEmpty(chargeBoxId)) return transactionData;
|
|
|
+ List<TransasctionData> transactionDatas = null;
|
|
|
+ if (string.IsNullOrEmpty(chargeBoxId)) return transactionDatas;
|
|
|
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var parameters = new DynamicParameters();
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
- parameters.Add(string.IsNullOrEmpty(sessionId) ? "@StartIdTag" : "@TransactionId", string.IsNullOrEmpty(sessionId) ? idTag : sessionId, DbType.String, ParameterDirection.Input);
|
|
|
+
|
|
|
|
|
|
using (SqlConnection conn = new SqlConnection(mainConnectionString))
|
|
|
{
|
|
|
string date = DateTime.UtcNow.ToString("yyMMdd");
|
|
|
- string strSql = "Select Top(1) Id , ConnectorId, StartTime,StartIdTag from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and " + (string.IsNullOrEmpty(sessionId) ? "StartIdTag=@StartIdTag" : "Id=@TransactionId") + " and StopTime='1991-01-01 00:00:00.000' order by Id desc;";
|
|
|
- transactionData = conn.Query<TransasctionData>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
|
|
|
+ string strSql = string.Empty;
|
|
|
+ if (string.IsNullOrEmpty(sessionId) && string.IsNullOrEmpty(idTag))
|
|
|
+ {
|
|
|
+ strSql = "Select Id, ConnectorId, StartTime, StartIdTag from TransactionRecord " +
|
|
|
+ "where StopTime = '1991-01-01 00:00:00.000' and ChargeBoxId = @ChargeBoxId and StartTime in (select max(StartTime) from[TransactionRecord] where StopTime = '1991-01-01 00:00:00.000' and ChargeBoxId = @ChargeBoxId group by ConnectorId )";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ parameters.Add(string.IsNullOrEmpty(sessionId) ? "@StartIdTag" : "@TransactionId", string.IsNullOrEmpty(sessionId) ? idTag : sessionId, DbType.String, ParameterDirection.Input);
|
|
|
+
|
|
|
+ strSql = "Select Id, ConnectorId, StartTime, StartIdTag from TransactionRecord" +
|
|
|
+ "where StopTime = '1991-01-01 00:00:00.000' and ChargeBoxId = @ChargeBoxId and StartTime in (select max(StartTime) from [TransactionRecord] where " + (string.IsNullOrEmpty(sessionId) ? "StartIdTag=@StartIdTag" : "Id=@TransactionId") + " and StopTime = '1991-01-01 00:00:00.000' and ChargeBoxId = @ChargeBoxId group by ConnectorId )";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ transactionDatas = conn.Query<TransasctionData>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).ToList();
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- catch
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
;
|
|
|
}
|
|
@@ -324,60 +341,64 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
|
|
|
for (int i = 0; i < requiredMeasurands.Count; i++)
|
|
|
{
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
- parameters.Add("@TransactionId", transactionData.Id, DbType.String, ParameterDirection.Input);
|
|
|
- parameters.Add("@MeasurandId", requiredMeasurands[i], DbType.String, ParameterDirection.Input);
|
|
|
-
|
|
|
- try
|
|
|
+ for (int j = 0; j < transactionDatas.Count; j++)
|
|
|
{
|
|
|
- using (SqlConnection conn = new SqlConnection(meterConnectionString))
|
|
|
- {
|
|
|
- string date = transactionData.StartTime.ToString("yyMMdd");
|
|
|
- string strSql = "Select Top(1) * from [dbo].[ConnectorMeterValueRecord" + date + "] where ChargeBoxId=@ChargeBoxId and TransactionId=@TransactionId and MeasurandId=@MeasurandId order by CreatedOn desc;";
|
|
|
- meterModel = conn.Query<ConnectorMeterValueModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
|
|
|
-
|
|
|
- }
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
+ parameters.Add("@TransactionId", transactionDatas[j].Id, DbType.String, ParameterDirection.Input);
|
|
|
+ parameters.Add("@MeasurandId", requiredMeasurands[i], DbType.String, ParameterDirection.Input);
|
|
|
|
|
|
- if (meterModel != null)
|
|
|
+ try
|
|
|
{
|
|
|
- if(transactionData.MeterValues== null)
|
|
|
+ using (SqlConnection conn = new SqlConnection(meterConnectionString))
|
|
|
{
|
|
|
- transactionData.MeterValues = new List<ConnectorMeterValue>();
|
|
|
+ string date = transactionDatas[j].StartTime.ToString("yyMMdd");
|
|
|
+ string strSql = "Select Top(1) * from [dbo].[ConnectorMeterValueRecord" + date + "] where ChargeBoxId=@ChargeBoxId and TransactionId=@TransactionId and MeasurandId=@MeasurandId order by CreatedOn desc;";
|
|
|
+ meterModel = conn.Query<ConnectorMeterValueModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).FirstOrDefault();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- transactionData.MeterValues.Add(new ConnectorMeterValue()
|
|
|
+ if (meterModel != null)
|
|
|
{
|
|
|
- ChargeBoxId = meterModel.ChargeBoxId,
|
|
|
- ConnectorId = meterModel.ConnectorId,
|
|
|
- CreatedOn = meterModel.CreatedOn,
|
|
|
- Context = meterModel.ContextId < 1 ? (ReadingContext?)null : (ReadingContext?)meterModel.ContextId,
|
|
|
- Format = meterModel.FormatId < 1 ? (ValueFormat?)null : (ValueFormat?)meterModel.FormatId,
|
|
|
- Location = meterModel.LocationId < 1 ? (Location?)null : (Location?)meterModel.LocationId,
|
|
|
- Measurand = meterModel.MeasurandId < 1 ? (Measurand?)null : (Measurand?)meterModel.MeasurandId,
|
|
|
- Phase = meterModel.PhaseId < 1 ? (Phase?)null : (Phase?)meterModel.PhaseId,
|
|
|
- Unit = meterModel.UnitId < 1 ? (UnitOfMeasure?)UnitOfMeasure.Wh : (UnitOfMeasure?)meterModel.UnitId,
|
|
|
- Value = meterModel.Value,
|
|
|
- TransactionId = meterModel.TransactionId
|
|
|
+ if (transactionDatas[j].MeterValues == null)
|
|
|
+ {
|
|
|
+ transactionDatas[j].MeterValues = new List<ConnectorMeterValue>();
|
|
|
+ }
|
|
|
|
|
|
- });
|
|
|
+ transactionDatas[j].MeterValues.Add(new ConnectorMeterValue()
|
|
|
+ {
|
|
|
+ ChargeBoxId = meterModel.ChargeBoxId,
|
|
|
+ ConnectorId = meterModel.ConnectorId,
|
|
|
+ CreatedOn = meterModel.CreatedOn,
|
|
|
+ Context = meterModel.ContextId < 1 ? (ReadingContext?)null : (ReadingContext?)meterModel.ContextId,
|
|
|
+ Format = meterModel.FormatId < 1 ? (ValueFormat?)null : (ValueFormat?)meterModel.FormatId,
|
|
|
+ Location = meterModel.LocationId < 1 ? (Location?)null : (Location?)meterModel.LocationId,
|
|
|
+ Measurand = meterModel.MeasurandId < 1 ? (Measurand?)null : (Measurand?)meterModel.MeasurandId,
|
|
|
+ Phase = meterModel.PhaseId < 1 ? (Phase?)null : (Phase?)meterModel.PhaseId,
|
|
|
+ Unit = meterModel.UnitId < 1 ? (UnitOfMeasure?)UnitOfMeasure.Wh : (UnitOfMeasure?)meterModel.UnitId,
|
|
|
+ Value = meterModel.Value,
|
|
|
+ TransactionId = meterModel.TransactionId
|
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- catch(Exception ex)
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
- return transactionData;
|
|
|
+ return transactionDatas;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public List<SessionDetail> GetSessionDetail(string chargeBoxId, string sessionId, string idTag, DateTime searchTime)
|
|
|
+ public List<SessionDetail> GetSessionDetail(string chargeBoxId, string sessionId, string idTag, DateTime startTime, DateTime stopTime)
|
|
|
{
|
|
|
List<SessionDetail> detail = new List<SessionDetail>();
|
|
|
List<TransactionRecordModel> transactionModel = null;
|
|
@@ -385,41 +406,49 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
|
|
|
|
|
|
var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
- parameters.Add("@TransactionId", sessionId, DbType.String, ParameterDirection.Input);
|
|
|
|
|
|
try
|
|
|
{
|
|
|
+
|
|
|
+ bool restrictedRange = false;
|
|
|
+ if (startTime != new DateTime(1991, 1, 1))
|
|
|
+ {
|
|
|
+ restrictedRange = true;
|
|
|
+ parameters.Add("@startTime", startTime, DbType.DateTime, ParameterDirection.Input);
|
|
|
+ parameters.Add("@stopTime", stopTime, DbType.DateTime, ParameterDirection.Input);
|
|
|
+ }
|
|
|
+
|
|
|
using (SqlConnection conn = new SqlConnection(mainConnectionString))
|
|
|
{
|
|
|
string strSql = string.Empty;
|
|
|
- if (!string.IsNullOrEmpty(sessionId))
|
|
|
+ if (!string.IsNullOrEmpty(sessionId) && string.IsNullOrEmpty(idTag))
|
|
|
{
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
parameters.Add("@TransactionId", sessionId, DbType.String, ParameterDirection.Input);
|
|
|
- strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and StopTime!='1991-01-01 00:00:00.000' Order by Id desc ;";
|
|
|
+ strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id=@TransactionId and StopTime!='1991-01-01 00:00:00.000' "+ (restrictedRange ? " and StartTime >=@startTime and StartTime <=@stopTime" : "" )+ " Order by Id desc ;";
|
|
|
}
|
|
|
- else if (!string.IsNullOrEmpty(idTag))
|
|
|
+ else if (!string.IsNullOrEmpty(idTag) && string.IsNullOrEmpty(sessionId))
|
|
|
{
|
|
|
- parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
+ if(!string.IsNullOrEmpty(chargeBoxId))
|
|
|
+ {
|
|
|
+ parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
+ }
|
|
|
+
|
|
|
parameters.Add("@StartIdTag", idTag, DbType.String, ParameterDirection.Input);
|
|
|
- strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and StartIdTag=@StartIdTag and StopTime!='1991-01-01 00:00:00.000' Order by Id desc ;";
|
|
|
+ strSql = "Select * from [dbo].[TransactionRecord] where "+ (!string.IsNullOrEmpty(chargeBoxId)? " ChargeBoxId=@ChargeBoxId and " :"")+ " StartIdTag=@StartIdTag and StopTime!='1991-01-01 00:00:00.000' " + (restrictedRange ? " and StartTime >=@startTime and StartTime <=@stopTime" : "") + " Order by Id desc ;";
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (searchTime == new DateTime())
|
|
|
- {
|
|
|
- return detail;
|
|
|
- }
|
|
|
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input);
|
|
|
- parameters.Add("@StartIdTag", idTag, DbType.String, ParameterDirection.Input);
|
|
|
- strSql = "Select Top(1) * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and StartIdTag=@StartIdTag and StopTime!='1991-01-01 00:00:00.000' Order by Id desc ;";
|
|
|
+
|
|
|
+ strSql = "Select * from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and StopTime!='1991-01-01 00:00:00.000' " + (restrictedRange ? " and StartTime >=@startTime and StartTime <=@stopTime" : "") + " Order by Id desc ;";
|
|
|
|
|
|
}
|
|
|
|
|
|
transactionModel = conn.Query<TransactionRecordModel>(strSql, parameters, null, true, EVCBConfiguration.DB_DefaultConnectionTimeout).ToList();
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -439,7 +468,7 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- catch
|
|
|
+ catch(Exception ex)
|
|
|
{
|
|
|
|
|
|
}
|
|
@@ -514,36 +543,8 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
|
|
|
private ConnectorType ConvertConnectorType(int value)
|
|
|
{
|
|
|
- ConnectorType result = ConnectorType.Other;
|
|
|
+ ConnectorType result = (ConnectorType)value;
|
|
|
|
|
|
- switch (value)
|
|
|
- {
|
|
|
- case 1://CHADEMO
|
|
|
- {
|
|
|
- result = ConnectorType.CHADEMO;
|
|
|
- }
|
|
|
- break;
|
|
|
- case 4://AC
|
|
|
- {
|
|
|
- result = ConnectorType.AC;
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- {
|
|
|
- result = ConnectorType.CCS;
|
|
|
- }
|
|
|
- break;
|
|
|
- case 3://GBT
|
|
|
- {
|
|
|
- result = ConnectorType.GBT;
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
return result;
|
|
|
}
|
|
|
|