using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DatabaseAccessor;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.WorkFlow.Entitys.Dto.FlowBefore;
using JNPF.WorkFlow.Entitys.Enum;
using JNPF.WorkFlow.Entitys.Model;
using JNPF.WorkFlow.Entitys.Model.Properties;
using JNPF.WorkFlow.Interfaces.Manager;
using JNPF.WorkFlow.Interfaces.Repository;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.WorkFlow.Service;
///
/// 流程审批.
///
[ApiDescriptionSettings(Tag = "WorkflowEngine", Name = "FlowBefore", Order = 303)]
[Route("api/workflow/Engine/[controller]")]
public class FlowBeforeService : IDynamicApiController, ITransient
{
private readonly IFlowTaskRepository _flowTaskRepository;
private readonly IFlowTaskManager _flowTaskManager;
private readonly IUserManager _userManager;
public FlowBeforeService(IFlowTaskRepository flowTaskRepository, IFlowTaskManager flowTaskManager, IUserManager userManager)
{
_flowTaskRepository = flowTaskRepository;
_flowTaskManager = flowTaskManager;
_userManager = userManager;
}
#region Get
///
/// 列表.
///
/// 请求参数.
/// 分类.
///
[HttpGet("List/{category}")]
public async Task GetList([FromQuery] FlowBeforeListQuery input, string category)
{
try
{
switch (category)
{
case "1":
return await _flowTaskRepository.GetWaitList(input);
case "2":
return await _flowTaskRepository.GetTrialList(input);
case "3":
return await _flowTaskRepository.GetCirculateList(input);
case "4":
return await _flowTaskRepository.GetBatchWaitList(input);
default:
var pageList = new SqlSugarPagedList()
{
list = new List(),
pagination = new Pagination()
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = 0
}
};
return PageResult.SqlSugarPageResult(pageList);
}
}
catch (Exception ex)
{
var pageList = new SqlSugarPagedList()
{
list = new List(),
pagination = new Pagination()
{
CurrentPage = input.currentPage,
PageSize = input.pageSize,
Total = 0
}
};
return PageResult.SqlSugarPageResult(pageList);
}
}
///
/// 获取任务详情.
///
/// 任务id.
/// 流程id.
/// 节点id.
/// 经办id.
///
[HttpGet("{id}")]
public async Task GetInfo(string id, [FromQuery] string flowId, [FromQuery] string taskNodeId, [FromQuery] string taskOperatorId)
{
try
{
return await _flowTaskManager.GetFlowBeforeInfo(id, flowId, taskNodeId, taskOperatorId);
}
catch (Exception ex)
{
throw Oops.Oh(ErrorCode.WF0033);
}
}
///
/// 审批汇总.
///
/// 主键值.
/// 分类(1:部门,2:角色,3:岗位).
///
[HttpGet("RecordList/{taskRecordId}")]
public async Task GetRecordList(string taskRecordId, [FromQuery] string category, [FromQuery] string type)
{
var recordList = await _flowTaskRepository.GetRecordListByCategory(taskRecordId, category, type);
var categoryId = recordList.Select(x => x.category).Distinct().ToList();
var list = new List();
foreach (var item in categoryId)
{
var categoryList = recordList.FindAll(x => x.category == item).ToList();
var output = new FlowBeforeRecordListOutput();
output.fullName = categoryList.FirstOrDefault()?.categoryName;
output.list = categoryList.OrderByDescending(x => x.handleTime).ToList();
list.Add(output);
}
return list;
}
///
/// 获取候选人编码.
///
/// 经办id.
/// 审批参数.
///
[HttpPost("Candidates/{taskOperatorId}")]
public async Task Candidates(string taskOperatorId, [FromBody] FlowHandleModel flowHandleModel)
{
if (taskOperatorId != "0")
{
var flowTaskParamter = await _flowTaskManager.Validation(taskOperatorId, flowHandleModel);
var flowEngine = _flowTaskRepository.GetFlowTemplateInfo(flowTaskParamter.flowTaskEntity.FlowId);
if (flowTaskParamter.flowTaskEntity.RejectDataId.IsNotEmptyOrNull())
{
return new List();
}
await _flowTaskManager.AdjustNodeByCon(flowEngine, flowHandleModel.formData, flowTaskParamter.flowTaskOperatorEntity);
}
return await _flowTaskManager.GetCandidateModelList(taskOperatorId, flowHandleModel);
}
///
/// 获取候选人.
///
/// 经办id.
/// 审批参数.
///
[HttpPost("CandidateUser/{taskOperatorId}")]
public async Task CandidateUser(string taskOperatorId, [FromBody] FlowHandleModel flowHandleModel)
{
return await _flowTaskManager.GetCandidateModelList(taskOperatorId, flowHandleModel, 1);
}
///
/// 批量审批流程分类列表.
///
///
[HttpGet("BatchFlowSelector")]
public async Task BatchFlowSelector()
{
return await _flowTaskRepository.BatchFlowSelector();
}
///
/// 批量审批流程列表.
///
///
///
[HttpGet("BatchFlowJsonList/{templateId}")]
public async Task BatchFlowJsonList(string templateId)
{
var list = (await _flowTaskRepository.GetWaitList()).FindAll(x => x.IsBatch == 1 && x.TemplateId == templateId);
var output = new List