193 lines
6.0 KiB
C#
193 lines
6.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using OpenAuth.App.Interface;
|
|
using OpenAuth.Repository.Domain;
|
|
using OpenAuth.Repository.Domain.workflow;
|
|
using workflow;
|
|
|
|
namespace OpenAuth.WebApi.Controllers.ServerController;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class CustomWorkflowController : ControllerBase
|
|
{
|
|
private readonly WorkflowEngineApp _workflowEngineApp;
|
|
private readonly IAuth _auth;
|
|
|
|
public CustomWorkflowController(WorkflowEngineApp workflowEngineApp, IAuth auth)
|
|
{
|
|
_workflowEngineApp = workflowEngineApp;
|
|
_auth = auth;
|
|
}
|
|
|
|
#region 基础接口
|
|
|
|
[HttpGet("user/by-role/{roleId:long}")]
|
|
public IActionResult GetUserNameByRoleId(long roleId)
|
|
{
|
|
try
|
|
{
|
|
var userName = _workflowEngineApp.GetUserNameByRoleId(roleId);
|
|
return Ok(new { Success = true, Data = userName });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 流程表单接口
|
|
|
|
[HttpPost("flow/initiate")]
|
|
public IActionResult InitiateAssessmentFlow([FromBody] InitiateAssessmentFlowRequest request)
|
|
{
|
|
try
|
|
{
|
|
var currentUser = _auth.GetCurrentUser()?.User;
|
|
if (currentUser == null)
|
|
return Unauthorized(new { Success = false, Message = "未登录" });
|
|
|
|
var instanceId = _workflowEngineApp.InitiateAssessmentFlow(currentUser.Id, currentUser.Name, request);
|
|
return Ok(new { Success = true, Data = new { FlowInstanceId = instanceId } });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpGet("flow/by-business/{businessNumber}")]
|
|
public IActionResult QueryAssessmentFlowByBusinessNo(string businessNumber)
|
|
{
|
|
try
|
|
{
|
|
var result = _workflowEngineApp.QueryAssessmentFlowByBusinessNo(businessNumber);
|
|
return Ok(new { Success = true, Data = result });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPut("form/update")]
|
|
public IActionResult UpdateAssessmentForm([FromBody] IllegalConstructionAssessment form)
|
|
{
|
|
try
|
|
{
|
|
var currentUser = _auth.GetCurrentUser()?.User;
|
|
if (currentUser == null)
|
|
return Unauthorized(new { Success = false, Message = "未登录" });
|
|
|
|
var success = _workflowEngineApp.UpdateAssessmentForm(form, currentUser.Id);
|
|
return Ok(new { Success = success, Message = success ? "更新成功" : "更新失败" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("form/page")]
|
|
public IActionResult QueryAllAssessmentForms([FromBody] PageQueryInput pageInput)
|
|
{
|
|
try
|
|
{
|
|
var result = _workflowEngineApp.QueryAllAssessmentForms(pageInput);
|
|
return Ok(new { Success = true, Data = result });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 待办查询接口
|
|
|
|
[HttpPost("flow/draft/{userId:long}")]
|
|
public IActionResult QueryMyDraft(long userId, [FromBody] PageQueryInput pageInput)
|
|
{
|
|
try
|
|
{
|
|
var result = _workflowEngineApp.QueryMyDraft(userId, pageInput);
|
|
return Ok(new { Success = true, Data = result });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("flow/todo/{userId:long}")]
|
|
public IActionResult QueryMyToDo(long userId, [FromBody] PageQueryInput pageInput)
|
|
{
|
|
try
|
|
{
|
|
var result = _workflowEngineApp.QueryMyToDo(userId, pageInput);
|
|
return Ok(new { Success = true, Data = result });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("flow/done/{userId:long}")]
|
|
public IActionResult QueryMyDone(long userId, [FromBody] PageQueryInput pageInput)
|
|
{
|
|
try
|
|
{
|
|
var result = _workflowEngineApp.QueryMyDone(userId, pageInput);
|
|
return Ok(new { Success = true, Data = result });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 待办处理接口
|
|
|
|
[HttpPost("flow/workitem/claim/{workitemId:long}/{userId:long}")]
|
|
public IActionResult ClaimDraftWorkitem(long workitemId, long userId)
|
|
{
|
|
try
|
|
{
|
|
var currentUser = _auth.GetCurrentUser()?.User;
|
|
if (currentUser == null)
|
|
return Unauthorized(new { Success = false, Message = "未登录" });
|
|
|
|
var success = _workflowEngineApp.ClaimDraftWorkitem(workitemId, userId, currentUser.Name);
|
|
return Ok(new { Success = success, Message = success ? "认领成功" : "认领失败" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPost("flow/workitem/handle/{userId:long}")]
|
|
public IActionResult HandleWorkitem(long userId, [FromBody] HandleWorkitemRequest request)
|
|
{
|
|
try
|
|
{
|
|
var currentUser = _auth.GetCurrentUser()?.User;
|
|
if (currentUser == null)
|
|
return Unauthorized(new { Success = false, Message = "未登录" });
|
|
|
|
var success = _workflowEngineApp.HandleWorkitem(userId, currentUser.Name, request);
|
|
return Ok(new { Success = success, Message = success ? "处理成功" : "处理失败" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new { Success = false, Message = ex.Message });
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
} |