22{
33 using System ;
44 using System . Collections . Generic ;
5- using System . Security . Claims ;
65 using System . Web ;
76 using APIJSON . NET . Models ;
87 using Microsoft . AspNetCore . Mvc ;
9- using Microsoft . Extensions . Configuration ;
108 using Microsoft . Extensions . Options ;
119 using Newtonsoft . Json . Linq ;
1210 using SqlSugar ;
1311 using System . Linq ;
12+ using APIJSON . NET . Services ;
1413 [ Route ( "api/[controller]" ) ]
1514 [ ApiController ]
1615 public class JsonController : ControllerBase
1716 {
1817
19- private JsonToSql jsonToSql ;
18+ private SelectTable selectTable ;
2019 private DbContext db ;
21- protected List < Role > roles ;
22- public JsonController ( JsonToSql jsonTo , DbContext _db , IOptions < List < Role > > _roles )
20+ private readonly IIdentityService _identitySvc ;
21+ public JsonController ( SelectTable _selectTable , DbContext _db , IIdentityService identityService )
2322 {
2423
25- jsonToSql = jsonTo ;
24+ selectTable = _selectTable ;
2625 db = _db ;
27- roles = _roles . Value ;
26+ _identitySvc = identityService ;
2827 }
2928 /// <summary>
3029 /// 查询
3130 /// </summary>
3231 /// <param name="json"></param>
3332 /// <returns></returns>
34- [ HttpPost ( "/Query " ) ]
35- public ActionResult Query ( [ FromBody ] string json )
33+ [ HttpGet ( "/get/{json} " ) ]
34+ public ActionResult Query ( string json )
3635 {
3736 json = HttpUtility . UrlDecode ( json ) ;
3837 JObject ht = new JObject ( ) ;
@@ -44,12 +43,12 @@ public ActionResult Query([FromBody]string json)
4443 foreach ( var item in jobject )
4544 {
4645 string key = item . Key . Trim ( ) ;
46+ var jb = JObject . Parse ( item . Value . ToString ( ) ) ;
47+ int page = jb [ "page" ] == null ? 0 : int . Parse ( jb [ "page" ] . ToString ( ) ) , count = jb [ "count" ] == null ? 0 : int . Parse ( jb [ "count" ] . ToString ( ) ) , query = jb [ "query" ] == null ? 0 : int . Parse ( jb [ "query" ] . ToString ( ) ) ;
48+ jb . Remove ( "page" ) ; jb . Remove ( "count" ) ;
4749 if ( key . Equals ( "[]" ) )
4850 {
4951 var htt = new JArray ( ) ;
50- var jb = JObject . Parse ( item . Value . ToString ( ) ) ;
51- int page = jb [ "page" ] == null ? 0 : int . Parse ( jb [ "page" ] . ToString ( ) ) , count = jb [ "count" ] == null ? 0 : int . Parse ( jb [ "count" ] . ToString ( ) ) , query = jb [ "query" ] == null ? 0 : int . Parse ( jb [ "query" ] . ToString ( ) ) ;
52- jb . Remove ( "page" ) ; jb . Remove ( "count" ) ;
5352 List < string > tables = new List < string > ( ) , where = new List < string > ( ) ;
5453 foreach ( var t in jb )
5554 {
@@ -58,32 +57,31 @@ public ActionResult Query([FromBody]string json)
5857 if ( tables . Count > 0 )
5958 {
6059 string table = tables [ 0 ] ;
61- var template = jsonToSql . GetTableData ( table , page , count , where [ 0 ] , null , User . FindFirstValue ( ClaimTypes . Role ) ) ;
60+ var template = selectTable . GetTableData ( table , page , count , where [ 0 ] , null ) ;
6261 foreach ( var dd in template )
6362 {
6463 var zht = new JObject ( ) ;
6564 zht . Add ( table , JToken . FromObject ( dd ) ) ;
6665 for ( int i = 1 ; i < tables . Count ; i ++ )
6766 {
6867 string subtable = tables [ i ] ;
69- if ( tables [ i ] . EndsWith ( "[]" ) )
68+ if ( subtable . EndsWith ( "[]" ) )
7069 {
71- subtable = tables [ i ] . Replace ( "[]" , "" ) ;
70+ subtable = subtable . TrimEnd ( "[]" . ToCharArray ( ) ) ;
7271 var jbb = JObject . Parse ( where [ i ] ) ;
7372 page = jbb [ "page" ] == null ? 0 : int . Parse ( jbb [ "page" ] . ToString ( ) ) ;
7473 count = jbb [ "count" ] == null ? 0 : int . Parse ( jbb [ "count" ] . ToString ( ) ) ;
7574
7675 var lt = new JArray ( ) ;
77- foreach ( var d in jsonToSql . GetTableData ( subtable , page , count , jbb [ subtable ] . ToString ( ) , zht , User . FindFirstValue ( ClaimTypes . Role ) ) )
76+ foreach ( var d in selectTable . GetTableData ( subtable , page , count , jbb [ subtable ] . ToString ( ) , zht ) )
7877 {
7978 lt . Add ( JToken . FromObject ( d ) ) ;
8079 }
8180 zht . Add ( tables [ i ] , lt ) ;
8281 }
8382 else
8483 {
85- var ddf = jsonToSql . GetTableData ( subtable , 0 , 0 , where [ i ] . ToString ( ) , zht , User . FindFirstValue ( ClaimTypes . Role ) ) ;
86-
84+ var ddf = selectTable . GetTableData ( subtable , 0 , 0 , where [ i ] . ToString ( ) , zht ) ;
8785 if ( ddf != null )
8886 {
8987 zht . Add ( subtable , JToken . FromObject ( ddf ) ) ;
@@ -98,15 +96,10 @@ public ActionResult Query([FromBody]string json)
9896 }
9997 else if ( key . EndsWith ( "[]" ) )
10098 {
101-
10299 var htt = new JArray ( ) ;
103- var jb = JObject . Parse ( item . Value . ToString ( ) ) ;
104- int page = jb [ "page" ] == null ? 0 : int . Parse ( jb [ "page" ] . ToString ( ) ) , count = jb [ "count" ] == null ? 0 : int . Parse ( jb [ "count" ] . ToString ( ) ) ;
105- jb . Remove ( "page" ) ;
106- jb . Remove ( "count" ) ;
107100 foreach ( var t in jb )
108101 {
109- foreach ( var d in jsonToSql . GetTableData ( t . Key , page , count , t . Value . ToString ( ) , null , User . FindFirstValue ( ClaimTypes . Role ) ) )
102+ foreach ( var d in selectTable . GetTableData ( t . Key , page , count , t . Value . ToString ( ) , null ) )
110103 {
111104 htt . Add ( JToken . FromObject ( d ) ) ;
112105 }
@@ -115,7 +108,7 @@ public ActionResult Query([FromBody]string json)
115108 }
116109 else
117110 {
118- var template = jsonToSql . GetTableData ( key , 0 , 0 , item . Value . ToString ( ) , ht , User . FindFirstValue ( ClaimTypes . Role ) ) ;
111+ var template = selectTable . GetTableData ( key , 0 , 0 , item . Value . ToString ( ) , ht ) ;
119112 if ( template != null )
120113 {
121114 ht . Add ( key , JToken . FromObject ( template ) ) ;
@@ -151,7 +144,7 @@ public ActionResult Add([FromBody]string json)
151144 foreach ( var item in jobject )
152145 {
153146 string key = item . Key . Trim ( ) ;
154- var role = jsonToSql . GetRole ( User . FindFirstValue ( ClaimTypes . Role ) ) ;
147+ var role = _identitySvc . GetRole ( ) ;
155148 if ( ! role . Insert . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
156149 {
157150 ht [ "code" ] = "500" ;
@@ -194,7 +187,7 @@ public ActionResult Edit([FromBody]string json)
194187 foreach ( var item in jobject )
195188 {
196189 string key = item . Key . Trim ( ) ;
197- var role = jsonToSql . GetRole ( User . FindFirstValue ( ClaimTypes . Role ) ) ;
190+ var role = _identitySvc . GetRole ( ) ;
198191 if ( ! role . Update . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
199192 {
200193 ht [ "code" ] = "500" ;
@@ -244,7 +237,7 @@ public ActionResult Remove([FromBody]string json)
244237 ht . Add ( "msg" , "success" ) ;
245238 try
246239 {
247- var role = jsonToSql . GetRole ( User . FindFirstValue ( ClaimTypes . Role ) ) ;
240+ var role = _identitySvc . GetRole ( ) ;
248241 JObject jobject = JObject . Parse ( json ) ;
249242 foreach ( var item in jobject )
250243 {
0 commit comments