|
@@ -38,7 +38,7 @@ public interface IMainDbService
|
|
|
Task<string> AddServerMessage(ServerMessage message);
|
|
|
Task<string> AddServerMessage(string ChargeBoxId, string OutAction, object OutRequest, string CreatedBy = "", DateTime? CreatedOn = null, string SerialNo = "", string InMessage = "");
|
|
|
ValueTask AddMachineError(byte ConnectorId, DateTime CreatedOn, int Status, string ChargeBoxId, int ErrorCodeId, string ErrorInfo, int PreStatus, string VendorErrorCode, string VendorId);
|
|
|
- ValueTask FillupFinishedTimetoMachineError(byte ConnectorId, DateTime FinishedOn, string ChargeBoxId);
|
|
|
+ ValueTask FillupFinishedTimetoMachineError(string ChargeBoxId, byte ConnectorId, DateTime FinishedOn);
|
|
|
|
|
|
ValueTask<Customer> GetCustomer(string id, CancellationToken token = default);
|
|
|
ValueTask<Customer> GetCustomer(Guid id, CancellationToken token = default);
|
|
@@ -87,6 +87,7 @@ public class MainDbService : IMainDbService
|
|
|
InitAddServerMessageHandler();
|
|
|
InitUpdateServerMessageUpdateOnHandler();
|
|
|
InitGetMachineConfigurationHandler();
|
|
|
+ InitUpdateErrorFinishedOnHandler();
|
|
|
}
|
|
|
|
|
|
private const string CustomerMemCacheKeyFromat = "Customer_{0}";
|
|
@@ -106,6 +107,7 @@ public class MainDbService : IMainDbService
|
|
|
private GroupHandler<ServerMessage, string> addServerMessageHandler;
|
|
|
private GroupHandler<int> updateServerMessageUpdateOnHandler;
|
|
|
private GroupHandler<string, List<MachineConfigurations>> getMachineConfigurationHandler;
|
|
|
+ private GroupHandler<UpdateErrofFinishedOnParam> updateErrorFinishedOnHandler;
|
|
|
|
|
|
public async Task<MachineAndCustomerInfo> GetMachineIdAndCustomerInfo(string ChargeBoxId, CancellationToken token = default)
|
|
|
{
|
|
@@ -238,10 +240,10 @@ public class MainDbService : IMainDbService
|
|
|
return AddMachineErrorDapper(ConnectorId, CreatedOn, Status, ChargeBoxId, ErrorCodeId, ErrorInfo, PreStatus, VendorErrorCode, VendorId);
|
|
|
}
|
|
|
|
|
|
- public ValueTask FillupFinishedTimetoMachineError(byte ConnectorId, DateTime FinishedOn, string ChargeBoxId)
|
|
|
+ public ValueTask FillupFinishedTimetoMachineError(string ChargeBoxId,byte ConnectorId, DateTime FinishedOn)
|
|
|
{
|
|
|
|
|
|
- return AddFinishedTimetoMachineErrorDapper(ConnectorId, FinishedOn, ChargeBoxId);
|
|
|
+ return AddFinishedTimetoMachineErrorDapper(ChargeBoxId, ConnectorId, FinishedOn);
|
|
|
}
|
|
|
|
|
|
public async Task<string> AddServerMessage(string ChargeBoxId, string OutAction, object OutRequest, string CreatedBy, DateTime? CreatedOn = null, string SerialNo = "", string InMessage = "")
|
|
@@ -592,6 +594,18 @@ public class MainDbService : IMainDbService
|
|
|
workerCnt: 10);
|
|
|
}
|
|
|
|
|
|
+ private void InitUpdateErrorFinishedOnHandler()
|
|
|
+ {
|
|
|
+ if (updateErrorFinishedOnHandler is not null)
|
|
|
+ {
|
|
|
+ throw new Exception($"{nameof(InitUpdateErrorFinishedOnHandler)} should only called once");
|
|
|
+ }
|
|
|
+
|
|
|
+ updateErrorFinishedOnHandler = new GroupHandler<UpdateErrofFinishedOnParam>(
|
|
|
+ handleFunc: BundelUpdateErrorFinishedOn,
|
|
|
+ logger: loggerFactory.CreateLogger("UpdateErrorFinishedOnHandler"),
|
|
|
+ workerCnt: 1);
|
|
|
+ }
|
|
|
|
|
|
private async Task UpdateMachineBasicInfoEF(string chargeBoxId, Machine machine)
|
|
|
{
|
|
@@ -838,42 +852,67 @@ public class MainDbService : IMainDbService
|
|
|
""", parameters);
|
|
|
}
|
|
|
|
|
|
- private async ValueTask AddFinishedTimetoMachineErrorDapper(byte connectorId, DateTime finishedTime, string chargeBoxId)
|
|
|
+ private async ValueTask AddFinishedTimetoMachineErrorDapper(string chargeBoxId, byte connectorId, DateTime finishedTime)
|
|
|
{
|
|
|
var getCommand = """
|
|
|
- SELECT Id
|
|
|
+ SELECT TOP(1) Id
|
|
|
FROM [dbo].[MachineError]
|
|
|
where ChargeBoxId=@ChargeBoxId and ConnectorId=@ConnectorId
|
|
|
Order by Id desc
|
|
|
""";
|
|
|
|
|
|
+ var parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@ConnectorId", connectorId, DbType.Int16, ParameterDirection.Input);
|
|
|
+ parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
|
|
|
+ //parameters.Add("@CreatedOn", previousErrorOn, DbType.DateTime, ParameterDirection.Input, 50);
|
|
|
+
|
|
|
+ int? recordId = null;
|
|
|
+ using (var conn = await sqlConnectionFactory.CreateAsync())
|
|
|
+ {
|
|
|
+ recordId = await conn.QueryFirstOrDefaultAsync<int?>(getCommand, parameters);
|
|
|
+ if (recordId is null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await updateErrorFinishedOnHandler.HandleAsync(new UpdateErrofFinishedOnParam(recordId.Value, finishedTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task BundelUpdateErrorFinishedOn(BundleHandlerData<UpdateErrofFinishedOnParam> bundleHandlerData)
|
|
|
+ {
|
|
|
var updateCommand = """
|
|
|
Update MachineError
|
|
|
set FinishedOn=@FinishedOn
|
|
|
where Id=@Id
|
|
|
""";
|
|
|
|
|
|
- var parameters = new DynamicParameters();
|
|
|
- parameters.Add("@ConnectorId", connectorId, DbType.Int16, ParameterDirection.Input);
|
|
|
- parameters.Add("@ChargeBoxId", chargeBoxId, DbType.String, ParameterDirection.Input, 50);
|
|
|
- //parameters.Add("@CreatedOn", previousErrorOn, DbType.DateTime, ParameterDirection.Input, 50);
|
|
|
+ var pams = bundleHandlerData.Datas;
|
|
|
+ using var conn = await sqlConnectionFactory.CreateAsync();
|
|
|
+ using var trans = await conn.BeginTransactionAsync();
|
|
|
|
|
|
- using var conn = await sqlConnectionFactory.CreateAsync();
|
|
|
+ DynamicParameters parameters = null;
|
|
|
|
|
|
- var recordId = await conn.QueryFirstOrDefaultAsync<int?>(getCommand, parameters);
|
|
|
- if (recordId is null)
|
|
|
+ foreach (var pam in pams)
|
|
|
{
|
|
|
- return;
|
|
|
+
|
|
|
+ parameters = new DynamicParameters();
|
|
|
+ parameters.Add("@Id", pam.Id, DbType.Int32, ParameterDirection.Input);
|
|
|
+ parameters.Add("@FinishedOn", pam.finishedOn, DbType.DateTime, ParameterDirection.Input);
|
|
|
+
|
|
|
+ await conn.ExecuteAsync(new CommandDefinition(
|
|
|
+ updateCommand,
|
|
|
+ parameters: parameters,
|
|
|
+ transaction: trans
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
- parameters = new DynamicParameters();
|
|
|
- parameters.Add("@Id", recordId, DbType.Int32, ParameterDirection.Input);
|
|
|
- parameters.Add("@FinishedOn", finishedTime, DbType.DateTime, ParameterDirection.Input, 50);
|
|
|
+ await trans.CommitAsync();
|
|
|
|
|
|
- await conn.ExecuteAsync(updateCommand, parameters);
|
|
|
- }
|
|
|
+ bundleHandlerData.CompletedDatas.AddRange(bundleHandlerData.Datas);
|
|
|
+ }
|
|
|
|
|
|
- private async Task BundleUpdateConnectorStatus(IEnumerable<StatusNotificationParam> statusNotifications)
|
|
|
+ private async Task BundleUpdateConnectorStatus(IEnumerable<StatusNotificationParam> statusNotifications)
|
|
|
{
|
|
|
using var db = await contextFactory.CreateDbContextAsync();
|
|
|
using var trans = await db.Database.BeginTransactionAsync();
|
|
@@ -1273,4 +1312,5 @@ public class MainDbService : IMainDbService
|
|
|
|
|
|
public record MachineAndCustomerInfo(string MachineId, Guid CustomerId, string CustomerName);
|
|
|
public record StatusNotificationParam(string Id, ConnectorStatus Status);
|
|
|
-public record UpdateMachineBasicInfoParam(string ChargeBoxId, Machine machine);
|
|
|
+public record UpdateMachineBasicInfoParam(string ChargeBoxId, Machine machine);
|
|
|
+public record UpdateErrofFinishedOnParam(int Id, DateTime finishedOn);
|