using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
namespace GDZZ.FlowCenter.Entity;
///
/// 流程连线
///
public class FlowLine
{
///
/// 线Id
///
public string id { get; set; }
///
/// 显示
///
public string label { get; set; }
///
/// 类型
///
public string type { get; set; }
///
/// 源头节点
///
public string sourceId { get; set; }
///
/// 目标节点
///
public string targetId { get; set; }
///
/// 名称
///
public string name { get; set; }
///
/// 连接样式
///
public LineStyle cls { get; set; }
/// 分支条件
public List Compares { get; set; }
///
/// 连线比较
///
///
///
public bool Compare(JObject frmDataJson)
{
bool result = true;
foreach (var compare in Compares)
{
compare.FieldName = compare.FieldName.ToLower();
compare.Value = compare.Value.ToLower();
decimal value=0; //参考值
decimal frmvalue=0; //表单中填写的值
if (compare.Operation!= DataCompare.Equal&& compare.Operation != DataCompare.NotEqual)
{
value = decimal.Parse(compare.Value);
frmvalue = decimal.Parse(frmDataJson.GetValue(compare.FieldName.ToLower()).ToString()); //表单中填写的值
}
bool res = false;
if (compare.Condition=="and")
{
switch (compare.Operation)
{
case DataCompare.Equal:
result &= compare.Value == frmDataJson.GetValue(compare.FieldName).ToString();
break;
case DataCompare.NotEqual:
result &= compare.Value != frmDataJson.GetValue(compare.FieldName).ToString();
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;
case DataCompare.In:
if (compare.FieldName == "申请人" || compare.FieldName == "所属部门")
{
var arr = compare.Value.Split(',');
foreach (var item in frmDataJson.GetValue(compare.FieldName).ToString().Split(','))
{
if (arr.Contains(item))
{
res = true;
break;
}
}
result &= res;
break;
}
else
{
var arr = compare.Value.Split(',');
if (arr.Contains(frmvalue.ToString()))
{
res = true;
break;
}
result &= res;
break;
}
case DataCompare.NotIn:
if (compare.FieldName == "申请人" || compare.FieldName == "所属部门")
{
var arr = compare.Value.Split(',');
foreach (var item in frmDataJson.GetValue(compare.FieldName).ToString().Split(','))
{
if (arr.Contains(item))
{
res = false;
break;
}
}
result &= res;
break;
}
else
{
var arr = compare.Value.Split(',');
if (arr.Contains(frmvalue.ToString()))
{
res = false;
break;
}
result &= res;
break;
}
}
}
else
{
switch (compare.Operation)
{
case DataCompare.Equal:
if (compare.FieldName == "申请人" || compare.FieldName == "所属部门")
{
var arr = compare.Value.Split(',');
foreach (var item in frmDataJson.GetValue(compare.FieldName).ToString().Split(','))
{
if (arr.Contains(item))
{
res = true;
break;
}
}
result |= res;
break;
}
result |= compare.Value == frmDataJson.GetValue(compare.FieldName).ToString();
break;
case DataCompare.NotEqual:
if (compare.FieldName == "申请人" || compare.FieldName == "所属部门")
{
var arr = compare.Value.Split(',');
foreach (var item in frmDataJson.GetValue(compare.FieldName).ToString().Split(','))
{
if (arr.Contains(item))
{
res = false;
break;
}
}
result |= res;
break;
}
result |= compare.Value != frmDataJson.GetValue(compare.FieldName).ToString();
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;
case DataCompare.In:
if (compare.FieldName == "申请人" || compare.FieldName == "所属部门")
{
var arr = compare.Value.Split(',');
foreach (var item in frmDataJson.GetValue(compare.FieldName).ToString().Split(','))
{
if (arr.Contains(item))
{
res = true;
break;
}
}
result |= res;
break;
}
else
{
var arr = compare.Value.Split(',');
if (arr.Contains(frmvalue.ToString()))
{
res = true;
}
result |= res;
break;
}
case DataCompare.NotIn:
if (compare.FieldName == "申请人" || compare.FieldName == "所属部门")
{
var arr = compare.Value.Split(',');
foreach (var item in frmDataJson.GetValue(compare.FieldName).ToString().Split(','))
{
if (arr.Contains(item))
{
res = false;
break;
}
}
result |= res;
break;
}
else
{
var arr = compare.Value.Split(',');
if (arr.Contains(frmvalue.ToString()))
{
res = false;
}
result |= res;
break;
}
}
}
}
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 const string In = "in";
public const string NotIn = "not in";
/// 操作类型比如大于/等于/小于
public string Operation { get; set; }
/// form种的字段名称
public string FieldName { get; set; }
/// 字段类型:"form":为表单中的字段,后期扩展系统表等.
public string FieldType { get; set; }
/// 实际的值
public string Value { get; set; }
///
/// 实际值的显示值
///
public string ValueName { get; set; }
///
/// 显示值
///
public string Name { get; set; }
///
/// 条件关系
///
public string Condition { get; set; }
}
///
/// 连接样式
///
public class LineStyle
{
///
/// 连接类型
///
public string linkType { get; set; }
///
/// 连接颜色
///
public string linkColor { get; set; }
///
///
///
public int linkThickness { get; set; }
}