qinchaoyue 6 months ago
parent
commit
2227883440

+ 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;
@@ -323,15 +325,42 @@ namespace Hotline.Api.Controllers
 
         }
 
-
         /// <summary>
         /// 批量审核
         /// </summary>
         /// <returns></returns>
         [HttpPost("batch_audit")]
-        public async Task KnowledgeBatchAuditAsync()
+        public async Task<string> KnowledgeBatchAuditAsync([FromBody] KnowledgeBatchAuditInDto dto)
         {
-            // TODO: qcy 批量审核 
+            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>
@@ -679,6 +708,7 @@ namespace Hotline.Api.Controllers
                 .ToPagedListAsync(pagedDto.PageIndex, pagedDto.PageSize);
             return new PagedDto<KnowledgeWorkFlowDto>(total, _mapper.Map<IReadOnlyList<KnowledgeWorkFlowDto>>(temp));
         }
+
         /// <summary>
         /// 知识查重
         /// </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

@@ -525,4 +525,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; }
+    }
 }