Browse Source

新增撤销件只有在部门才发撤销短信

tangjiang 6 months ago
parent
commit
32b3e9ef38
1 changed files with 31 additions and 20 deletions
  1. 31 20
      src/Hotline.Api/Controllers/OrderRevocationController.cs

+ 31 - 20
src/Hotline.Api/Controllers/OrderRevocationController.cs

@@ -1,12 +1,14 @@
 using Hotline.Application.FlowEngine;
 using Hotline.Caching.Interfaces;
 using Hotline.FlowEngine.WorkflowModules;
+using Hotline.FlowEngine.Workflows;
 using Hotline.Orders;
 using Hotline.Push.Notifies;
 using Hotline.SeedData;
 using Hotline.Settings;
 using Hotline.Share.Dtos.FlowEngine;
 using Hotline.Share.Dtos.Order;
+using Hotline.Share.Enums.FlowEngine;
 using Hotline.Share.Enums.Order;
 using Hotline.Share.Enums.Push;
 using Hotline.Users;
@@ -31,6 +33,7 @@ namespace Hotline.Api.Controllers
         private readonly IRepository<SystemOrganize> _systemOrganizeRepository;
         private readonly IRepository<User> _userRepository;
         private readonly IMediator _mediator;
+        private readonly IWorkflowDomainService _workflowDomainService;
 
 
         public OrderRevocationController(IMapper mapper,
@@ -41,7 +44,8 @@ namespace Hotline.Api.Controllers
             ISystemSettingCacheManager systemSettingCacheManager,
             IRepository<SystemOrganize> systemOrganizeRepository,
             IRepository<User> userRepository,
-             IMediator mediator)
+            IMediator mediator,
+            IWorkflowDomainService workflowDomainService)
         {
             _mapper = mapper;
             _orderRevocationRepository = orderRevocationRepository;
@@ -52,6 +56,7 @@ namespace Hotline.Api.Controllers
             _systemOrganizeRepository = systemOrganizeRepository;
             _userRepository = userRepository;
             _mediator = mediator;
+            _workflowDomainService = workflowDomainService;
         }
 
         /// <summary>
@@ -140,27 +145,33 @@ namespace Hotline.Api.Controllers
 
                             #region 处理短信业务
                             //如果需要发短信、处理短信业务
-                            if (dto.IsSendSms)
-                            {
-                                //处理短信业务
-                                var acceptSmsRoleIds = _systemSettingCacheManager.GetSetting(SettingConstants.AcceptSmsRoleIds)?.SettingValue;
-                                //查询部门所有账号
-                                var userlist = await _userRepository.Queryable().Where(x =>
-                                    x.OrgId == order.CurrentHandleOrgId && !string.IsNullOrEmpty(x.PhoneNo) &&
-                                    x.Roles.Any(d => acceptSmsRoleIds.Contains(d.Id))).ToListAsync();
-                                //发送短信
-                                foreach (var user in userlist)
+                            if (dto.IsSendSms && !string.IsNullOrEmpty(order.WorkflowId))
+                            {  //查询当前工单的实际办理节点,如果在热线中心不处理,如果在部门需要更新期满时间
+                                var workflow = await _workflowDomainService.GetWorkflowAsync(order.WorkflowId, withSteps: true, withTraces: true, cancellationToken: HttpContext.RequestAborted);
+                                var nowWorkflow = workflow.Steps.Where(p => p.Id == order.ActualHandleStepId && p.BusinessType >= EBusinessType.Department && p.BusinessType <= EBusinessType.DepartmentLeader).FirstOrDefault();
+                                //在部门才需要发送短信
+                                if (nowWorkflow != null && order.CenterToOrgTime.HasValue)
                                 {
-                                    var messageDto = new Share.Dtos.Push.MessageDto
+                                    //处理短信业务
+                                    var acceptSmsRoleIds = _systemSettingCacheManager.GetSetting(SettingConstants.AcceptSmsRoleIds)?.SettingValue;
+                                    //查询部门所有账号
+                                    var userlist = await _userRepository.Queryable().Where(x =>
+                                        x.OrgId == order.CurrentHandleOrgId && !string.IsNullOrEmpty(x.PhoneNo) &&
+                                        x.Roles.Any(d => acceptSmsRoleIds.Contains(d.Id))).ToListAsync();
+                                    //发送短信
+                                    foreach (var user in userlist)
                                     {
-                                        PushBusiness = EPushBusiness.OrderRevocationSms,
-                                        PushPlatform = EPushPlatform.Sms,
-                                        Name = user.Name,
-                                        TemplateCode = "1016",
-                                        Params = new List<string>() { order.No },
-                                        TelNumber = user.PhoneNo,
-                                    };
-                                    await _mediator.Publish(new PushMessageNotify(messageDto), HttpContext.RequestAborted);
+                                        var messageDto = new Share.Dtos.Push.MessageDto
+                                        {
+                                            PushBusiness = EPushBusiness.OrderRevocationSms,
+                                            PushPlatform = EPushPlatform.Sms,
+                                            Name = user.Name,
+                                            TemplateCode = "1016",
+                                            Params = new List<string>() { order.No },
+                                            TelNumber = user.PhoneNo,
+                                        };
+                                        await _mediator.Publish(new PushMessageNotify(messageDto), HttpContext.RequestAborted);
+                                    }
                                 }
 
                             }