回调地址移动至租户端模板表

usertest
嵇文龙 4 months ago
parent b83efab256
commit 6ef97c4ffc

@ -230,7 +230,7 @@ namespace DS.WMS.Core.Application.Dtos
/// </summary>
public string? LoadPort { get; set; }
// <summary>
/// <summary>
/// 卸货港
/// </summary>
public string? DischargePort { get; set; }

@ -18,7 +18,7 @@ public class FlowInstanceAuditReq
public string NodeId { get; set; }
/// <summary>
/// 审核状态 1 同意 2 不同意
/// 审核状态1 同意 2 不同意
/// </summary>
public int Status { get; set; }
@ -28,6 +28,9 @@ public class FlowInstanceAuditReq
public string AuditNote { get; set; } = "";
}
/// <summary>
/// 审核信息
/// </summary>
public class FlowAuditInfo
{
public FlowInstance Instance { get; set; }

@ -27,7 +27,14 @@ public class FlowInstance : BaseTenantModel<long>
/// 模板Id
/// </summary>
[Description("模板Id")]
public long? TemplateId { get; set; }
public long TemplateId { get; set; }
/// <summary>
/// 引用模板
/// </summary>
[Navigate(NavigateType.OneToOne, nameof(TemplateId))]
public FlowTemplateTenant? Template { get; set; }
/// <summary>
/// 客户自定义名称
/// </summary>
@ -88,13 +95,13 @@ public class FlowInstance : BaseTenantModel<long>
/// <summary>
/// 执行人变更回调地址
/// </summary>
[SugarColumn(ColumnDescription = "执行人变更回调地址", IsNullable = true, Length = 255)]
public string? MakerNotifyURL { get; set; }
[SugarColumn(IsIgnore = true)]
public string? MarkerNotifyURL { get; set; }
/// <summary>
/// 审批完成回调地址
/// </summary>
[SugarColumn(ColumnDescription = "审批完成回调地址", IsNullable = true, Length = 255)]
[SugarColumn(IsIgnore = true)]
public string? CallbackURL { get; set; }
/// <summary>

@ -49,7 +49,7 @@ public class FlowTemplateTenant : BaseTenantModel<long>
/// 执行人变更回调地址
/// </summary>
[SugarColumn(ColumnDescription = "执行人变更回调地址", IsNullable = true, Length = 255)]
public string? MakerNotifyURL { get; set; }
public string? MarkerNotifyURL { get; set; }
/// <summary>
/// 回调地址

@ -1,5 +1,5 @@
using DS.Module.Core;
using DS.Module.SqlSugar;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Flow.Interface;
@ -7,7 +7,6 @@ using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
using Mapster;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
namespace DS.WMS.Core.Flow.Method;
@ -16,11 +15,8 @@ namespace DS.WMS.Core.Flow.Method;
/// </summary>
public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanceService
{
readonly ISaasDbService saasService;
public ClientFlowInstanceService(IServiceProvider serviceProvider) : base(serviceProvider)
{
saasService = serviceProvider.GetRequiredService<ISaasDbService>();
}
protected override FlowInstance? BuildInstance(CreateFlowInstanceReq req)
@ -39,7 +35,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
PermissionId = template.PermissionId,
ColumnView = template.ColumnView,
Content = template.Content,
MakerNotifyURL = template.MakerNotifyURL,
MarkerNotifyURL = template.MarkerNotifyURL,
CallbackURL = template.CallbackURL,
Type = template.AuditType
};
@ -52,7 +48,10 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
var nextNode = wfruntime.NextNode;
var nextConditionNodeId = wfruntime.GetClientNextConditionNodeId(nextNode);
var nextConditionNode = wfruntime.ChildNodes.First(x => x.Id == nextConditionNodeId);
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 =>
@ -70,7 +69,7 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
protected override FlowRuntime CreateRuntimeService(FlowInstance instance)
{
return new FlowRuntime(instance, Db, saasService, User);
return new FlowRuntime(instance, Db, TenantDb, User);
}
/// <summary>
@ -110,12 +109,21 @@ public class ClientFlowInstanceService : FlowInstanceService, IClientFlowInstanc
/// <returns></returns>
public DataResult AuditFlowInstance(FlowAuditInfo info)
{
if (info == null)
return DataResult.Failed("¸Ã¹¤×÷Á÷²»´æÔÚ!", MultiLanguageConst.FlowInstanceNotExist);
ArgumentNullException.ThrowIfNull(info, nameof(info));
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);
}
}

