|
|
|
@ -24,6 +24,8 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
protected readonly IUser user;
|
|
|
|
|
private readonly ICommonService _commonService;
|
|
|
|
|
|
|
|
|
|
private ApiFox api;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
@ -34,6 +36,14 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
_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)
|
|
|
|
@ -57,7 +67,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
@ -129,7 +139,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
instance.ActivityName = wfruntime.CurrentNode.Name;
|
|
|
|
|
instance.PreviousId = "";
|
|
|
|
|
instance.MakerList = GetCurrentMakers(wfruntime);
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Ready.ToEnumInt();
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Ready;
|
|
|
|
|
|
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
|
|
|
|
|
@ -176,7 +186,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
}
|
|
|
|
@ -195,7 +205,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name;
|
|
|
|
|
instance.MakerList =
|
|
|
|
|
(wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1");
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Draft.ToEnumInt();
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Draft;
|
|
|
|
|
|
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
|
|
|
|
|
@ -242,7 +252,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
}
|
|
|
|
@ -258,9 +268,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
instance.PreviousId = wfruntime.CurrentNodeId;
|
|
|
|
|
instance.MakerList =
|
|
|
|
|
(wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1");
|
|
|
|
|
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4
|
|
|
|
|
? FlowStatusEnum.Approve.ToEnumInt()
|
|
|
|
|
: FlowStatusEnum.Running.ToEnumInt());
|
|
|
|
|
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
|
|
|
|
|
|
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
|
|
|
|
|
@ -293,7 +301,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
}
|
|
|
|
@ -328,7 +336,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
var res = runtime.NodeConfluence(runtime.CurrentNodeId, tag);
|
|
|
|
|
if (res == TagState.No.ToString("D"))
|
|
|
|
|
{
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt();
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject;
|
|
|
|
|
}
|
|
|
|
|
else if (!string.IsNullOrEmpty(res))
|
|
|
|
|
{
|
|
|
|
@ -342,9 +350,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
instance.ActivityId = runtime.NextNodeId;
|
|
|
|
|
instance.ActivityType = runtime.NextNodeType;
|
|
|
|
|
instance.ActivityName = runtime.NextNode.Name;
|
|
|
|
|
instance.FlowStatus = runtime.NextNodeType == 4
|
|
|
|
|
? FlowStatusEnum.Approve.ToEnumInt()
|
|
|
|
|
: FlowStatusEnum.Running.ToEnumInt();
|
|
|
|
|
instance.FlowStatus = runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running;
|
|
|
|
|
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
|
|
|
|
|
}
|
|
|
|
|
// AddTransHistory(wfruntime);
|
|
|
|
@ -371,13 +377,11 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
instance.ActivityType = runtime.NextNodeType;
|
|
|
|
|
instance.ActivityName = runtime.NextNode.Name;
|
|
|
|
|
instance.MakerList = runtime.NextNodeType == 4 ? "1" : GetNextMakers(runtime);
|
|
|
|
|
instance.FlowStatus = (runtime.NextNodeType == 4
|
|
|
|
|
? FlowStatusEnum.Approve.ToEnumInt()
|
|
|
|
|
: FlowStatusEnum.Running.ToEnumInt());
|
|
|
|
|
instance.FlowStatus = (runtime.NextNodeType == 4 ? FlowStatusEnum.Approve : FlowStatusEnum.Running);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject.ToEnumInt(); //表示该节点不同意
|
|
|
|
|
instance.FlowStatus = FlowStatusEnum.Reject; //表示该节点不同意
|
|
|
|
|
runtime.NextNodeId = "-1";
|
|
|
|
|
runtime.NextNodeType = 4;
|
|
|
|
|
}
|
|
|
|
@ -425,13 +429,6 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
/// <param name="instance">运行实例</param>
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
@ -442,29 +439,13 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
FlowStatus = (FlowStatusEnum)instance.FlowStatus,
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
await ex.LogAsync(db);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
http?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
await db.Updateable<FlowInstance>().SetColumns(it => new FlowInstance { IsCallbackExecuted = true })
|
|
|
|
|
.Where(it => it.Id == id).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual FlowRuntime CreateRuntimeService(FlowInstance instance)
|
|
|
|
|