using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.WorkFlow.Entitys.Dto.FlowMonitor;
using JNPF.WorkFlow.Interfaces.Repository;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.WorkFlow.Service;
///
/// 流程监控.
///
[ApiDescriptionSettings(Tag = "WorkflowEngine", Name = "FlowMonitor", Order = 304)]
[Route("api/workflow/Engine/[controller]")]
public class FlowMonitorService : IDynamicApiController, ITransient
{
private readonly IFlowTaskRepository _flowTaskRepository;
///
public FlowMonitorService(IFlowTaskRepository flowTaskRepository)
{
_flowTaskRepository = flowTaskRepository;
}
#region GET
///
/// 列表.
///
/// 请求参数.
///
[HttpGet("")]
public async Task GetList([FromQuery] FlowMonitorListQuery input)
{
return await _flowTaskRepository.GetMonitorList(input);
}
///
/// 批量删除.
///
///
///
[HttpDelete]
public async Task Delete([FromBody] FlowMonitorDeleteInput input)
{
var ids = input.ids.Split(",").ToList();
var tsakList = await _flowTaskRepository.GetTaskList(x => ids.Contains(x.Id) && x.FlowType == 1);
if (tsakList.Any()) throw Oops.Oh(ErrorCode.WF0012, tsakList.FirstOrDefault().FullName);
tsakList = await _flowTaskRepository.GetTaskList(x => ids.Contains(x.Id) && !x.ParentId.Equals("0") && !SqlFunc.IsNullOrEmpty(x.ParentId));
if (tsakList.Any()) throw Oops.Oh(ErrorCode.WF0003, tsakList.FirstOrDefault().FullName);
foreach (var item in input.ids.Split(","))
{
var entity = _flowTaskRepository.GetTaskFirstOrDefault(item);
if (entity.IsNotEmptyOrNull())
{
await _flowTaskRepository.DeleteSubTask(entity);
await _flowTaskRepository.DeleteTask(entity);
}
}
}
#endregion
}