2
2
{
3
3
using System ;
4
4
using System . Collections . Generic ;
5
- using System . Security . Claims ;
6
5
using System . Web ;
7
6
using APIJSON . NET . Models ;
8
7
using Microsoft . AspNetCore . Mvc ;
9
- using Microsoft . Extensions . Configuration ;
10
8
using Microsoft . Extensions . Options ;
11
9
using Newtonsoft . Json . Linq ;
12
10
using SqlSugar ;
13
11
using System . Linq ;
12
+ using APIJSON . NET . Services ;
14
13
[ Route ( "api/[controller]" ) ]
15
14
[ ApiController ]
16
15
public class JsonController : ControllerBase
17
16
{
18
17
19
- private JsonToSql jsonToSql ;
18
+ private SelectTable selectTable ;
20
19
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 )
23
22
{
24
23
25
- jsonToSql = jsonTo ;
24
+ selectTable = _selectTable ;
26
25
db = _db ;
27
- roles = _roles . Value ;
26
+ _identitySvc = identityService ;
28
27
}
29
28
/// <summary>
30
29
/// 查询
31
30
/// </summary>
32
31
/// <param name="json"></param>
33
32
/// <returns></returns>
34
- [ HttpPost ( "/Query " ) ]
35
- public ActionResult Query ( [ FromBody ] string json )
33
+ [ HttpGet ( "/get/{json} " ) ]
34
+ public ActionResult Query ( string json )
36
35
{
37
36
json = HttpUtility . UrlDecode ( json ) ;
38
37
JObject ht = new JObject ( ) ;
@@ -44,12 +43,12 @@ public ActionResult Query([FromBody]string json)
44
43
foreach ( var item in jobject )
45
44
{
46
45
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" ) ;
47
49
if ( key . Equals ( "[]" ) )
48
50
{
49
51
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" ) ;
53
52
List < string > tables = new List < string > ( ) , where = new List < string > ( ) ;
54
53
foreach ( var t in jb )
55
54
{
@@ -58,32 +57,31 @@ public ActionResult Query([FromBody]string json)
58
57
if ( tables . Count > 0 )
59
58
{
60
59
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 ) ;
62
61
foreach ( var dd in template )
63
62
{
64
63
var zht = new JObject ( ) ;
65
64
zht . Add ( table , JToken . FromObject ( dd ) ) ;
66
65
for ( int i = 1 ; i < tables . Count ; i ++ )
67
66
{
68
67
string subtable = tables [ i ] ;
69
- if ( tables [ i ] . EndsWith ( "[]" ) )
68
+ if ( subtable . EndsWith ( "[]" ) )
70
69
{
71
- subtable = tables [ i ] . Replace ( "[]" , "" ) ;
70
+ subtable = subtable . TrimEnd ( "[]" . ToCharArray ( ) ) ;
72
71
var jbb = JObject . Parse ( where [ i ] ) ;
73
72
page = jbb [ "page" ] == null ? 0 : int . Parse ( jbb [ "page" ] . ToString ( ) ) ;
74
73
count = jbb [ "count" ] == null ? 0 : int . Parse ( jbb [ "count" ] . ToString ( ) ) ;
75
74
76
75
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 ) )
78
77
{
79
78
lt . Add ( JToken . FromObject ( d ) ) ;
80
79
}
81
80
zht . Add ( tables [ i ] , lt ) ;
82
81
}
83
82
else
84
83
{
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 ) ;
87
85
if ( ddf != null )
88
86
{
89
87
zht . Add ( subtable , JToken . FromObject ( ddf ) ) ;
@@ -98,15 +96,10 @@ public ActionResult Query([FromBody]string json)
98
96
}
99
97
else if ( key . EndsWith ( "[]" ) )
100
98
{
101
-
102
99
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" ) ;
107
100
foreach ( var t in jb )
108
101
{
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 ) )
110
103
{
111
104
htt . Add ( JToken . FromObject ( d ) ) ;
112
105
}
@@ -115,7 +108,7 @@ public ActionResult Query([FromBody]string json)
115
108
}
116
109
else
117
110
{
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 ) ;
119
112
if ( template != null )
120
113
{
121
114
ht . Add ( key , JToken . FromObject ( template ) ) ;
@@ -151,7 +144,7 @@ public ActionResult Add([FromBody]string json)
151
144
foreach ( var item in jobject )
152
145
{
153
146
string key = item . Key . Trim ( ) ;
154
- var role = jsonToSql . GetRole ( User . FindFirstValue ( ClaimTypes . Role ) ) ;
147
+ var role = _identitySvc . GetRole ( ) ;
155
148
if ( ! role . Insert . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
156
149
{
157
150
ht [ "code" ] = "500" ;
@@ -194,7 +187,7 @@ public ActionResult Edit([FromBody]string json)
194
187
foreach ( var item in jobject )
195
188
{
196
189
string key = item . Key . Trim ( ) ;
197
- var role = jsonToSql . GetRole ( User . FindFirstValue ( ClaimTypes . Role ) ) ;
190
+ var role = _identitySvc . GetRole ( ) ;
198
191
if ( ! role . Update . Table . Contains ( key , StringComparer . CurrentCultureIgnoreCase ) )
199
192
{
200
193
ht [ "code" ] = "500" ;
@@ -244,7 +237,7 @@ public ActionResult Remove([FromBody]string json)
244
237
ht . Add ( "msg" , "success" ) ;
245
238
try
246
239
{
247
- var role = jsonToSql . GetRole ( User . FindFirstValue ( ClaimTypes . Role ) ) ;
240
+ var role = _identitySvc . GetRole ( ) ;
248
241
JObject jobject = JObject . Parse ( json ) ;
249
242
foreach ( var item in jobject )
250
243
{
0 commit comments