|
@@ -1,10 +1,12 @@
|
|
|
using Hotline.Caching.Interfaces;
|
|
|
+using Hotline.File;
|
|
|
using Hotline.FlowEngine.Workflows;
|
|
|
using Hotline.Orders;
|
|
|
using Hotline.Repository.SqlSugar.Extensions;
|
|
|
using Hotline.Repository.SqlSugar.Ts;
|
|
|
using Hotline.Settings.TimeLimits;
|
|
|
using Hotline.Share.Dtos;
|
|
|
+using Hotline.Share.Dtos.File;
|
|
|
using Hotline.Share.Dtos.FlowEngine;
|
|
|
using Hotline.Share.Dtos.FlowEngine.Workflow;
|
|
|
using Hotline.Share.Dtos.Order;
|
|
@@ -32,6 +34,7 @@ public class OrderApplication : IOrderApplication, IScopeDependency
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
private readonly IRepository<OrderWord> _orderWrodRepository;
|
|
|
private readonly IRepositoryTextSearch<OrderTs> _repositoryts;
|
|
|
+ private readonly IFileRepository _fileRepository;
|
|
|
|
|
|
public OrderApplication(
|
|
|
IOrderDomainService orderDomainService,
|
|
@@ -41,7 +44,8 @@ public class OrderApplication : IOrderApplication, IScopeDependency
|
|
|
ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
IMapper mapper,
|
|
|
IRepository<OrderWord> orderWrodRepository,
|
|
|
- IRepositoryTextSearch<OrderTs> repositoryts
|
|
|
+ IRepositoryTextSearch<OrderTs> repositoryts,
|
|
|
+ IFileRepository fileRepository
|
|
|
)
|
|
|
{
|
|
|
_orderDomainService = orderDomainService;
|
|
@@ -52,6 +56,7 @@ public class OrderApplication : IOrderApplication, IScopeDependency
|
|
|
_systemSettingCacheManager = systemSettingCacheManager;
|
|
|
_orderWrodRepository = orderWrodRepository;
|
|
|
_repositoryts = repositoryts;
|
|
|
+ _fileRepository = fileRepository;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -243,4 +248,98 @@ public class OrderApplication : IOrderApplication, IScopeDependency
|
|
|
else await _repositoryts.AddVectorAsync(orderId, DateTime.Now, tags, cancellationToken);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 接收外部平台工单
|
|
|
+ /// </summary>
|
|
|
+ public Task<AddOrderResponse> ReceiveOrderFromExternalAsync(AddOrderDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ switch (dto.Source)
|
|
|
+ {
|
|
|
+ case ESource.ProvinceStraight:
|
|
|
+ return ReceiveOrderFromProvinceAsync(dto, dto.Files, cancellationToken);
|
|
|
+ case ESource.Police110:
|
|
|
+ case ESource.CityDataExchangeLz:
|
|
|
+ case ESource.ConvergenceMedia:
|
|
|
+ case ESource.WebPortal:
|
|
|
+ return ReceiveOrderFromOtherPlatformAsync(dto, dto.Files, cancellationToken);
|
|
|
+ case ESource.Hotline:
|
|
|
+ case ESource.HotlineImport:
|
|
|
+ default:
|
|
|
+ throw new ArgumentOutOfRangeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #region private
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 接受外部工单(除省平台)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private async Task<AddOrderResponse> ReceiveOrderFromOtherPlatformAsync(AddOrderDto dto, List<FileDto> files, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(dto.ExternalId))
|
|
|
+ throw new UserFriendlyException("工单外部编号不能为空");
|
|
|
+
|
|
|
+ var order = await _orderRepository.Queryable()
|
|
|
+ .FirstAsync(d => d.ExternalId == dto.ExternalId, cancellationToken);
|
|
|
+ if (order == null)
|
|
|
+ {
|
|
|
+ order = _mapper.Map<Order>(dto);
|
|
|
+ order.InitId();
|
|
|
+ if (files != null && files.Any())
|
|
|
+ order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
|
|
|
+ await _orderDomainService.AddAsync(order, cancellationToken);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _mapper.Map(dto, order);
|
|
|
+ if (files != null && files.Any())
|
|
|
+ order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
|
|
|
+ await _orderRepository.FileAsync(order, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ return _mapper.Map<AddOrderResponse>(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 接受省平台工单
|
|
|
+ /// </summary>
|
|
|
+ private async Task<AddOrderResponse> ReceiveOrderFromProvinceAsync(AddOrderDto dto, List<FileDto> files, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(dto.ProvinceNo))
|
|
|
+ throw new UserFriendlyException("无效省工单编号");
|
|
|
+
|
|
|
+ var order = await _orderRepository.GetAsync(d => d.ProvinceNo == dto.ProvinceNo, cancellationToken);
|
|
|
+ if (order is null)
|
|
|
+ {
|
|
|
+ order = _mapper.Map<Order>(dto);
|
|
|
+ order.InitId();
|
|
|
+ if (files != null && files.Any())
|
|
|
+ order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
|
|
|
+ await _orderDomainService.AddAsync(order, cancellationToken);
|
|
|
+
|
|
|
+ var orderExtension = await _orderDomainService.GetOrderExtensionsAsync(dto.ProvinceNo, cancellationToken);
|
|
|
+ if (orderExtension is not null)
|
|
|
+ {
|
|
|
+ orderExtension.Id = order.Id;
|
|
|
+ await _orderDomainService.UpdateExtensionAsync(orderExtension, cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (files != null && files.Any())
|
|
|
+ order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, "", cancellationToken);
|
|
|
+ await _orderRepository.FileAsync(order, cancellationToken);
|
|
|
+ // 特提(撤回至发起)todo
|
|
|
+ //if (!string.IsNullOrEmpty(order.WorkflowId))
|
|
|
+ // await _workflowApplication.RecallToStartAsync(order.WorkflowId, "省工单重派", cancellationToken);
|
|
|
+ }
|
|
|
+ return _mapper.Map<AddOrderResponse>(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|