Skip to content

Commit 527b941

Browse files
author
cd\zhuzhiqing
committed
提出common项目
1 parent 2e71556 commit 527b941

18 files changed

+742
-27
lines changed

APIJSON.NET/APIJSON.NET.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APIJSON.NET", "APIJSON.NET\
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APIJSON.NET.Test", "APIJSON.NET.Test\APIJSON.NET.Test.csproj", "{0828346E-207E-49F8-AD57-E1AB6B6E4077}"
99
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiJson.Common", "APIJSONCommon\ApiJson.Common.csproj", "{D0DF93E9-DD06-425B-96FE-935E9A82D327}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{0828346E-207E-49F8-AD57-E1AB6B6E4077}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{0828346E-207E-49F8-AD57-E1AB6B6E4077}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{0828346E-207E-49F8-AD57-E1AB6B6E4077}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{D0DF93E9-DD06-425B-96FE-935E9A82D327}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{D0DF93E9-DD06-425B-96FE-935E9A82D327}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{D0DF93E9-DD06-425B-96FE-935E9A82D327}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{D0DF93E9-DD06-425B-96FE-935E9A82D327}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="AspectCore.Extensions.Reflection" Version="1.1.0" />
19-
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
19+
<PackageReference Include="Microsoft.AspNetCore.App"/>
2020
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
2121
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.1.1" />
2222
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.1.1" />

APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
namespace 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}";

APIJSON.NET/APIJSON.NET/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public static void Main(string[] args)
1313

1414
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
1515
{
16-
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
16+
return WebHost.CreateDefaultBuilder(args)
17+
.UseUrls("http://*:89")
18+
.UseStartup<Startup>();
1719
}
1820
}
1921
}

APIJSON.NET/APIJSON.NET/Services/IdentityService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Role GetRole()
5050
{
5151
return (false, $"appsettings.json权限配置不正确!");
5252
}
53-
string tablerole = role.Select.Table.FirstOrDefault(it => it.Equals(table, StringComparison.CurrentCultureIgnoreCase));
53+
string tablerole = role.Select.Table.FirstOrDefault(it => it.Equals(table, StringComparison.CurrentCultureIgnoreCase) || it=="*");
5454

5555
if (string.IsNullOrEmpty(tablerole))
5656
{

APIJSON.NET/APIJSON.NET/Services/TableMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace APIJSON.NET.Services
66
{
77
public class TableMapper : ITableMapper
88
{
9-
private readonly Dictionary<string, string> _options= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
9+
private readonly Dictionary<string, string> _options = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
1010
public TableMapper(IOptions<Dictionary<string, string>> options)
1111
{
1212
foreach (var item in options.Value)

APIJSON.NET/APIJSON.NET/Startup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
8585
});
8686

8787
app.UseJwtTokenMiddleware();
88-
DbInit.Initialize(app);
8988
}
9089
}
9190
}

APIJSON.NET/APIJSON.NET/appsettings.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ConnectionStrings": {
3-
"DbType": 1, //0:MySql,1:SqlServer,2:Sqlite
4-
"ConnectionString": "Server=liaozengbo\\sql2018; Database=Sample; User Id=sa;Password=sa123;"
3+
"DbType": 0, //0:MySql,1:SqlServer,2:Sqlite
4+
"ConnectionString": "Server=192.168.2.25;Database=yunwei;Uid=root;Pwd=xmjk;Port=3306;Character Set=utf8;"
55
//"ConnectionString": "Server=119.29.9.25;Port=3306;Database=test;Uid=root;Pwd=1q,2w.3e?;CharSet=UTF8;"
66
},
77
"Authentication": {
@@ -16,8 +16,8 @@
1616
{
1717
"name": "role1", //权限名称 唯一
1818
"select": { //查询权限
19-
"table": [ "moment", "User", "Comment" ], //可操作的表
20-
"column": [ "*", "*", "*" ], //可操作的字段
19+
"table": [ "*" ], //可操作的表
20+
"column": [ "*" ], //可操作的字段
2121
"where": []
2222
},
2323
"update": { //修改权限
@@ -42,7 +42,8 @@
4242
],
4343
"tablempper": //别名表映射
4444
{
45-
"user": "apijson_user"
45+
"user": "apijson_user",
46+
"org": "web_organization"
4647
}
4748

4849
}

APIJSON.NET/APIJSON.NET/wwwroot/js/main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,11 @@
142142
},
143143
methods: {
144144
hpost: function () {
145-
146145
$.ajax({
147146
url: $('#rest-url').val(),
148147
type: "POST", dataType: "json",
149148
contentType: "application/json;charset=utf-8",
150-
data: JSON.stringify($('#vInput').val()),
149+
data: $('#vInput').val(),//JSON.stringify($('#vInput').val()),
151150
success: function (data) {
152151

153152
App.jsonhtml = data;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="AspectCore.Extensions.Reflection" Version="1.1.0" />
9+
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.1" />
10+
<PackageReference Include="sqlSugarCore" Version="4.9.7.2" />
11+
</ItemGroup>
12+
13+
</Project>

APIJSON.NET/APIJSONCommon/FuncList.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace ApiJson.Common
5+
{
6+
/// <summary>
7+
/// 自定义方法
8+
/// </summary>
9+
public class FuncList
10+
{
11+
public string Merge(object a, object b)
12+
{
13+
return a.ToString() + b.ToString();
14+
}
15+
public object MergeObj(object a, object b)
16+
{
17+
return new { a, b };
18+
}
19+
public bool isContain(object a, object b)
20+
{
21+
return a.ToString().Split(',').Contains(b);
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace ApiJson.Common
2+
{
3+
public static class StringExtensions
4+
{
5+
6+
/// <summary>
7+
/// 是否有值
8+
/// </summary>
9+
/// <param name="str"></param>
10+
/// <returns></returns>
11+
public static bool IsValue(this object str)
12+
{
13+
return str != null && !string.IsNullOrEmpty(str.ToString());
14+
}
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ApiJson.Common
2+
{
3+
using SqlSugar;
4+
public class DbOptions
5+
{
6+
public DbType DbType { get; set; }
7+
public string ConnectionString { get; set; }
8+
}
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace ApiJson.Common.Models
2+
{
3+
public class RoleItem
4+
{
5+
public string[] Table { get; set; }
6+
public string[] Column { get; set; }
7+
public string[] Filter { get; set; }
8+
}
9+
public class Role
10+
{
11+
public string Name { get; set; }
12+
public RoleItem Select { get; set; }
13+
public RoleItem Update { get; set; }
14+
public RoleItem Insert { get; set; }
15+
public RoleItem Delete { get; set; }
16+
17+
}
18+
19+
}

0 commit comments

Comments
 (0)