From 0275e34067b7bcfe8b50c70706402f7cf152e67a Mon Sep 17 00:00:00 2001
From: haptear
Date: Thu, 30 May 2019 17:09:36 +0800
Subject: [PATCH 01/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ToSql=E6=8E=A5=E5=8F=A3?=
=?UTF-8?q?=EF=BC=8C=E5=A4=84=E7=90=86@column=E9=87=8D=E5=91=BD=E5=90=8D?=
=?UTF-8?q?=E5=88=97=E5=90=8D=E6=97=B6=E7=9A=84sql=E6=B3=A8=E5=85=A5?=
=?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../APIJSONCommon/Properties/AssemblyInfo.cs | 6 +-
APIJSON.NET/APIJSONCommon/SelectTable.cs | 98 ++++++++++++++++++-
2 files changed, 98 insertions(+), 6 deletions(-)
diff --git a/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs b/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
index b890e44..12c27cf 100644
--- a/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
+++ b/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
@@ -6,7 +6,7 @@
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ApiJson.Common")]
-[assembly: AssemblyDescription("单表查询的返回节点指定为Infos")]
+[assembly: AssemblyDescription("增加ToSql接口,处理sql注入的情况")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ApiJson.Common")]
@@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.0.4.0")]
-[assembly: AssemblyFileVersion("0.0.4.0")]
+[assembly: AssemblyVersion("0.0.6.0")]
+[assembly: AssemblyFileVersion("0.0.6.0")]
diff --git a/APIJSON.NET/APIJSONCommon/SelectTable.cs b/APIJSON.NET/APIJSONCommon/SelectTable.cs
index 4e76118..de56221 100644
--- a/APIJSON.NET/APIJSONCommon/SelectTable.cs
+++ b/APIJSON.NET/APIJSONCommon/SelectTable.cs
@@ -66,6 +66,19 @@ public object ExecFunc(string funcname, object[] param, Type[] types)
return result;
}
+ private string ToSql(string subtable, int page, int count, int query, string json)
+ {
+ JObject values = JObject.Parse(json);
+ page = values["page"] == null ? page : int.Parse(values["page"].ToString());
+ count = values["count"] == null ? count : int.Parse(values["count"].ToString());
+ query = values["query"] == null ? query : int.Parse(values["query"].ToString());
+ values.Remove("page");
+ values.Remove("count");
+ subtable = _tableMapper.GetTableName(subtable);
+ var tb = sugarQueryable(subtable, "*", values,null);
+ var xx= tb.Skip((page - 1) * count).Take(10).ToSql();
+ return xx.Key;
+ }
///
///
///
@@ -187,8 +200,9 @@ public JObject Query(string queryJson)
/// 单表查询
///
///
+ /// 返回数据的节点名称 默认为 infos
///
- public JObject QuerySingle(JObject queryObj)
+ public JObject QuerySingle(JObject queryObj, string nodeName = "infos")
{
JObject resultObj = new JObject();
resultObj.Add("code", "200");
@@ -202,7 +216,7 @@ public JObject QuerySingle(JObject queryObj)
if (key.EndsWith("[]"))
{
- total = QuerySingleList(resultObj, item, "Infos");
+ total = QuerySingleList(resultObj, item, nodeName);
}
else if (key.Equals("func"))
{
@@ -222,6 +236,25 @@ public JObject QuerySingle(JObject queryObj)
return resultObj;
}
+ ///
+ /// 获取查询语句
+ ///
+ ///
+ ///
+ public string ToSql(JObject queryObj)
+ {
+ foreach (var item in queryObj)
+ {
+ string key = item.Key.Trim();
+
+ if (key.EndsWith("[]"))
+ {
+ return ToSql(item);
+ }
+ }
+ return string.Empty;
+ }
+
///
/// 解析并查询
///
@@ -284,6 +317,7 @@ private int QuerySingleList(JObject resultObj, KeyValuePair item
int total = 0;
jb.Remove("page"); jb.Remove("count"); jb.Remove("query");
+
var htt = new JArray();
foreach (var t in jb)
{
@@ -307,6 +341,23 @@ private int QuerySingleList(JObject resultObj, KeyValuePair item
return total;
}
+ private string ToSql(KeyValuePair item)
+ {
+ string key = item.Key.Trim();
+ var jb = JObject.Parse(item.Value.ToString());
+ int page = jb["page"] == null ? 0 : int.Parse(jb["page"].ToString());
+ int count = jb["count"] == null ? 10 : int.Parse(jb["count"].ToString());
+ int query = jb["query"] == null ? 0 : int.Parse(jb["query"].ToString());
+
+ jb.Remove("page"); jb.Remove("count"); jb.Remove("query");
+ var htt = new JArray();
+ foreach (var t in jb)
+ {
+ return ToSql(t.Key, page, count, query, t.Value.ToString());
+ }
+
+ return string.Empty;
+ }
//单表查询
private int QuerySingleList(JObject resultObj, KeyValuePair item)
{
@@ -495,7 +546,13 @@ private void ProcessColumn(string subtable, string selectrole, JObject values, I
if (colName == "*" || int.TryParse(colName, out int colNumber) || (IsCol(subtable, colName) && _identitySvc.ColIsRole(colName, selectrole.Split(','))))
{
if (ziduan.Length > 1)
- str.Append(ziduan[0] + " as " + ziduan[1] + ",");
+ {
+ if (ziduan[1].Length > 20)
+ {
+ throw new Exception("别名不能超过20个字符");
+ }
+ str.Append(ziduan[0] + " as " + ReplaceSQLChar(ziduan[1]) + ",");
+ }
else
str.Append(ziduan[0] + ",");
@@ -744,5 +801,40 @@ private void FuzzyQuery(string subtable, List conModels, KeyV
conModels.Add(new ConditionalModel() { FieldName = vakey.TrimEnd('$'), ConditionalType = conditionalType, FieldValue = fieldValue.TrimEnd("%".ToArray()).TrimStart("%".ToArray()) });
}
}
+
+ public string ReplaceSQLChar(string str)
+ {
+ if (str == String.Empty)
+ return String.Empty;
+ str = str.Replace("'", "");
+ str = str.Replace(";", "");
+ str = str.Replace(",", "");
+ str = str.Replace("?", "");
+ str = str.Replace("<", "");
+ str = str.Replace(">", "");
+ str = str.Replace("(", "");
+ str = str.Replace(")", "");
+ str = str.Replace("@", "");
+ str = str.Replace("=", "");
+ str = str.Replace("+", "");
+ str = str.Replace("*", "");
+ str = str.Replace("&", "");
+ str = str.Replace("#", "");
+ str = str.Replace("%", "");
+ str = str.Replace("$", "");
+ str = str.Replace("\"", "");
+
+ //删除与数据库相关的词
+ str = Regex.Replace(str, "delete from", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "drop table", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "truncate", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "xp_cmdshell", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "exec master", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "net localgroup administrators", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "net user", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "-", "", RegexOptions.IgnoreCase);
+ str = Regex.Replace(str, "truncate", "", RegexOptions.IgnoreCase);
+ return str;
+ }
}
}
From dab0e09bd36cde1c237b6c304fe735b211a5a9ee Mon Sep 17 00:00:00 2001
From: haptear
Date: Thu, 18 Jul 2019 18:20:31 +0800
Subject: [PATCH 02/19] =?UTF-8?q?sqlSugarCore=E5=8D=87=E7=BA=A7=E5=88=B05.?=
=?UTF-8?q?0.9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj | 14 +++++++++++---
APIJSON.NET/APIJSONCommon/SelectTable.cs | 2 +-
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
index 66d75af..95a2c55 100644
--- a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
+++ b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
@@ -2,18 +2,26 @@
netstandard2.0
- 0.0.1
- 通用查询组件
+ 0.0.6
+ 0.0.6 增加ToSql接口,处理sql注入的情况
+通用查询组件
+ ApiJson.Common.Core
+ true
+
-
+
+
+
+
+
diff --git a/APIJSON.NET/APIJSONCommon/SelectTable.cs b/APIJSON.NET/APIJSONCommon/SelectTable.cs
index de56221..42c5014 100644
--- a/APIJSON.NET/APIJSONCommon/SelectTable.cs
+++ b/APIJSON.NET/APIJSONCommon/SelectTable.cs
@@ -625,7 +625,7 @@ private void ProcessHaving(JObject values, ISugarQueryable tb)
hw.Add(model);
}
- var d = db.Context.Utilities.ConditionalModelToSql(hw);
+ //var d = db.Context.Utilities.ConditionalModelToSql(hw);
//tb.Having(d.Key, d.Value);
tb.Having(string.Join(",", havingItems));
}
From 5a3f25c2e56d5419d22eaef29f8fd16a8de061ee Mon Sep 17 00:00:00 2001
From: lzb <635990945@qq.com>
Date: Mon, 22 Jul 2019 11:08:23 +0800
Subject: [PATCH 03/19] =?UTF-8?q?#=E4=BF=AE=E5=A4=8D=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E9=94=99=E8=AF=AF#?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj | 2 +-
APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj | 3 ++-
APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs | 1 -
APIJSON.NET/APIJSONCommon/Services/IIdentityService.cs | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj
index 634243e..d4d0dd7 100644
--- a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj
+++ b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj
@@ -20,7 +20,7 @@
-
+
diff --git a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
index 66d75af..e89cd9f 100644
--- a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
+++ b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
@@ -1,9 +1,10 @@
-
+
netstandard2.0
0.0.1
通用查询组件
+ false
diff --git a/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs b/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
index 12c27cf..fbcdc6a 100644
--- a/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
+++ b/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
diff --git a/APIJSON.NET/APIJSONCommon/Services/IIdentityService.cs b/APIJSON.NET/APIJSONCommon/Services/IIdentityService.cs
index d911702..db6c8ce 100644
--- a/APIJSON.NET/APIJSONCommon/Services/IIdentityService.cs
+++ b/APIJSON.NET/APIJSONCommon/Services/IIdentityService.cs
@@ -25,7 +25,7 @@ public interface IIdentityService
///
///
///
- Tuple GetSelectRole(string table);
+ (bool, string) GetSelectRole(string table);
bool ColIsRole(string col, string[] selectrole);
From cf41a26c6d0fea7ae753a24a19e05a64e750e626 Mon Sep 17 00:00:00 2001
From: TommyLemon
Date: Sun, 1 Sep 2019 16:36:23 +0800
Subject: [PATCH 04/19] Update README.md
---
README.md | 79 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 67 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index 8bb8849..081c094 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
# APIJSON.NET
这是 APIJSON 的 C# .NET CORE 版后端实现。
+
APIJSON
@@ -14,11 +15,12 @@
-
+
-
+
+
@@ -29,7 +31,7 @@
English
通用文档
视频教程
- 在线工具
+ 在线工具
@@ -39,7 +41,7 @@
---
-APIJSON是一种为API而生的JSON网络传输协议。
+APIJSON是一种专为API而生的 JSON网络传输协议 以及 基于这套协议实现的ORM库。
为 简单的增删改查、复杂的查询、简单的事务操作 提供了完全自动化的API。
能大幅降低开发和沟通成本,简化开发流程,缩短开发周期。
适合中小型前后端分离的项目,尤其是互联网创业项目和企业自用项目。
@@ -57,10 +59,10 @@ APIJSON是一种为API而生的JSON网络传输协议。
#### 在线解析
* 自动生成接口文档,清晰可读永远最新
-* 自动生成请求代码,支持Android和iOS
-* 自动生成JavaBean文件,一键下载
+* 自动校验与格式化,支持高亮和收展
+* 自动生成各种语言代码,一键下载
* 自动管理与测试接口用例,一键共享
-* 自动校验与格式化JSON,支持高亮和收展
+* 自动给请求JSON加注释,一键切换
#### 对于前端
* 不用再向后端催接口、求文档
@@ -108,10 +110,17 @@ APIJSON是一种为API而生的JSON网络传输协议。
### 为什么要用APIJSON?
-[前后端10大痛点解析](https://github.com/TommyLemon/APIJSON/wiki)
+[前后端 关于接口的 沟通、文档、联调 等 10 大痛点解析](https://github.com/TommyLemon/APIJSON/wiki)
### 快速上手
-https://github.com/liaozb/APIJSON.NET/tree/master/APIJSON.NET
+
+#### 1.后端部署
+可以跳过这个步骤,直接用APIJSON服务器IP地址 apijson.cn:8080 来测试接口。
+见 [APIJSON后端部署 - Java](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-Java-Server)
+
+#### 2.前端部署
+可以跳过这个步骤,直接使用 [APIAuto-自动化接口管理工具](https://github.com/TommyLemon/APIAuto) 或 下载客户端App。
+见 [Android](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-Android) 或 [iOS](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-iOS) 或 [JavaScript](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-JavaScript)
### 下载客户端App
@@ -121,6 +130,22 @@ https://github.com/liaozb/APIJSON.NET/tree/master/APIJSON.NET
测试及自动生成代码工具
[APIJSONTest.apk](http://files.cnblogs.com/files/tommylemon/APIJSONTest.apk)
+### 使用登记
+
+
+
+[您在使用APIJSON吗?](https://github.com/TommyLemon/APIJSON/issues/73)
+
### 技术交流
如果有什么问题或建议可以 [提ISSUE](https://github.com/liaozb/APIJSON.NET/issues) 或 [加群](https://github.com/TommyLemon/APIJSON#%E6%8A%80%E6%9C%AF%E4%BA%A4%E6%B5%81),交流技术,分享经验。
@@ -129,12 +154,17 @@ https://github.com/liaozb/APIJSON.NET/tree/master/APIJSON.NET
### 贡献者们

+

+
+
+
感谢大家的贡献。
+
### 相关推荐
[APIJSON, 让接口和文档见鬼去吧!](https://my.oschina.net/tommylemon/blog/805459)
@@ -146,16 +176,40 @@ https://github.com/liaozb/APIJSON.NET/tree/master/APIJSON.NET
[3步创建APIJSON后端新表及配置](https://my.oschina.net/tommylemon/blog/889074)
+[APIJSON 自动化接口和文档的快速开发神器 (一)](https://blog.csdn.net/qq_41829492/article/details/88670940)
-### 其它项目
-[APIJSON](https://github.com/TommyLemon/APIJSON) 码云最有价值项目:后端接口和文档自动化,前端(客户端) 定制返回JSON的数据和结构
+### 生态项目
+[APIAuto](https://github.com/TommyLemon/APIAuto) 自动化接口管理工具,自动生成文档与注释、自动生成代码、自动化回归测试、自动静态检查等
-[APIJSONAuto](https://github.com/TommyLemon/APIJSONAuto) 自动化接口管理工具,自动生成文档与注释、自动生成代码、自动化回归测试、自动静态检查等
+[apijson-doc](https://github.com/vincentCheng/apijson-doc) APIJSON 官方文档,提供排版清晰、搜索方便的文档内容展示,包括设计规范、图文教程等
+
+[apijson.org](https://github.com/APIJSON/apijson.org) APIJSON 官方网站,提供 APIJSON 的 功能简介、登记用户、作者与贡献者、相关链接 等
+
+[APIJSON](https://github.com/APIJSON/APIJSON) Java 版 APIJSON ,支持 MySQL, PostgreSQL, Oracle, TiDB
+
+[apijson-php](https://github.com/qq547057827/apijson-php) PHP 版 APIJSON,基于 ThinkPHP,支持 MySQL, PostgreSQL, MS SQL Server, Oracle 等
+
+[apijson](https://github.com/TEsTsLA/apijson) Node.ts 版 APIJSON,支持 MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite, MariaDB, WebSQL
+
+[uliweb-apijson](https://github.com/zhangchunlin/uliweb-apijson) Python 版 APIJSON,支持 MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite 等
+
+[APIJSON](https://github.com/crazytaxi824/APIJSON) Go 版 APIJSON,功能开发中...
+
+[APIJSONKOTLIN](https://github.com/luckyxiaomo/APIJSONKOTLIN) Kotlin 版 APIJSON,基础框架搭建中...
+
+[APIJSONParser](https://github.com/Zerounary/APIJSONParser) 第三方 APIJSON 解析器,将 JSON 动态解析成 SQL
+
+[ApiJsonByJFinal](https://gitee.com/zhiyuexin/ApiJsonByJFinal) 整合 APIJSON 和 JFinal 的 Demo
+
+[SpringServer1.2-APIJSON](https://github.com/Airforce-1/SpringServer1.2-APIJSON) 智慧党建服务器端,提供 上传 和 下载 文件的接口
+
+[AbsGrade](https://github.com/APIJSON/AbsGrade) 抽象列表分级工具,支持微信朋友圈单层评论、QQ空间双层评论、百度网盘多层(无限层)文件夹等
[APIJSON-Android-RxJava](https://github.com/TommyLemon/APIJSON-Android-RxJava) 仿微信朋友圈动态实战项目,ZBLibrary(UI) + APIJSON(HTTP) + RxJava(Data)
[Android-ZBLibrary](https://github.com/TommyLemon/Android-ZBLibrary) Android MVP快速开发框架,Demo全面,注释详细,使用简单,代码严谨
+
感谢热心的作者们的贡献,点 ⭐Star 支持下他们吧。
### 持续更新
@@ -166,3 +220,4 @@ https://gitee.com/liaozb/APIJSON.NET
### 我要赞赏
如果你喜欢 APIJSON.NET,感觉它帮助到了你,可以点右上角 ⭐Star 支持一下,谢谢 ^_^
+
From bf06526f4623ddfa1d41e1b6f910f83357f8927d Mon Sep 17 00:00:00 2001
From: TommyLemon
Date: Sun, 1 Sep 2019 16:37:51 +0800
Subject: [PATCH 05/19] Update README.md
---
README.md | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 081c094..1e6eab5 100644
--- a/README.md
+++ b/README.md
@@ -154,11 +154,9 @@ APIJSON是一种专为API而生的 JSON网络传输协议 以及 基于这套协
### 贡献者们

-

-
+
-
From 0c27ac85ce0c0753a847a1b644897f301e152568 Mon Sep 17 00:00:00 2001
From: TommyLemon
Date: Sun, 1 Sep 2019 16:39:11 +0800
Subject: [PATCH 06/19] Update README.md
---
README.md | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 1e6eab5..f69859e 100644
--- a/README.md
+++ b/README.md
@@ -113,14 +113,7 @@ APIJSON是一种专为API而生的 JSON网络传输协议 以及 基于这套协
[前后端 关于接口的 沟通、文档、联调 等 10 大痛点解析](https://github.com/TommyLemon/APIJSON/wiki)
### 快速上手
-
-#### 1.后端部署
-可以跳过这个步骤,直接用APIJSON服务器IP地址 apijson.cn:8080 来测试接口。
-见 [APIJSON后端部署 - Java](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-Java-Server)
-
-#### 2.前端部署
-可以跳过这个步骤,直接使用 [APIAuto-自动化接口管理工具](https://github.com/TommyLemon/APIAuto) 或 下载客户端App。
-见 [Android](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-Android) 或 [iOS](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-iOS) 或 [JavaScript](https://github.com/TommyLemon/APIJSON/tree/master/APIJSON-JavaScript)
+https://github.com/liaozb/APIJSON.NET/tree/master/APIJSON.NET
### 下载客户端App
From 56ef8e6ba58a613e984af2b108e86ebdca0c0781 Mon Sep 17 00:00:00 2001
From: TommyLemon
Date: Sun, 1 Sep 2019 16:40:10 +0800
Subject: [PATCH 07/19] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index f69859e..e55807b 100644
--- a/README.md
+++ b/README.md
@@ -147,7 +147,7 @@ https://github.com/liaozb/APIJSON.NET/tree/master/APIJSON.NET
### 贡献者们

-

+

From f64c5bca0a4f9ed7e05cfe3fd56afd0247aa3fdf Mon Sep 17 00:00:00 2001
From: haptear
Date: Tue, 3 Dec 2019 10:14:23 +0800
Subject: [PATCH 08/19] =?UTF-8?q?0.0.8=20=E6=B8=85=E7=90=86SelectTable=20?=
=?UTF-8?q?=E6=94=AF=E6=8C=81=E9=87=8D=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
APIJSON.NET/APIJSON.NET.Test/Program.cs | 1 +
.../APIJSON.NET/Controllers/JsonController.cs | 33 ++-
.../APIJSON.NET/Services/IdentityService.cs | 44 ++-
.../APIJSONCommon/ApiJson.Common.csproj | 5 +-
.../APIJSONCommon/Properties/AssemblyInfo.cs | 6 +-
APIJSON.NET/APIJSONCommon/SelectTable.cs | 263 ++++++++----------
6 files changed, 197 insertions(+), 155 deletions(-)
diff --git a/APIJSON.NET/APIJSON.NET.Test/Program.cs b/APIJSON.NET/APIJSON.NET.Test/Program.cs
index b23ebdc..8258537 100644
--- a/APIJSON.NET/APIJSON.NET.Test/Program.cs
+++ b/APIJSON.NET/APIJSON.NET.Test/Program.cs
@@ -1,5 +1,6 @@
using RestSharp;
using System;
+using System.Text.RegularExpressions;
namespace APIJSON.NET.Test
{
diff --git a/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs b/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
index 1fd8d2e..16dd406 100644
--- a/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
+++ b/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
@@ -57,7 +57,8 @@ public ActionResult Test()
public async Task Query([FromBody] JObject jobject)
{
- JObject resultJobj = new SelectTable(_identitySvc, _tableMapper, db.Db).Query(jobject);
+ var st = new SelectTable(_identitySvc, _tableMapper, db.Db);
+ JObject resultJobj = st.Query(jobject);
return Ok(resultJobj);
}
@@ -75,9 +76,25 @@ public async Task QueryByTable([FromRoute]string table)
JObject jobject = JObject.Parse(json);
ht.Add(table + "[]", jobject);
- ht.Add("total@", "");
+
+ if (jobject["query"] != null && jobject["query"].ToString() != "0" && jobject["total@"] == null)
+ {
+ //自动添加总计数量
+ ht.Add("total@", "");
+ }
+
+ //每页最大1000条数据
+ if (jobject["count"] != null && int.Parse(jobject["count"].ToString()) > 1000)
+ {
+ throw new Exception("count分页数量最大不能超过1000");
+ }
+
+ bool isDebug = (jobject["@debug"] != null && jobject["@debug"].ToString() != "0");
+ jobject.Remove("@debug");
bool hasTableKey = false;
+ List ignoreConditions = new List { "page", "count", "query" };
+ JObject tableConditions = new JObject();//表的其它查询条件,比如过滤,字段等
foreach (var item in jobject)
{
if (item.Key.Equals(table, StringComparison.CurrentCultureIgnoreCase))
@@ -85,10 +102,20 @@ public async Task QueryByTable([FromRoute]string table)
hasTableKey = true;
break;
}
+ if (!ignoreConditions.Contains(item.Key.ToLower()))
+ {
+ tableConditions.Add(item.Key, item.Value);
+ }
+ }
+
+ foreach (var removeKey in tableConditions)
+ {
+ jobject.Remove(removeKey.Key);
}
+
if (!hasTableKey)
{
- jobject.Add(table, new JObject());
+ jobject.Add(table, tableConditions);
}
return await Query(ht);
diff --git a/APIJSON.NET/APIJSON.NET/Services/IdentityService.cs b/APIJSON.NET/APIJSON.NET/Services/IdentityService.cs
index dce67b4..b017ab0 100644
--- a/APIJSON.NET/APIJSON.NET/Services/IdentityService.cs
+++ b/APIJSON.NET/APIJSON.NET/Services/IdentityService.cs
@@ -10,25 +10,47 @@
namespace APIJSON.NET.Services
{
+ ///
+ ///
+ ///
public class IdentityService : IIdentityService
{
private IHttpContextAccessor _context;
private List roles;
+ ///
+ ///
+ ///
+ ///
+ ///
public IdentityService(IHttpContextAccessor context, IOptions> _roles)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
roles = _roles.Value;
}
+
+ ///
+ ///
+ ///
+ ///
public string GetUserIdentity()
{
return _context.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
}
+ ///
+ ///
+ ///
+ ///
public string GetUserRoleName()
{
return _context.HttpContext.User.FindFirstValue(ClaimTypes.Role);
}
+
+ ///
+ ///
+ ///
+ ///
public Role GetRole()
{
var role = new Role();
@@ -43,23 +65,37 @@ public Role GetRole()
}
return role;
}
- public (bool, string) GetSelectRole(string table)
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public Tuple GetSelectRole(string table)
{
var role = GetRole();
if (role == null || role.Select == null || role.Select.Table == null)
{
- return (false, $"appsettings.json权限配置不正确!");
+ return Tuple.Create(false, $"appsettings.json权限配置不正确!");
}
string tablerole = role.Select.Table.FirstOrDefault(it => it == "*" || it.Equals(table, StringComparison.CurrentCultureIgnoreCase));
if (string.IsNullOrEmpty(tablerole))
{
- return (false, $"表名{table}没权限查询!");
+ return Tuple.Create(false, $"表名{table}没权限查询!");
}
int index = Array.IndexOf(role.Select.Table, tablerole);
string selectrole = role.Select.Column[index];
- return (true, selectrole);
+ return Tuple.Create(true, selectrole);
}
+
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public bool ColIsRole(string col, string[] selectrole)
{
if (selectrole.Contains("*"))
diff --git a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
index 5148960..653a203 100644
--- a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
+++ b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
@@ -2,8 +2,9 @@
netstandard2.0
- 0.0.7
- 0.0.7 修复not in的缺陷,增加~ 不等于的支持
+ 0.0.8
+ 0.0.8 清理SelectTable 支持重载
+0.0.7 修复not in的缺陷,增加~ 不等于的支持
0.0.6 增加ToSql接口,处理sql注入的情况
通用查询组件
ApiJson.Common.Core
diff --git a/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs b/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
index fbcdc6a..c60d3fa 100644
--- a/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
+++ b/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
@@ -5,7 +5,7 @@
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ApiJson.Common")]
-[assembly: AssemblyDescription("增加ToSql接口,处理sql注入的情况")]
+[assembly: AssemblyDescription("修复not in的缺陷,增加~ 不等于的支持")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ApiJson.Common")]
@@ -31,5 +31,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.0.6.0")]
-[assembly: AssemblyFileVersion("0.0.6.0")]
+[assembly: AssemblyVersion("0.0.7.0")]
+[assembly: AssemblyFileVersion("0.0.7.0")]
diff --git a/APIJSON.NET/APIJSONCommon/SelectTable.cs b/APIJSON.NET/APIJSONCommon/SelectTable.cs
index 89109a5..44e7fb3 100644
--- a/APIJSON.NET/APIJSONCommon/SelectTable.cs
+++ b/APIJSON.NET/APIJSONCommon/SelectTable.cs
@@ -36,7 +36,7 @@ public SelectTable(IIdentityService identityService, ITableMapper tableMapper, S
///
///
///
- public bool IsTable(string table)
+ public virtual bool IsTable(string table)
{
return db.DbMaintenance.GetTableInfoList().Any(it => it.Name.Equals(table, StringComparison.CurrentCultureIgnoreCase));
}
@@ -46,39 +46,11 @@ public bool IsTable(string table)
///
///
///
- public bool IsCol(string table, string col)
+ public virtual bool IsCol(string table, string col)
{
return db.DbMaintenance.GetColumnInfosByTableName(table).Any(it => it.DbColumnName.Equals(col, StringComparison.CurrentCultureIgnoreCase));
}
- ///
- /// 动态调用方法
- ///
- ///
- ///
- ///
- ///
- public object ExecFunc(string funcname, object[] param, Type[] types)
- {
- var method = typeof(FuncList).GetMethod(funcname);
- var reflector = method.GetReflector();
- var result = reflector.Invoke(new FuncList(), param);
- return result;
- }
-
- private string ToSql(string subtable, int page, int count, int query, string json)
- {
- JObject values = JObject.Parse(json);
- page = values["page"] == null ? page : int.Parse(values["page"].ToString());
- count = values["count"] == null ? count : int.Parse(values["count"].ToString());
- query = values["query"] == null ? query : int.Parse(values["query"].ToString());
- values.Remove("page");
- values.Remove("count");
- subtable = _tableMapper.GetTableName(subtable);
- var tb = sugarQueryable(subtable, "*", values, null);
- var xx = tb.Skip((page - 1) * count).Take(10).ToSql();
- return xx.Key;
- }
///
///
///
@@ -88,7 +60,7 @@ private string ToSql(string subtable, int page, int count, int query, string jso
///
///
///
- public Tuple GetTableData(string subtable, int page, int count, int query, string json, JObject dd)
+ public virtual Tuple GetTableData(string subtable, int page, int count, int query, string json, JObject dd)
{
var role = _identitySvc.GetSelectRole(subtable);
@@ -130,69 +102,17 @@ public Tuple GetTableData(string subtable, int page, int count, in
}
}
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public dynamic GetFirstData(string subtable, string json, JObject dd)
- {
-
- var role = _identitySvc.GetSelectRole(subtable);
- if (!role.Item1)//没有权限返回异常
- {
- throw new Exception(role.Item2);
- }
- string selectrole = role.Item2;
- subtable = _tableMapper.GetTableName(subtable);
- JObject values = JObject.Parse(json);
- values.Remove("page");
- values.Remove("count");
- var tb = sugarQueryable(subtable, selectrole, values, dd).First();
- var dic = (IDictionary)tb;
- foreach (var item in values.Properties().Where(it => it.Name.EndsWith("()")))
- {
- if (item.Value.IsValue())
- {
- string func = item.Value.ToString().Substring(0, item.Value.ToString().IndexOf("("));
- string param = item.Value.ToString().Substring(item.Value.ToString().IndexOf("(") + 1).TrimEnd(')');
- var types = new List();
- var paramss = new List