Parcourir la source

新增批量审核接口

qinchaoyue il y a 5 mois
Parent
commit
129f77d62e

+ 33 - 3
src/Hotline.Api/Controllers/KnowledgeController.cs

@@ -10,6 +10,7 @@ using Hotline.Application.Systems;
 using Hotline.Application.Tools;
 using Hotline.File;
 using Hotline.FlowEngine.WorkflowModules;
+using Hotline.FlowEngine.Workflows;
 using Hotline.KnowledgeBase;
 using Hotline.KnowledgeBase.Notifies;
 using Hotline.Permissions;
@@ -36,6 +37,7 @@ using Microsoft.AspNetCore.Mvc;
 using Microsoft.EntityFrameworkCore.Metadata.Internal;
 using Org.BouncyCastle.Utilities.IO;
 using SqlSugar;
+using System.Text;
 using System.Threading;
 using XF.Domain.Authentications;
 using XF.Domain.Exceptions;
@@ -328,9 +330,37 @@ namespace Hotline.Api.Controllers
         /// </summary>
         /// <returns></returns>
         [HttpPost("batch_audit")]
-        public async Task KnowledgeBatchAuditAsync()
-        { 
-            // TODO: qcy 批量审核 
+        public async Task<string> KnowledgeBatchAuditAsync([FromBody] KnowledgeBatchAuditInDto dto)
+        {
+            var result = new StringBuilder();
+            var fail = 0;
+            var success = 0;
+            foreach (var knowledgeId in dto.KnowledgeIds)
+            {
+                try
+                {
+                    var knowledge = await _knowledgeDomainService.KnowledgeInfo(knowledgeId, HttpContext.RequestAborted);
+                    dto.NextWorkflowDto.WorkflowId = knowledge.WorkflowId;
+                    var next = await _workflowApplication.GetNextStepsAsync(knowledge.WorkflowId, HttpContext.RequestAborted);
+                    dto.NextWorkflowDto.StepId = next.StepId;
+                    dto.NextWorkflowDto.NextStepCode = next.Steps.First().Key;
+                    dto.NextWorkflowDto.NextStepName = next.Steps.First().Value;
+                    if (dto.IsPass)
+                        await _workflowApplication.NextAsync(dto.NextWorkflowDto, cancellationToken: HttpContext.RequestAborted);
+                    else
+                    {
+                        var reject = dto.NextWorkflowDto.Adapt<RejectDto>();
+                        await _workflowApplication.RejectAsync(reject, HttpContext.RequestAborted);
+                    }
+                }
+                catch (UserFriendlyException e)
+                {
+                    result.Append(e.Message);
+                    fail++;
+                }
+                success++;
+            }
+            return $"总共: {dto.KnowledgeIds.Length}, 成功: {success}, 失败: {fail}, 失败原因: {result.ToString()}";
         }
 
         /// <summary>

+ 10 - 0
src/Hotline.Application.Tests/Controller/KnowledgeControllerTest.cs

@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Application.Tests.Controller;
+public class KnowledgeControllerTest
+{
+}

+ 18 - 0
src/Hotline.Share/Dtos/Knowledge/KnowledgeDto.cs

@@ -523,4 +523,22 @@ namespace Hotline.Share.Dtos.Knowledge
         /// </summary>
         public string TypeTxt => Type?.GetDescription();
     }
+
+    public class KnowledgeBatchAuditInDto
+    {
+        /// <summary>
+        /// 流程信息
+        /// </summary>
+        public NextWorkflowDto NextWorkflowDto { get; set; }
+
+        /// <summary>
+        /// 知识Id集合
+        /// </summary>
+        public string[] KnowledgeIds { get; set; }
+
+        /// <summary>
+        /// 是否通过
+        /// </summary>
+        public bool IsPass { get; set; }
+    }
 }