Jason 1 年之前
父节点
当前提交
5501b6457f

+ 25 - 6
src/Hotline.Api/Controllers/ArticleController.cs

@@ -1,13 +1,18 @@
-using Hotline.Article;
+using Hotline.Application.FlowEngine;
+using Hotline.Article;
+using Hotline.FlowEngine.WfModules;
 using Hotline.Permissions;
 using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Settings;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Article;
+using Hotline.Share.Dtos.FlowEngine;
+using Hotline.Share.Dtos.Order;
 using Hotline.Share.Enums.Article;
 using MapsterMapper;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.OpenApi.Writers;
+using XF.Domain.Exceptions;
 using XF.Domain.Repository;
 using XF.Utility.EnumExtensions;
 
@@ -20,14 +25,15 @@ namespace Hotline.Api.Controllers
         private readonly IMapper _mapper;
         private readonly ISystemDomainService _systemDomainService;
         private readonly ISystemOrganizeRepository _organizeRepository;
+        private readonly IWorkflowApplication _workflowApplication;
 
-        public ArticleController(IRepository<Bulletin> bulletinRepository,IMapper mapper, ISystemDomainService systemDomainService, ISystemOrganizeRepository organizeRepository)
+        public ArticleController(IRepository<Bulletin> bulletinRepository,IMapper mapper, ISystemDomainService systemDomainService, ISystemOrganizeRepository organizeRepository, IWorkflowApplication workflowApplication)
         {
             _bulletinRepository = bulletinRepository;
             _mapper = mapper;
             _systemDomainService = systemDomainService;
             _organizeRepository = organizeRepository;
-
+            _workflowApplication = workflowApplication;
         }
 
         #region 公告
@@ -73,12 +79,25 @@ namespace Hotline.Api.Controllers
         /// <returns></returns>
         [Permission(EPermission.AddBulletin)]
         [HttpPost("bulletin/add")]
-        public async Task AddBulletin([FromBody]AddBulletinDto dto)
+        public async Task AddBulletin([FromBody]BulletinFlowDto dto)
         {
-            var model = _mapper.Map<Bulletin>(dto);
+
+            var model = _mapper.Map<Bulletin>(dto.Data);
             model.BulletinState = Share.Enums.Article.EBulletinState.InReview;
             model.ReadedNum = 0;
-            await _bulletinRepository.AddAsync(model, HttpContext.RequestAborted);
+            var id = await _bulletinRepository.AddAsync(model, HttpContext.RequestAborted);
+            try
+            {
+                var startDto = _mapper.Map<StartWorkflowDto>(dto.Workflow);
+                startDto.DefinitionModuleCode = WorkflowModuleConsts.BulletinApply;
+                startDto.Title = model.Title;
+                await _workflowApplication.StartWorkflowAsync(startDto, id, HttpContext.RequestAborted);
+            }
+            catch (Exception ex)
+            {
+                await _bulletinRepository.RemoveAsync(id, false, HttpContext.RequestAborted);
+                throw new UserFriendlyException($"新增公告流程失败!,{ex.Message}", "新增公告流程失败");
+            }
         }
 
         /// <summary>

+ 6 - 0
src/Hotline.Share/Dtos/Order/OrderStartFlowDto.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using Hotline.Share.Dtos.Article;
 using Hotline.Share.Dtos.FlowEngine;
 
 namespace Hotline.Share.Dtos.Order
@@ -21,4 +22,9 @@ namespace Hotline.Share.Dtos.Order
     {
 
     }
+
+    public class BulletinFlowDto:StartWorkflowDto<AddBulletinDto>
+    {
+
+    }
 }

+ 6 - 0
src/Hotline/FlowEngine/WfModules/WorkflowModuleConsts.cs

@@ -47,6 +47,11 @@ public class WorkflowModuleConsts
     /// </summary>
     public const string TelRestApply = "TelRestApply";
 
+    /// <summary>
+    /// 公告审批
+    /// </summary>
+    public const string BulletinApply = "BulletinApply";
+
     public static List<WorkflowModule> AllModules =>
         new()
         {
@@ -58,5 +63,6 @@ public class WorkflowModuleConsts
             new(OrderDelay,"工单延期"),
             new(OrderPrevious,"工单退回"),
             new(OrderScreen,"工单甄别"),
+            new(BulletinApply,"公告审批")
         };
 }

+ 1 - 1
src/Hotline/Settings/SysDicTypeConsts.cs

@@ -162,6 +162,6 @@ public class SysDicTypeConsts
 
     /// <summary>
     /// 公告类型
-    /// </summary>
+    /// </summary>      
     public const string BulletinType = "BulletinType";
 }