OrderScreenNextWorkflowHandler.cs 3.7 KB

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