|
|
|
@ -10,6 +10,9 @@ using Mapster;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Flow.Method;
|
|
|
|
|
|
|
|
|
@ -50,20 +53,20 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
{
|
|
|
|
|
if (req.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("非法请求!",MultiLanguageConst.IllegalRequest);
|
|
|
|
|
return DataResult.Failed("非法请求!", MultiLanguageConst.IllegalRequest);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.ToEnumInt() || info.FlowStatus == FlowStatusEnum.Ready.ToEnumInt()))
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("只能修改【就绪】和【撤销】状态的流程",MultiLanguageConst.FlowEditOnlyReadyAndCancel);
|
|
|
|
|
return DataResult.Failed("只能修改【就绪】和【撤销】状态的流程", MultiLanguageConst.FlowEditOnlyReadyAndCancel);
|
|
|
|
|
}
|
|
|
|
|
info = req.Adapt(info);
|
|
|
|
|
|
|
|
|
|
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
|
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -84,7 +87,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
|
|
|
|
|
if (template == null)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该流程模板已不存在,请重新设计流程!",MultiLanguageConst.FlowTemplateNotExist);
|
|
|
|
|
return DataResult.Failed("该流程模板已不存在,请重新设计流程!", MultiLanguageConst.FlowTemplateNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -104,7 +107,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
{
|
|
|
|
|
if (!wfruntime.CurrentNode.Users.Contains(user.UserId))
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流指定用户非本人!",MultiLanguageConst.FlowInstanceAssignUser);
|
|
|
|
|
return DataResult.Failed("该工作流指定用户非本人!", MultiLanguageConst.FlowInstanceAssignUser);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -115,7 +118,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
var intersectRoles = wfruntime.CurrentNode.Roles.Intersect(userRoles).ToList();
|
|
|
|
|
if (intersectRoles.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流指定角色非本人!",MultiLanguageConst.FlowInstanceAssignRole);
|
|
|
|
|
return DataResult.Failed("该工作流指定角色非本人!", MultiLanguageConst.FlowInstanceAssignRole);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -141,14 +144,14 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
+ userInfo.UserName
|
|
|
|
|
+ "创建了一个流程进程【"
|
|
|
|
|
+ flowInstance.CustomName + "】"
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
db.Insertable(history).ExecuteCommand();
|
|
|
|
|
// var info = db.Queryable<FlowInstance>().Where(x => x.Id == req.Id).First();
|
|
|
|
|
//
|
|
|
|
|
// info = req.Adapt(info);
|
|
|
|
|
//
|
|
|
|
|
// db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
|
return DataResult.Successed("创建工作流实例成功!",MultiLanguageConst.FlowInstanceCreateSuccess);
|
|
|
|
|
return DataResult.Successed("创建工作流实例成功!", MultiLanguageConst.FlowInstanceCreateSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -161,12 +164,12 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
var instance = db.Queryable<FlowInstance>().First(x => x.Id == req.Id);
|
|
|
|
|
if (instance.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流不存在!",MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流已完成!",MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instance.ActivityId = "";
|
|
|
|
@ -193,17 +196,17 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
// 设置为驼峰命名
|
|
|
|
|
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
|
|
|
|
|
};
|
|
|
|
|
instance.Content = JsonConvert.SerializeObject(wfruntime.ToFlowRoot(),Formatting.None, serializerSettings);
|
|
|
|
|
instance.Content = JsonConvert.SerializeObject(wfruntime.ToFlowRoot(), Formatting.None, serializerSettings);
|
|
|
|
|
db.Updateable(instance).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
|
|
|
|
|
var history = new FlowInstanceHistory
|
|
|
|
|
{
|
|
|
|
|
InstanceId = instance.Id,
|
|
|
|
|
Content =$"【撤销】由{ userInfo.UserName }撤销,备注:{req.Note}"
|
|
|
|
|
};
|
|
|
|
|
Content = $"【撤销】由{userInfo.UserName}撤销,备注:{req.Note}"
|
|
|
|
|
};
|
|
|
|
|
db.Insertable(history).ExecuteCommand();
|
|
|
|
|
return DataResult.Successed("撤销成功!",MultiLanguageConst.FlowInstanceCancelSuccess);
|
|
|
|
|
return DataResult.Successed("撤销成功!", MultiLanguageConst.FlowInstanceCancelSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -225,12 +228,12 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
var instance = db.Queryable<FlowInstance>().First(x => x.Id == long.Parse(id));
|
|
|
|
|
if (instance.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流不存在!",MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流已完成!",MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建运行实例
|
|
|
|
@ -251,18 +254,50 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
wfruntime.FlowInstanceId = instance.Id;
|
|
|
|
|
|
|
|
|
|
#endregion 根据运行实例改变当前节点状态
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.Updateable(instance).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//执行回调URL
|
|
|
|
|
if (!instance.CallbackURL.IsNullOrEmpty() && Uri.TryCreate(instance.CallbackURL, UriKind.RelativeOrAbsolute, out Uri? uri))
|
|
|
|
|
{
|
|
|
|
|
HttpClient http = new HttpClient();
|
|
|
|
|
http.DefaultRequestHeaders.Add("User-Agent", "X-HttpClient");
|
|
|
|
|
//请求参数设置
|
|
|
|
|
var jsonRequest = new StringContent("", Encoding.UTF8, "application/json");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
http.PostAsync(uri, jsonRequest).ContinueWith(t =>
|
|
|
|
|
{
|
|
|
|
|
var response = t.Result;
|
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
//todo:记录错误日志
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取响应内容
|
|
|
|
|
var responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//todo:记录错误日志
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
http?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
|
|
|
|
|
var history = new FlowInstanceHistory
|
|
|
|
|
{
|
|
|
|
|
InstanceId = instance.Id,
|
|
|
|
|
Content =$"【启动】由{ userInfo.UserName }启动该流程。"
|
|
|
|
|
};
|
|
|
|
|
Content = $"【启动】由{userInfo.UserName}启动该流程。"
|
|
|
|
|
};
|
|
|
|
|
db.Insertable(history).ExecuteCommand();
|
|
|
|
|
return DataResult.Successed("更新成功!",MultiLanguageConst.FlowInstanceUpdateSuccess);
|
|
|
|
|
return DataResult.Successed("更新成功!", MultiLanguageConst.FlowInstanceUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -273,12 +308,12 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
var instance = db.Queryable<FlowInstance>().First(x => x.Id == req.Id);
|
|
|
|
|
if (instance.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流不存在!",MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
return DataResult.Failed("该工作流不存在!", MultiLanguageConst.FlowInstanceNotExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (instance.FlowStatus == FlowStatusEnum.Approve.ToEnumInt())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流已完成!",MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
return DataResult.Failed("该工作流已完成!", MultiLanguageConst.FlowInstanceFinished);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tag = new FlowTag
|
|
|
|
@ -294,7 +329,7 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
|
|
|
|
|
if (wfruntime.CurrentNodeId != req.NodeId)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("该工作流审批节点与当前节点不一致!",MultiLanguageConst.FlowInstanceNodeIdConflict);
|
|
|
|
|
return DataResult.Failed("该工作流审批节点与当前节点不一致!", MultiLanguageConst.FlowInstanceNodeIdConflict);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 会签
|
|
|
|
@ -355,16 +390,16 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
wfruntime.NextNodeType = 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion 一般审核
|
|
|
|
|
var serializerSettings = new JsonSerializerSettings
|
|
|
|
|
{
|
|
|
|
|
// 设置为驼峰命名
|
|
|
|
|
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
|
|
|
|
|
};
|
|
|
|
|
instance.Content = JsonConvert.SerializeObject(wfruntime.ToFlowRoot(),Formatting.None, serializerSettings);
|
|
|
|
|
instance.Content = JsonConvert.SerializeObject(wfruntime.ToFlowRoot(), Formatting.None, serializerSettings);
|
|
|
|
|
db.Updateable(instance).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var history = new FlowInstanceHistory
|
|
|
|
|
{
|
|
|
|
|
InstanceId = instance.Id,
|
|
|
|
@ -372,10 +407,10 @@ public class FlowInstanceService : IFlowInstanceService
|
|
|
|
|
+ "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
|
|
|
|
|
+ "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
|
|
|
|
|
+ tag.Description
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
db.Insertable(history).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
return DataResult.Successed("审批成功!",MultiLanguageConst.FlowInstanceAuditSuccess);
|
|
|
|
|
|
|
|
|
|
return DataResult.Successed("审批成功!", MultiLanguageConst.FlowInstanceAuditSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataResult<FlowInstanceRes> GetFlowInstanceInfo(string id)
|
|
|
|
|