using Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using NetTaste; using OpenAuth.App; using OpenAuth.App.Config; using OpenAuth.App.Interface; using OpenAuth.App.Request; using OpenAuth.App.Response; using OpenAuth.Repository.Domain; using System.Threading.Tasks; using OpenAuth.App.BaseApp.WFTask; namespace OpenAuth.WebApi.Controllers { /// /// 流程实例 /// [Route("api/[controller]/[action]")] [ApiController] public class WFProcessController : ControllerBase { WFSchemeInfoApp schemeInfoApp; WFProcessApp processApp; WFTaskApp taskApp; IAuth auth; public WFProcessController( WFSchemeInfoApp schemeInfoApp, WFProcessApp processApp, WFTaskApp taskApp, IAuth auth ) { this.schemeInfoApp = schemeInfoApp; this.processApp = processApp; this.taskApp = taskApp; this.auth = auth; } #region 查询 #region 流程实例 /// /// 获取流程信息 /// workflow/process/{id} /// /// 任务id /// [HttpGet] public async Task> Get(string id) { var res = new WFTaskDto(); res.Process = await processApp.GetEntity(id); res.Scheme = await schemeInfoApp.GetSchemeEntity(res.Process.SchemeId); res.Logs = await taskApp.GetLogList(id); res.Tasks = await taskApp.GetUnFinishTaskList(id); return new Response { Result = res, Message = "success" }; } /// /// 获取流程信息 适配 BPMN /// workflow/process/{id} /// /// /// [HttpGet] public async Task> GetBPMN(string id) { var res = new BPMNWFTaskDto(); res.FlowViewer = new FlowUnit(); var process = await processApp.GetEntity(id); res.Process = process; var scheme = await schemeInfoApp.GetSchemeEntity(process.SchemeId); res.Scheme = scheme; res.FlowContent = scheme.FlowContent; res.Logs = await taskApp.GetLogList(id); var unfinishTasks = await taskApp.GetUnFinishTaskList(id); res.Tasks = unfinishTasks; res.FlowViewer.UnfinishedTaskSet = unfinishTasks.Select(a => a.UnitId).ToList(); List unfids = new List(); if (unfinishTasks.Count() > 0) { unfids = unfinishTasks.Select(r => r.Id).ToList(); } var finishTasks = await taskApp.GetFinishTaskList(id, unfids); res.FlowViewer.FinishedTaskSet = finishTasks.Select(a => a.UnitId).ToList(); return new Response { Result = res, Message = "success" }; } #endregion #region 草稿实例 /// /// 草稿实例 /// workflow/process/draft/{id} /// /// 草稿id /// [HttpGet] public async Task> GetDraft(string id) { var res = new WFTaskDto(); res.Process = await processApp.GetEntity(id); if(res.Process != null) { res.Scheme = await schemeInfoApp.GetSchemeEntity(res.Process.SchemeId); } return new Response { Result = res, Message = "success" }; } #endregion #region 流程实例分页 /// /// 获取流程列表 /// workflow/process/page /// /// 分页参数 /// 查询参数 /// [HttpGet] public async Task>>> LoadPage([FromQuery] PageReq pageReq, [FromQuery] WFProcessSearchDto searchParams) { var pageInfo = await processApp.GetPageList(pageReq, searchParams); return new Response>> { Result = pageInfo, Message = "success" }; } #endregion #region 我的流程 /// /// 我的流程分页 /// workflow/process/mypage /// /// 分页参数 /// 查询参数 /// [HttpGet] public async Task>>> LoadMyPage([FromQuery] PageReq pageReq, [FromQuery] WFProcessSearchDto searchParams) { var pageInfo = await processApp.GetMyPageList(pageReq, searchParams, 1); return new Response>> { Result = pageInfo, Message = "success" }; } #endregion #region 我的草稿分页 /// /// 我的草稿分页 /// "workflow/process/mydraftpage /// /// 分页参数 /// 查询参数 /// [HttpGet] public async Task>>> LoadMyDraftPage([FromQuery] PageReq pageReq, [FromQuery] WFProcessSearchDto searchParams) { var pageInfo = await processApp.GetMyPageList(pageReq, searchParams, 2); return new Response>> { Result = pageInfo, Message = "success" }; } #endregion #region 获取下一节点审核人 /// /// 获取下一节点审核人 /// workflow/process/nextusers /// /// 流程模板编码 /// 流程进程主键 /// 流程节点Id /// 流程操作代码 /// 创建人 /// [HttpGet] public async Task>>> LoadNextAuditors(string code, string processId, string nodeId, string operationCode, string userId) { var data = await processApp.GetNextAuditors(code, processId, nodeId, operationCode, userId); return new Response>> { Result = data }; } #endregion #endregion #region 保存草稿 /// /// 保存草稿 /// workflow/process/draft /// /// 提交参数 /// [HttpPost] public async Task> SaveDraft(WFProcessDto dto) { var result = new Response(); try { result = await processApp.SaveDraft(dto.ProcessId, dto.SchemeCode, dto.UserId, dto.InstanceInfo, dto.ParentProcessId, dto.ParentNodeId, dto.ParentTaskId, dto.IsChild, dto.Title); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } /// /// 保存草稿 /// workflow/process/draft /// /// 提交参数 /// [HttpPost] public async Task> SaveDraftWithUser(WFProcessDto dto) { var result = new Response(); try { result = await processApp.SaveDraftWithUser(dto.ProcessId, dto.SchemeCode, dto.UserId, dto.InstanceInfo, dto.ParentProcessId, dto.ParentNodeId, dto.ParentTaskId, dto.IsChild, dto.Title); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 删除草稿 /// /// 删除草稿 /// workflow/process/draft/{id} /// /// 提交参数 /// [HttpPost] public async Task> DeleteDraft(string id) { var result = new Response(); try { result = await processApp.DeleteDraft(id); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 创建流程 /// /// 创建流程 /// workflow/process/create /// /// 提交参数 /// [HttpPost] public async Task> Create(WFProcessDto dto) { var result = new Response(); try { result = await processApp.Create(dto.ProcessId, dto.SchemeCode, dto.UserId, dto.NextUsers, dto.InstanceInfo, dto.Title); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } /// /// 创建流程 /// workflow/process/create /// /// 提交参数 /// [HttpPost] public async Task> CreateWithUser(WFProcessDto dto) { var result = new Response(); try { result = await processApp.CreateWithUser(dto.ProcessId, dto.SchemeCode, dto.UserId, dto.NextUsers, dto.InstanceInfo, dto.Title); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 重新创建流程 /// /// 重新创建流程 /// workflow/process/createAgain /// /// 提交参数 /// [HttpPost] public async Task> CreateAgain(WFProcessDto dto) { var result = new Response(); try { result = await processApp.CreateAgain(dto.ProcessId, dto.Des); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 撤销流程 /// /// 撤销流程(只有在该流程未被处理的情况下) /// workflow/process/revoke/{id} /// /// 流程进程主键 [HttpPost] public async Task> Revoke(string id) { var result = new Response(); try { result.Result = await processApp.RevokeFlow(id); result.Message = "success"; } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 作废流程 /// /// 作废流程 /// workflow/process/{id} /// /// 流程进程主键 /// [HttpPost] public async Task> Delete(string id) { var result = new Response(); try { result = await processApp.DeleteProcess(id); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 催办流程 /// /// 催办流程 /// workflow/process/urge/{id} /// /// 流程进程主键 [HttpPost] public async Task> Urge(string id) { var result = new Response(); try { result = await processApp.UrgeFlow(id); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } /// /// 督办流程 /// /// 流程id /// 1 督办 0 取消督办 /// [HttpPost] public async Task> Supervise(string id,int supervise) { var result = new Response(); try { result = await processApp.Supervise(id,supervise); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 流程审核 /// /// 流程审核-有问题 /// workflow/process/audit/{id} /// /// 任务id [HttpPost] public async Task> Audit(string id, WFProcessDto dto) { var result = new Response(); try { await processApp.AuditFlow(id, dto.Code, dto.Name, dto.Des, dto.NextUsers, dto.StampImg, dto.StampPassWord, dto.NextId); result.Result = true; result.Message = "success"; } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 流程撤回 /// /// 流程撤回 /// workflow/process/Retract/{id} /// /// 任务id [HttpPost] public async Task> Retract(string id, WFProcessDto dto) { var result = new Response(); try { await processApp.RetractFlow(id, dto.Code, dto.Name, dto.Des, dto.NextUsers, dto.StampImg, dto.StampPassWord, dto.NextId); result.Result = true; result.Message = "success"; } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 流程批量审核 /// /// 流程批量审核-有问题 /// workflow/process/audits/{code} /// /// 任务id [HttpPost] public async Task> Audits(string code, List taskList) { await processApp.AuditFlows(code, taskList); return null; } #endregion #region 撤销审核 /// /// 撤销审核 /// workflow/process/audit/revoke/{id} /// /// 流程实例主键 /// 流程任务主键 /// [HttpPost] public async Task> RevokeAudit(string id, string taskId) { var result = new Response(); try { result = await processApp.RevokeAudit(id, taskId); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 加签 /// /// 加签 /// workflow/process/sign/{id} /// /// 任务id /// [HttpPost] public async Task> Sign(string id, WFProcessDto dto) { var result = new Response(); try { result = await processApp.SignFlow(id, dto.ToUserId, dto.Des); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 加签审核 /// /// 加签审核 /// workflow/process/signaudit/{id} /// /// 任务id /// [HttpPost] public async Task> SignAudit(string id, WFProcessDto dto) { var result = new Response(); try { result = await processApp.SignAudit(id, dto.Code, dto.Name, dto.Des); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 确认阅读 /// /// 确认阅读 /// workflow/process/read/{id} /// /// 流程任务主键 /// [HttpPost] public async Task> ReadFlow(string id) { var result = new Response(); try { result = await processApp.ReadFlow(id); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 转移审核人 /// /// 转移审核人 /// workflow/process/transfer/{id} /// /// 流程任务主键 /// [HttpPost] public async Task> TransferUser(string id, WFProcessDto dto) { var result = new Response(); try { result = await processApp.TransferUser(id, dto.ToUserId, dto.Des); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion #region 指派流程审核人 /// /// 指派流程审核人 /// workflow/process/point/{id} /// /// 流程任务主键 /// [HttpPost] public async Task> PointUser(string id, WFProcessPointDto dto) { var result = new Response(); try { result = await processApp.PointUser(id, dto.List); } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return result; } #endregion } }