xf vor 2 Jahren
Ursprung
Commit
9d09eaa694

+ 9 - 1
src/Hotline.Api/Controllers/OrderController.cs

@@ -2,6 +2,7 @@
 using Hotline.FlowEngine.Definitions;
 using Hotline.FlowEngine.Workflows;
 using Hotline.Orders;
+using Hotline.Orders.Notifications;
 using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Settings;
 using Hotline.Settings.Hotspots;
@@ -11,6 +12,7 @@ using Hotline.Share.Dtos.Order;
 using Hotline.Share.Enums.Order;
 using Hotline.Share.Requests;
 using MapsterMapper;
+using MediatR;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using XF.Domain.Authentications;
@@ -35,6 +37,7 @@ public class OrderController : BaseController
     private readonly IDefinitionDomainService _definitionDomainService;
     private readonly ISessionContext _sessionContext;
     private readonly IMapper _mapper;
+    private readonly IMediator _mediator;
 
     public OrderController(
         IOrderDomainService orderDomainService,
@@ -46,7 +49,8 @@ public class OrderController : BaseController
         ISystemOrganizeRepository organizeRepository,
         IDefinitionDomainService definitionDomainService,
         ISessionContext sessionContext,
-        IMapper mapper)
+        IMapper mapper,
+        IMediator mediator)
     {
         _orderDomainService = orderDomainService;
         _orderRepository = orderRepository;
@@ -58,6 +62,7 @@ public class OrderController : BaseController
         _definitionDomainService = definitionDomainService;
         _sessionContext = sessionContext;
         _mapper = mapper;
+        _mediator = mediator;
     }
 
     /// <summary>
@@ -122,6 +127,9 @@ public class OrderController : BaseController
         if (!string.IsNullOrEmpty(order?.WorkflowId))
             order.Workflow = await _workflowDomainService.GetWorkflowAsync(order.WorkflowId, withSupplements: true, cancellationToken: HttpContext.RequestAborted);
 
+        _mediator.Publish(new GetOrderDetailNotify(order.Workflow, _sessionContext.RequiredUserId,
+            _sessionContext.UserName, _sessionContext.RequiredOrgCode, _sessionContext.OrgName));
+
         return _mapper.Map<OrderDto>(order);
     }
 

+ 0 - 1
src/Hotline.Api/Controllers/TestController.cs

@@ -3,7 +3,6 @@ using Hotline.CallCenter.BlackLists;
 using Hotline.CallCenter.Devices;
 using Hotline.CallCenter.Ivrs;
 using Hotline.FlowEngine.Definitions;
-using Hotline.FlowEngine.Notifies;
 using Hotline.FlowEngine.Workflows;
 using Hotline.Identity.Accounts;
 using Hotline.Identity.Roles;

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/EndWorkflowHandler.cs

@@ -1,4 +1,4 @@
-using Hotline.FlowEngine.Notifies;
+using Hotline.FlowEngine.Notifications;
 using Hotline.Settings;
 using Hotline.Share.Enums.Order;
 using MediatR;

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/NextStepHandler.cs

@@ -1,5 +1,5 @@
 using Hotline.Application.FlowEngine;
-using Hotline.FlowEngine.Notifies;
+using Hotline.FlowEngine.Notifications;
 using Hotline.FlowEngine.Workflows;
 using Hotline.Orders;
 using Hotline.Settings;

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/PreviousStepHandler.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using Hotline.FlowEngine.Notifies;
+using Hotline.FlowEngine.Notifications;
 using MediatR;
 
 namespace Hotline.Application.Handlers.FlowEngine

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/StartWorkflowHandler.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using Hotline.Application.FlowEngine;
-using Hotline.FlowEngine.Notifies;
+using Hotline.FlowEngine.Notifications;
 using Hotline.Orders;
 using Hotline.Settings;
 using Hotline.Share.Enums.Order;

+ 1 - 1
src/Hotline.Application/Handlers/FlowEngine/TerminalWorkflowHandler.cs

@@ -1,4 +1,4 @@
-using Hotline.FlowEngine.Notifies;
+using Hotline.FlowEngine.Notifications;
 using MediatR;
 
 namespace Hotline.Application.Handlers.FlowEngine;

