using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Repository.Interface.WorkProcess;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using GxPress.Entity.WorkProcess;
using GxPress.Result.App.Process;
using GxPress.Service.Interface;
using System.Linq;
using GxPress.Common.Tools;
namespace GxPress.Api.AppControllers
{
[Route("api/app/process")]
[ApiController]
[Authorize]
public class AppProcessController : ControllerBase
{
private readonly IProcessGroupRepository _processGroupRepository;
private readonly IProcessRepository _processRepository;
private readonly IProcessService _processService;
private readonly ILoginContext _loginContext;
public AppProcessController(IProcessGroupRepository processGroupRepository, IProcessRepository processRepository, IProcessService processService, ILoginContext loginContext)
{
_processGroupRepository = processGroupRepository;
_processRepository = processRepository;
_processService = processService;
_loginContext = loginContext;
}
///
/// 获取工作流程列表
///
///
[HttpGet]
[AllowAnonymous]
public async Task> GetProcessList()
{
return await _processRepository.GetListByDepartmentIdAsync(_loginContext.DepartmentId);
}
///
/// 获取工作流程
///
///
[HttpGet("{id}")]
public async Task GetProcess(int id)
{
var processDto = await _processService.GetAsync(id);
var result = new GetProcessResult
{
Id = processDto.Id,
Name = processDto.Name,
IconUrl =StringUtils.AddDomain(processDto.IconUrl),
Description = processDto.Description,
FormFields = processDto.FormFields,
AllowApproverCheck = processDto.AllowApproverCheck,
AllowCarbonCopy = processDto.AllowCarbonCopy
};
result.ApproverCheckUserIds = new List();
//获取流程接点
foreach (var item in processDto.ProcessNodes)
//添加系统审核人
result.ApproverCheckUserIds.AddRange(item.ApproverChecks.Select(n => n.UserId));
result.ApproverCheckUserIds.Add(_loginContext.AccountId);
return result;
}
///
/// 获取流程组与流程列表
///
///
[HttpGet("groups")]
[AllowAnonymous]
public async Task> GetProcessGroupList()
{
var groups = await _processGroupRepository.GetListAsync();
foreach (var processGroup in groups)
{
var processes = await _processRepository.GetListByGroupIdAsync(processGroup.Id);
processGroup.Processes = processes;
}
return groups;
}
}
}