|
7 | 7 | using System; |
8 | 8 | using System.Collections.Generic; |
9 | 9 | using System.Linq; |
| 10 | + using System.Reflection; |
| 11 | + using System.Text.RegularExpressions; |
| 12 | + |
10 | 13 | public class SelectTable |
11 | 14 | { |
12 | 15 | private readonly IIdentityService _identitySvc; |
@@ -37,6 +40,24 @@ public bool IsCol(string table, string col) |
37 | 40 | { |
38 | 41 | return db.Db.DbMaintenance.GetColumnInfosByTableName(table).Any(it => it.DbColumnName.Equals(col, StringComparison.CurrentCultureIgnoreCase)); |
39 | 42 | } |
| 43 | + /// <summary> |
| 44 | + /// 动态调用方法 |
| 45 | + /// </summary> |
| 46 | + /// <param name="funcname"></param> |
| 47 | + /// <param name="param"></param> |
| 48 | + /// <param name="types"></param> |
| 49 | + /// <returns></returns> |
| 50 | + public object ExecFunc(string funcname,object[] param, Type[] types) |
| 51 | + { |
| 52 | + Type type = typeof(FuncList); |
| 53 | + Object obj = Activator.CreateInstance(type); |
| 54 | + MethodInfo mt = type.GetMethod(funcname,types); |
| 55 | + if (mt==null) |
| 56 | + { |
| 57 | + throw new Exception($"{funcname}没有获取到相应的函数"); |
| 58 | + } |
| 59 | + return mt.Invoke(obj, param); |
| 60 | + } |
40 | 61 |
|
41 | 62 | public (dynamic,int) GetTableData(string subtable, int page, int count, string json, JObject dd) |
42 | 63 | { |
@@ -78,8 +99,26 @@ public dynamic GetFirstData(string subtable, string json, JObject dd) |
78 | 99 | JObject values = JObject.Parse(json); |
79 | 100 | values.Remove("page"); |
80 | 101 | values.Remove("count"); |
81 | | - var tb = sugarQueryable(subtable, selectrole, values, dd); |
82 | | - return tb.First(); |
| 102 | + var tb = sugarQueryable(subtable, selectrole, values, dd).First(); |
| 103 | + var dic = (IDictionary<string, object>)tb; |
| 104 | + foreach (var item in values.Properties().Where(it => it.Name.EndsWith("()"))) |
| 105 | + { |
| 106 | + if (item.Value.IsValue()) |
| 107 | + { |
| 108 | + string func = item.Value.ToString().Substring(0, item.Value.ToString().IndexOf("(")); |
| 109 | + string param = item.Value.ToString().Substring(item.Value.ToString().IndexOf("(") + 1).TrimEnd(')') ; |
| 110 | + var types = new List<Type>(); |
| 111 | + var paramss = new List<object>(); |
| 112 | + foreach (var va in param.Split(",")) |
| 113 | + { |
| 114 | + types.Add(typeof(object)); |
| 115 | + paramss.Add(tb.Where(it => it.Key.Equals(va)).Select(i => i.Value)); |
| 116 | + } |
| 117 | + dic[item.Name] =ExecFunc(func, paramss.ToArray(), types.ToArray()); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + return tb; |
83 | 122 |
|
84 | 123 | } |
85 | 124 | private ISugarQueryable<System.Dynamic.ExpandoObject> sugarQueryable(string subtable, string selectrole, JObject values, JObject dd) |
|
0 commit comments