OpenAuth.Net/OpenAuth.App/FlowApproverApp/FlowApproverApp.cs

157 lines
5.6 KiB
C#
Raw Normal View History

2024-09-22 21:22:18 +08:00
using System;
2024-09-25 21:54:00 +08:00
using System.Collections.Generic;
2024-09-28 20:18:48 +08:00
using System.Linq;
2024-09-22 21:22:18 +08:00
using System.Threading.Tasks;
using Infrastructure;
using OpenAuth.App.Interface;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
2024-09-25 21:30:56 +08:00
using SqlSugar;
2024-09-22 21:22:18 +08:00
namespace OpenAuth.App
{
2024-09-25 21:30:56 +08:00
public class FlowApproverApp : SqlSugarBaseApp<FlowApprover>
2024-09-22 21:22:18 +08:00
{
2024-09-26 11:21:18 +08:00
/// <summary>
/// 加签
/// </summary>
2024-09-25 21:30:56 +08:00
public void Add(AddApproverReq obj)
2024-09-22 21:22:18 +08:00
{
var loginContext = _auth.GetCurrentUser();
if (loginContext == null)
{
throw new CommonException("登录已过期", Define.INVALID_TOKEN);
}
2024-09-25 21:30:56 +08:00
2024-09-26 12:25:34 +08:00
//先删除已有的加签记录
Repository.Delete(u => u.InstanceId == obj.InstanceId && u.ActivityId == obj.ActivityId);
2024-09-25 21:54:00 +08:00
var objs =new List<FlowApprover>();
foreach (var approver in obj.Approvers)
{
var addobj = approver.MapTo<FlowApprover>();
if (string.IsNullOrEmpty(addobj.Id))
{
addobj.Id = Guid.NewGuid().ToString();
}
CaculateCascade(addobj);
2024-09-26 11:21:18 +08:00
addobj.InstanceId = obj.InstanceId;
addobj.ActivityId = obj.ActivityId;
2024-09-26 12:25:34 +08:00
addobj.ApproveType = obj.ApproveType;
addobj.ReturnToSignNode = obj.ReturnToSignNode;
2024-09-26 11:21:18 +08:00
addobj.Reason = obj.Reason;
2024-09-25 21:54:00 +08:00
addobj.CreateDate = DateTime.Now;
addobj.CreateUserId = loginContext.User.Id;
addobj.CreateUserName = loginContext.User.Name;
2024-09-26 11:21:18 +08:00
objs.Add(addobj);
2024-09-25 21:54:00 +08:00
}
2024-09-25 21:30:56 +08:00
2024-09-25 21:54:00 +08:00
Repository.InsertRange(objs);
2025-02-25 23:54:53 +08:00
SugarClient.Insertable(new FlowInstanceOperationHistory
{
InstanceId = obj.InstanceId,
CreateUserId = loginContext.User.Id,
CreateUserName = loginContext.User.Name,
CreateDate = DateTime.Now,
2025-02-26 10:48:26 +08:00
Content = $"【加签】{loginContext.User.Name}加签给:{string.Join(",", objs.Select(u => u.ApproverName))}"
2025-02-25 23:54:53 +08:00
}).ExecuteCommand();
2024-09-22 21:22:18 +08:00
}
2024-09-25 21:30:56 +08:00
public void Update(AddApproverReq application)
{
var updateobj = application.MapTo<FlowApprover>();
Repository.Update(updateobj);
2024-09-22 21:22:18 +08:00
}
2024-09-25 21:30:56 +08:00
/// <summary>
/// 加载当前节点的加签人
/// </summary>
public async Task<TableResp<FlowApprover>> Load(QueryApproverReq request)
{
var objs = await Repository.GetListAsync(u =>
u.InstanceId == request.FlowInstanceId && u.ActivityId == request.ActivityId);
return new TableResp<FlowApprover>()
{
data = objs
};
}
2024-09-28 20:18:48 +08:00
/// <summary>
/// 获取当前可以审批的加签人ID列表
/// <para>如果是顺序执行,取第一个人</para>
/// <para>否则并行且/并行或都是返回所有加签人</para>
/// </summary>
public string[] GetApproverIds(QueryApproverReq req)
{
var approvers = GetApprovers(req);
2024-09-29 11:55:03 +08:00
if (approvers == null)
{
return Array.Empty<string>();
}
2024-09-28 20:18:48 +08:00
//否则并行且/并行或都是返回所有加签人
return approvers.Select(u => u.ApproverId).ToArray();
}
/// <summary>
/// 获取当前可以审批的加签人列表
/// <para>如果是顺序执行,取第一个人</para>
/// <para>否则并行且/并行或都是返回所有加签人</para>
/// </summary>
2024-09-28 20:18:48 +08:00
public FlowApprover[] GetApprovers(QueryApproverReq req)
{
var query= Repository.AsQueryable()
.Where(u => u.InstanceId == req.FlowInstanceId
&& u.ActivityId == req.ActivityId && u.Status == 0); //本节点待审批的加签人
if (query.Count() == 0)
{
return null;
}
//如果是顺序执行,取第一个人
if (query.First().ApproveType == 0)
{
var result = query.OrderBy(u => u.OrderNo).First();
return new[] { result };
}
//否则并行且/并行或都是返回所有加签人
return query.ToArray();
}
/// <summary>
/// 审批加签节点
/// </summary>
2024-09-29 14:59:12 +08:00
public bool Verify(VerifyApproverReq verifyApproverReq)
2024-09-28 20:18:48 +08:00
{
2024-09-29 14:59:12 +08:00
var approve = Get(verifyApproverReq.Id);
if (approve == null)
{
throw new Exception("加签审批失败,没能找打对应的加签人信息");
}
2024-09-28 20:18:48 +08:00
Repository.Update(u => new FlowApprover()
{
Status = verifyApproverReq.Status,
VerifyComment = verifyApproverReq.VerifyComment,
VerifyDate = DateTime.Now
}, u => u.Id == verifyApproverReq.Id);
2024-09-29 14:59:12 +08:00
if (approve.ApproveType == 2)
{
//如果是并行或,只需要一个审批通过即可
return Repository.IsAny(u => u.InstanceId == approve.InstanceId
&& u.ActivityId == approve.ActivityId && u.Status == 1);
}
//没有未处理的加签信息
return !Repository.IsAny(u => u.InstanceId == approve.InstanceId
&& u.ActivityId == approve.ActivityId && u.Status == 0);
2024-09-28 20:18:48 +08:00
}
2024-09-25 21:30:56 +08:00
public FlowApproverApp(ISqlSugarClient client, IAuth auth) : base(client, auth)
2024-09-22 21:22:18 +08:00
{
}
}
}