using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.Interface;
using OpenAuth.App.workflow;
namespace OpenAuth.WebApi.Controllers.ServerController;
///
/// 工作流核心API接口(流程发起/处理 + 拟办/待办/已办/未办结/已完成/全部事项查询)
///
[ApiController]
[Route("api/[controller]/[action]")]
public class WorkflowController : ControllerBase
{
private readonly WorkflowEngineApp _workflowEngineApp;
private readonly IAuth _auth;
// 构造函数注入依赖
public WorkflowController(WorkflowEngineApp workflowEngineApp, IAuth auth)
{
_workflowEngineApp = workflowEngineApp;
_auth = auth;
}
#region 一、流程操作接口
///
/// 发起流程(区县提交) 拟办需要重新提交
///
/// 发起流程请求参数
/// 流程实例ID
[HttpPost]
public ActionResult> InitiateFlow([FromBody] InitiateFlowRequestDto requestDto)
{
try
{
requestDto.FlowCode = "IllegalConstructionFlow";
// 获取当前登录用户(实际项目中从Token/IAuth中解析)
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto.Fail("未登录或登录过期"));
var instanceId = _workflowEngineApp.InitiateFlow(
currentUser.Id,
currentUser.Name,
requestDto);
return Ok(ApiResponseDto.Success(instanceId, "流程发起成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto.Fail(ex.Message));
}
}
///
/// 处理工作项(执法监督科转发 审核科会签 (系统自动完成驳回及归档))
///
/// 处理工作项请求参数
/// 处理结果
[HttpPost]
public ActionResult> HandleWorkitem([FromBody] HandleWorkitemRequestDto requestDto)
{
try
{
// 获取当前登录用户(实际项目中从Token/IAuth中解析)
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto.Fail("未登录或登录过期"));
var result = _workflowEngineApp.HandleWorkitem(
currentUser.Id,
currentUser.Name,
requestDto);
return Ok(ApiResponseDto.Success(result, "工作项处理成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto.Fail(ex.Message));
}
}
#endregion
#region 二、完整查询接口(拟办/待办/已办/未办结/已完成/全部事项)
///
/// 保存拟办(逻辑待完善)
///
///
[HttpPost]
public ActionResult> SaveDraft([FromBody] InitiateFlowRequestDto requestDto)
{
// 先保存到表单中,发起流程时,根据业务编号确定存不存,如果已经存在,则修改状态为已提交
try
{
requestDto.FlowCode = "IllegalConstructionFlow";
// 获取当前登录用户(实际项目中从Token/IAuth中解析)
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto.Fail("未登录或登录过期"));
var result = _workflowEngineApp.SaveDraft(requestDto);
return Ok(ApiResponseDto.Success(result));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto.Fail(ex.Message));
}
}
///
/// 查询我的拟办(未测试)
///
/// 分页查询参数
/// 分页拟办结果
[HttpGet]
public ActionResult>> QueryMyDraft(
[FromQuery] PageQueryRequestDto pageQueryDto)
{
try
{
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto>.Fail("未登录或登录过期"));
var result = _workflowEngineApp.QueryMyDraft(currentUser.Id, pageQueryDto);
return Ok(ApiResponseDto>.Success(result, "拟办查询成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto>.Fail(ex.Message));
}
}
///
/// 查询我的待办(已分配/待处理事项)
///
/// 分页查询参数
/// 分页待办结果
[HttpGet]
public ActionResult>> QueryMyToDo(
[FromQuery] PageQueryRequestDto pageQueryDto)
{
try
{
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto>.Fail("未登录或登录过期"));
var result = _workflowEngineApp.QueryMyToDo(currentUser.Id, pageQueryDto);
return Ok(ApiResponseDto>.Success(result, "待办查询成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto>.Fail(ex.Message));
}
}
///
/// 查询我的已办(已处理完成事项)
///
/// 分页查询参数
/// 分页已办结果
[HttpGet]
public ActionResult>> QueryMyDone(
[FromQuery] PageQueryRequestDto pageQueryDto)
{
try
{
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto>.Fail("未登录或登录过期"));
var result = _workflowEngineApp.QueryMyDone(currentUser.Id, pageQueryDto);
return Ok(ApiResponseDto>.Success(result, "已办查询成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto>.Fail(ex.Message));
}
}
///
/// 查询我的未办结(参与过/流程未完成事项)
///
/// 分页查询参数
/// 分页未办结结果
[HttpGet]
public ActionResult>> QueryMyUnfinished(
[FromQuery] PageQueryRequestDto pageQueryDto)
{
try
{
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto>.Fail("未登录或登录过期"));
var result = _workflowEngineApp.QueryMyUnfinished(currentUser.Id, pageQueryDto);
return Ok(ApiResponseDto>.Success(result, "未办结查询成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto>.Fail(ex.Message));
}
}
///
/// 查询我的已完成(参与过/流程已归档事项)
///
/// 分页查询参数
/// 分页已完成结果
[HttpGet]
public ActionResult>> QueryMyCompleted(
[FromQuery] PageQueryRequestDto pageQueryDto)
{
try
{
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto>.Fail("未登录或登录过期"));
var result = _workflowEngineApp.QueryMyCompleted(currentUser.Id, pageQueryDto);
return Ok(ApiResponseDto>.Success(result, "已完成查询成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto>.Fail(ex.Message));
}
}
///
/// 查询我的全部事项(拟办+待办+已办+未办结+已完成)
///
/// 分页查询参数
/// 分页全部事项结果
[HttpGet]
public ActionResult>> QueryMyAllItems(
[FromQuery] PageQueryRequestDto pageQueryDto)
{
try
{
var currentUser = _auth.GetCurrentUser().User;
if (currentUser == null)
return BadRequest(ApiResponseDto>.Fail("未登录或登录过期"));
var result = _workflowEngineApp.QueryMyAllItems(currentUser.Id, pageQueryDto);
return Ok(ApiResponseDto>.Success(result, "全部事项查询成功"));
}
catch (Exception ex)
{
return StatusCode(500, ApiResponseDto>.Fail(ex.Message));
}
}
#endregion
///
/// 详情
///
///
[HttpGet]
public ActionResult> Detail(string businessNo)
{
var detail = _workflowEngineApp.Detail(businessNo);
return Ok(ApiResponseDto.Success(detail));
}
}