1
1
namespace APIJSON . NET . Controllers
2
2
{
3
- using System ;
4
- using System . Collections . Generic ;
5
- using System . Web ;
6
- using APIJSON . NET . Models ;
3
+ using APIJSON . NET . Services ;
4
+ using Microsoft . AspNetCore . Cors ;
7
5
using Microsoft . AspNetCore . Mvc ;
8
- using Microsoft . Extensions . Options ;
9
6
using Newtonsoft . Json . Linq ;
10
7
using SqlSugar ;
8
+ using System ;
9
+ using System . Collections . Generic ;
10
+ using System . IO ;
11
11
using System . Linq ;
12
- using APIJSON . NET . Services ;
13
- using System . Reflection ;
14
- using Microsoft . AspNetCore . Cors ;
12
+ using System . Net . Http ;
13
+ using System . Text ;
14
+ using System . Threading . Tasks ;
15
+ using System . Web ;
15
16
16
17
[ Route ( "api/[controller]" ) ]
17
18
[ ApiController ]
@@ -22,14 +23,63 @@ public class JsonController : ControllerBase
22
23
private SelectTable selectTable ;
23
24
private DbContext db ;
24
25
private readonly IIdentityService _identitySvc ;
25
- public JsonController ( SelectTable _selectTable , DbContext _db , IIdentityService identityService )
26
+ public JsonController ( SelectTable _selectTable , DbContext _db , IIdentityService identityService )
26
27
{
27
28
28
29
selectTable = _selectTable ;
29
30
db = _db ;
30
31
_identitySvc = identityService ;
31
32
}
32
-
33
+
34
+ /// <summary>
35
+ ///
36
+ /// </summary>
37
+ /// <returns></returns>
38
+ public ActionResult Test ( )
39
+ {
40
+ string str = "{\" page\" :1,\" count\" :3,\" query\" :2,\" Org\" :{\" @column\" :\" Id,Name\" }}" ;
41
+ var content = new StringContent ( str ) ;
42
+
43
+ HttpClient hc = new HttpClient ( ) ;
44
+ var response = hc . PostAsync ( "http://localhost:89/api/json/org" , content ) . Result ;
45
+ string result = ( response . Content . ReadAsStringAsync ( ) . Result ) ; //result就是返回的结果。
46
+ return Content ( result ) ;
47
+ }
48
+
49
+ [ HttpPost ( "{table}" ) ]
50
+
51
+ public async Task < ActionResult > Query1 ( [ FromRoute ] string table )
52
+ {
53
+
54
+ string json = string . Empty ;
55
+ using ( StreamReader reader = new StreamReader ( Request . Body , Encoding . UTF8 ) )
56
+ {
57
+ json = await reader . ReadToEndAsync ( ) ;
58
+ }
59
+
60
+ json = HttpUtility . UrlDecode ( json ) ;
61
+ JObject ht = new JObject ( ) ;
62
+
63
+ JObject jobject = JObject . Parse ( json ) ;
64
+ ht . Add ( table + "[]" , jobject ) ;
65
+ ht . Add ( "total@" , "" ) ;
66
+
67
+ bool hasTableKey = false ;
68
+ foreach ( var item in jobject )
69
+ {
70
+ if ( item . Key . Equals ( table , StringComparison . CurrentCultureIgnoreCase ) )
71
+ {
72
+ hasTableKey = true ;
73
+ break ;
74
+ }
75
+ }
76
+ if ( ! hasTableKey )
77
+ {
78
+ jobject . Add ( table , new JObject ( ) ) ;
79
+ }
80
+ var newJson = Newtonsoft . Json . JsonConvert . SerializeObject ( ht ) ;
81
+ return Query ( newJson ) ;
82
+ }
33
83
/// <summary>
34
84
/// 查询
35
85
/// </summary>
@@ -123,7 +173,12 @@ public ActionResult Query([FromBody]string json)
123
173
var htt = new JArray ( ) ;
124
174
foreach ( var t in jb )
125
175
{
126
- foreach ( var d in selectTable . GetTableData ( t . Key , page , count , t . Value . ToString ( ) , null ) . Item1 )
176
+ var temp = selectTable . GetTableData ( t . Key , page , count , t . Value . ToString ( ) , null ) ;
177
+ if ( query > 0 )
178
+ {
179
+ total = temp . Item2 ;
180
+ }
181
+ foreach ( var d in temp . Item1 )
127
182
{
128
183
htt . Add ( JToken . FromObject ( d ) ) ;
129
184
}
@@ -145,7 +200,7 @@ public ActionResult Query([FromBody]string json)
145
200
types . Add ( typeof ( object ) ) ;
146
201
param . Add ( va ) ;
147
202
}
148
- bb . Add ( f . Key , JToken . FromObject ( selectTable . ExecFunc ( f . Key , param . ToArray ( ) , types . ToArray ( ) ) ) ) ;
203
+ bb . Add ( f . Key , JToken . FromObject ( selectTable . ExecFunc ( f . Key , param . ToArray ( ) , types . ToArray ( ) ) ) ) ;
149
204
}
150
205
ht . Add ( "func" , bb ) ;
151
206
}
@@ -254,7 +309,7 @@ public ActionResult Edit([FromBody]string json)
254
309
dt . Add ( "id" , value [ "id" ] . ToString ( ) ) ;
255
310
foreach ( var f in value )
256
311
{
257
- if ( f . Key . ToLower ( ) != "id" && selectTable . IsCol ( key , f . Key ) && ( role . Update . Column . Contains ( "*" ) || role . Update . Column . Contains ( f . Key , StringComparer . CurrentCultureIgnoreCase ) ) )
312
+ if ( f . Key . ToLower ( ) != "id" && selectTable . IsCol ( key , f . Key ) && ( role . Update . Column . Contains ( "*" ) || role . Update . Column . Contains ( f . Key , StringComparer . CurrentCultureIgnoreCase ) ) )
258
313
{
259
314
dt . Add ( f . Key , f . Value ) ;
260
315
}
@@ -293,13 +348,13 @@ public ActionResult Remove([FromBody]string json)
293
348
var value = JObject . Parse ( item . Value . ToString ( ) ) ;
294
349
var sb = new System . Text . StringBuilder ( 100 ) ;
295
350
sb . Append ( $ "delete FROM { key } where ") ;
296
- if ( role . Delete == null || role . Delete . Table == null )
351
+ if ( role . Delete == null || role . Delete . Table == null )
297
352
{
298
353
ht [ "code" ] = "500" ;
299
354
ht [ "msg" ] = "delete权限未配置" ;
300
355
break ;
301
356
}
302
- if ( ! role . Delete . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
357
+ if ( ! role . Delete . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
303
358
{
304
359
ht [ "code" ] = "500" ;
305
360
ht [ "msg" ] = $ "没权限删除{ key } ";
0 commit comments