OrderScreenNextWorkflowHandler.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using DotNetCore.CAP;
  2. using Hotline.Configurations;
  3. using Hotline.FlowEngine.Notifications;
  4. using Hotline.FlowEngine.WorkflowModules;
  5. using Hotline.Orders;
  6. using Hotline.Share.Dtos.Order;
  7. using Hotline.Share.Enums.Order;
  8. using Hotline.Share.Mq;
  9. using MapsterMapper;
  10. using MediatR;
  11. using Microsoft.Extensions.Options;
  12. using XF.Domain.Authentications;
  13. using XF.Domain.Extensions;
  14. using XF.Domain.Repository;
  15. namespace Hotline.Application.Orders.Handles.OrderScreen;
  16. public class OrderScreenNextWorkflowHandler : INotificationHandler<NextStepNotify>
  17. {
  18. private readonly ICapPublisher _capPublisher;
  19. private readonly IMapper _mapper;
  20. private readonly IOrderScreenRepository _orderScreenRepository;
  21. private readonly ISessionContext _sessionContext;
  22. private readonly IRepository<OrderScreenDetail> _orderScreenDetailRepository;
  23. private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
  24. public OrderScreenNextWorkflowHandler(
  25. ICapPublisher capPublisher,
  26. IMapper mapper,
  27. IOrderScreenRepository orderScreenRepository,
  28. ISessionContext sessionContext,
  29. IOptionsSnapshot<AppConfiguration> appOptions,
  30. IRepository<OrderScreenDetail> orderScreenDetailRepository)
  31. {
  32. _capPublisher = capPublisher;
  33. _mapper = mapper;
  34. _orderScreenRepository = orderScreenRepository;
  35. _sessionContext = sessionContext;
  36. _orderScreenDetailRepository = orderScreenDetailRepository;
  37. _appOptions = appOptions;
  38. }
  39. /// <summary>Handles a notification</summary>
  40. /// <param name="notification">The notification</param>
  41. /// <param name="cancellationToken">Cancellation token</param>
  42. public async Task Handle(NextStepNotify notification, CancellationToken cancellationToken)
  43. {
  44. if (notification.Workflow.ModuleCode == WorkflowModuleConsts.OrderScreen)
  45. {
  46. var workflow = notification.Workflow;
  47. var nextTag = notification.NextStepDefine.Tag.TryDeserialize<DefinitionTag>();
  48. var screen = await _orderScreenRepository.Queryable().Includes(x => x.Order)
  49. .Where(x => x.Id == workflow.ExternalId).FirstAsync(cancellationToken);
  50. if (screen != null)
  51. {
  52. screen.Status = EScreenStatus.Approval;
  53. screen.Flowed(workflow.FlowedUserIds, workflow.FlowedOrgIds, workflow.HandlerUsers, workflow.HandlerOrgs);
  54. //如果下个节点是省审批,则修改为省甄别
  55. if (nextTag is not null && nextTag.Type == TagDefaults.TagType.Org && nextTag.Value == TagDefaults.TagValue.Province)
  56. screen.IsProScreen = true;
  57. await _orderScreenRepository.UpdateAsync(screen, cancellationToken);
  58. }
  59. if (nextTag is not null && nextTag.Type == TagDefaults.TagType.Org)
  60. {
  61. switch (nextTag.Value)
  62. {
  63. case TagDefaults.TagValue.Province:
  64. if (screen != null)
  65. {
  66. var screenDto = _mapper.Map<OrderScreenListDto>(screen);
  67. if (screen.Order != null && screen.Order.Source == ESource.ProvinceStraight)
  68. {
  69. var screenOrderDto = _mapper.Map<OrderDto>(screen.Order);
  70. //省件甄别--以省审批前一个节点整理的甄别意见为准推送省上 宜宾
  71. if (_appOptions.Value.IsYiBin)
  72. {
  73. screenDto.Content = notification.Dto.Opinion;
  74. screenDto.Files = new List<Share.Dtos.File.FileDto>();
  75. }
  76. //推省上
  77. _capPublisher.Publish(EventNames.HotlineOrderScreenApply, new PublishScreenDto()
  78. {
  79. Order = screenOrderDto,
  80. Screen = screenDto,
  81. ClientGuid = ""
  82. });
  83. }
  84. }
  85. break;
  86. }
  87. }
  88. OrderScreenDetail detail = new OrderScreenDetail
  89. {
  90. ScreenId = screen.Id
  91. };
  92. detail.Audit(_sessionContext.UserId, _sessionContext.UserName, _sessionContext.OrgId, _sessionContext.OrgName, 1);
  93. await _orderScreenDetailRepository.AddAsync(detail, cancellationToken);
  94. }
  95. }
  96. }