//
// Copyright (c) 2019 openauth.net.cn. All rights reserved.
//
// www.cnblogs.com/yubaolee
// 2019-03-05
// 流程中的连线
using System.Collections.Generic;
using Infrastructure.Extensions;
using Newtonsoft.Json.Linq;
namespace OpenAuth.App.Flow
{
///
/// 流程连线
///
public class FlowLine
{
public string id { get; set; }
public string label { get; set; }
public string type { get; set; }
public string from { get; set; }
public string to { get; set; }
public string name { get; set; }
public bool dash { get; set; }
/// 分支条件
public List Compares { get; set; }
public bool Compare(JObject frmDataJson)
{
bool result = true;
foreach (var compare in Compares)
{
bool isDecimal = decimal.TryParse(compare.Value, out decimal value);
var fieldVal = frmDataJson.GetValue(compare.FieldName.ToLower()).ToString();
if (isDecimal) //如果是数字或小数
{
decimal frmvalue = decimal.Parse(fieldVal); //表单中填写的值
switch (compare.Operation)
{
case DataCompare.Equal:
result &= compare.Value == fieldVal;
break;
case DataCompare.Larger:
result &= frmvalue > value;
break;
case DataCompare.Less:
result &= frmvalue < value;
break;
case DataCompare.LargerEqual:
result &= frmvalue >= value;
break;
case DataCompare.LessEqual:
result &= frmvalue <= value;
break;
}
}
else //如果只是字符串,只判断相等
{
result &= compare.Value == fieldVal;
}
}
return result;
}
}
///
/// 分支条件
///
public class DataCompare
{
public const string Larger = ">";
public const string Less = "<";
public const string LargerEqual = ">=";
public const string LessEqual = "<=";
public const string NotEqual = "!=";
public const string Equal = "=";
/// 操作类型比如大于/等于/小于
public string Operation { get; set; }
/// form种的字段名称
public string FieldName { get; set; }
/// 字段类型:"form":为表单中的字段,后期扩展系统表等.
public string FieldType { get; set; }
/// 比较的值
public string Value { get; set; }
}
}