identificationOfCultivatedL.../OpenAuth.WebApi/Controllers/ServerController/CustomWorkflowController.cs

264 lines
9.9 KiB
C#
Raw Normal View History

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