|
@@ -1,9 +1,9 @@
|
|
using Hotline.BatchTask;
|
|
using Hotline.BatchTask;
|
|
|
|
+using Hotline.BatchTask.Notifications;
|
|
using Quartz;
|
|
using Quartz;
|
|
using Hotline.Share.Enums.BatchTask;
|
|
using Hotline.Share.Enums.BatchTask;
|
|
-using Hotline.Share.Dtos.Order;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
-using Hotline.Application.OrderApp.OrderVisitApp;
|
|
|
|
|
|
+using Hotline.EventBus;
|
|
using Hotline.Share.Dtos.Order.OrderVisit;
|
|
using Hotline.Share.Dtos.Order.OrderVisit;
|
|
using Hotline.Share.Dtos.Order.OrderDelay;
|
|
using Hotline.Share.Dtos.Order.OrderDelay;
|
|
|
|
|
|
@@ -13,12 +13,16 @@ namespace Hotline.Application.Jobs
|
|
{
|
|
{
|
|
private readonly IApptaskDomainService _apptaskDomainService;
|
|
private readonly IApptaskDomainService _apptaskDomainService;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
+ private readonly Publisher _publisher;
|
|
|
|
|
|
- public ApptaskJob(IApptaskDomainService apptaskDomainService,
|
|
|
|
- IServiceProvider serviceProvider)
|
|
|
|
|
|
+ public ApptaskJob(
|
|
|
|
+ IApptaskDomainService apptaskDomainService,
|
|
|
|
+ IServiceProvider serviceProvider,
|
|
|
|
+ Publisher publisher)
|
|
{
|
|
{
|
|
_apptaskDomainService = apptaskDomainService;
|
|
_apptaskDomainService = apptaskDomainService;
|
|
_serviceProvider = serviceProvider;
|
|
_serviceProvider = serviceProvider;
|
|
|
|
+ _publisher = publisher;
|
|
}
|
|
}
|
|
|
|
|
|
public async Task Execute(IJobExecutionContext context)
|
|
public async Task Execute(IJobExecutionContext context)
|
|
@@ -26,21 +30,43 @@ namespace Hotline.Application.Jobs
|
|
//Console.WriteLine($"执行ApptaskJob: {DateTime.Now}");
|
|
//Console.WriteLine($"执行ApptaskJob: {DateTime.Now}");
|
|
var task = await _apptaskDomainService.GetWaitingTaskAsync(context.CancellationToken);
|
|
var task = await _apptaskDomainService.GetWaitingTaskAsync(context.CancellationToken);
|
|
if (task is null) return;
|
|
if (task is null) return;
|
|
|
|
+ ApptaskExecuteResult? result = null;
|
|
switch (task.TaskType)
|
|
switch (task.TaskType)
|
|
{
|
|
{
|
|
case ETaskType.OrderDelay:
|
|
case ETaskType.OrderDelay:
|
|
var delayExecutor = _serviceProvider.GetService<IApptaskExecutor<OrderDelayReviewRequest>>();
|
|
var delayExecutor = _serviceProvider.GetService<IApptaskExecutor<OrderDelayReviewRequest>>();
|
|
- await _apptaskDomainService.ExecuteAsync(delayExecutor, task, context.CancellationToken);
|
|
|
|
|
|
+ result = await _apptaskDomainService.ExecuteAsync(delayExecutor, task, context.CancellationToken);
|
|
break;
|
|
break;
|
|
case ETaskType.OrderScreen:
|
|
case ETaskType.OrderScreen:
|
|
break;
|
|
break;
|
|
case ETaskType.VoiceVisit:
|
|
case ETaskType.VoiceVisit:
|
|
var vvExecutor = _serviceProvider.GetService<IApptaskExecutor<VoiceVisitRequest>>();
|
|
var vvExecutor = _serviceProvider.GetService<IApptaskExecutor<VoiceVisitRequest>>();
|
|
- await _apptaskDomainService.ExecuteAsync(vvExecutor, task, context.CancellationToken);
|
|
|
|
|
|
+ result = await _apptaskDomainService.ExecuteAsync(vvExecutor, task, context.CancellationToken);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (result is not null)
|
|
|
|
+ {
|
|
|
|
+ if (result.IsSuccess)
|
|
|
|
+ {
|
|
|
|
+ //todo pub single complete suc
|
|
|
|
+ await _publisher.PublishAsync(new ApptaskSuccessNotify(task), PublishStrategy.Async, context.CancellationToken);
|
|
|
|
+
|
|
|
|
+ //todo check if task is all complete
|
|
|
|
+ //pub all complete
|
|
|
|
+ var isCompleted = await _apptaskDomainService.IsCompletedAsync(task.ApptaskId, context.CancellationToken);
|
|
|
|
+ if (isCompleted)
|
|
|
|
+ await _publisher.PublishAsync(new ApptaskCompletedNotify(task), PublishStrategy.Async, context.CancellationToken);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //todo pub single complete fail
|
|
|
|
+ await _publisher.PublishAsync(new ApptaskFailNotify(task), PublishStrategy.Async, context.CancellationToken);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
|
|
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
|