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#

6 months ago
using DS.Module.Core;
using DS.Module.Core.Extensions;
6 months ago
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Flow.Interface;
using DS.WMS.Core.Op.Entity;
6 months ago
using DS.WMS.Core.Sys.Entity;
using Mapster;
using Masuit.Tools.Systems;
6 months ago
namespace DS.WMS.Core.Flow.Method;
/// <summary>
/// <20><EFBFBD>˹<EFBFBD><CBB9><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanceService
6 months ago
{
/// <summary>
/// <20><>ʼ<EFBFBD><CABC>
/// </summary>
/// <param name="serviceProvider"></param>
public ClientFlowInstanceService(IServiceProvider serviceProvider) : base(serviceProvider)
6 months ago
{
}
protected override FlowInstance? BuildInstance(CreateFlowInstanceReq req)
6 months ago
{
if (string.IsNullOrEmpty(req.TemplateId.ToString()))
return null;
6 months ago
FlowTemplateTenant template = Db.Queryable<FlowTemplateTenant>().First(x => x.Id == req.TemplateId);
6 months ago
return template == null ? null : new FlowInstance
6 months ago
{
CustomName = template.Name,
TemplateId = template.Id,
BusinessId = req.BusinessId,
BusinessType = req.BusinessType,
6 months ago
PermissionId = template.PermissionId,
ColumnView = template.ColumnView,
Content = template.Content,
MarkerNotifyURL = template.MarkerNotifyURL,
CallbackURL = template.CallbackURL,
Type = template.AuditType
6 months ago
};
}
protected override string GetForkNodeMakers(FlowRuntime wfruntime, string forkNodeId)
6 months ago
{
string makerList = "";
var nextNode = wfruntime.NextNode;
var nextConditionNodeId = wfruntime.GetClientNextConditionNodeId(nextNode);
var nextConditionNode = wfruntime.ChildNodes.Find(x => x.Id == nextConditionNodeId);
if (nextConditionNode == null)
return makerList;
6 months ago
if (nextConditionNode.AssigneeType == "role")
{
var users = Db.Queryable<SysRoleUser>().Where(x =>
6 months ago
nextConditionNode.Roles.Contains(x.RoleId.ToString()))
.Select(x => x.UserId).Distinct().ToList();
makerList = GenericHelper.ArrayToString(users, makerList);
}
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);
}
6 months ago
/// <summary>
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>Ϣ
6 months ago
/// </summary>
/// <param name="businessId">ҵ<><D2B5>ID</param>
/// <param name="businessType">ҵ<><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
/// <param name="types"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
6 months ago
/// <returns></returns>
public DataResult<List<FlowInstanceRes>> GetFlowInstances(long businessId, BusinessType? businessType, params AuditType?[] types)
6 months ago
{
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);
6 months ago
}
6 months ago
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="info"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5></param>
/// <returns></returns>
public DataResult AuditFlowInstance(FlowAuditInfo info)
{
ArgumentNullException.ThrowIfNull(info, nameof(info));
6 months ago
if (info.Instance == null)
return DataResult.Failed(<>ܻ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MultiLanguageConst.Operation_Failed);
if (info.Instance.FlowStatus == FlowStatusEnum.Approve)
6 months ago
return DataResult.Failed("<22>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", 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;
}
6 months ago
return AuditFlowCore(info.Status, info.AuditNote, info.Instance);
}
6 months ago
}