11namespace APIJSON . NET . Controllers
22{
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 ;
75 using Microsoft . AspNetCore . Mvc ;
8- using Microsoft . Extensions . Options ;
96 using Newtonsoft . Json . Linq ;
107 using SqlSugar ;
8+ using System ;
9+ using System . Collections . Generic ;
10+ using System . IO ;
1111 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 ;
1516
1617 [ Route ( "api/[controller]" ) ]
1718 [ ApiController ]
@@ -22,14 +23,63 @@ public class JsonController : ControllerBase
2223 private SelectTable selectTable ;
2324 private DbContext db ;
2425 private readonly IIdentityService _identitySvc ;
25- public JsonController ( SelectTable _selectTable , DbContext _db , IIdentityService identityService )
26+ public JsonController ( SelectTable _selectTable , DbContext _db , IIdentityService identityService )
2627 {
2728
2829 selectTable = _selectTable ;
2930 db = _db ;
3031 _identitySvc = identityService ;
3132 }
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+ }
3383 /// <summary>
3484 /// 查询
3585 /// </summary>
@@ -123,7 +173,12 @@ public ActionResult Query([FromBody]string json)
123173 var htt = new JArray ( ) ;
124174 foreach ( var t in jb )
125175 {
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 )
127182 {
128183 htt . Add ( JToken . FromObject ( d ) ) ;
129184 }
@@ -145,7 +200,7 @@ public ActionResult Query([FromBody]string json)
145200 types . Add ( typeof ( object ) ) ;
146201 param . Add ( va ) ;
147202 }
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 ( ) ) ) ) ;
149204 }
150205 ht . Add ( "func" , bb ) ;
151206 }
@@ -254,7 +309,7 @@ public ActionResult Edit([FromBody]string json)
254309 dt . Add ( "id" , value [ "id" ] . ToString ( ) ) ;
255310 foreach ( var f in value )
256311 {
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 ) ) )
258313 {
259314 dt . Add ( f . Key , f . Value ) ;
260315 }
@@ -293,13 +348,13 @@ public ActionResult Remove([FromBody]string json)
293348 var value = JObject . Parse ( item . Value . ToString ( ) ) ;
294349 var sb = new System . Text . StringBuilder ( 100 ) ;
295350 sb . Append ( $ "delete FROM { key } where ") ;
296- if ( role . Delete == null || role . Delete . Table == null )
351+ if ( role . Delete == null || role . Delete . Table == null )
297352 {
298353 ht [ "code" ] = "500" ;
299354 ht [ "msg" ] = "delete权限未配置" ;
300355 break ;
301356 }
302- if ( ! role . Delete . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
357+ if ( ! role . Delete . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
303358 {
304359 ht [ "code" ] = "500" ;
305360 ht [ "msg" ] = $ "没权限删除{ key } ";
0 commit comments