@ -1,12 +1,10 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Flow.Interface;
using DS.WMS.Core.Sys.Entity;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using SqlSugar;
@ -15,13 +13,11 @@ namespace DS.WMS.Core.Flow.Method;
/// <summary>
/// 工作流服务
/// </summary>
public class FlowInstanceService : IFlowInstanceService
public class FlowInstanceService : ServiceBase, IFlowInstanceService
{
static readonly ApiFox api;
protected readonly ISqlSugarClient Db;
protected readonly IUser User;
static FlowInstanceService()
static FlowInstanceService()
{
api = new ApiFox();
}
@ -30,10 +26,8 @@ public class FlowInstanceService : IFlowInstanceService
/// 初始化
/// </summary>
/// <param name="serviceProvider"></param>
public FlowInstanceService(IServiceProvider serviceProvider)
public FlowInstanceService(IServiceProvider serviceProvider) : base(serviceProvider)
{
Db = serviceProvider.GetRequiredService<ISqlSugarClient>();
User = serviceProvider.GetRequiredService<IUser>();
}
/// <summary>
@ -106,7 +100,7 @@ public class FlowInstanceService : IFlowInstanceService
PermissionId = template.PermissionId,
ColumnView = template.ColumnView,
Content = template.Content,
MakerNotifyURL = template.MakerNotifyURL,
MarkerNotifyURL = template.MakerNotifyURL,
CallbackURL = template.CallbackURL,
Type = template.AuditType
};
@ -304,15 +298,20 @@ public class FlowInstanceService : IFlowInstanceService
return DataResult.Successed("更新成功!", instance, MultiLanguageConst.FlowInstanceUpdateSuccess);
}
/// <summary>
/// 审核工作流实例
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult AuditFlowInstance(FlowInstanceAuditReq req)
{
var instance = Db.Queryable<FlowInstance>().First(x => x.Id == req.Id);
var instance = GetFlowInstance(req.Id);
if (instance.IsNull())
{
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
}
if (instance.FlowStatus == FlowStatusEnum.Approve)
else if (instance.FlowStatus == FlowStatusEnum.Approve)
{
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
}
@ -320,6 +319,13 @@ public class FlowInstanceService : IFlowInstanceService
return AuditFlowCore(req.Status, req.AuditNote, instance);
}
/// <summary>
/// 工作流实例审核实现
/// </summary>
/// <param name="status"></param>
/// <param name="auditNote"></param>
/// <param name="instance"></param>
/// <returns></returns>
protected virtual DataResult AuditFlowCore(int status, string auditNote, FlowInstance instance)
{
ArgumentNullException.ThrowIfNull(instance, nameof(instance));
@ -376,7 +382,7 @@ public class FlowInstanceService : IFlowInstanceService
var markers = GetNextMarkers(instance);
//获取会签下一执行人,进行通知
if (markers?.Length > 0 && !instance.MakerNotifyURL.IsNullOrEmpty())
if (markers?.Length > 0 && !instance.MarkerNotifyURL.IsNullOrEmpty() && markers?.Length > 0)
{
Task.Factory.StartNew(() => NotifyMakerChangedAsync(instance, [long.Parse(markers[0])]));
}
@ -467,7 +473,7 @@ public class FlowInstanceService : IFlowInstanceService
api.DefaultHeaders.Remove("Authorization");
api.DefaultHeaders.Add("Authorization", "Bearer " + User.GetToken());
await api.PostAsync<DataResult>(instance.MakerNotifyURL, callback);
await api.PostAsync<DataResult>(instance.MarkerNotifyURL, callback);
}
/// <summary>
@ -505,6 +511,34 @@ public class FlowInstanceService : IFlowInstanceService
}
}
/// <summary>
/// 获取运行实例信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public FlowInstance GetFlowInstance(long id)
{
return Db.Queryable<FlowInstance>().Where(x => x.Id == id)
.InnerJoin<FlowTemplateTenant>((f, ft) => f.TemplateId == ft.Id).Select((f, ft) => new FlowInstance
{
ActivityId = f.ActivityId,
ActivityName = f.ActivityName,
ActivityType = f.ActivityType,
BusinessId = f.BusinessId,
BusinessType = f.BusinessType,
CallbackURL = ft.CallbackURL,
MarkerNotifyURL = ft.MarkerNotifyURL,
ColumnView = f.ColumnView,
Content = f.Content,
FlowStatus = f.FlowStatus,
Id = f.Id,
MakerList = f.MakerList,
PreviousId = f.PreviousId,
PermissionId = f.PermissionId,
Type = f.Type
}).First();
}
protected virtual FlowRuntime CreateRuntimeService(FlowInstance instance)
{
return new FlowRuntime(instance, Db, null, User);

@ -21,12 +21,12 @@ public class FlowRuntime
/// <summary>
/// 构造函数
/// </summary>
public FlowRuntime(FlowInstance instance, ISqlSugarClient _db, ISaasDbService saasService, IUser user)
public FlowRuntime(FlowInstance instance, ISqlSugarClient _db, ISqlSugarClient tenantDb, IUser user)
{
db = _db;
BusinessId = instance.BusinessId;
ColumnView = instance.ColumnView;
this.saasService = saasService;
this.tenantDb = tenantDb;
this.user = user;
InitNodes(instance.Content); //获取工作流模板内容的json对象;
@ -60,7 +60,7 @@ public class FlowRuntime
public long BusinessId { get; set; }
public string ColumnView { get; set; }
public ISqlSugarClient db { get; set; }
public ISaasDbService saasService { get; set; }
public ISqlSugarClient tenantDb { get; set; }
public IUser user { get; set; }
/// <summary>
@ -178,10 +178,13 @@ public class FlowRuntime
private List<FlowChild> GetFlowConditions(FlowChild parent)
{
var conditionNodes = new List<FlowChild>();
foreach (var item in parent.Children)
if (parent.Children != null)
{
conditionNodes.Add(item);
}
foreach (var item in parent.Children)
{
conditionNodes.Add(item);
}
}
return conditionNodes;
}
@ -400,7 +403,7 @@ public class FlowRuntime
return ChildNodes.Where(x => x.Pid == conditionId).First().Id;
}
public string GetClientNextConditionNodeId(FlowChild parent)
public string? GetClientNextConditionNodeId(FlowChild parent)
{
var conditionNodes = GetFlowConditions(parent);
var conditionId = string.Empty;
@ -563,8 +566,7 @@ public class FlowRuntime
JsonConvert.SerializeObject(conditionalCollections));
// var info = db.Queryable<SysUser>().Where(x => x.Id == BusinessId).Where(conditionalModels)
// .First();
var tentDb = saasService.GetBizDbScopeById(user.TenantId);
var info = tentDb.Queryable<object>().AS(ColumnView).Where("Id=@Id", new { Id = BusinessId }).Where(conditionalModels).First();
var info = tenantDb.Queryable<object>().AS(ColumnView).Where("Id=@Id", new { Id = BusinessId }).Where(conditionalModels).First();
if (info.IsNotNull())
{
conditionId = conditionNodes[i].Id;
@ -572,7 +574,7 @@ public class FlowRuntime
}
}
return ChildNodes.Where(x => x.Pid == conditionId).First().Id;
return ChildNodes?.Find(x => x.Pid == conditionId)?.Id;
}
/// <summary>

