using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.WorkFlow.Entitys.Dto.FlowLaunch; using JNPF.WorkFlow.Entitys.Model; using JNPF.WorkFlow.Interfaces.Manager; using JNPF.WorkFlow.Interfaces.Repository; using Microsoft.AspNetCore.Mvc; namespace JNPF.WorkFlow.Service; /// /// 流程发起. /// [ApiDescriptionSettings(Tag = "WorkflowEngine", Name = "FlowLaunch", Order = 305)] [Route("api/workflow/Engine/[controller]")] public class FlowLaunchService : IDynamicApiController, ITransient { private readonly IFlowTaskRepository _flowTaskRepository; private readonly IFlowTaskManager _flowTaskManager; public FlowLaunchService(IFlowTaskRepository flowTaskRepository, IFlowTaskManager flowTaskManager) { _flowTaskRepository = flowTaskRepository; _flowTaskManager = flowTaskManager; } #region GET /// /// 列表. /// /// 请求参数. /// [HttpGet("")] public async Task GetList([FromQuery] FlowLaunchListQuery input) { return await _flowTaskRepository.GetLaunchList(input); } #endregion #region POST /// /// 删除. /// /// 主键值. /// [HttpDelete("{id}")] public async Task Delete(string id) { var entity = _flowTaskRepository.GetTaskFirstOrDefault(id); if (entity == null) throw Oops.Oh(ErrorCode.COM1005); if (!entity.ParentId.Equals("0") && entity.ParentId.IsNotEmptyOrNull()) throw Oops.Oh(ErrorCode.WF0003, entity.FullName); if (entity.FlowType == 1) throw Oops.Oh(ErrorCode.WF0012, entity.FullName); await _flowTaskRepository.DeleteSubTask(entity); var isOk = await _flowTaskRepository.DeleteTask(entity); if (isOk < 1) throw Oops.Oh(ErrorCode.COM1002); } /// /// 撤回 /// 注意:在撤回流程时要保证你的下一节点没有处理这条记录;如已处理则无法撤销流程. /// /// 主键值. /// 流程经办. /// [HttpPut("{id}/Actions/Withdraw")] public async Task Revoke(string id, [FromBody] FlowHandleModel flowHandleModel) { var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(id, flowHandleModel); if (flowTaskParamter.flowTaskEntity.Status != 1) throw Oops.Oh(ErrorCode.WF0011); if (flowTaskParamter.flowTaskEntity.ParentId.IsNotEmptyOrNull()&& !flowTaskParamter.flowTaskEntity.ParentId.Equals("0")) throw Oops.Oh(ErrorCode.WF0015); await _flowTaskManager.Revoke(flowTaskParamter); } /// /// 催办. /// /// /// [HttpPost("Press/{id}")] public async Task Press(string id) { var flowTaskParamter = await _flowTaskRepository.GetTaskParamterByTaskId(id, null); await _flowTaskManager.Press(flowTaskParamter); } #endregion }