支持审批流程中的分支网关和节点触发条件
This commit is contained in:
@@ -6,7 +6,9 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using YLErp.BLL.Eod;
|
||||
using YLErp.DBModels;
|
||||
using YLErp.Helpers;
|
||||
using YLErp.Model.Enum;
|
||||
using YLErp.Modules.TradeModule;
|
||||
|
||||
namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
@@ -43,7 +45,9 @@ namespace YLErp.Modules.SystemModule
|
||||
approvalGroupId = item.approvalGroupId,
|
||||
node = item.node,
|
||||
parentNode = item.parentNode,
|
||||
approvalCondition = item.approvalCondition
|
||||
approvalCondition = item.approvalCondition,
|
||||
conditionConfig = item.conditionConfig,
|
||||
triggerCondition = item.triggerCondition
|
||||
}).ToList();
|
||||
|
||||
DbContext.approvalprocess.AddRange(list);
|
||||
@@ -81,6 +85,21 @@ namespace YLErp.Modules.SystemModule
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == ProcessCategoryConst.Close) // 需求②:了结/平仓/行权审批流程
|
||||
{
|
||||
if (data != null && data.Count > 0)
|
||||
{
|
||||
ChangeTradeProcess(data, delList);
|
||||
}
|
||||
else
|
||||
{
|
||||
var trade = DbContext.trade.Where(x => x.ValidState == "Valid" && (x.TradeStatus == ConsTrade.平仓待复核 || x.TradeStatus == ConsTrade.行权待复核 || x.TradeStatus == ConsTrade.互换待复核)).ToList();
|
||||
if (trade != null && trade.Count > 0)
|
||||
{
|
||||
throw new ServiceException("有交易在审批中,不能删除审批流程!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == "CreditProcess")
|
||||
{
|
||||
if (data != null && data.Count == 0)
|
||||
@@ -578,7 +597,8 @@ namespace YLErp.Modules.SystemModule
|
||||
{
|
||||
var roles = UserBLL.GetRolesByUserId(userId).Select(o => o.Id);
|
||||
var groupId = UserBLL.GetApprovalProcessGroup(userId);
|
||||
var tradeProcess = TradeProcess();
|
||||
// 需求②:按交易状态推断开仓/了结流程。
|
||||
var tradeProcess = TradeProcessByCategory(trade);
|
||||
bool approvalBranch = tradeProcess.Any(x => x.approvalGroupId != 0);//审批流程有分支情况
|
||||
trade.ProcessOrderBranch = 0;
|
||||
if (trade.ProcessOrderId <= 0)
|
||||
@@ -612,6 +632,16 @@ namespace YLErp.Modules.SystemModule
|
||||
trade.ProcessOrderId = ProcessTradeLog.审批中;
|
||||
}
|
||||
}
|
||||
// 需求①:开仓交易首次进入审批时,应用触发条件——跳过起始就不满足触发条件的节点。
|
||||
// 若所有节点均不满足 → 直接审批通过,无需审核。
|
||||
if (tradeProcess.Count > 0)
|
||||
{
|
||||
ApplyTriggerOnStart(tradeProcess, trade, userId);
|
||||
if (trade.ProcessOrderId == ProcessTradeLog.审批通过)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// 如果是审批组
|
||||
var orderIdCount = tradeProcess.Where(x => x.order == trade.ProcessOrderId);//判断是否有分支
|
||||
int processOrderNode = orderIdCount.Count() > 1 ? trade.ProcessOrderBranch : 0;
|
||||
@@ -658,6 +688,65 @@ namespace YLErp.Modules.SystemModule
|
||||
return -2;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 需求①:开仓交易首次进入审批流程时,从起始节点应用触发条件。
|
||||
/// <para>跳过起始就不满足触发条件的节点;若所有节点均不满足 → 直接审批通过。</para>
|
||||
/// </summary>
|
||||
private void ApplyTriggerOnStart(List<approvalprocess> tradeProcess, trade trade, int userId)
|
||||
{
|
||||
// 取当前起点节点(主干 node=0)
|
||||
var start = tradeProcess.FirstOrDefault(x => x.order == trade.ProcessOrderId && x.node == 0);
|
||||
if (start == null)
|
||||
{
|
||||
start = tradeProcess.FirstOrDefault(x => x.order >= trade.ProcessOrderId && x.node == 0);
|
||||
}
|
||||
if (start == null) return;
|
||||
|
||||
// 构建求值上下文(开仓场景无 trade_cash,CurrentNotional 不设)
|
||||
var ctx = new ConditionContext
|
||||
{
|
||||
UserId = userId,
|
||||
Trade = trade,
|
||||
ProcessCategory = ProcessCategoryConst.Resolve(trade),
|
||||
InitGroupId = UserBLL.GetApprovalProcessGroup(userId)
|
||||
};
|
||||
|
||||
// ===== 临时诊断日志(定位触发条件是否生效,验证后删除)=====
|
||||
try
|
||||
{
|
||||
var tn = trade?.TradeNumber ?? "?";
|
||||
var initNotional = trade?.OriginalStockEqvNotional ?? 0;
|
||||
System.Diagnostics.Debug.WriteLine($"[ApplyTriggerOnStart] trade={tn}, 期初名义本金={initNotional}, 起点order={start.order}, 起点triggerCondition={start.triggerCondition ?? "(空)"}, 节点数={tradeProcess.Count}");
|
||||
foreach (var n in tradeProcess)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($" 节点 order={n.order}, node={n.node}, roleId={n.roleId}, triggerCondition={n.triggerCondition ?? "(空)"}");
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
var target = ConditionEvaluator.FindFirstTriggeredNode(tradeProcess, start, ctx);
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"[ApplyTriggerOnStart] FindFirstTriggeredNode 结果 = {(target == null ? "null(全不满足,直接通过)" : "order=" + target.order)}");
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
// 所有节点都不满足触发条件 → 直接审批通过
|
||||
trade.ProcessOrderId = ProcessTradeLog.审批通过;
|
||||
trade.CheckTradeUpdate = Convert.ToInt32(TradeCheckEnum.StatusOfNew);
|
||||
trade.ProcessOptDate = DateTime.Now;
|
||||
trade.ProcessStatus = ProcessTradeStatus.通过审批.ToString();
|
||||
return;
|
||||
}
|
||||
if (target.order != trade.ProcessOrderId)
|
||||
{
|
||||
trade.ProcessOrderId = target.order;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有交易审批节点
|
||||
/// </summary>
|
||||
@@ -668,6 +757,21 @@ namespace YLErp.Modules.SystemModule
|
||||
return tradeOrders;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按交易推断流程类别(开仓/了结)获取审批节点(需求②)。
|
||||
/// <para>了结类优先取 CloseProcess;未配置则回退 TradeProcess。</para>
|
||||
/// </summary>
|
||||
public List<approvalprocess> TradeProcessByCategory(trade td)
|
||||
{
|
||||
var category = ProcessCategoryConst.Resolve(td);
|
||||
var orders = DbContext.approvalprocess.Where(t => t.processType == category).OrderBy(o => o.order).ToList();
|
||||
if (category == ProcessCategoryConst.Close && orders.Count == 0)
|
||||
{
|
||||
return TradeProcess();
|
||||
}
|
||||
return orders;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -686,6 +790,12 @@ namespace YLErp.Modules.SystemModule
|
||||
public int node { get; set; }
|
||||
public int parentNode { get; set; }
|
||||
public int approvalCondition { get; set; }
|
||||
|
||||
/// <summary>分支网关条件(JSON),需求①③共用。为空则回退旧 approvalGroupId/approvalCondition 二元判断。</summary>
|
||||
public string conditionConfig { get; set; }
|
||||
|
||||
/// <summary>节点触发条件(JSON),需求①:满足才进入该审批节点,不满足则跳过。</summary>
|
||||
public string triggerCondition { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 审批流程修改节点
|
||||
|
||||
Reference in New Issue
Block a user