修改泛型通用接口

This commit is contained in:
2023-11-16 17:31:39 +08:00
parent 4689be2ed1
commit 9915cbd4f9
10 changed files with 211 additions and 153 deletions

View File

@@ -24,11 +24,12 @@ internal class VmQueryParser
_dataAccess = dataAccess;
_root = rootModel;
_input = input;
ParseQueryInput();
}
/// <summary>
/// 解析查询参数
/// </summary>
public void ParseQueryInput()
private void ParseQueryInput()
{
// 初始化根模型
Navigates.Clear();
@@ -263,6 +264,92 @@ internal class VmQueryParser
/// <param name="filter"></param>
/// <returns></returns>
public List<IConditionalModel> GetConditionalModels()
{
List<IConditionalModel> wheres = new();
// 处理软删除
var softDeletedProp = _root.GetSoftDeleted();
if (softDeletedProp != null && !Navigates[MAIN_ALIES].wheres.Any(a => a.code == softDeletedProp.code))
{
wheres.Add(new ConditionalModel { FieldName = MAIN_ALIES + "." + softDeletedProp.field, FieldValue = "0", ConditionalType = ConditionalType.Equal, CSharpTypeName = softDeletedProp.csType });
}
foreach (VmNavigate? nav in Navigates.Values.Where(a => (a.path == MAIN_ALIES || a.navConfig.navType == eNavigateType.OneToOne) && a.wheres.Count > 0))
{
foreach (VmWhereProp where in nav.wheres)
{
// 当条件为集合数据时
if (where.value is IEnumerable<object> arrObj)
{
object[] val = arrObj.ToArray();
string op = val[0].ToString()!;
switch (op)
{
case "><":
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = where.csType });
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = where.csType });
break;
case ">=<":
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = where.csType });
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = where.csType });
break;
case "><=":
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = where.csType });
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = where.csType });
break;
case ">=<=":
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = where.csType });
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = where.csType });
break;
case "in":
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = string.Join(',', val.Skip(1)), ConditionalType = ConditionalType.In, CSharpTypeName = where.csType });
break;
default: op = string.Empty; break;
}
}
else
{
ConditionalType conditionalType = ConditionalType.Equal;
string? value = where.value?.ToString();
if (string.IsNullOrEmpty(value))
{
continue;
}
if (value.Length >= 2)
{
string op = value[..2];
switch (op)
{
case "%%": conditionalType = ConditionalType.Like; break;
case ">>": conditionalType = ConditionalType.GreaterThan; break;
case "<<": conditionalType = ConditionalType.LessThan; break;
case ">=": conditionalType = ConditionalType.GreaterThanOrEqual; break;
case "<=": conditionalType = ConditionalType.LessThanOrEqual; break;
case "==": conditionalType = ConditionalType.Equal; break;
default: op = string.Empty; break;
}
if (!string.IsNullOrEmpty(op))
{
value = value.RemovePreFix(op);
if (value.ToLower() == "null")
{
value = null;
}
}
}
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = value, ConditionalType = conditionalType, CSharpTypeName = where.csType });
}
}
}
return wheres;
}
/// <summary>
/// 生成查询过滤条件
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
public List<IConditionalModel> FilterSofeDeleted()
{
List<IConditionalModel> wheres = new();
foreach (VmNavigate? nav in Navigates.Values.Where(a => (a.path == MAIN_ALIES || a.navConfig.navType == eNavigateType.OneToOne) && a.wheres.Count > 0))