|
|
@ -24,6 +24,8 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
protected readonly IUser user;
|
|
|
|
protected readonly IUser user;
|
|
|
|
private readonly ICommonService _commonService;
|
|
|
|
private readonly ICommonService _commonService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApiFox api;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -34,6 +36,14 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
_commonService = _serviceProvider.GetRequiredService<ICommonService>();
|
|
|
|
_commonService = _serviceProvider.GetRequiredService<ICommonService>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api = new ApiFox();
|
|
|
|
|
|
|
|
api.BeforeSend += Api_BeforeSend;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Api_BeforeSend(object? sender, BeforeSendEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
e.RequestHeaders.Add("Authorization", "Bearer " + user.GetToken());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DataResult<List<FlowInstanceRes>> GetListByPage(PageRequest request)
|
|
|
|
public DataResult<List<FlowInstanceRes>> GetListByPage(PageRequest request)
|
|
|
@ -57,7 +67,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
var info = db.Queryable<FlowInstance>().Where(x => x.Id == req.Id).First();
|
|
|
|
var info = db.Queryable<FlowInstance>().Where(x => x.Id == req.Id).First();
|
|
|
|
if (!(info.FlowStatus == FlowStatusEnum.Draft.ToEnumInt() || info.FlowStatus == FlowStatusEnum.Ready.ToEnumInt()))
|
|
|
|
if (!(info.FlowStatus == FlowStatusEnum.Draft || info.FlowStatus == FlowStatusEnum.Ready))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return DataResult.Failed("只能修改【就绪】和【撤销】状态的流程", MultiLanguageConst.FlowEditOnlyReadyAndCancel);
|
|
|
|
return DataResult.Failed("只能修改【就绪】和【撤销】状态的流程", MultiLanguageConst.FlowEditOnlyReadyAndCancel);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -129,7 +139,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
instance.ActivityName = wfruntime.CurrentNode.Name;
|
|
|
|
instance.ActivityName = wfruntime.CurrentNode.Name;
|
|
|
|
instance.PreviousId = "";
|
|
|
|
instance.PreviousId = "";
|
|
|
|
instance.MakerList = GetCurrentMakers(wfruntime);
|
|
|
|
instance.MakerList = GetCurrentMakers(wfruntime);
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Ready.ToEnumInt();
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Ready;
|
|
|
|
|
|
|
|
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
|
|
|
|
|
|
|
@ -176,7 +186,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -195,7 +205,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name;
|
|
|
|
instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name;
|
|
|
|
instance.MakerList =
|
|
|
|
instance.MakerList =
|
|
|
|
(wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1");
|
|
|
|
(wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1");
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Draft.ToEnumInt();
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Draft;
|
|
|
|
|
|
|
|
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
|
|
|
|
|
|
|
@ -242,7 +252,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -258,9 +268,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
instance.PreviousId = wfruntime.CurrentNodeId;
|
|
|
|
instance.PreviousId = wfruntime.CurrentNodeId;
|
|
|
|
instance.MakerList =
|
|
|
|
instance.MakerList =
|
|
|
|
(wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1");
|
|
|
|
(wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1");
|
|
|
|
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4
|
|
|
|
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
|
|
|
|
? FlowStatusEnum.Approve.ToEnumInt()
|
|
|
|
|
|
|
|
: FlowStatusEnum.Running.ToEnumInt());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
|
|
|
|
|
|
|
@ -293,7 +301,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -328,7 +336,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
var res = runtime.NodeConfluence(runtime.CurrentNodeId, tag);
|
|
|
|
var res = runtime.NodeConfluence(runtime.CurrentNodeId, tag);
|
|
|
|
if (res == TagState.No.ToString("D"))
|
|
|
|
if (res == TagState.No.ToString("D"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt();
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!string.IsNullOrEmpty(res))
|
|
|
|
else if (!string.IsNullOrEmpty(res))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -342,9 +350,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
instance.ActivityId = runtime.NextNodeId;
|
|
|
|
instance.ActivityId = runtime.NextNodeId;
|
|
|
|
instance.ActivityType = runtime.NextNodeType;
|
|
|
|
instance.ActivityType = runtime.NextNodeType;
|
|
|
|
instance.ActivityName = runtime.NextNode.Name;
|
|
|
|
instance.ActivityName = runtime.NextNode.Name;
|
|
|
|
instance.FlowStatus = runtime.NextNodeType == 4
|
|
|
|
instance.FlowStatus = runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running;
|
|
|
|
? FlowStatusEnum.Approve.ToEnumInt()
|
|
|
|
|
|
|
|
: FlowStatusEnum.Running.ToEnumInt();
|
|
|
|
|
|
|
|
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
|
|
|
|
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// AddTransHistory(wfruntime);
|
|
|
|
// AddTransHistory(wfruntime);
|
|
|
@ -371,13 +377,11 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
instance.ActivityType = runtime.NextNodeType;
|
|
|
|
instance.ActivityType = runtime.NextNodeType;
|
|
|
|
instance.ActivityName = runtime.NextNode.Name;
|
|
|
|
instance.ActivityName = runtime.NextNode.Name;
|
|
|
|
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
|
|
|
|
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
|
|
|
|
instance.FlowStatus = (runtime.NextNodeType == 4
|
|
|
|
instance.FlowStatus = (runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
|
|
|
|
? FlowStatusEnum.Approve.ToEnumInt()
|
|
|
|
|
|
|
|
: FlowStatusEnum.Running.ToEnumInt());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt(); //表示该节点不同意
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject; //表示该节点不同意
|
|
|
|
runtime.NextNodeId = "-1";
|
|
|
|
runtime.NextNodeId = "-1";
|
|
|
|
runtime.NextNodeType = 4;
|
|
|
|
runtime.NextNodeType = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -425,13 +429,6 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
/// <param name="instance">运行实例</param>
|
|
|
|
/// <param name="instance">运行实例</param>
|
|
|
|
protected virtual async Task RunCallbackAsync(FlowInstance instance)
|
|
|
|
protected virtual async Task RunCallbackAsync(FlowInstance instance)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!Uri.TryCreate(instance.CallbackURL, UriKind.RelativeOrAbsolute, out Uri? uri))
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpClient http = new HttpClient();
|
|
|
|
|
|
|
|
http.DefaultRequestHeaders.Add("User-Agent", "X-HttpClient");
|
|
|
|
|
|
|
|
http.DefaultRequestHeaders.Add("Authorization", "Bearer " + user.GetToken());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//请求参数设置
|
|
|
|
//请求参数设置
|
|
|
|
var callback = new FlowCallback
|
|
|
|
var callback = new FlowCallback
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -442,29 +439,13 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
FlowStatus = (FlowStatusEnum)instance.FlowStatus,
|
|
|
|
FlowStatus = (FlowStatusEnum)instance.FlowStatus,
|
|
|
|
RejectReason = instance.Note
|
|
|
|
RejectReason = instance.Note
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var jsonRequest = new StringContent(JsonConvert.SerializeObject(callback), Encoding.UTF8, "application/json");
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var response = await http.PostAsync(uri, jsonRequest);
|
|
|
|
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await new HttpRequestException("回调请求失败", null, response.StatusCode).LogAsync(db);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新回调执行标识
|
|
|
|
await api.PostAsync<DataResult>(instance.CallbackURL, callback);
|
|
|
|
var id = instance.Id;
|
|
|
|
|
|
|
|
db.Updateable<FlowInstance>().SetColumns(it => new FlowInstance { IsCallbackExecuted = true })
|
|
|
|
//更新回调执行标识
|
|
|
|
.Where(it => it.Id == id).ExecuteCommand();
|
|
|
|
var id = instance.Id;
|
|
|
|
}
|
|
|
|
await db.Updateable<FlowInstance>().SetColumns(it => new FlowInstance { IsCallbackExecuted = true })
|
|
|
|
catch (Exception ex)
|
|
|
|
.Where(it => it.Id == id).ExecuteCommandAsync();
|
|
|
|
{
|
|
|
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
http?.Dispose();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual FlowRuntime CreateRuntimeService(FlowInstance instance)
|
|
|
|
protected virtual FlowRuntime CreateRuntimeService(FlowInstance instance)
|
|
|
|