You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.6 KiB
C#
136 lines
4.6 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.WMS.Core.Flow.Dtos;
|
|
using DS.WMS.Core.Flow.Entity;
|
|
using DS.WMS.Core.Flow.Interface;
|
|
using DS.WMS.Core.Op.Entity;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using Mapster;
|
|
using Masuit.Tools.Systems;
|
|
|
|
namespace DS.WMS.Core.Flow.Method;
|
|
|
|
/// <summary>
|
|
/// 租户端工作流实例管理
|
|
/// </summary>
|
|
public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanceService
|
|
{
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public ClientFlowInstanceService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
{
|
|
}
|
|
|
|
protected override FlowInstance? BuildInstance(CreateFlowInstanceReq req)
|
|
{
|
|
if (string.IsNullOrEmpty(req.TemplateId.ToString()))
|
|
return null;
|
|
|
|
FlowTemplateTenant template = Db.Queryable<FlowTemplateTenant>().First(x => x.Id == req.TemplateId);
|
|
|
|
return template == null ? null : new FlowInstance
|
|
{
|
|
CustomName = template.Name,
|
|
TemplateId = template.Id,
|
|
BusinessId = req.BusinessId,
|
|
BusinessType = req.BusinessType,
|
|
PermissionId = template.PermissionId,
|
|
ColumnView = template.ColumnView,
|
|
Content = template.Content,
|
|
MarkerNotifyURL = template.MarkerNotifyURL,
|
|
CallbackURL = template.CallbackURL,
|
|
Type = template.AuditType
|
|
};
|
|
}
|
|
|
|
protected override string GetForkNodeMakers(FlowRuntime wfruntime, string forkNodeId)
|
|
{
|
|
string makerList = "";
|
|
|
|
var nextNode = wfruntime.NextNode;
|
|
|
|
var nextConditionNodeId = wfruntime.GetNextConditionNodeId(nextNode);
|
|
var nextConditionNode = wfruntime.ChildNodes.Find(x => x.Id == nextConditionNodeId);
|
|
if (nextConditionNode == null)
|
|
return makerList;
|
|
|
|
if (nextConditionNode.AssigneeType == "role")
|
|
{
|
|
var users = Db.Queryable<SysRoleUser>().Where(x =>
|
|
nextConditionNode.Roles.Contains(x.RoleId.ToString()))
|
|
.Select(x => x.UserId).Distinct().ToList();
|
|
makerList = string.Join(",", users);
|
|
}
|
|
else if (nextConditionNode.AssigneeType == "user")
|
|
{
|
|
makerList = string.Join(",", nextConditionNode.Users);
|
|
}
|
|
|
|
return makerList;
|
|
}
|
|
|
|
protected override FlowRuntime CreateRuntimeService(FlowInstance instance)
|
|
{
|
|
return new FlowRuntime(instance, Db, TenantDb, User);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取工作流实例信息
|
|
/// </summary>
|
|
/// <param name="businessId">业务ID</param>
|
|
/// <param name="businessType">业务类型</param>
|
|
/// <param name="types">审批类型</param>
|
|
/// <returns></returns>
|
|
public DataResult<List<FlowInstanceRes>> GetFlowInstances(long businessId, BusinessType? businessType, params AuditType?[] types)
|
|
{
|
|
var query = Db.Queryable<FlowInstance>().Where(x => x.BusinessId == businessId && x.FlowStatus != FlowStatusEnum.Ready)
|
|
.WhereIF(businessType.HasValue, x => x.BusinessType == businessType.Value)
|
|
.WhereIF(types != null && types.Length > 0, x => types.Contains(x.Type));
|
|
|
|
var list = query.Select(x => new FlowInstance
|
|
{
|
|
Id = x.Id,
|
|
Content = x.Content,
|
|
Type = x.Type,
|
|
FlowStatus = x.FlowStatus
|
|
}).ToList();
|
|
|
|
var list2 = list.Select(x => x.Adapt<FlowInstanceRes>()).ToList();
|
|
foreach (var item in list2)
|
|
{
|
|
item.AuditTypeName = item.AuditType?.GetDescription();
|
|
}
|
|
|
|
return DataResult<List<FlowInstanceRes>>.Success(list2);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工作流审批
|
|
/// </summary>
|
|
/// <param name="info">工作流实例</param>
|
|
/// <returns></returns>
|
|
public DataResult AuditFlowInstance(FlowAuditInfo info)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(info, nameof(info));
|
|
|
|
if (info.Instance == null)
|
|
return DataResult.Failed("未能获取工作流", MultiLanguageConst.Operation_Failed);
|
|
|
|
if (info.Instance.FlowStatus == FlowStatusEnum.Approve)
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
if (info.Instance.CallbackURL.IsNullOrEmpty())
|
|
{
|
|
var template = Db.Queryable<FlowTemplateTenant>().Where(x => x.Id == info.Instance.TemplateId)
|
|
.Select(x => new { x.MarkerNotifyURL, x.CallbackURL }).First();
|
|
|
|
info.Instance.CallbackURL = template.CallbackURL;
|
|
info.Instance.MarkerNotifyURL = template.MarkerNotifyURL;
|
|
}
|
|
|
|
|
|
return AuditFlowCore(info.Status, info.AuditNote, info.Instance);
|
|
}
|
|
} |