|
@@ -5,7 +5,9 @@ using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using Hotline.Application.FlowEngine;
|
|
using Hotline.Application.FlowEngine;
|
|
using Hotline.DataSharing.Province.Notifications;
|
|
using Hotline.DataSharing.Province.Notifications;
|
|
|
|
+using Hotline.File;
|
|
using Hotline.Orders;
|
|
using Hotline.Orders;
|
|
|
|
+using Hotline.Share.Dtos.File;
|
|
using Hotline.Share.Dtos.Order;
|
|
using Hotline.Share.Dtos.Order;
|
|
using Hotline.Share.Enums.Order;
|
|
using Hotline.Share.Enums.Order;
|
|
using MapsterMapper;
|
|
using MapsterMapper;
|
|
@@ -21,18 +23,21 @@ namespace Hotline.Application.Handlers.Order
|
|
private readonly IOrderDomainService _orderDomainService;
|
|
private readonly IOrderDomainService _orderDomainService;
|
|
private readonly IWorkflowApplication _workflowApplication;
|
|
private readonly IWorkflowApplication _workflowApplication;
|
|
private readonly IMapper _mapper;
|
|
private readonly IMapper _mapper;
|
|
|
|
+ private readonly IFileRepository _fileRepository;
|
|
|
|
|
|
- public ReceiveOrderNotifyHandler(
|
|
|
|
|
|
+ public ReceiveOrderNotifyHandler(
|
|
IOrderRepository orderRepository,
|
|
IOrderRepository orderRepository,
|
|
IOrderDomainService orderDomainService,
|
|
IOrderDomainService orderDomainService,
|
|
IWorkflowApplication workflowApplication,
|
|
IWorkflowApplication workflowApplication,
|
|
- IMapper mapper)
|
|
|
|
|
|
+ IMapper mapper,
|
|
|
|
+ IFileRepository fileRepository)
|
|
{
|
|
{
|
|
_orderRepository = orderRepository;
|
|
_orderRepository = orderRepository;
|
|
_orderDomainService = orderDomainService;
|
|
_orderDomainService = orderDomainService;
|
|
_workflowApplication = workflowApplication;
|
|
_workflowApplication = workflowApplication;
|
|
_mapper = mapper;
|
|
_mapper = mapper;
|
|
- }
|
|
|
|
|
|
+ _fileRepository = fileRepository;
|
|
|
|
+ }
|
|
|
|
|
|
/// <summary>Handles a request</summary>
|
|
/// <summary>Handles a request</summary>
|
|
/// <param name="request">The request</param>
|
|
/// <param name="request">The request</param>
|
|
@@ -41,14 +46,15 @@ namespace Hotline.Application.Handlers.Order
|
|
public Task<AddOrderResponse?> Handle(ReceiveOrderNotify request, CancellationToken cancellationToken)
|
|
public Task<AddOrderResponse?> Handle(ReceiveOrderNotify request, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
var dto = request.AddOrderDto;
|
|
var dto = request.AddOrderDto;
|
|
|
|
+ var files = request.Files;
|
|
switch (dto.Source)
|
|
switch (dto.Source)
|
|
{
|
|
{
|
|
case ESource.ProvinceStraight:
|
|
case ESource.ProvinceStraight:
|
|
- return ReceiveOrderFromProvinceAsync(dto, cancellationToken);
|
|
|
|
|
|
+ return ReceiveOrderFromProvinceAsync(dto, files, cancellationToken);
|
|
case ESource.Police110:
|
|
case ESource.Police110:
|
|
case ESource.CityDataExchangeLz:
|
|
case ESource.CityDataExchangeLz:
|
|
case ESource.ConvergenceMedia:
|
|
case ESource.ConvergenceMedia:
|
|
- return ReceiveOrderFromOtherPlatformAsync(dto, cancellationToken);
|
|
|
|
|
|
+ return ReceiveOrderFromOtherPlatformAsync(dto, files, cancellationToken);
|
|
case ESource.Hotline:
|
|
case ESource.Hotline:
|
|
case ESource.HotlineImport:
|
|
case ESource.HotlineImport:
|
|
default:
|
|
default:
|
|
@@ -62,28 +68,39 @@ namespace Hotline.Application.Handlers.Order
|
|
/// <param name="dto"></param>
|
|
/// <param name="dto"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- private async Task<AddOrderResponse?> ReceiveOrderFromOtherPlatformAsync(AddOrderDto dto,
|
|
|
|
- CancellationToken cancellationToken)
|
|
|
|
|
|
+ private async Task<AddOrderResponse?> ReceiveOrderFromOtherPlatformAsync(AddOrderDto dto, List<FileDto> files,
|
|
|
|
+
|
|
|
|
+ CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
if (string.IsNullOrEmpty(dto.ExternalId))
|
|
if (string.IsNullOrEmpty(dto.ExternalId))
|
|
throw new UserFriendlyException("工单外部编号不能为空");
|
|
throw new UserFriendlyException("工单外部编号不能为空");
|
|
|
|
|
|
- var exists = await _orderRepository.AnyAsync(d => d.ExternalId == dto.ExternalId, cancellationToken);
|
|
|
|
- if (exists) return null;
|
|
|
|
- var order = _mapper.Map<Hotline.Orders.Order>(dto);
|
|
|
|
- var orderId = await _orderDomainService.AddAsync(order, cancellationToken);
|
|
|
|
- return new AddOrderResponse
|
|
|
|
|
|
+ var exists = await _orderRepository.Queryable().Where(d => d.ExternalId == dto.ExternalId).FirstAsync(cancellationToken);
|
|
|
|
+ if (exists != null)
|
|
|
|
+ {
|
|
|
|
+ if (files != null && files.Any()) exists.FileJson = await _fileRepository.AddFileAsync(files, exists.Id, cancellationToken);
|
|
|
|
+ await _orderRepository.FileAsync(exists, cancellationToken);
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- Id = orderId,
|
|
|
|
- No = order.No,
|
|
|
|
- Password = order.Password!
|
|
|
|
- };
|
|
|
|
|
|
+ var order = _mapper.Map<Hotline.Orders.Order>(dto);
|
|
|
|
+ order.InitId();
|
|
|
|
+ if (files != null && files.Any()) order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, cancellationToken);
|
|
|
|
+ var orderId = await _orderDomainService.AddAsync(order, cancellationToken);
|
|
|
|
+ return new AddOrderResponse
|
|
|
|
+ {
|
|
|
|
+ Id = orderId,
|
|
|
|
+ No = order.No,
|
|
|
|
+ Password = order.Password!
|
|
|
|
+ };
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 接受省平台工单
|
|
/// 接受省平台工单
|
|
/// </summary>
|
|
/// </summary>
|
|
- private async Task<AddOrderResponse?> ReceiveOrderFromProvinceAsync(AddOrderDto dto, CancellationToken cancellationToken)
|
|
|
|
|
|
+ private async Task<AddOrderResponse?> ReceiveOrderFromProvinceAsync(AddOrderDto dto, List<FileDto> files, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
if (string.IsNullOrEmpty(dto.ProvinceNo))
|
|
if (string.IsNullOrEmpty(dto.ProvinceNo))
|
|
throw new UserFriendlyException("无效省工单编号");
|
|
throw new UserFriendlyException("无效省工单编号");
|
|
@@ -92,29 +109,32 @@ namespace Hotline.Application.Handlers.Order
|
|
if (order is null)
|
|
if (order is null)
|
|
{
|
|
{
|
|
order = _mapper.Map<Hotline.Orders.Order>(dto);
|
|
order = _mapper.Map<Hotline.Orders.Order>(dto);
|
|
- var orderId = await _orderDomainService.AddAsync(order, cancellationToken);
|
|
|
|
|
|
+ order.InitId();
|
|
|
|
+ if (files != null && files.Any()) order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, cancellationToken);
|
|
|
|
+ await _orderDomainService.AddAsync(order, cancellationToken);
|
|
|
|
|
|
if (order.Source is ESource.ProvinceStraight)
|
|
if (order.Source is ESource.ProvinceStraight)
|
|
{
|
|
{
|
|
var orderExtension = await _orderDomainService.GetOrderExtensionsAsync(dto.ProvinceNo, cancellationToken);
|
|
var orderExtension = await _orderDomainService.GetOrderExtensionsAsync(dto.ProvinceNo, cancellationToken);
|
|
if (orderExtension is not null)
|
|
if (orderExtension is not null)
|
|
{
|
|
{
|
|
- orderExtension.Id = orderId;
|
|
|
|
|
|
+ orderExtension.Id = order.Id;
|
|
await _orderDomainService.UpdateExtensionAsync(orderExtension, cancellationToken);
|
|
await _orderDomainService.UpdateExtensionAsync(orderExtension, cancellationToken);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- return new AddOrderResponse
|
|
|
|
|
|
+ return new AddOrderResponse
|
|
{
|
|
{
|
|
- Id = orderId,
|
|
|
|
|
|
+ Id = order.Id,
|
|
No = order.No,
|
|
No = order.No,
|
|
Password = order.Password!
|
|
Password = order.Password!
|
|
};
|
|
};
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- // 特提(撤回至发起)
|
|
|
|
- if (!string.IsNullOrEmpty(order.WorkflowId))
|
|
|
|
|
|
+ if (files != null && files.Any()) order.FileJson = await _fileRepository.AddFileAsync(files, order.Id, cancellationToken);
|
|
|
|
+ await _orderRepository.FileAsync(order, cancellationToken);
|
|
|
|
+ // 特提(撤回至发起)
|
|
|
|
+ if (!string.IsNullOrEmpty(order.WorkflowId))
|
|
await _workflowApplication.RecallToStartAsync(order.WorkflowId, "省工单重派", cancellationToken);
|
|
await _workflowApplication.RecallToStartAsync(order.WorkflowId, "省工单重派", cancellationToken);
|
|
return _mapper.Map<AddOrderResponse>(order);
|
|
return _mapper.Map<AddOrderResponse>(order);
|
|
}
|
|
}
|