增加工作流回调地址

usertest
嵇文龙 6 months ago
parent e0471ee0c4
commit 9312405054

@ -211,6 +211,8 @@ namespace DS.WMS.Core.Fee.Method
return result > 0 ? DataResult.Successed("保存成功", records, MultiLanguageConst.DataCreateSuccess) : DataResult.Successed("操作失败!", MultiLanguageConst.Operation_Failed);
}
/// <summary>
/// 根据费用明细转换为模板明细
/// </summary>

@ -75,4 +75,10 @@ public class FlowInstance: BaseTenantModel<long>
/// </summary>
[SugarColumn(ColumnDescription = "流程内容", IsNullable = true, ColumnDataType=StaticConfig.CodeFirst_BigString)]
public string Content { get; set; }
/// <summary>
/// 回调地址
/// </summary>
[SugarColumn(ColumnDescription = "回调地址", IsNullable = true, Length = 255)]
public string CallbackURL { get; set; }
}

@ -16,12 +16,12 @@ public class FlowTemplate : BaseModel<long>
/// </summary>
public string Name { get; set; }
/// <summary>
/// 模块Id
/// </summary>
public long PermissionId { get; set; }
/// <summary>
///中文视图名;设计打印方案时,提供中文快捷按钮的视图来源
/// </summary>
@ -31,7 +31,7 @@ public class FlowTemplate : BaseModel<long>
/// <summary>
/// 流程内容
/// </summary>
[SugarColumn(ColumnDescription = "内容", IsNullable = true, ColumnDataType=StaticConfig.CodeFirst_BigString)]
[SugarColumn(ColumnDescription = "内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)]
public string Content { get; set; }
/// <summary>
@ -39,10 +39,16 @@ public class FlowTemplate : BaseModel<long>
/// </summary>
[SugarColumn(ColumnDescription = "排序")]
public int? OrderNo { get; set; } = 100;
/// <summary>
/// 状态
/// </summary>
[SugarColumn(ColumnDescription = "状态")]
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 回调地址
/// </summary>
[SugarColumn(ColumnDescription = "回调地址", IsNullable = true, Length = 255)]
public string CallbackURL { get; set; }
}

@ -44,4 +44,10 @@ public class FlowTemplateTenant : BaseTenantModel<long>
/// </summary>
[SugarColumn(ColumnDescription = "状态")]
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 回调地址
/// </summary>
[SugarColumn(ColumnDescription = "回调地址", IsNullable = true, Length = 255)]
public string CallbackURL { get; set; }
}

@ -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)

@ -115,5 +115,19 @@ namespace DS.WMS.FeeApi.Controllers
var res = _invokeService.Delete(model.Ids);
return res;
}
/// <summary>
/// 提交审核
/// </summary>
/// <param name="model">费用记录ID</param>
/// <returns></returns>
[HttpPost, Route("SubmitReview")]
public DataResult SubmitReview([FromBody] IdModel model)
{
if (model == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
}
}
}

Loading…
Cancel
Save