+ 30 - 0
src/Hotline.Application/Handlers/Order/GetOrderDetailHandler.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Hotline.FlowEngine.Workflows;
+using Hotline.Orders.Notifications;
+using MediatR;
+
+namespace Hotline.Application.Handlers.Order
+{
+    public class GetOrderDetailHandler : INotificationHandler<GetOrderDetailNotify>
+    {
+        private readonly IWorkflowDomainService _workflowDomainService;
+
+        public GetOrderDetailHandler(IWorkflowDomainService workflowDomainService)
+        {
+            _workflowDomainService = workflowDomainService;
+        }
+
+        /// <summary>Handles a notification</summary>
+        /// <param name="notification">The notification</param>
+        /// <param name="cancellationToken">Cancellation token</param>
+        public async Task Handle(GetOrderDetailNotify notification, CancellationToken cancellationToken)
+        {
+            await _workflowDomainService.AcceptAsync(notification.Workflow, notification.UserId, notification.UserName,
+                notification.OrgCode, notification.OrgName, cancellationToken);
+        }
+    }
+}

+ 5 - 3
src/Hotline.Application/Mappers/MapperConfigs.cs

@@ -61,9 +61,11 @@ namespace Hotline.Application.Mappers
                 .IgnoreIf((s, d) => s.OrderReport == null, d => d.OrderReport)
                 .IgnoreIf((s, d) => s.Workflow == null, d => d.Workflow)
                 .IgnoreIf((s, d) => s.Employee == null, d => d.EmployeeName, d => d.EmployeeStaffNo)
-                .Map(d => d.EmployeeName, x => x.Employee.Name)
-                .Map(d => d.EmployeeStaffNo, x => x.Employee.StaffNo)
-                .IgnoreNullValues(true);
+                .Ignore(d => d.Workflow.Definition)
+                .Ignore(d => d.Workflow.StepBoxes)
+                .Ignore(d => d.Workflow.Traces)
+                .Ignore(d => d.Workflow.Supplements)
+                ;
 
             config.ForType<AddOrderDto, Order>()
                 .IgnoreIf((s, d) => s.OrderComplain == null, d => d.OrderComplain)

+ 1 - 2
src/Hotline/FlowEngine/Notifies/WorkflowNotify.cs → src/Hotline/FlowEngine/Notifications/WorkflowNotify.cs

@@ -2,9 +2,8 @@
 using Hotline.FlowEngine.Workflows;
 using Hotline.Share.Dtos.FlowEngine;
 using MediatR;
-using XF.Domain.Entities;
 
-namespace Hotline.FlowEngine.Notifies;
+namespace Hotline.FlowEngine.Notifications;
 
 public record WorkflowNotify(Workflow Workflow, StepDefine StepDefine, BasicWorkflowDto Dto) : INotification;
 

+ 1 - 1
src/Hotline/FlowEngine/Workflows/IWorkflowDomainService.cs

@@ -22,7 +22,7 @@ namespace Hotline.FlowEngine.Workflows
         /// <summary>
         /// 受理,接办
         /// </summary>
-        Task AcceptAsync(Workflow workflow, CancellationToken cancellationToken);
+        Task AcceptAsync(Workflow workflow, string userId, string userName, string orgCode, string orgName, CancellationToken cancellationToken);
 
         /// <summary>
         /// 办理(流转至下一节点)

+ 14 - 9
src/Hotline/FlowEngine/Workflows/WorkflowDomainService.cs

@@ -1,5 +1,5 @@
 using Hotline.FlowEngine.Definitions;
-using Hotline.FlowEngine.Notifies;
+using Hotline.FlowEngine.Notifications;
 using Hotline.SeedData;
 using Hotline.Share.Dtos.FlowEngine;
 using Hotline.Share.Enums.FlowEngine;
@@ -144,30 +144,30 @@ namespace Hotline.FlowEngine.Workflows
         /// <summary>
         /// 受理(接办)
         /// </summary>
