|
@@ -104,7 +104,7 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
""";
|
|
|
|
|
|
var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@MachineIds", machineIds);
|
|
|
+ parameters.Add("@MachineIds", machineIds, direction: ParameterDirection.Input,size: 36);
|
|
|
|
|
|
using SqlConnection conn = await mainDbConneciotnFactory.CreateAsync();
|
|
|
var tmp = await conn.QueryAsync<LastUpdatedTimeDto>(cmd, parameters);
|
|
@@ -191,8 +191,7 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
ConnectorId = _RefConnector is null ? i : _RefConnector.ConnectorId,
|
|
|
Status = cp.Status == Status.Offline ? Status.Offline : _RefConnector is null ? Status.Unknown : ConvertConnectorStatus(_RefConnector.Status),
|
|
|
ConnectorType = ConvertConnectorType(int.Parse(_machine.ConnectorType.Split(',')[i - 1])),
|
|
|
- FaultMessage = _RefConnector is null ? "Connector not found" : ((ChargePointErrorCode)_RefConnector.ChargePointErrorCodeId).ToString() + (string.IsNullOrEmpty(_RefConnector.VendorErrorCode) ? "" : "-" + _RefConnector.VendorErrorCode)
|
|
|
-
|
|
|
+ FaultMessage = _RefConnector is null ? ChargePointErrorCode.NoError.ToString() : ((ChargePointErrorCode)_RefConnector.ChargePointErrorCodeId).ToString() + (string.IsNullOrEmpty(_RefConnector.VendorErrorCode) ? "" : "-" + _RefConnector.VendorErrorCode)
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -205,7 +204,7 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
Dictionary<string , Machine> _machines = new();
|
|
|
|
|
|
var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@MachineIds", machineIds);
|
|
|
+ parameters.Add("@MachineIds", machineIds, direction: ParameterDirection.Input, size: 36);
|
|
|
string strSql = """
|
|
|
SELECT Id,ChargeBoxId,ChargePointSerialNumber,ChargePointModel,RatedPower,Online,OfflineOn ,GunAmt,Latitude,Longitude,ConnectorType
|
|
|
FROM [dbo].[Machine]
|
|
@@ -286,7 +285,7 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
Dictionary<string, List<ConnectorStatus>> toReturn = new();
|
|
|
IEnumerable<ConnectorStatus> _Connectors;// = new List<ConnectorStatus>();
|
|
|
var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@ChargeBoxIds", chargeBoxIds);
|
|
|
+ parameters.Add("@ChargeBoxIds", chargeBoxIds, direction: ParameterDirection.Input, size: 50);
|
|
|
string strSql = """
|
|
|
SELECT ChargeBoxId,ConnectorId,Status,ChargePointErrorCodeId,VendorErrorCode
|
|
|
FROM [dbo].[ConnectorStatus]
|
|
@@ -318,6 +317,11 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
|
|
|
|
|
|
public int GetNumberofConnectors(string chargeBoxId)
|
|
|
+ {
|
|
|
+ return GetNumberofConnectorsAsync(chargeBoxId).Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<int> GetNumberofConnectorsAsync(string chargeBoxId)
|
|
|
{
|
|
|
int count = 0;
|
|
|
|
|
@@ -326,10 +330,10 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
{
|
|
|
var parameters = new DynamicParameters();
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
|
|
|
- using (SqlConnection conn = mainDbConneciotnFactory.Create())
|
|
|
+ using (SqlConnection conn = await mainDbConneciotnFactory.CreateAsync())
|
|
|
{
|
|
|
string strSql = "Select GunAmt from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and IsDelete=0; ";
|
|
|
- count = conn.ExecuteScalarAsync<int>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout).Result;
|
|
|
+ count = await conn.ExecuteScalarAsync<int>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -352,6 +356,11 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
}
|
|
|
|
|
|
public int? GetConnectorwithOngoingTransaction(string chargeBoxId, int transactionId)
|
|
|
+ {
|
|
|
+ return GetConnectorwithOngoingTransactionAsync(chargeBoxId, transactionId).Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<int?> GetConnectorwithOngoingTransactionAsync(string chargeBoxId, int transactionId)
|
|
|
{
|
|
|
int? connectorId = null;
|
|
|
|
|
@@ -360,19 +369,22 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
var parameters = new DynamicParameters();
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
|
|
|
parameters.Add("@TransactionId", transactionId, DbType.Int32, ParameterDirection.Input);
|
|
|
- using (SqlConnection conn = mainDbConneciotnFactory.Create())
|
|
|
+ using (SqlConnection conn = await mainDbConneciotnFactory.CreateAsync())
|
|
|
{
|
|
|
string strSql = "Select ConnectorId from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id= @TransactionId and StopTime='1991/01/01'; ";
|
|
|
- connectorId = conn.QueryFirstOrDefault<int?>(strSql, parameters);
|
|
|
+ connectorId = await conn.QueryFirstOrDefaultAsync<int?>(strSql, parameters);
|
|
|
}
|
|
|
|
|
|
return connectorId;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public bool IsTransactionRunning(string chargeBoxId, int transactionId)
|
|
|
+ {
|
|
|
+ return IsTransactionRunningAsync(chargeBoxId, transactionId).Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<bool> IsTransactionRunningAsync(string chargeBoxId, int transactionId)
|
|
|
{
|
|
|
bool exists = false;
|
|
|
|
|
@@ -381,10 +393,10 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
var parameters = new DynamicParameters();
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
|
|
|
parameters.Add("@TransactionId", transactionId, DbType.Int32, ParameterDirection.Input);
|
|
|
- using (SqlConnection conn = mainDbConneciotnFactory.Create())
|
|
|
+ using (SqlConnection conn = await mainDbConneciotnFactory.CreateAsync())
|
|
|
{
|
|
|
string strSql = "Select Id from [dbo].[TransactionRecord] where ChargeBoxId=@ChargeBoxId and Id= @TransactionId and StopTime='1991/01/01'; ";
|
|
|
- int id = conn.QueryFirstOrDefault<Int32>(strSql, parameters);//.FirstOrDefault();
|
|
|
+ int id = await conn.QueryFirstOrDefaultAsync<Int32>(strSql, parameters);//.FirstOrDefault();
|
|
|
exists = id > 0 ? true : false;
|
|
|
}
|
|
|
return exists;
|
|
@@ -397,6 +409,11 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
/// <param name="connectorId">充電槍號(0代表樁/槍號從1開始)</param>
|
|
|
/// <returns>依據OCPP狀態回覆 NULL表示離線</returns>
|
|
|
public ChargePointStatus? GetChargePointCurrentSatus(string chargeBoxId, int connectorId = 0)
|
|
|
+ {
|
|
|
+ return GetChargePointCurrentSatusAsync(chargeBoxId, connectorId).Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<ChargePointStatus?> GetChargePointCurrentSatusAsync(string chargeBoxId, int connectorId = 0)
|
|
|
{
|
|
|
ChargePointStatus? _status = null;
|
|
|
|
|
@@ -406,16 +423,16 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
|
|
|
parameters.Add("@ConnectorId", connectorId, DbType.Int32, ParameterDirection.Input);
|
|
|
|
|
|
- using (SqlConnection conn = mainDbConneciotnFactory.Create())
|
|
|
+ using (SqlConnection conn = await mainDbConneciotnFactory.CreateAsync())
|
|
|
{
|
|
|
string strSql = "Select online from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and IsDelete=0; ";
|
|
|
- bool online = conn.ExecuteScalar<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
|
|
|
+ bool online = await conn.ExecuteScalarAsync<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
|
|
|
|
|
|
if (online)
|
|
|
{
|
|
|
string connectorStrSql = "Select Status from [dbo].[ConnectorStatus] where ChargeBoxId=@ChargeBoxId and ConnectorId=@ConnectorId; ";
|
|
|
|
|
|
- int _statusfromdb = conn.QueryFirstOrDefault<Int32>(connectorStrSql, parameters);//.FirstOrDefault();
|
|
|
+ int _statusfromdb = await conn.QueryFirstOrDefaultAsync<Int32>(connectorStrSql, parameters);//.FirstOrDefault();
|
|
|
|
|
|
_status = (_statusfromdb <= 0 && connectorId == 0) ? ChargePointStatus.Available : (_statusfromdb <= 0 ? ((ChargePointStatus?)null) : ((ChargePointStatus)_statusfromdb));
|
|
|
|
|
@@ -427,6 +444,11 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
}
|
|
|
|
|
|
public bool IsOnline(string chargeBoxId)
|
|
|
+ {
|
|
|
+ return IsOnlineAsync(chargeBoxId).Result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<bool> IsOnlineAsync(string chargeBoxId)
|
|
|
{
|
|
|
bool online = false;
|
|
|
|
|
@@ -436,10 +458,10 @@ namespace EVCB_OCPP.WEBAPI.Services
|
|
|
parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
|
|
|
|
|
|
|
|
|
- using (SqlConnection conn = mainDbConneciotnFactory.Create())
|
|
|
+ using (SqlConnection conn = await mainDbConneciotnFactory.CreateAsync())
|
|
|
{
|
|
|
string strSql = "Select online from [dbo].[Machine] where ChargeBoxId=@ChargeBoxId and IsDelete=0; ";
|
|
|
- online = conn.ExecuteScalar<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
|
|
|
+ online = await conn.ExecuteScalarAsync<bool>(strSql, parameters, null, EVCBConfiguration.DB_DefaultConnectionTimeout);
|
|
|
}
|
|
|
|
|
|
return online;
|