@ -0,0 +1,59 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using Masuit.Tools.Systems;
using SqlSugar;
namespace DS.WMS.Core.Op.Dtos.TaskInteraction
{
/// <summary>
/// 关联任务DTO
/// </summary>
public class BusinessTaskDto
{
/// <summary>
/// 任务类型
/// </summary>
public TaskBaseTypeEnum TaskType { get; set; }
/// <summary>
/// 任务类型名称
/// </summary>
public string TaskTypeName => TaskType.GetDescription();
/// <summary>
/// 任务状态
/// </summary>
public TaskStatusEnum TaskStatus { get; set; }
/// <summary>
/// 下一任务类型
/// </summary>
public TaskBaseTypeEnum? NextType { get; set; }
/// <summary>
/// 下一任务类型名称
/// </summary>
public string NextTypeName => NextType.GetDescription();
/// <summary>
/// 接收人ID列表
/// </summary>
public string? RecvUsers { get; set; }
/// <summary>
/// 获取接收人用户ID列表
/// </summary>
public long[] RecvUserIdArray => RecvUsers.IsNullOrEmpty() ? [] :
RecvUsers.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
/// <summary>
/// 创建人ID
/// </summary>
public long CreateBy { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
}
}

@ -2,6 +2,7 @@
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity;
namespace DS.WMS.Core.Op.Interface.TaskInteraction
{
@ -10,6 +11,14 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction
/// </summary>
public interface ITaskService
{
/// <summary>
/// 获取关联业务的所有任务
/// </summary>
/// <param name="id">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
Task<DataResult<List<BusinessTaskDto>>> GetTasks(long id, BusinessType businessType);
/// <summary>
/// 创建关联任务
/// </summary>

@ -1,5 +1,4 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.Core.Helpers;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Flow.Dtos;
@ -13,6 +12,7 @@ using DS.WMS.Core.Op.Interface.TaskInteraction;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.TaskPlat.Dtos;
using DS.WMS.Core.TaskPlat.Interface;
using Masuit.Tools;
using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
@ -40,7 +40,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// 初始化
/// </summary>
/// <param name="provider"></param>
protected TaskService(IServiceProvider provider) : base(provider)
public TaskService(IServiceProvider provider) : base(provider)
{
ManagerService = provider.GetRequiredService<ITaskManageService>();
FlowService = new Lazy<IClientFlowInstanceService>(provider.GetRequiredService<IClientFlowInstanceService>());
@ -63,6 +63,22 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
return (TaskBaseTypeEnum)(currentTypeVal + 1);
}
/// <summary>
/// 获取关联业务的所有任务
/// </summary>
/// <param name="id">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
public async Task<DataResult<List<BusinessTaskDto>>> GetTasks(long id, BusinessType businessType)
{
var list = await TenantDb.Queryable<BusinessTask>().Where(
x => x.BusinessId == id && x.BusinessType == businessType).Select<BusinessTaskDto>().ToListAsync();
var result = DataResult<List<BusinessTaskDto>>.Success(list);
result.Count = list.Count;
return result;
}
/// <summary>
/// 确保任务交互模块已授权
/// </summary>
@ -110,7 +126,9 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
.Where(x => x.BusinessId == request.BusinessId &&
x.BusinessType == request.BusinessType && x.TaskType == TaskBaseTypeEnum.WAIT_ORDER_AUDIT)
.ExecuteCommandAsync();
}
}
return result;
}
@ -142,12 +160,21 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
if (task.FlowId == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.FlowNotFound));
return FlowService.Value.AuditFlowInstance(new FlowAuditInfo
var result = FlowService.Value.AuditFlowInstance(new FlowAuditInfo
{
AuditNote = request.Remark,
Status = request.Result,
Instance = await Db.Queryable<FlowInstance>().FirstAsync(x => x.Id == task.FlowId.Value)
});
var flow = await Db.Queryable<FlowInstance>().Where(x => x.Id == task.FlowId.Value).Select(x => new
{
x.FlowStatus,
x.MakerList,
}).FirstAsync();
result.Data = (string.IsNullOrEmpty(flow.MakerList) || flow.MakerList == "-1") && flow.FlowStatus == FlowStatusEnum.Approve;
return result;
}
/// <summary>

@ -3,6 +3,7 @@ using DS.Module.Core;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using Microsoft.AspNetCore.Mvc;
@ -24,6 +25,18 @@ namespace DS.WMS.OpApi.Controllers
taskService = service;
}
/// <summary>
/// 获取指定业务的关联任务
/// </summary>
/// <param name="businessId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
[HttpGet, Route("GetList")]
public async Task<DataResult<List<BusinessTaskDto>>> GetListAsync([FromQuery]long businessId, [FromQuery] BusinessType businessType)
{
return await taskService.GetTasks(businessId, businessType);
}
/// <summary>
/// 创建关联任务
/// </summary>

Loading…
Cancel
Save