-        public async Task AcceptAsync(Workflow workflow, CancellationToken cancellationToken)
+        public async Task AcceptAsync(Workflow workflow, string userId, string userName, string orgCode, string orgName, CancellationToken cancellationToken)
         {
             //工单完成以后查看的场景
             if (workflow.Status is not EWorkflowStatus.Runnable) return;
 
-            var (currentStepBox, currentStep) = GetUnCompleteStepOrDefault(workflow.StepBoxes, _sessionContext.RequiredOrgCode, _sessionContext.RequiredUserId);
+            var (currentStepBox, currentStep) = GetUnCompleteStepOrDefault(workflow.StepBoxes, orgCode, userId);
             if (currentStep is null) return;
             if (currentStep.Status is EWorkflowStepStatus.Accepted) return;
             if (currentStep.HandlerType is EHandlerType.AssignUser or EHandlerType.Role)
             {
                 //userId
-                if (currentStep.HandlerId != _sessionContext.RequiredUserId) return;
+                if (currentStep.HandlerId != userId) return;
             }
             else
             {
                 //orgId
-                if (currentStep.HandlerId != _sessionContext.RequiredOrgCode) return;
+                if (currentStep.HandlerId != orgCode) return;
             }
             if (currentStep.StepType is EStepType.End)
                 throw new UserFriendlyException("当前流程已流转到最终步骤");
 
             if (currentStepBox.Status is EWorkflowStepStatus.Assigned)
                 currentStepBox.Status = EWorkflowStepStatus.Accepted;
-            currentStep.Accept(_sessionContext.RequiredUserId, _sessionContext.UserName);
+            currentStep.Accept(userId, userName);
 
             //接办时非会签并且有多个接办部门时需更新接办部门
             if (!workflow.IsInCountersign())
@@ -177,7 +177,7 @@ namespace Hotline.FlowEngine.Workflows
                 {
                     await _workflowAssignRepository.RemoveRangeAsync(assigns, cancellationToken);
 
-                    var assign = WorkflowAssign.Create(workflow.Id, _sessionContext.OrgCode, _sessionContext.OrgName);
+                    var assign = WorkflowAssign.Create(workflow.Id, orgCode, orgName);
                     await _workflowAssignRepository.AddAsync(assign, cancellationToken);
                 }
             }
@@ -198,7 +198,12 @@ namespace Hotline.FlowEngine.Workflows
 
             var (currentStepBox, currentStep) = GetUnCompleteStep(workflow.StepBoxes, _sessionContext.RequiredOrgCode, _sessionContext.RequiredUserId);
             if (currentStep.Status is EWorkflowStepStatus.Assigned)
-                await AcceptAsync(workflow, cancellationToken);
+                await AcceptAsync(workflow,
+                    _sessionContext.RequiredUserId,
+                    _sessionContext.UserName,
+                    _sessionContext.RequiredOrgCode,
+                    _sessionContext.OrgName,
+                    cancellationToken);
             if (currentStep.StepType is EStepType.End)
                 throw new UserFriendlyException("当前流程已流转到最终步骤");
 
@@ -644,7 +649,7 @@ namespace Hotline.FlowEngine.Workflows
                 await _workflowStepRepository.AddAsync(stepBox, cancellationToken);
             }
 
-            if (stepBoxDefine.StepType is EStepType.CountersignEnd)
+            if (stepBoxDefine.StepType is EStepType.CountersignEnd && workflow.IsInCountersign())
             {
                 if (prevStep is null)
                     throw new UserFriendlyException($"汇总节点的上级节点不能为空节点,workflowId: {workflow.Id}", "创建汇总节点异常");

+ 31 - 0
src/Hotline/Orders/Notifications/GetOrderDetailNotify.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Hotline.FlowEngine.Workflows;
+using MediatR;
+
+namespace Hotline.Orders.Notifications
+{
+    /// <summary>
+    /// 查询工单详情
+    /// </summary>
+    public class GetOrderDetailNotify : INotification
+    {
+        public GetOrderDetailNotify(Workflow workflow, string userId, string userName, string orgCode, string orgName)
+        {
+            Workflow = workflow;
+            UserId = userId;
+            UserName = userName;
+            OrgCode = orgCode;
+            OrgName = orgName;
+        }
+
+        public string UserId { get; set; }
+        public string UserName { get; set; }
+        public string OrgCode { get; set; }
+        public string OrgName { get; set; }
+        public Workflow Workflow { get; set; }
+    }
+}