1
huangxiaoqiang
2025-10-20 63dcb7fc55d32960f643f4040900ce9a0e33536d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_Core.Utilities;
 
namespace WIDESEA_Core
{
    public class PageDataOptions
    {
        public int Page { get; set; }
        public int Rows { get; set; }
        public int Total { get; set; }
        public string TableName { get; set; }
        public string Sort { get; set; }
        /// <summary>
        /// 排序方式
        /// </summary>
        public string Order { get; set; }
        public string Wheres { get; set; }
        public bool Export { get; set; }
        public object Value { get; set; }
        /// <summary>
        /// 查询条件
        /// </summary>
        public List<SearchParameters> Filter { get; set; }
        public string ValidatePageOptions(PropertyInfo[] entityProperties)
        {
            string where = string.Empty;
            List<SearchParameters> searchParametersList = new List<SearchParameters>();
            if (this.Filter != null && this.Filter.Count > 0)
            {
                searchParametersList.AddRange(Filter);
            }
            else if (!string.IsNullOrEmpty(Wheres))
            {
                try
                {
                    searchParametersList = Wheres.DeserializeObject<List<SearchParameters>>();
                    Filter = searchParametersList;
                }
                catch { }
            }
            for (int i = 0; i < searchParametersList.Count; i++)
            {
                if (string.IsNullOrEmpty(searchParametersList[i].Value))
                {
                    continue;
                }
 
                PropertyInfo? property = entityProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault();
 
                if (property == null) continue;
 
                List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList();
                if (results == null || results.Count() == 0)
                {
                    continue;
                }
                for (int j = 0; j < results.Count(); j++)
                {
                    if (j == 0)
                    {
                        where += "(";
                    }
                    LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition();
                    if (expressionType == LinqExpressionType.Equal)
                    {
                        where += $"{searchParametersList[i].Name} = '{results[j].Item3}'";
                    }
                    else
                    {
                        where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'";
                    }
 
                    if (j == results.Count() - 1)
                    {
                        where += ")";
                    }
                    else
                    {
                        where += " or ";
                    }
                }
                if (i < searchParametersList.Count - 1)
                    where += " and ";
            }
            return where;
        }
    }
    public class SearchParameters
    {
        public string Name { get; set; }
        public string Value { get; set; }
        //查询类型:LinqExpressionType
        public string DisplayType { get; set; }
    }
 
}