临时提交
parent
6cc7902a85
commit
cbe0e794db
|
|
@ -4,6 +4,7 @@ using OpenAuth.App.Interface;
|
||||||
using OpenAuth.Repository;
|
using OpenAuth.Repository;
|
||||||
using OpenAuth.Repository.Domain;
|
using OpenAuth.Repository.Domain;
|
||||||
using OpenAuth.Repository.Domain.workflow;
|
using OpenAuth.Repository.Domain.workflow;
|
||||||
|
using OpenAuth.WebApi.Controllers.ServerController;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace workflow;
|
namespace workflow;
|
||||||
|
|
@ -18,9 +19,21 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using OpenAuth.App.BaseApp.Base;
|
||||||
|
using OpenAuth.App.Interface;
|
||||||
|
using OpenAuth.Repository;
|
||||||
|
using OpenAuth.Repository.Domain;
|
||||||
|
using OpenAuth.Repository.Domain.workflow;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 完整工作流引擎(适配:区县→执法监督科→5个审核科会签→汇总归档/退回)
|
/// 完整工作流引擎(适配:区县→执法监督科→5个审核科会签→汇总归档/退回)
|
||||||
|
/// 包含:流程发起/处理 + 拟办/待办/已办/未办结/已完成/全部事项查询
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext>
|
public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext>
|
||||||
{
|
{
|
||||||
|
|
@ -45,12 +58,19 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
_sqlSugar = Repository.AsSugarClient();
|
_sqlSugar = Repository.AsSugarClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 1. 发起流程(区县提交→流转至执法监督科)
|
#region 一、核心业务:流程发起/处理
|
||||||
|
|
||||||
public long InitiateFlow(long userId, string userName, InitiateFlowRequest request)
|
/// <summary>
|
||||||
|
/// 发起流程(区县提交→流转至执法监督科)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">发起人ID</param>
|
||||||
|
/// <param name="userName">发起人姓名</param>
|
||||||
|
/// <param name="requestDto">发起流程请求参数</param>
|
||||||
|
/// <returns>流程实例ID</returns>
|
||||||
|
public long InitiateFlow(long userId, string userName, InitiateFlowRequestDto requestDto)
|
||||||
{
|
{
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (string.IsNullOrEmpty(request.FlowCode) || string.IsNullOrEmpty(request.BusinessNo))
|
if (string.IsNullOrEmpty(requestDto.FlowCode) || string.IsNullOrEmpty(requestDto.BusinessNo))
|
||||||
throw new Exception("流程编码和业务编号不能为空");
|
throw new Exception("流程编码和业务编号不能为空");
|
||||||
if (userId <= 0 || string.IsNullOrEmpty(userName))
|
if (userId <= 0 || string.IsNullOrEmpty(userName))
|
||||||
throw new Exception("发起人ID和姓名不能为空");
|
throw new Exception("发起人ID和姓名不能为空");
|
||||||
|
|
@ -64,10 +84,10 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
|
|
||||||
// 步骤1:查询启用的流程模板(违法建设认定流程)
|
// 步骤1:查询启用的流程模板(违法建设认定流程)
|
||||||
var template = _sqlSugar.Queryable<ZyFlowTemplate>()
|
var template = _sqlSugar.Queryable<ZyFlowTemplate>()
|
||||||
.Where(t => t.FlowCode == request.FlowCode && t.IsEnabled == true)
|
.Where(t => t.FlowCode == requestDto.FlowCode && t.IsEnabled == true)
|
||||||
.First();
|
.First();
|
||||||
if (template == null)
|
if (template == null)
|
||||||
throw new Exception($"流程模板【{request.FlowCode}】不存在或未启用");
|
throw new Exception($"流程模板【{requestDto.FlowCode}】不存在或未启用");
|
||||||
|
|
||||||
// 步骤2:查询流程开始节点(区县提交)
|
// 步骤2:查询流程开始节点(区县提交)
|
||||||
var startNode = _sqlSugar.Queryable<ZyFlowNode>()
|
var startNode = _sqlSugar.Queryable<ZyFlowNode>()
|
||||||
|
|
@ -81,7 +101,7 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
{
|
{
|
||||||
TemplateId = template.TemplateId,
|
TemplateId = template.TemplateId,
|
||||||
FlowCode = template.FlowCode,
|
FlowCode = template.FlowCode,
|
||||||
BusinessNo = request.BusinessNo,
|
BusinessNo = requestDto.BusinessNo,
|
||||||
Status = "Submitted", // 已提交
|
Status = "Submitted", // 已提交
|
||||||
CurrentNodeId = startNode.NodeId,
|
CurrentNodeId = startNode.NodeId,
|
||||||
InitiatorId = userId,
|
InitiatorId = userId,
|
||||||
|
|
@ -106,10 +126,10 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
_sqlSugar.Insertable(startWorkitem).ExecuteCommand();
|
_sqlSugar.Insertable(startWorkitem).ExecuteCommand();
|
||||||
|
|
||||||
// 步骤5:保存流程变量(标题、附件路径等)
|
// 步骤5:保存流程变量(标题、附件路径等)
|
||||||
var attachmentPaths = SaveAttachments(request.Attachments);
|
var attachmentPaths = SaveAttachments(requestDto.Attachments);
|
||||||
var flowVariables = new List<ZyFlowVariable>
|
var flowVariables = new List<ZyFlowVariable>
|
||||||
{
|
{
|
||||||
new ZyFlowVariable { InstanceId = instanceId, VarKey = "Title", VarValue = request.Title },
|
new ZyFlowVariable { InstanceId = instanceId, VarKey = "Title", VarValue = requestDto.Title },
|
||||||
new ZyFlowVariable { InstanceId = instanceId, VarKey = "AttachmentPaths", VarValue = attachmentPaths },
|
new ZyFlowVariable { InstanceId = instanceId, VarKey = "AttachmentPaths", VarValue = attachmentPaths },
|
||||||
new ZyFlowVariable
|
new ZyFlowVariable
|
||||||
{
|
{
|
||||||
|
|
@ -135,14 +155,17 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
return instanceId;
|
return instanceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
/// <summary>
|
||||||
|
/// 处理工作项(执法监督科转发/审核科会签/汇总处理)
|
||||||
#region 2. 处理工作项(执法监督科转发/审核科会签/汇总处理)
|
/// </summary>
|
||||||
|
/// <param name="userId">处理人ID</param>
|
||||||
public bool HandleWorkitem(long userId, string userName, HandleWorkitemRequest request)
|
/// <param name="userName">处理人姓名</param>
|
||||||
|
/// <param name="requestDto">处理工作项请求参数</param>
|
||||||
|
/// <returns>处理结果(成功/失败)</returns>
|
||||||
|
public bool HandleWorkitem(long userId, string userName, HandleWorkitemRequestDto requestDto)
|
||||||
{
|
{
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (request.WorkitemId <= 0)
|
if (requestDto.WorkitemId <= 0)
|
||||||
throw new Exception("工作项ID无效");
|
throw new Exception("工作项ID无效");
|
||||||
if (userId <= 0 || string.IsNullOrEmpty(userName))
|
if (userId <= 0 || string.IsNullOrEmpty(userName))
|
||||||
throw new Exception("处理人ID和姓名不能为空");
|
throw new Exception("处理人ID和姓名不能为空");
|
||||||
|
|
@ -154,7 +177,7 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
|
|
||||||
// 步骤1:查询待处理的工作项(仅待办状态可处理)
|
// 步骤1:查询待处理的工作项(仅待办状态可处理)
|
||||||
var workitem = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
var workitem = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
||||||
.Where(w => w.WorkitemId == request.WorkitemId && w.Status == "ToDo")
|
.Where(w => w.WorkitemId == requestDto.WorkitemId && w.Status == "ToDo")
|
||||||
.First();
|
.First();
|
||||||
if (workitem == null)
|
if (workitem == null)
|
||||||
throw new Exception("工作项不存在、已处理或状态异常");
|
throw new Exception("工作项不存在、已处理或状态异常");
|
||||||
|
|
@ -172,7 +195,7 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
// 步骤3:更新当前工作项为已完成
|
// 步骤3:更新当前工作项为已完成
|
||||||
workitem.Status = "Done";
|
workitem.Status = "Done";
|
||||||
workitem.HandleTime = DateTime.Now;
|
workitem.HandleTime = DateTime.Now;
|
||||||
workitem.Comment = string.IsNullOrEmpty(request.Comment) ? "处理完成" : request.Comment;
|
workitem.Comment = string.IsNullOrEmpty(requestDto.Comment) ? "处理完成" : requestDto.Comment;
|
||||||
_sqlSugar.Updateable(workitem).ExecuteCommand();
|
_sqlSugar.Updateable(workitem).ExecuteCommand();
|
||||||
|
|
||||||
// 步骤4:按节点类型分支处理核心逻辑
|
// 步骤4:按节点类型分支处理核心逻辑
|
||||||
|
|
@ -185,7 +208,7 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
|
|
||||||
// 并行节点:5个审核科会签
|
// 并行节点:5个审核科会签
|
||||||
case "Parallel" when _auditDeptRoleIds.Contains(currentNode.RoleId):
|
case "Parallel" when _auditDeptRoleIds.Contains(currentNode.RoleId):
|
||||||
ProcessParallelAudit(flowInstance.InstanceId, currentNode.NodeId, userId, userName, request);
|
ProcessParallelAudit(flowInstance.InstanceId, currentNode.NodeId, userId, userName, requestDto);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 分支节点:汇总(归档/退回区县)
|
// 分支节点:汇总(归档/退回区县)
|
||||||
|
|
@ -213,23 +236,105 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 3. 流程查询(我的待办/我的已办)
|
#region 二、完整查询:拟办/待办/已办/未办结/已完成/全部事项
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询我的待办工作项
|
/// 我的拟办(未认领/待分配给当前用户的事项)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<FlowQueryResult> QueryMyToDo(long userId)
|
/// <param name="userId">当前用户ID</param>
|
||||||
|
/// <param name="pageQueryDto">分页参数</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
public PageQueryResultDto<FlowQuerySingleResultDto> QueryMyDraft(long userId, PageQueryRequestDto pageQueryDto)
|
||||||
{
|
{
|
||||||
|
// 参数初始化
|
||||||
if (userId <= 0)
|
if (userId <= 0)
|
||||||
return new List<FlowQueryResult>();
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
pageQueryDto = pageQueryDto ?? new PageQueryRequestDto();
|
||||||
|
var pageIndex = pageQueryDto.PageIndex < 1 ? 1 : pageQueryDto.PageIndex;
|
||||||
|
var pageSize = pageQueryDto.PageSize < 1 ? 10 : pageQueryDto.PageSize;
|
||||||
|
|
||||||
// 步骤1:查询当前用户的待办工作项
|
// 拟办逻辑:工作项状态为"Draft"(拟办)、对应角色匹配当前用户、未分配具体处理人
|
||||||
var toDoWorkitems = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
var draftQuery = _sqlSugar
|
||||||
.Where(w => w.HandlerId == userId && w.Status == "ToDo")
|
.Queryable<ZyFlowWorkitem, ZyFlowNode>((w, n) => new JoinQueryInfos(
|
||||||
|
JoinType.Inner, w.NodeId == n.NodeId))
|
||||||
|
.Where((w, n) =>
|
||||||
|
w.Status == "Draft" && _auditDeptRoleIds.Contains(n.RoleId)
|
||||||
|
&& (w.HandlerId == null || w.HandlerId == 0)
|
||||||
|
&& w.HandlerName != "")
|
||||||
|
.OrderByDescending((w, n) => w.ReceiveTime);
|
||||||
|
|
||||||
|
// 分页查询
|
||||||
|
var totalCount = draftQuery.Count();
|
||||||
|
var draftWorkitems = draftQuery
|
||||||
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// 步骤2:组装返回结果
|
// 组装返回结果
|
||||||
var queryResults = new List<FlowQueryResult>();
|
var dataList = new List<FlowQuerySingleResultDto>();
|
||||||
|
foreach (var workitem in draftWorkitems)
|
||||||
|
{
|
||||||
|
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
||||||
|
.Where(i => i.InstanceId == workitem.InstanceId)
|
||||||
|
.First();
|
||||||
|
if (flowInstance == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
||||||
|
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
||||||
|
.First()?.VarValue ?? string.Empty;
|
||||||
|
|
||||||
|
dataList.Add(new FlowQuerySingleResultDto
|
||||||
|
{
|
||||||
|
InstanceId = flowInstance.InstanceId,
|
||||||
|
BusinessNo = flowInstance.BusinessNo,
|
||||||
|
Title = flowTitle,
|
||||||
|
NodeName = workitem.NodeName,
|
||||||
|
Status = "Draft", // 拟办状态
|
||||||
|
CreateTime = flowInstance.CreateTime,
|
||||||
|
InitiatorName = flowInstance.InitiatorName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>
|
||||||
|
{
|
||||||
|
PageIndex = pageIndex,
|
||||||
|
PageSize = pageSize,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
DataList = dataList
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 我的待办(已分配给当前用户、待处理的事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">当前用户ID</param>
|
||||||
|
/// <param name="pageQueryDto">分页参数</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
public PageQueryResultDto<FlowQuerySingleResultDto> QueryMyToDo(long userId, PageQueryRequestDto pageQueryDto)
|
||||||
|
{
|
||||||
|
// 参数初始化
|
||||||
|
if (userId <= 0)
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
pageQueryDto = pageQueryDto ?? new PageQueryRequestDto();
|
||||||
|
var pageIndex = pageQueryDto.PageIndex < 1 ? 1 : pageQueryDto.PageIndex;
|
||||||
|
var pageSize = pageQueryDto.PageSize < 1 ? 10 : pageQueryDto.PageSize;
|
||||||
|
|
||||||
|
// 待办逻辑:工作项状态为"ToDo"、处理人ID为当前用户
|
||||||
|
var toDoQuery = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
||||||
|
.Where(w => w.HandlerId == userId && w.Status == "ToDo")
|
||||||
|
.OrderByDescending(w => w.ReceiveTime);
|
||||||
|
|
||||||
|
// 分页查询
|
||||||
|
var totalCount = toDoQuery.Count();
|
||||||
|
var toDoWorkitems = toDoQuery
|
||||||
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// 组装返回结果
|
||||||
|
var dataList = new List<FlowQuerySingleResultDto>();
|
||||||
foreach (var workitem in toDoWorkitems)
|
foreach (var workitem in toDoWorkitems)
|
||||||
{
|
{
|
||||||
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
||||||
|
|
@ -238,12 +343,11 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
if (flowInstance == null)
|
if (flowInstance == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 查询流程标题
|
|
||||||
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
||||||
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
||||||
.First()?.VarValue ?? string.Empty;
|
.First()?.VarValue ?? string.Empty;
|
||||||
|
|
||||||
queryResults.Add(new FlowQueryResult
|
dataList.Add(new FlowQuerySingleResultDto
|
||||||
{
|
{
|
||||||
InstanceId = flowInstance.InstanceId,
|
InstanceId = flowInstance.InstanceId,
|
||||||
BusinessNo = flowInstance.BusinessNo,
|
BusinessNo = flowInstance.BusinessNo,
|
||||||
|
|
@ -255,27 +359,51 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryResults;
|
return new PageQueryResultDto<FlowQuerySingleResultDto>
|
||||||
|
{
|
||||||
|
PageIndex = pageIndex,
|
||||||
|
PageSize = pageSize,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
DataList = dataList
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查询我的已办工作项
|
/// 我的已办(当前用户已处理完成的事项)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<FlowQueryResult> QueryMyDone(long userId)
|
/// <param name="userId">当前用户ID</param>
|
||||||
|
/// <param name="pageQueryDto">分页参数</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
public PageQueryResultDto<FlowQuerySingleResultDto> QueryMyDone(long userId, PageQueryRequestDto pageQueryDto)
|
||||||
{
|
{
|
||||||
|
// 参数初始化
|
||||||
if (userId <= 0)
|
if (userId <= 0)
|
||||||
return new List<FlowQueryResult>();
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
pageQueryDto = pageQueryDto ?? new PageQueryRequestDto();
|
||||||
|
var pageIndex = pageQueryDto.PageIndex < 1 ? 1 : pageQueryDto.PageIndex;
|
||||||
|
var pageSize = pageQueryDto.PageSize < 1 ? 10 : pageQueryDto.PageSize;
|
||||||
|
|
||||||
// 步骤1:查询当前用户已完成的工作项对应的流程实例ID(去重)
|
// 已办逻辑:工作项状态为"Done"、处理人ID为当前用户(去重流程实例)
|
||||||
var doneInstanceIds = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
var doneInstanceIds = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
||||||
.Where(w => w.HandlerId == userId && w.Status == "Done")
|
.Where(w => w.HandlerId == userId && w.Status == "Done")
|
||||||
.Select(w => w.InstanceId)
|
.Select(w => w.InstanceId)
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// 步骤2:组装返回结果
|
if (!doneInstanceIds.Any())
|
||||||
var queryResults = new List<FlowQueryResult>();
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
foreach (var instanceId in doneInstanceIds)
|
|
||||||
|
// 分页处理实例ID
|
||||||
|
var pagedInstanceIds = doneInstanceIds
|
||||||
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
var totalCount = doneInstanceIds.Count;
|
||||||
|
|
||||||
|
// 组装返回结果
|
||||||
|
var dataList = new List<FlowQuerySingleResultDto>();
|
||||||
|
foreach (var instanceId in pagedInstanceIds)
|
||||||
{
|
{
|
||||||
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
||||||
.Where(i => i.InstanceId == instanceId)
|
.Where(i => i.InstanceId == instanceId)
|
||||||
|
|
@ -283,18 +411,16 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
if (flowInstance == null)
|
if (flowInstance == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 查询流程标题
|
|
||||||
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
||||||
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
||||||
.First()?.VarValue ?? string.Empty;
|
.First()?.VarValue ?? string.Empty;
|
||||||
|
|
||||||
// 查询最新的已完成工作项
|
|
||||||
var lastWorkitem = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
var lastWorkitem = _sqlSugar.Queryable<ZyFlowWorkitem>()
|
||||||
.Where(w => w.InstanceId == instanceId && w.Status == "Done")
|
.Where(w => w.InstanceId == instanceId && w.HandlerId == userId && w.Status == "Done")
|
||||||
.OrderByDescending(w => w.HandleTime)
|
.OrderByDescending(w => w.HandleTime)
|
||||||
.First();
|
.First();
|
||||||
|
|
||||||
queryResults.Add(new FlowQueryResult
|
dataList.Add(new FlowQuerySingleResultDto
|
||||||
{
|
{
|
||||||
InstanceId = flowInstance.InstanceId,
|
InstanceId = flowInstance.InstanceId,
|
||||||
BusinessNo = flowInstance.BusinessNo,
|
BusinessNo = flowInstance.BusinessNo,
|
||||||
|
|
@ -306,12 +432,245 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryResults;
|
return new PageQueryResultDto<FlowQuerySingleResultDto>
|
||||||
|
{
|
||||||
|
PageIndex = pageIndex,
|
||||||
|
PageSize = pageSize,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
DataList = dataList
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 我的未办结(当前用户参与过、流程尚未完成的事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">当前用户ID</param>
|
||||||
|
/// <param name="pageQueryDto">分页参数</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
public PageQueryResultDto<FlowQuerySingleResultDto> QueryMyUnfinished(long userId, PageQueryRequestDto pageQueryDto)
|
||||||
|
{
|
||||||
|
// 参数初始化
|
||||||
|
if (userId <= 0)
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
pageQueryDto = pageQueryDto ?? new PageQueryRequestDto();
|
||||||
|
var pageIndex = pageQueryDto.PageIndex < 1 ? 1 : pageQueryDto.PageIndex;
|
||||||
|
var pageSize = pageQueryDto.PageSize < 1 ? 10 : pageQueryDto.PageSize;
|
||||||
|
|
||||||
|
// 未办结逻辑:
|
||||||
|
// 1. 当前用户参与过(处理过/待处理)
|
||||||
|
// 2. 流程状态不是"Completed"(未完成)
|
||||||
|
var unfinishedInstanceIds = _sqlSugar.Queryable<ZyFlowWorkitem, ZyFlowInstance>((w, i) => new JoinQueryInfos(
|
||||||
|
JoinType.Inner, w.InstanceId == i.InstanceId))
|
||||||
|
.Where((w, i) => (w.HandlerId == userId || (w.Status == "Draft" && _auditDeptRoleIds.Contains(w.NodeId)))
|
||||||
|
&& i.Status != "Completed")
|
||||||
|
.Select((w, i) => i.InstanceId)
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (!unfinishedInstanceIds.Any())
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
|
||||||
|
// 分页处理实例ID
|
||||||
|
var pagedInstanceIds = unfinishedInstanceIds
|
||||||
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
var totalCount = unfinishedInstanceIds.Count;
|
||||||
|
|
||||||
|
// 组装返回结果
|
||||||
|
var dataList = new List<FlowQuerySingleResultDto>();
|
||||||
|
foreach (var instanceId in pagedInstanceIds)
|
||||||
|
{
|
||||||
|
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
||||||
|
.Where(i => i.InstanceId == instanceId)
|
||||||
|
.First();
|
||||||
|
if (flowInstance == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
||||||
|
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
||||||
|
.First()?.VarValue ?? string.Empty;
|
||||||
|
|
||||||
|
var currentNode = _sqlSugar.Queryable<ZyFlowNode>()
|
||||||
|
.Where(n => n.NodeId == flowInstance.CurrentNodeId)
|
||||||
|
.First();
|
||||||
|
|
||||||
|
dataList.Add(new FlowQuerySingleResultDto
|
||||||
|
{
|
||||||
|
InstanceId = flowInstance.InstanceId,
|
||||||
|
BusinessNo = flowInstance.BusinessNo,
|
||||||
|
Title = flowTitle,
|
||||||
|
NodeName = currentNode?.NodeName ?? string.Empty,
|
||||||
|
Status = flowInstance.Status,
|
||||||
|
CreateTime = flowInstance.CreateTime,
|
||||||
|
InitiatorName = flowInstance.InitiatorName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>
|
||||||
|
{
|
||||||
|
PageIndex = pageIndex,
|
||||||
|
PageSize = pageSize,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
DataList = dataList
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 我的已完成(当前用户参与过、流程已归档完成的事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">当前用户ID</param>
|
||||||
|
/// <param name="pageQueryDto">分页参数</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
public PageQueryResultDto<FlowQuerySingleResultDto> QueryMyCompleted(long userId, PageQueryRequestDto pageQueryDto)
|
||||||
|
{
|
||||||
|
// 参数初始化
|
||||||
|
if (userId <= 0)
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
pageQueryDto = pageQueryDto ?? new PageQueryRequestDto();
|
||||||
|
var pageIndex = pageQueryDto.PageIndex < 1 ? 1 : pageQueryDto.PageIndex;
|
||||||
|
var pageSize = pageQueryDto.PageSize < 1 ? 10 : pageQueryDto.PageSize;
|
||||||
|
|
||||||
|
// 已完成逻辑:
|
||||||
|
// 1. 当前用户参与过(处理过/待处理)
|
||||||
|
// 2. 流程状态是"Completed"(已完成)
|
||||||
|
var completedInstanceIds = _sqlSugar.Queryable<ZyFlowWorkitem, ZyFlowInstance>((w, i) => new JoinQueryInfos(
|
||||||
|
JoinType.Inner, w.InstanceId == i.InstanceId))
|
||||||
|
.Where((w, i) => (w.HandlerId == userId || (w.Status == "Draft" && _auditDeptRoleIds.Contains(w.NodeId)))
|
||||||
|
&& i.Status == "Completed")
|
||||||
|
.Select((w, i) => i.InstanceId)
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (!completedInstanceIds.Any())
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
|
||||||
|
// 分页处理实例ID
|
||||||
|
var pagedInstanceIds = completedInstanceIds
|
||||||
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
var totalCount = completedInstanceIds.Count;
|
||||||
|
|
||||||
|
// 组装返回结果
|
||||||
|
var dataList = new List<FlowQuerySingleResultDto>();
|
||||||
|
foreach (var instanceId in pagedInstanceIds)
|
||||||
|
{
|
||||||
|
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
||||||
|
.Where(i => i.InstanceId == instanceId)
|
||||||
|
.First();
|
||||||
|
if (flowInstance == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
||||||
|
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
||||||
|
.First()?.VarValue ?? string.Empty;
|
||||||
|
|
||||||
|
var lastNode = _sqlSugar.Queryable<ZyFlowNode>()
|
||||||
|
.Where(n => n.NodeId == flowInstance.CurrentNodeId)
|
||||||
|
.First();
|
||||||
|
|
||||||
|
dataList.Add(new FlowQuerySingleResultDto
|
||||||
|
{
|
||||||
|
InstanceId = flowInstance.InstanceId,
|
||||||
|
BusinessNo = flowInstance.BusinessNo,
|
||||||
|
Title = flowTitle,
|
||||||
|
NodeName = lastNode?.NodeName ?? "流程归档",
|
||||||
|
Status = flowInstance.Status,
|
||||||
|
CreateTime = flowInstance.CreateTime,
|
||||||
|
InitiatorName = flowInstance.InitiatorName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>
|
||||||
|
{
|
||||||
|
PageIndex = pageIndex,
|
||||||
|
PageSize = pageSize,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
DataList = dataList
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 我的全部事项(拟办+待办+已办+未办结+已完成,去重整合)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">当前用户ID</param>
|
||||||
|
/// <param name="pageQueryDto">分页参数</param>
|
||||||
|
/// <returns>分页结果</returns>
|
||||||
|
public PageQueryResultDto<FlowQuerySingleResultDto> QueryMyAllItems(long userId, PageQueryRequestDto pageQueryDto)
|
||||||
|
{
|
||||||
|
// 参数初始化
|
||||||
|
if (userId <= 0)
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
pageQueryDto = pageQueryDto ?? new PageQueryRequestDto();
|
||||||
|
var pageIndex = pageQueryDto.PageIndex < 1 ? 1 : pageQueryDto.PageIndex;
|
||||||
|
var pageSize = pageQueryDto.PageSize < 1 ? 10 : pageQueryDto.PageSize;
|
||||||
|
|
||||||
|
// 全部事项逻辑:当前用户相关的所有流程实例(去重)
|
||||||
|
var allInstanceIds = _sqlSugar.Queryable<ZyFlowWorkitem, ZyFlowInstance>((w, i) => new JoinQueryInfos(
|
||||||
|
JoinType.Inner, w.InstanceId == i.InstanceId))
|
||||||
|
.Where((w, i) => w.HandlerId == userId || (w.Status == "Draft" && _auditDeptRoleIds.Contains(w.NodeId))
|
||||||
|
|| i.InitiatorId == userId)
|
||||||
|
.Select((w, i) => i.InstanceId)
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (!allInstanceIds.Any())
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>();
|
||||||
|
|
||||||
|
// 分页处理实例ID
|
||||||
|
var pagedInstanceIds = allInstanceIds
|
||||||
|
.Skip((pageIndex - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
var totalCount = allInstanceIds.Count;
|
||||||
|
|
||||||
|
// 组装返回结果
|
||||||
|
var dataList = new List<FlowQuerySingleResultDto>();
|
||||||
|
foreach (var instanceId in pagedInstanceIds)
|
||||||
|
{
|
||||||
|
var flowInstance = _sqlSugar.Queryable<ZyFlowInstance>()
|
||||||
|
.Where(i => i.InstanceId == instanceId)
|
||||||
|
.First();
|
||||||
|
if (flowInstance == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var flowTitle = _sqlSugar.Queryable<ZyFlowVariable>()
|
||||||
|
.Where(v => v.InstanceId == flowInstance.InstanceId && v.VarKey == "Title")
|
||||||
|
.First()?.VarValue ?? string.Empty;
|
||||||
|
|
||||||
|
var currentNode = _sqlSugar.Queryable<ZyFlowNode>()
|
||||||
|
.Where(n => n.NodeId == flowInstance.CurrentNodeId)
|
||||||
|
.First();
|
||||||
|
|
||||||
|
dataList.Add(new FlowQuerySingleResultDto
|
||||||
|
{
|
||||||
|
InstanceId = flowInstance.InstanceId,
|
||||||
|
BusinessNo = flowInstance.BusinessNo,
|
||||||
|
Title = flowTitle,
|
||||||
|
NodeName = currentNode?.NodeName ?? string.Empty,
|
||||||
|
Status = flowInstance.Status,
|
||||||
|
CreateTime = flowInstance.CreateTime,
|
||||||
|
InitiatorName = flowInstance.InitiatorName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PageQueryResultDto<FlowQuerySingleResultDto>
|
||||||
|
{
|
||||||
|
PageIndex = pageIndex,
|
||||||
|
PageSize = pageSize,
|
||||||
|
TotalCount = totalCount,
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
DataList = dataList
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 4. 核心辅助方法(流转/会签/汇总/附件等)
|
#region 三、内部核心辅助方法(仅内部调用,不对外暴露)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 流程节点流转核心方法
|
/// 流程节点流转核心方法
|
||||||
|
|
@ -377,10 +736,10 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
/// 处理并行会签(保存结果+判断是否全部完成)
|
/// 处理并行会签(保存结果+判断是否全部完成)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ProcessParallelAudit(long instanceId, long nodeId, long userId, string userName,
|
private void ProcessParallelAudit(long instanceId, long nodeId, long userId, string userName,
|
||||||
HandleWorkitemRequest request)
|
HandleWorkitemRequestDto requestDto)
|
||||||
{
|
{
|
||||||
// 校验会签结果
|
// 校验会签结果
|
||||||
if (string.IsNullOrEmpty(request.AuditResult))
|
if (string.IsNullOrEmpty(requestDto.AuditResult))
|
||||||
throw new Exception("会签需选择审核结果(Pass/Reject)");
|
throw new Exception("会签需选择审核结果(Pass/Reject)");
|
||||||
|
|
||||||
// 步骤1:获取当前用户所属科室名称
|
// 步骤1:获取当前用户所属科室名称
|
||||||
|
|
@ -392,8 +751,8 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
InstanceId = instanceId,
|
InstanceId = instanceId,
|
||||||
NodeId = nodeId,
|
NodeId = nodeId,
|
||||||
DeptName = deptName,
|
DeptName = deptName,
|
||||||
AuditResult = request.AuditResult,
|
AuditResult = requestDto.AuditResult,
|
||||||
AuditComment = request.Comment,
|
AuditComment = requestDto.Comment,
|
||||||
AuditorId = userId,
|
AuditorId = userId,
|
||||||
AuditorName = userName,
|
AuditorName = userName,
|
||||||
AuditTime = DateTime.Now
|
AuditTime = DateTime.Now
|
||||||
|
|
@ -417,11 +776,11 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
private void ProcessSummaryNode(ZyFlowInstance flowInstance, ZyFlowNode summaryNode, long userId, string userName)
|
private void ProcessSummaryNode(ZyFlowInstance flowInstance, ZyFlowNode summaryNode, long userId, string userName)
|
||||||
{
|
{
|
||||||
// 步骤1:判断是否全部审核通过
|
// 步骤1:判断是否全部审核通过
|
||||||
var isAllPass = _sqlSugar.Queryable<ZyFlowParallelAudit>()
|
var hasReject = _sqlSugar.Queryable<ZyFlowParallelAudit>()
|
||||||
.Where(a => a.InstanceId == flowInstance.InstanceId)
|
.Where(a => a.InstanceId == flowInstance.InstanceId)
|
||||||
.Any(a=> a.AuditResult != "Pass");
|
.Any(a => a.AuditResult != "Pass");
|
||||||
|
var isAllPass = !hasReject;
|
||||||
|
|
||||||
// todo
|
|
||||||
// 步骤2:解析汇总节点下一节点(归档/退回)
|
// 步骤2:解析汇总节点下一节点(归档/退回)
|
||||||
var nextNodeIds = summaryNode.NextNodeIds?.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
var nextNodeIds = summaryNode.NextNodeIds?.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Select(long.Parse)
|
.Select(long.Parse)
|
||||||
|
|
@ -429,13 +788,13 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
if (nextNodeIds.Count < 2)
|
if (nextNodeIds.Count < 2)
|
||||||
throw new Exception("汇总节点需配置2个后续节点(归档/退回区县)");
|
throw new Exception("汇总节点需配置2个后续节点(归档/退回区县)");
|
||||||
|
|
||||||
// 步骤3:确定目标节点(通过→归档,不通过→退回)
|
// 步骤3:确定目标节点(通过→归档[下标0],不通过→退回区县[下标1])
|
||||||
var targetNodeId = !isAllPass ? nextNodeIds[0] : nextNodeIds[1];
|
var targetNodeId = isAllPass ? nextNodeIds[0] : nextNodeIds[1];
|
||||||
var targetNode = _sqlSugar.Queryable<ZyFlowNode>()
|
var targetNode = _sqlSugar.Queryable<ZyFlowNode>()
|
||||||
.Where(n => n.NodeId == targetNodeId)
|
.Where(n => n.NodeId == targetNodeId)
|
||||||
.First();
|
.First();
|
||||||
if (targetNode == null)
|
if (targetNode == null)
|
||||||
return;
|
throw new Exception($"汇总节点目标节点【{(isAllPass ? "归档" : "退回区县")}】不存在");
|
||||||
|
|
||||||
// 步骤4:创建目标节点工作项
|
// 步骤4:创建目标节点工作项
|
||||||
var summaryWorkitem = new ZyFlowWorkitem
|
var summaryWorkitem = new ZyFlowWorkitem
|
||||||
|
|
@ -448,7 +807,7 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
Status = isAllPass ? "Done" : "ToDo",
|
Status = isAllPass ? "Done" : "ToDo",
|
||||||
ReceiveTime = DateTime.Now,
|
ReceiveTime = DateTime.Now,
|
||||||
HandleTime = isAllPass ? DateTime.Now : null,
|
HandleTime = isAllPass ? DateTime.Now : null,
|
||||||
Comment = isAllPass ? "所有审核科通过,流程归档完成" : "存在审核不通过项,退回区县修改"
|
Comment = isAllPass ? "所有审核科通过,流程归档完成" : "存在审核不通过项,退回区县修改补充材料"
|
||||||
};
|
};
|
||||||
_sqlSugar.Insertable(summaryWorkitem).ExecuteCommand();
|
_sqlSugar.Insertable(summaryWorkitem).ExecuteCommand();
|
||||||
|
|
||||||
|
|
@ -475,8 +834,8 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
private void CreateAuditDeptWorkitem(long instanceId, ZyFlowNode parallelNode, long roleId)
|
private void CreateAuditDeptWorkitem(long instanceId, ZyFlowNode parallelNode, long roleId)
|
||||||
{
|
{
|
||||||
// 获取科室用户信息
|
// 获取科室用户信息
|
||||||
var (userId, userName, deptName) = GetRoleFirstUserInfo(roleId);
|
var userInfo = GetRoleFirstUserInfo(roleId);
|
||||||
if (userId <= 0 || string.IsNullOrEmpty(userName))
|
if (userInfo.userId <= 0 || string.IsNullOrEmpty(userInfo.userName))
|
||||||
throw new Exception($"审核科角色【{roleId}】未配置有效用户");
|
throw new Exception($"审核科角色【{roleId}】未配置有效用户");
|
||||||
|
|
||||||
// 创建工作项
|
// 创建工作项
|
||||||
|
|
@ -484,9 +843,9 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
{
|
{
|
||||||
InstanceId = instanceId,
|
InstanceId = instanceId,
|
||||||
NodeId = parallelNode.NodeId,
|
NodeId = parallelNode.NodeId,
|
||||||
NodeName = $"{parallelNode.NodeName}({deptName})",
|
NodeName = $"{parallelNode.NodeName}({userInfo.deptName})",
|
||||||
HandlerId = userId,
|
HandlerId = userInfo.userId,
|
||||||
HandlerName = userName,
|
HandlerName = userInfo.userName,
|
||||||
Status = "ToDo",
|
Status = "ToDo",
|
||||||
ReceiveTime = DateTime.Now,
|
ReceiveTime = DateTime.Now,
|
||||||
Comment = "请完成违法建设认定相关审核工作"
|
Comment = "请完成违法建设认定相关审核工作"
|
||||||
|
|
@ -572,45 +931,25 @@ public class WorkflowEngineApp : SqlSugarBaseApp<SysCategoryType, SugarDbContext
|
||||||
return deptName ?? "未知科室";
|
return deptName ?? "未知科室";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取角色下第一个用户ID
|
|
||||||
/// </summary>
|
|
||||||
private long GetRoleFirstUserId(long roleId)
|
|
||||||
{
|
|
||||||
var userInfo = GetRoleFirstUserInfo(roleId);
|
|
||||||
return userInfo.userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取角色下第一个用户姓名
|
|
||||||
/// </summary>
|
|
||||||
private string GetRoleFirstUserName(long roleId)
|
|
||||||
{
|
|
||||||
var userInfo = GetRoleFirstUserInfo(roleId);
|
|
||||||
return userInfo.userName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取角色下第一个用户的完整信息
|
/// 获取角色下第一个用户的完整信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private (long userId, string userName, string deptName) GetRoleFirstUserInfo(long roleId)
|
private (long userId, string userName, string deptName) GetRoleFirstUserInfo(long roleId)
|
||||||
{
|
{
|
||||||
var sql = @"
|
var userInfo = _sqlSugar
|
||||||
SELECT
|
.Queryable<SysOrg, SysUserOrg, SysUser>((o, uo, u) => new JoinQueryInfos(
|
||||||
u.""Id"" as UserId,
|
JoinType.Inner, o.Id == uo.OrgId && uo.UserId == u.Id))
|
||||||
u.""Name"" as UserName,
|
.Select((o, uo, u) => new
|
||||||
o.""Name"" as DeptName
|
{
|
||||||
FROM sys_user u
|
UserId = u.Id,
|
||||||
INNER JOIN sys_userrole r ON u.""Id"" = r.""UserId""
|
UserName = u.Name,
|
||||||
INNER JOIN sys_userorg uo ON u.""Id"" = uo.""UserId""
|
DeptName = o.Name
|
||||||
INNER JOIN sys_org o ON uo.""OrgId"" = o.""Id""
|
})
|
||||||
WHERE r.""RoleId"" = @RoleId
|
|
||||||
LIMIT 1";
|
|
||||||
|
|
||||||
var userInfo = _sqlSugar.SqlQueryable<dynamic>(sql)
|
|
||||||
.AddParameters(new { RoleId = roleId })
|
|
||||||
.First();
|
.First();
|
||||||
|
|
||||||
|
if (userInfo == null)
|
||||||
|
return (0, string.Empty, string.Empty);
|
||||||
|
|
||||||
return (userInfo.UserId, userInfo.UserName ?? string.Empty, userInfo.DeptName ?? string.Empty);
|
return (userInfo.UserId, userInfo.UserName ?? string.Empty, userInfo.DeptName ?? string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,217 @@
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace OpenAuth.WebApi.Controllers.ServerController;
|
||||||
|
|
||||||
|
#region 一、接口入参DTO(所有请求参数,对应Controller接收的参数)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发起流程请求参数
|
||||||
|
/// </summary>
|
||||||
|
public class InitiateFlowRequestDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 流程编码(唯一标识流程模板,如:IllegalConstructionFlow_2026)
|
||||||
|
/// </summary>
|
||||||
|
public string FlowCode { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 业务编号(唯一标识该笔业务,如:WJ20260205001、XZ20260205002)
|
||||||
|
/// </summary>
|
||||||
|
public string BusinessNo { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程标题(用于展示,如:"XX区域违法建设认定申请")
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上传附件列表(业务相关证明材料、表单等)
|
||||||
|
/// </summary>
|
||||||
|
public List<IFormFile> Attachments { get; set; } = new List<IFormFile>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理工作项请求参数
|
||||||
|
/// </summary>
|
||||||
|
public class HandleWorkitemRequestDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工作项ID(待处理事项的唯一标识,从待办查询接口获取)
|
||||||
|
/// </summary>
|
||||||
|
public long WorkitemId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理备注(可选,记录处理意见、流转说明等)
|
||||||
|
/// </summary>
|
||||||
|
public string? Comment { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 审核结果(仅会签节点必填,可选值:Pass(通过)/Reject(驳回))
|
||||||
|
/// </summary>
|
||||||
|
public string? AuditResult { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询通用请求参数(所有查询接口共用)
|
||||||
|
/// </summary>
|
||||||
|
public class PageQueryRequestDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 当前页码(默认1,从1开始计数)
|
||||||
|
/// </summary>
|
||||||
|
public int PageIndex { get; set; } = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 每页显示条数(默认10,可自定义,建议不超过50)
|
||||||
|
/// </summary>
|
||||||
|
public int PageSize { get; set; } = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 二、接口出参DTO(所有返回结果,对应Controller返回的数据)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程查询单条结果返回值(所有查询接口的单条数据格式)
|
||||||
|
/// </summary>
|
||||||
|
public class FlowQuerySingleResultDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 流程实例ID(唯一标识该流程实例,用于后续操作)
|
||||||
|
/// </summary>
|
||||||
|
public long InstanceId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 业务编号(对应发起流程时的BusinessNo)
|
||||||
|
/// </summary>
|
||||||
|
public string BusinessNo { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程标题(对应发起流程时的Title)
|
||||||
|
/// </summary>
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前节点名称(如:"区县提交"、"政策法规科审核"、"汇总归档")
|
||||||
|
/// </summary>
|
||||||
|
public string NodeName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程状态(枚举值:Draft(拟办)、Submitted(已提交)、Forwarded(已转发)、Auditing(审核中)、Summarized(已汇总)、Completed(已完成)、Rejected(已驳回))
|
||||||
|
/// </summary>
|
||||||
|
public string Status { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程发起时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? CreateTime { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发起人姓名
|
||||||
|
/// </summary>
|
||||||
|
public string InitiatorName { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页查询通用返回值(所有分页查询接口共用,泛型适配不同数据列表)
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">数据列表的泛型类型(如:FlowQuerySingleResultDto)</typeparam>
|
||||||
|
public class PageQueryResultDto<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 当前页码(与请求参数的PageIndex对应)
|
||||||
|
/// </summary>
|
||||||
|
public int PageIndex { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 每页显示条数(与请求参数的PageSize对应)
|
||||||
|
/// </summary>
|
||||||
|
public int PageSize { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 总记录数(符合查询条件的所有数据条数)
|
||||||
|
/// </summary>
|
||||||
|
public long TotalCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 总页数(自动计算:TotalCount / PageSize,向上取整)
|
||||||
|
/// </summary>
|
||||||
|
public int TotalPages { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前页的数据列表
|
||||||
|
/// </summary>
|
||||||
|
public List<T> DataList { get; set; } = new List<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 接口全局统一响应格式(所有接口返回结果的统一封装,提高前端对接效率)
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">响应数据的泛型类型(如:long、bool、PageQueryResultDto<FlowQuerySingleResultDto>)</typeparam>
|
||||||
|
public class ApiResponseDto<T>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 响应状态码(200:操作成功,500:操作失败,400:参数错误/未登录,404:资源不存在)
|
||||||
|
/// </summary>
|
||||||
|
public int Code { get; set; } = 200;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 响应消息(成功时返回"操作成功",失败时返回具体错误信息)
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; } = "操作成功";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 响应数据(成功时返回具体业务数据,失败时可返回null或附加说明数据)
|
||||||
|
/// </summary>
|
||||||
|
public T? Data { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建成功响应(静态方法,简化Controller调用)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">成功时的业务数据</param>
|
||||||
|
/// <param name="message">自定义成功消息(可选,默认"操作成功")</param>
|
||||||
|
/// <returns>统一响应格式对象</returns>
|
||||||
|
public static ApiResponseDto<T> Success(T? data = default, string message = "操作成功")
|
||||||
|
{
|
||||||
|
return new ApiResponseDto<T>
|
||||||
|
{
|
||||||
|
Code = 200,
|
||||||
|
Message = message,
|
||||||
|
Data = data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建失败响应(静态方法,简化Controller调用)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">具体错误消息</param>
|
||||||
|
/// <param name="data">失败时的附加数据(可选,默认null)</param>
|
||||||
|
/// <returns>统一响应格式对象</returns>
|
||||||
|
public static ApiResponseDto<T> Fail(string message = "操作失败", T? data = default)
|
||||||
|
{
|
||||||
|
return new ApiResponseDto<T>
|
||||||
|
{
|
||||||
|
Code = 500,
|
||||||
|
Message = message,
|
||||||
|
Data = data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建参数错误/未登录响应(静态方法,适配400状态码场景)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">具体错误消息</param>
|
||||||
|
/// <param name="data">附加数据(可选)</param>
|
||||||
|
/// <returns>统一响应格式对象</returns>
|
||||||
|
public static ApiResponseDto<T> BadRequest(string message = "参数错误或未登录", T? data = default)
|
||||||
|
{
|
||||||
|
return new ApiResponseDto<T>
|
||||||
|
{
|
||||||
|
Code = 400,
|
||||||
|
Message = message,
|
||||||
|
Data = data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
|
|
||||||
namespace OpenAuth.Repository.Domain.workflow;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 发起流程请求DTO
|
|
||||||
/// </summary>
|
|
||||||
public class InitiateFlowRequest
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 流程编码
|
|
||||||
/// </summary>
|
|
||||||
public string FlowCode { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 业务编号
|
|
||||||
/// </summary>
|
|
||||||
public string BusinessNo { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 流程标题
|
|
||||||
/// </summary>
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 附件列表
|
|
||||||
/// </summary>
|
|
||||||
public List<IFormFile>? Attachments { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 处理工作项请求DTO
|
|
||||||
/// </summary>
|
|
||||||
public class HandleWorkitemRequest
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 工作项ID
|
|
||||||
/// </summary>
|
|
||||||
public long WorkitemId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 处理意见
|
|
||||||
/// </summary>
|
|
||||||
public string? Comment { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 会签结果(Pass/Reject)
|
|
||||||
/// </summary>
|
|
||||||
public string? AuditResult { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 流程查询结果DTO
|
|
||||||
/// </summary>
|
|
||||||
public class FlowQueryResult
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 流程实例ID
|
|
||||||
/// </summary>
|
|
||||||
public long InstanceId { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 业务编号
|
|
||||||
/// </summary>
|
|
||||||
public string BusinessNo { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 流程标题
|
|
||||||
/// </summary>
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 当前节点名称
|
|
||||||
/// </summary>
|
|
||||||
public string NodeName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 流程状态
|
|
||||||
/// </summary>
|
|
||||||
public string Status { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建时间
|
|
||||||
/// </summary>
|
|
||||||
public DateTime? CreateTime { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 发起人姓名
|
|
||||||
/// </summary>
|
|
||||||
public string InitiatorName { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
namespace OpenAuth.WebApi.Controllers.ServerController;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 统一API返回结果
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
public class ApiResult<T>
|
|
||||||
{
|
|
||||||
public bool Success { get; set; }
|
|
||||||
public string Message { get; set; }
|
|
||||||
public T Data { get; set; }
|
|
||||||
public int TotalCount { get; set; } // 分页总条数
|
|
||||||
|
|
||||||
public static ApiResult<T> Ok(T data, int totalCount = 0, string message = "操作成功")
|
|
||||||
{
|
|
||||||
return new ApiResult<T>
|
|
||||||
{
|
|
||||||
Success = true,
|
|
||||||
Message = message,
|
|
||||||
Data = data,
|
|
||||||
TotalCount = totalCount
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ApiResult<T> Error(string message = "操作失败")
|
|
||||||
{
|
|
||||||
return new ApiResult<T>
|
|
||||||
{
|
|
||||||
Success = false,
|
|
||||||
Message = message,
|
|
||||||
Data = default(T),
|
|
||||||
TotalCount = 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 通用分页输入
|
|
||||||
public class PageInput
|
|
||||||
{
|
|
||||||
public int PageIndex { get; set; } = 1;
|
|
||||||
public int PageSize { get; set; } = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 通用分页输出
|
|
||||||
public class PageOutput<T>
|
|
||||||
{
|
|
||||||
public int PageIndex { get; set; }
|
|
||||||
public int PageSize { get; set; }
|
|
||||||
public long TotalCount { get; set; }
|
|
||||||
public int TotalPages { get; set; }
|
|
||||||
public List<T> Data { get; set; } = new List<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发起流程请求
|
|
||||||
public class InitiateFlowRequest
|
|
||||||
{
|
|
||||||
public string FlowCode { get; set; } = string.Empty;
|
|
||||||
public string BusinessNo { get; set; } = string.Empty;
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
public List<IFormFile>? Attachments { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理工作项请求
|
|
||||||
public class HandleWorkitemRequest
|
|
||||||
{
|
|
||||||
public long WorkitemId { get; set; }
|
|
||||||
public string? Comment { get; set; }
|
|
||||||
public string? AuditResult { get; set; } // Pass/Reject
|
|
||||||
}
|
|
||||||
|
|
||||||
// 工作项查询结果(拟办/待办/已办)
|
|
||||||
public class FlowQueryResult
|
|
||||||
{
|
|
||||||
public long InstanceId { get; set; }
|
|
||||||
public string BusinessNo { get; set; } = string.Empty;
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
public string NodeName { get; set; } = string.Empty;
|
|
||||||
public string Status { get; set; } = string.Empty;
|
|
||||||
public DateTime? CreateTime { get; set; }
|
|
||||||
public string InitiatorName { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 流程实例查询结果(未办结/已完成)
|
|
||||||
public class FlowInstanceQueryResult
|
|
||||||
{
|
|
||||||
public long InstanceId { get; set; }
|
|
||||||
public string BusinessNo { get; set; } = string.Empty;
|
|
||||||
public string FlowName { get; set; } = string.Empty;
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
public string CurrentNodeName { get; set; } = string.Empty;
|
|
||||||
public string Status { get; set; } = string.Empty;
|
|
||||||
public string InitiatorName { get; set; } = string.Empty;
|
|
||||||
public DateTime? CreateTime { get; set; }
|
|
||||||
public DateTime? FinishTime { get; set; }
|
|
||||||
}
|
|
||||||
|
|
@ -6,186 +6,235 @@ using workflow;
|
||||||
|
|
||||||
namespace OpenAuth.WebApi.Controllers.ServerController;
|
namespace OpenAuth.WebApi.Controllers.ServerController;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using OpenAuth.App.Interface;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 工作流核心API接口(流程发起/处理 + 拟办/待办/已办/未办结/已完成/全部事项查询)
|
||||||
|
/// </summary>
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]/[action]")]
|
||||||
public class CustomWorkflowController : ControllerBase
|
public class WorkflowController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly WorkflowEngineApp _workflowEngineApp;
|
private readonly WorkflowEngineApp _workflowEngineApp;
|
||||||
private readonly IAuth _auth;
|
private readonly IAuth _auth;
|
||||||
|
|
||||||
public CustomWorkflowController(WorkflowEngineApp workflowEngineApp, IAuth auth)
|
// 构造函数注入依赖
|
||||||
|
public WorkflowController(WorkflowEngineApp workflowEngineApp, IAuth auth)
|
||||||
{
|
{
|
||||||
_workflowEngineApp = workflowEngineApp;
|
_workflowEngineApp = workflowEngineApp;
|
||||||
_auth = auth;
|
_auth = auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 基础接口
|
#region 一、流程操作接口
|
||||||
|
|
||||||
[HttpGet("user/by-role/{roleId:long}")]
|
/// <summary>
|
||||||
public IActionResult GetUserNameByRoleId(long roleId)
|
/// 发起流程(区县提交)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestDto">发起流程请求参数</param>
|
||||||
|
/// <returns>流程实例ID</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult<ApiResponseDto<long>> InitiateFlow([FromForm] InitiateFlowRequestDto requestDto)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userName = _workflowEngineApp.GetUserNameByRoleId(roleId);
|
// 获取当前登录用户(实际项目中从Token/IAuth中解析)
|
||||||
return Ok(new { Success = true, Data = userName });
|
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, "流程发起成功"));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { Success = false, Message = ex.Message });
|
return StatusCode(500, ApiResponseDto<long>.Fail(ex.Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 处理工作项(执法监督科转发/审核科会签/汇总处理)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="requestDto">处理工作项请求参数</param>
|
||||||
|
/// <returns>处理结果</returns>
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult<ApiResponseDto<bool>> HandleWorkitem([FromBody] HandleWorkitemRequestDto requestDto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 获取当前登录用户(实际项目中从Token/IAuth中解析)
|
||||||
|
var currentUser = _auth.GetCurrentUser().User;
|
||||||
|
if (currentUser == null)
|
||||||
|
return BadRequest(ApiResponseDto<bool>.Fail("未登录或登录过期"));
|
||||||
|
|
||||||
|
var result = _workflowEngineApp.HandleWorkitem(
|
||||||
|
currentUser.Id,
|
||||||
|
currentUser.Name,
|
||||||
|
requestDto);
|
||||||
|
|
||||||
|
return Ok(ApiResponseDto<bool>.Success(result, "工作项处理成功"));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ApiResponseDto<bool>.Fail(ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 流程表单接口
|
#region 二、完整查询接口(拟办/待办/已办/未办结/已完成/全部事项)
|
||||||
|
|
||||||
[HttpPost("flow/initiate")]
|
/// <summary>
|
||||||
public IActionResult InitiateAssessmentFlow([FromBody] InitiateAssessmentFlowRequest request)
|
/// 查询我的拟办(未认领/待分配事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageQueryDto">分页查询参数</param>
|
||||||
|
/// <returns>分页拟办结果</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>> QueryMyDraft(
|
||||||
|
[FromQuery] PageQueryRequestDto pageQueryDto)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var currentUser = _auth.GetCurrentUser()?.User;
|
var currentUser = _auth.GetCurrentUser().User;
|
||||||
if (currentUser == null)
|
if (currentUser == null)
|
||||||
return Unauthorized(new { Success = false, Message = "未登录" });
|
return BadRequest(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail("未登录或登录过期"));
|
||||||
|
|
||||||
var instanceId = _workflowEngineApp.InitiateAssessmentFlow(currentUser.Id, currentUser.Name, request);
|
var result = _workflowEngineApp.QueryMyDraft(currentUser.Id, pageQueryDto);
|
||||||
return Ok(new { Success = true, Data = new { FlowInstanceId = instanceId } });
|
|
||||||
|
return Ok(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Success(result, "拟办查询成功"));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { Success = false, Message = ex.Message });
|
return StatusCode(500, ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail(ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("flow/by-business/{businessNumber}")]
|
/// <summary>
|
||||||
public IActionResult QueryAssessmentFlowByBusinessNo(string businessNumber)
|
/// 查询我的待办(已分配/待处理事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageQueryDto">分页查询参数</param>
|
||||||
|
/// <returns>分页待办结果</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>> QueryMyToDo(
|
||||||
|
[FromQuery] PageQueryRequestDto pageQueryDto)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = _workflowEngineApp.QueryAssessmentFlowByBusinessNo(businessNumber);
|
var currentUser = _auth.GetCurrentUser().User;
|
||||||
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)
|
if (currentUser == null)
|
||||||
return Unauthorized(new { Success = false, Message = "未登录" });
|
return BadRequest(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail("未登录或登录过期"));
|
||||||
|
|
||||||
var success = _workflowEngineApp.UpdateAssessmentForm(form, currentUser.Id);
|
var result = _workflowEngineApp.QueryMyToDo(currentUser.Id, pageQueryDto);
|
||||||
return Ok(new { Success = success, Message = success ? "更新成功" : "更新失败" });
|
|
||||||
|
return Ok(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Success(result, "待办查询成功"));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { Success = false, Message = ex.Message });
|
return StatusCode(500, ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail(ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("form/page")]
|
/// <summary>
|
||||||
public IActionResult QueryAllAssessmentForms([FromBody] PageQueryInput pageInput)
|
/// 查询我的已办(已处理完成事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageQueryDto">分页查询参数</param>
|
||||||
|
/// <returns>分页已办结果</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>> QueryMyDone(
|
||||||
|
[FromQuery] PageQueryRequestDto pageQueryDto)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = _workflowEngineApp.QueryAllAssessmentForms(pageInput);
|
var currentUser = _auth.GetCurrentUser().User;
|
||||||
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)
|
if (currentUser == null)
|
||||||
return Unauthorized(new { Success = false, Message = "未登录" });
|
return BadRequest(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail("未登录或登录过期"));
|
||||||
|
|
||||||
var success = _workflowEngineApp.ClaimDraftWorkitem(workitemId, userId, currentUser.Name);
|
var result = _workflowEngineApp.QueryMyDone(currentUser.Id, pageQueryDto);
|
||||||
return Ok(new { Success = success, Message = success ? "认领成功" : "认领失败" });
|
|
||||||
|
return Ok(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Success(result, "已办查询成功"));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { Success = false, Message = ex.Message });
|
return StatusCode(500, ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail(ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("flow/workitem/handle/{userId:long}")]
|
/// <summary>
|
||||||
public IActionResult HandleWorkitem(long userId, [FromBody] HandleWorkitemRequest request)
|
/// 查询我的未办结(参与过/流程未完成事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageQueryDto">分页查询参数</param>
|
||||||
|
/// <returns>分页未办结结果</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>> QueryMyUnfinished(
|
||||||
|
[FromQuery] PageQueryRequestDto pageQueryDto)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var currentUser = _auth.GetCurrentUser()?.User;
|
var currentUser = _auth.GetCurrentUser().User;
|
||||||
if (currentUser == null)
|
if (currentUser == null)
|
||||||
return Unauthorized(new { Success = false, Message = "未登录" });
|
return BadRequest(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail("未登录或登录过期"));
|
||||||
|
|
||||||
var success = _workflowEngineApp.HandleWorkitem(userId, currentUser.Name, request);
|
var result = _workflowEngineApp.QueryMyUnfinished(currentUser.Id, pageQueryDto);
|
||||||
return Ok(new { Success = success, Message = success ? "处理成功" : "处理失败" });
|
|
||||||
|
return Ok(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Success(result, "未办结查询成功"));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(new { Success = false, Message = ex.Message });
|
return StatusCode(500, ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail(ex.Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询我的已完成(参与过/流程已归档事项)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageQueryDto">分页查询参数</param>
|
||||||
|
/// <returns>分页已完成结果</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>> QueryMyCompleted(
|
||||||
|
[FromQuery] PageQueryRequestDto pageQueryDto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var currentUser = _auth.GetCurrentUser().User;
|
||||||
|
if (currentUser == null)
|
||||||
|
return BadRequest(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail("未登录或登录过期"));
|
||||||
|
|
||||||
|
var result = _workflowEngineApp.QueryMyCompleted(currentUser.Id, pageQueryDto);
|
||||||
|
|
||||||
|
return Ok(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Success(result, "已完成查询成功"));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail(ex.Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询我的全部事项(拟办+待办+已办+未办结+已完成)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pageQueryDto">分页查询参数</param>
|
||||||
|
/// <returns>分页全部事项结果</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult<ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>> QueryMyAllItems(
|
||||||
|
[FromQuery] PageQueryRequestDto pageQueryDto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var currentUser = _auth.GetCurrentUser().User;
|
||||||
|
if (currentUser == null)
|
||||||
|
return BadRequest(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail("未登录或登录过期"));
|
||||||
|
|
||||||
|
var result = _workflowEngineApp.QueryMyAllItems(currentUser.Id, pageQueryDto);
|
||||||
|
|
||||||
|
return Ok(ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Success(result, "全部事项查询成功"));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ApiResponseDto<PageQueryResultDto<FlowQuerySingleResultDto>>.Fail(ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue