8000 Merge pull request #26 from haptear/master · APIJSON/APIJSON-CSharp@a133493 · GitHub
[go: up one dir, main page]

Skip to content

Commit a133493

Browse files
authored
Merge pull request liaozb#26 from haptear/master
升级sqlSugarCore版本 处理启动后显示404无网页的问题
2 parents 0525f90 + 2edec64 commit a133493

File tree

12 files changed

+243
-177
lines changed

12 files changed

+243
-177
lines changed

APIJSON.NET/APIJSON.NET.Test/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using RestSharp;
22
using System;
3+
using System.Text.RegularExpressions;
34

45
namespace APIJSON.NET.Test
56
{

APIJSON.NET/APIJSON.NET/Controllers/HomeController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public class HomeController : Controller
1010
{
1111
public IActionResult Index()
1212
{
13-
return Redirect("index.html");
13+
return File("./index.html", "text/html");
14+
//return Redirect("index.html");
1415
}
1516
}
1617
}

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public ActionResult Test()
5757

5858
public async Task<ActionResult> Query([FromBody] JObject jobject)
5959
{
60-
JObject resultJobj = new SelectTable(_identitySvc, _tableMapper, db.Db).Query(jobject);
60+
var st = new SelectTable(_identitySvc, _tableMapper, db.Db);
61+
JObject resultJobj = st.Query(jobject);
6162
return Ok(resultJobj);
6263
}
6364

@@ -75,20 +76,46 @@ public async Task<ActionResult> QueryByTable([FromRoute]string table)
7576

7677
JObject jobject = JObject.Parse(json);
7778
ht.Add(table + "[]", jobject);
78-
ht.Add("total@", "");
79+
80+
if (jobject["query"] != null && jobject["query"].ToString() != "0" && jobject["total@"] == null)
81+
{
82+
//自动添加总计数量
83+
ht.Add("total@", "");
84+
}
85+
86+
//每页最大1000条数据
87+
if (jobject["count"] != null && int.Parse(jobject["cou F438 nt"].ToString()) > 1000)
88+
{
89+
throw new Exception("count分页数量最大不能超过1000");
90+
}
91+
92+
bool isDebug = (jobject["@debug"] != null && jobject["@debug"].ToString() != "0");
93+
jobject.Remove("@debug");
7994

8095
bool hasTableKey = false;
96+
List<string> ignoreConditions = new List<string> { "page", "count", "query" };
97+
JObject tableConditions = new JObject();//表的其它查询条件,比如过滤,字段等
8198
foreach (var item in jobject)
8299
{
83100
if (item.Key.Equals(table, StringComparison.CurrentCultureIgnoreCase))
84101
{
85102
hasTableKey = true;
86103
break;
87104
}
105+
if (!ignoreConditions.Contains(item.Key.ToLower()))
106+
{
107+
tableConditions.Add(item.Key, item.Value);
108+
}
109+
}
110+
111+
foreach (var removeKey in tableConditions)
112+
{
113+
jobject.Remove(removeKey.Key);
88114
}
115+
89116
if (!hasTableKey)
90117
{
91-
jobject.Add(table, new JObject());
118+
jobject.Add(table, tableConditions);
92119
}
93120

94121
return await Query(ht);

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,47 @@
1010

1111
namespace APIJSON.NET.Services
1212
{
13+
/// <summary>
14+
///
15+
/// </summary>
1316
public class IdentityService : IIdentityService
1417
{
1518
private IHttpContextAccessor _context;
1619
private List<Role> roles;
1720

21+
/// <summary>
22+
///
23+
/// </summary>
24+
/// <param name="context"></param>
25+
/// <param name="_roles"></param>
1826
public IdentityService(IHttpContextAccessor context, IOptions<List<Role>> _roles)
1927
{
2028
_context = context ?? throw new ArgumentNullException(nameof(context));
2129
roles = _roles.Value;
2230
}
31+
32+
/// <summary>
33+
///
34+
/// </summary>
35+
/// <returns></returns>
2336
public string GetUserIdentity()
2437
{
2538
return _context.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
2639
}
2740

41+
/// <summary>
42+
///
43+
/// </summary>
44+
/// <returns></returns>
2845
public string GetUserRoleName()
2946
{
3047
return _context.HttpContext.User.FindFirstValue(ClaimTypes.Role);
3148
}
49+
50+
/// <summary>
51+
///
52+
/// </summary>
53+
/// <returns></returns>
3254
public Role GetRole()
3355
{
3456
var role = new Role();
@@ -43,23 +65,37 @@ public Role GetRole()
4365
}
4466
return role;
4567
}
46-
public (bool, string) GetSelectRole(string table)
68+
69+
/// <summary>
70+
///
71+
/// </summary>
72+
/// <param name="table"></param>
73+
/// <returns></returns>
74+
public Tuple<bool, string> GetSelectRole(string table)
4775
{
4876
var role = GetRole();
4977
if (role == null || role.Select == null || role.Select.Table == null)
5078
{
51-
return (false, $"appsettings.json权限配置不正确!");
79+
return Tuple.Create(false, $"appsettings.json权限配置不正确!");
5280
}
5381
string tablerole = role.Select.Table.FirstOrDefault(it => it == "*" || it.Equals(table, StringComparison.CurrentCultureIgnoreCase));
5482

5583
if (string.IsNullOrEmpty(tablerole))
5684
{
57-
return (false, $"表名{table}没权限查询!");
85+
return Tuple.Create(false, $"表名{table}没权限查询!");
5886
}
5987
int index = Array.IndexOf(role.Select.Table, tablerole);
6088
string selectrole = role.Select.Column[index];
61-
return (true, selectrole);
89+
return Tuple.Create(true, selectrole);
6290
}
91+
92+
93+
/// <summary>
94+
///
95+
/// </summary>
96+
/// <param name="col"></param>
97+
/// <param name="selectrole"></param>
98+
/// <returns></returns>
6399
public bool ColIsRole(string col, string[] selectrole)
64100
{
65101
if (selectrole.Contains("*"))

APIJSON.NET/APIJSON.NET/Startup.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ public void ConfigureServices(IServiceCollection services)
7070
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
7171
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
7272
{
73-
74-
app.UseAuthentication();
75-
7673
app.UseRouting();
74+
app.UseAuthentication();
75+
app.UseDefaultFiles();
7776
app.UseStaticFiles();
7877
app.UseCors(_defaultCorsPolicyName);
7978
app.UseSwagger();
@@ -84,7 +83,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
8483
});
8584
app.UseEndpoints(endpoints =>
8685
{
87-
endpoints.MapControllers();
86+
endpoints.MapDefaultControllerRoute();
87+
//endpoints.MapControllers();
8888
});
8989
app.UseJwtTokenMiddleware();
9090
DbInit.Initialize(app);

APIJSON.NET/APIJSON.NET/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"ConnectionStrings": {
33
"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;"
4+
"ConnectionString": "Server=192.168.2.25;Database=yunwei1.8;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
"CorsUrls": "http://localhost:5000,http://localhost5001",
@@ -17,8 +17,8 @@
1717
{
1818
"name": "role1", //权限名称 唯一
1919
"select": { //查询权限
20-
"table": [ "moment", "User", "Comment" ], //可操作的表
21-
"column": [ "*", "*", "*" ], //可操作的字段
20+
"table": [ "*" ], //可操作的表
21+
"column": [ "*" ], //可操作的字段
2222
"where": []
2323
},
2424
"update": { //修改权限

APIJSON.NET/APIJSON.NET/wwwroot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<option value="add">add</option>
3636
<option value="edit">edit</option>
3737
<option value="remove">remove</option>
38-
<!--<option value="org">org</option>-->
38+
<option value="org">org</option>
3939

4040
</select>
4141
<button @click="hpost()">发送请求</button>

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: $('#vInput').val(),
149+
data: $('#vInput').val(),//JSON.stringify($('#vInput').val()),
151150
success: function (data) {
152151

153152
App.jsonhtml = data;
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Version>0.0.1</Version>
6-
<Description>通用查询组件</Description>
7-
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<Version>0.0.11</Version>
6+
<Description>
7+
0.0.11 升级sqlSugarCore版本 解决如果查找字段是关键字(例如:key)时出错的问题
8+
0.0.10 处理别名如果为关键字的缺陷
9+
0.0.8 清理SelectTable 支持重载
10+
0.0.7 修复not in的缺陷,增加~ 不等于的支持
11+
0.0.6 增加ToSql接口,处理sql注入的情况
12+
通用查询组件</Description>
13+
<PackageId>ApiJson.Common.Core</PackageId>
14+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
815
</PropertyGroup>
916

1017
<ItemGroup>
18+
<Compile Remove="Properties\AssemblyInfo.cs" />
1119
<Compile Remove="SelectTable - 副本.cs" />
1220
</ItemGroup>
1321

1422
<ItemGroup>
1523
<PackageReference Include="AspectCore.Extensions.Reflection" Version="2.1.0" />
1624
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.4" />
17-
<PackageReference Include="sqlSugarCore" Version="5.0.0.15" />
25+
<PackageReference Include="sqlSugarCore" Version="5.0.5.5" />
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<Folder Include="Properties\" />
1830
</ItemGroup>
1931

2032
</Project>

APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// 控制。更改这些特性值可修改
66
// 与程序集关联的信息。
77
[assembly: AssemblyTitle("ApiJson.Common")]
8-
[assembly: AssemblyDescription("增加ToSql接口,处理sql注入的情况")]
8+
[assembly: AssemblyDescription("0.0.19 处理别名如果为关键字的缺陷")]
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("")]
1111
[assembly: AssemblyProduct("ApiJson.Common")]
@@ -31,5 +31,5 @@
3131
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
3232
//通过使用 "*",如下所示:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("0.0.6.0")]
35-
[assembly: AssemblyFileVersion("0.0.6.0")]
34+
[assembly: AssemblyVersion("0.0.10.0")]
35+
[assembly: AssemblyFileVersion("0.0.10.0")]

0 commit comments

Comments
 (0)
0