|
@@ -1,4 +1,5 @@
|
|
|
using Azure;
|
|
|
+using Azure.Core;
|
|
|
using Dapper;
|
|
|
using EVCB_OCPP.Domain;
|
|
|
using EVCB_OCPP.Domain.ConnectionFactory;
|
|
@@ -74,6 +75,8 @@ public interface IMainDbService
|
|
|
Task<TransactionRecord> GetTransaction(int txId);
|
|
|
Task SetPncNotifiyResult(int txid, bool isNotifySuccess, string eVCCID);
|
|
|
Task ReportStopTx(int txid, NotifyTransactionCompletedResult reportResults);
|
|
|
+ Task<bool> GetIsEvseDiagnosticsStatusAvalaible(string charger_SN);
|
|
|
+ Task ContinueLastEvseDiagnostic(string chargeboxId);
|
|
|
}
|
|
|
|
|
|
public class MainDbService : IMainDbService
|
|
@@ -663,6 +666,97 @@ public class MainDbService : IMainDbService
|
|
|
await dbConn.ExecuteAsync(cmd, parameters);
|
|
|
}
|
|
|
|
|
|
+ public async Task<bool> GetIsEvseDiagnosticsStatusAvalaible(string chargeboxId)
|
|
|
+ {
|
|
|
+ var cmd = """
|
|
|
+ SELECT TOP (1) [EVSE_Status]
|
|
|
+ FROM [dbo].[MachineOperateRecord]
|
|
|
+ where [Action] = 'GetDiagnostics' and [EVSE_Value] != '' and ChargeBoxId = @ChargeBoxId
|
|
|
+ order by id desc
|
|
|
+ """;
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@ChargeBoxId", chargeboxId, size: 50);
|
|
|
+
|
|
|
+ using var dbConn = await sqlConnectionFactory.CreateAsync();
|
|
|
+ var result = await dbConn.QueryFirstOrDefaultAsync<int?>(cmd, parameters);
|
|
|
+ return result == null ? true : (result.Value == (int)DiagnosticsStatus.Uploaded || result.Value == (int)DiagnosticsStatus.UploadFailed);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task ContinueLastEvseDiagnostic(string chargeboxId)
|
|
|
+ {
|
|
|
+ using var db = await contextFactory.CreateDbContextAsync();
|
|
|
+
|
|
|
+ var updatedRecord = await db.MachineOperateRecord
|
|
|
+ .Where(x => x.ChargeBoxId == chargeboxId && x.Action == "GetDiagnostics" && x.RequestType == 1 && x.EvseValue != "")
|
|
|
+ .OrderByDescending(x => x.Id)
|
|
|
+ .FirstOrDefaultAsync();
|
|
|
+
|
|
|
+ var needUpdateRecord = await db.MachineOperateRecord
|
|
|
+ .Where(x => x.ChargeBoxId == chargeboxId && x.Action == "GetDiagnostics" && x.RequestType == 1 && x.EvseValue == "")
|
|
|
+ .OrderByDescending(x => x.Id)
|
|
|
+ .FirstOrDefaultAsync();
|
|
|
+
|
|
|
+ if (updatedRecord == null)
|
|
|
+ {
|
|
|
+ logger.LogInformation("chargeboxId:{0} updatedRecord null", chargeboxId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needUpdateRecord == null)
|
|
|
+ {
|
|
|
+ logger.LogInformation("chargeboxId:{0} needUpdateRecord null", chargeboxId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ needUpdateRecord.EvseStatus = updatedRecord.EvseStatus;
|
|
|
+ needUpdateRecord.EvseValue = updatedRecord.EvseValue;
|
|
|
+ needUpdateRecord.Status = updatedRecord.Status;
|
|
|
+ await db.SaveChangesAsync();
|
|
|
+
|
|
|
+ //var getLastUpdatedDataCmd = """
|
|
|
+ // SELECT TOP (1) [Id], [EVSE_Value], [EVSE_Status]
|
|
|
+ // FROM [dbo].[MachineOperateRecord]
|
|
|
+ // WHERE [Action] = 'GetDiagnostics' and [EVSE_Status] != 0 and ChargeBoxId = @ChargeBoxId
|
|
|
+ // order by Id desc
|
|
|
+ // """;
|
|
|
+ //var getLastIdCmd = """
|
|
|
+ // SELECT TOP (1) [Id]
|
|
|
+ // FROM [dbo].[MachineOperateRecord]
|
|
|
+ // WHERE [Action] = 'GetDiagnostics' and ChargeBoxId = @ChargeBoxId
|
|
|
+ // order by Id desc
|
|
|
+ // """;
|
|
|
+ //var updateLastCmd = """
|
|
|
+ // Update [dbo].[MachineOperateRecord]
|
|
|
+ // SET [EVSE_Value] = @EVSE_Value, [EVSE_Status] = @EVSE_Status
|
|
|
+ // WHERE [Id] = @Id
|
|
|
+ // """;
|
|
|
+
|
|
|
+ //using var dbConn = await sqlConnectionFactory.CreateAsync();
|
|
|
+ //var parameters = new DynamicParameters();
|
|
|
+
|
|
|
+ //parameters.Add("@ChargeBoxId", chargeboxId, size: 50);
|
|
|
+ //var getDataResult = await dbConn.QueryFirstOrDefaultAsync<MachineOperateRecord>(getLastUpdatedDataCmd, parameters);
|
|
|
+ //if (getDataResult is null)
|
|
|
+ //{
|
|
|
+ // logger.LogInformation("chargebox:{0} diagnostic get updated faied", chargeboxId);
|
|
|
+ //}
|
|
|
+
|
|
|
+ //var getNeedUpdateIdResult = await dbConn.QueryFirstOrDefaultAsync<int?>(getLastIdCmd, parameters);
|
|
|
+ //if (getNeedUpdateIdResult is null)
|
|
|
+ //{
|
|
|
+ // logger.LogInformation("chargebox:{0} diagnostic get update id faied", chargeboxId);
|
|
|
+ //}
|
|
|
+
|
|
|
+ //parameters = new DynamicParameters();
|
|
|
+ //parameters.Add("@EVSE_Value", getDataResult.EvseValue);
|
|
|
+ //parameters.Add("@EVSE_Status", getDataResult.EvseStatus);
|
|
|
+ //var updateResult = await dbConn.ExecuteAsync(updateLastCmd, parameters);
|
|
|
+ //if (updateResult == 0)
|
|
|
+ //{
|
|
|
+ // logger.LogInformation("chargebox:{0} diagnostic update faied", chargeboxId);
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
private void InitUpdateConnectorStatusHandler()
|
|
|
{
|
|
|
if (statusNotificationHandler is not null)
|