|
@@ -0,0 +1,143 @@
|
|
|
+using Hotline.DataSharing.Province.HuiJu.Send;
|
|
|
+using Hotline.DataSharing.Province.Other;
|
|
|
+using Hotline.DataSharing.Province.Services;
|
|
|
+using Hotline.DataSharing.Province.XieTong.Receive;
|
|
|
+using Hotline.DataSharing.Province.XieTong.Send;
|
|
|
+using MediatR;
|
|
|
+using Microsoft.Extensions.DependencyInjection;
|
|
|
+using Microsoft.Extensions.Hosting;
|
|
|
+using XF.Domain.Repository;
|
|
|
+
|
|
|
+namespace Hotline.Application.DataSharing.Province
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// 后台定时任务
|
|
|
+ /// </summary>
|
|
|
+ public class PushDataBgService : BackgroundService
|
|
|
+ {
|
|
|
+ private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="serviceScopeFactory"></param>
|
|
|
+ public PushDataBgService(IServiceScopeFactory serviceScopeFactory)
|
|
|
+ {
|
|
|
+ _serviceScopeFactory = serviceScopeFactory;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="stoppingToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
+ {
|
|
|
+ //10分钟扫描一次数据库
|
|
|
+ using var sc = _serviceScopeFactory.CreateScope();
|
|
|
+ var time = TimeSpan.FromSeconds(60 * 10);
|
|
|
+ while (!stoppingToken.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ using var scope = _serviceScopeFactory.CreateScope();
|
|
|
+ var _waitingPushDataRepository = scope.ServiceProvider.GetService<IRepository<DsWaitingPushData>>();
|
|
|
+ var _sendCaseInfoRepository = scope.ServiceProvider.GetService<IRepository<DsSendCaseInfo>>();
|
|
|
+ var _mediator = scope.ServiceProvider.GetService<IMediator>();
|
|
|
+ var _pusherProviderService = scope.ServiceProvider.GetService<IPusherProviderService>();
|
|
|
+
|
|
|
+ #region 批量推送省数据
|
|
|
+ //查询待推送数据
|
|
|
+ var listData = await _waitingPushDataRepository
|
|
|
+ .Queryable()
|
|
|
+ .OrderByDescending(p => p.Priority)
|
|
|
+ .ToListAsync();
|
|
|
+ var isContinue = true;
|
|
|
+ if (listData != null && listData.Count > 0)
|
|
|
+ {
|
|
|
+ List<DsSubmitCaseProcess> submitCaseProcesses = new(); //服务工单处理过程
|
|
|
+ List<DsSubmitCaseResult> submitCaseResults = new(); //服务工单处理结果
|
|
|
+ List<DsSubmitVisitInfo> submitVisitInfos = new(); //服务工单回访评价
|
|
|
+ List<DsGetCaseMaterialInfo> getCaseMaterialInfos = new();//附件上传处理
|
|
|
+
|
|
|
+ //根据查询出来数据组装推送数据
|
|
|
+ foreach (var item in listData)
|
|
|
+ {
|
|
|
+ switch (item.ServiceInterface)
|
|
|
+ {
|
|
|
+ case "SubmitCaseProcess"://服务工单处理过程
|
|
|
+ var caseProcess = System.Text.Json.JsonSerializer.Deserialize<DsSubmitCaseProcess>(item.Data);
|
|
|
+ if (caseProcess != null) submitCaseProcesses.Add(caseProcess);
|
|
|
+ break;
|
|
|
+ case "SubmitCaseResult": //服务工单处理结果
|
|
|
+ var caseResult = System.Text.Json.JsonSerializer.Deserialize<DsSubmitCaseResult>(item.Data);
|
|
|
+ if (caseResult != null) submitCaseResults.Add(caseResult);
|
|
|
+ break;
|
|
|
+ case "SubmitVisitInfo"://服务工单回访评价
|
|
|
+ var visitInfo = System.Text.Json.JsonSerializer.Deserialize<DsSubmitVisitInfo>(item.Data);
|
|
|
+ if (visitInfo != null) submitVisitInfos.Add(visitInfo);
|
|
|
+ break;
|
|
|
+ case "GetCaseMaterialInfo"://附件
|
|
|
+ var materialInfo = System.Text.Json.JsonSerializer.Deserialize<DsGetCaseMaterialInfo>(item.Data);
|
|
|
+ if (materialInfo != null) getCaseMaterialInfos.Add(materialInfo);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //推送对应消息
|
|
|
+ //服务工单处理过程
|
|
|
+ if (submitCaseProcesses != null && submitCaseProcesses.Count > 0)
|
|
|
+ {
|
|
|
+ await _pusherProviderService.SubmitCaseProcessPusher(submitCaseProcesses, default);
|
|
|
+ // await _mediator.Publish(new SubmitCaseProcessNotification(submitCaseProcesses));
|
|
|
+ }
|
|
|
+
|
|
|
+ //服务工单处理结果
|
|
|
+ if (submitCaseResults != null && submitCaseResults.Count > 0)
|
|
|
+ {
|
|
|
+ await _pusherProviderService.SubmitCaseResultPusher(submitCaseResults, default);
|
|
|
+ // await _mediator.Publish(new SubmitCaseResultNotification(submitCaseResults));
|
|
|
+ }
|
|
|
+
|
|
|
+ //服务工单回访评价
|
|
|
+ if (submitVisitInfos != null && submitVisitInfos.Count > 0)
|
|
|
+ {
|
|
|
+ await _pusherProviderService.SubmitVisitInfoPusher(submitVisitInfos, default);
|
|
|
+ // await _mediator.Publish(new SubmitVisitInfoNotification(submitVisitInfos));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //附件上传处理
|
|
|
+ if (getCaseMaterialInfos != null && getCaseMaterialInfos.Count > 0)
|
|
|
+ {
|
|
|
+ await _pusherProviderService.GetCaseMaterialInfoPusher(getCaseMaterialInfos, default);
|
|
|
+ // await _mediator.Publish(new GetCaseMaterialInfoNotification(getCaseMaterialInfos));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ isContinue = false;
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 拉取12315工单办理信息
|
|
|
+ //查询是否存在需要拉取办理信息的工单
|
|
|
+ var listSendCaseInfo = await _sendCaseInfoRepository
|
|
|
+ .Queryable()
|
|
|
+ .OrderBy(p => p.CreationTime)
|
|
|
+ .ToListAsync();
|
|
|
+ //处理数据
|
|
|
+ if (listSendCaseInfo != null && listSendCaseInfo.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in listSendCaseInfo)
|
|
|
+ await _pusherProviderService.GetCaseDistrecordSendPusher(item.CaseSerial, default);// _mediator.Publish(new GetCaseDistrecordSendNotification(item.CaseSerial));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ isContinue = false;
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ //如果数据都为空,停止
|
|
|
+ if (!isContinue)
|
|
|
+ await Task.Delay(time, stoppingToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|