feat(FreeSqlExtensions): support MultiFilter component (#3751)

* fix: 重构逻辑修复条件不正确问题

* chore: bump version 8.1.2

* refactor: 精简代码
This commit is contained in:
Argo Zhang 2024-06-28 19:10:29 +08:00 committed by GitHub
parent 659b8cfa43
commit 5223e8ac6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 34 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>8.1.1</Version>
<Version>8.1.2</Version>
</PropertyGroup>
<PropertyGroup>

View File

@ -13,7 +13,7 @@ namespace BootstrapBlazor.DataAccess.FreeSql;
public static class FreeSqlExtensions
{
/// <summary>
///
/// QueryPageOptions 转化为 FreeSql ORM DynamicFilterInfo 类型扩展方法
/// </summary>
/// <param name="option"></param>
/// <returns></returns>
@ -51,41 +51,26 @@ public static class FreeSqlExtensions
return ret;
}
private static DynamicFilterInfo ToDynamicFilter(this IFilterAction filter)
/// <summary>
/// IFilterAction 转化为 DynamicFilterInfo 扩展方法
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
public static DynamicFilterInfo ToDynamicFilter(this IFilterAction filter)
{
var actions = filter.GetFilterConditions();
var item = new DynamicFilterInfo();
if (actions.Filters != null)
{
// TableFilter 最多仅两个条件
if (actions.Filters.Count == 2)
{
item.Logic = actions.FilterLogic.ToDynamicFilterLogic();
item.Filters = actions.Filters.Select(i => new DynamicFilterInfo()
{
Field = i.FieldKey,
Value = i.FieldValue,
Operator = i.FilterAction.ToDynamicFilterOperator()
}).ToList();
}
else
{
var c = actions.Filters.First();
item.Field = c.FieldKey;
item.Value = c.FieldValue;
item.Operator = c.FilterAction.ToDynamicFilterOperator();
}
}
else
{
item.Field = actions.FieldKey;
item.Value = actions.FieldValue;
item.Operator = actions.FilterAction.ToDynamicFilterOperator();
}
return item;
var filterKeyValueAction = filter.GetFilterConditions();
return filterKeyValueAction.ParseDynamicFilterInfo();
}
private static DynamicFilterInfo ParseDynamicFilterInfo(this FilterKeyValueAction filterKeyValueAction) => new()
{
Operator = filterKeyValueAction.FilterAction.ToDynamicFilterOperator(),
Logic = filterKeyValueAction.FilterLogic.ToDynamicFilterLogic(),
Field = filterKeyValueAction.FieldKey,
Value = filterKeyValueAction.FieldValue,
Filters = filterKeyValueAction.Filters?.Select(i => i.ParseDynamicFilterInfo()).ToList()
};
private static DynamicFilterLogic ToDynamicFilterLogic(this FilterLogic logic) => logic switch
{
FilterLogic.And => DynamicFilterLogic.And,