From 1a65cf39c19c5cd574e6228d35878319bf7aa0ca Mon Sep 17 00:00:00 2001
From: liaozb <635990945@qq.com>
Date: Thu, 23 Jun 2022 16:09:57 +0800
Subject: [PATCH 1/5] =?UTF-8?q?#=E5=8D=87=E7=BA=A7=E5=88=B0.net6.0#?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj | 14 ++-
APIJSON.NET/APIJSON.NET/Program.cs | 90 ++++++++++++++++---
APIJSON.NET/APIJSON.NET/appsettings.json | 16 ++--
.../APIJSONCommon/ApiJson.Common.csproj | 6 +-
4 files changed, 94 insertions(+), 32 deletions(-)
diff --git a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj
index d33ec88..a370b61 100644
--- a/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj
+++ b/APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj
@@ -1,7 +1,7 @@
- netcoreapp3.1
+ net6.0
@@ -19,19 +19,17 @@
-
-
-
+
+
+
-
-
-
+
-
+
diff --git a/APIJSON.NET/APIJSON.NET/Program.cs b/APIJSON.NET/APIJSON.NET/Program.cs
index 2fa47dc..47669b6 100644
--- a/APIJSON.NET/APIJSON.NET/Program.cs
+++ b/APIJSON.NET/APIJSON.NET/Program.cs
@@ -1,19 +1,83 @@
-using Microsoft.AspNetCore;
+using APIJSON.NET;
+using APIJSON.NET.Models;
+using APIJSON.NET.Services;
+using Microsoft.AspNetCore;
+using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.IdentityModel.Tokens;
+using Microsoft.OpenApi.Models;
+using System;
+using System.Collections.Generic;
using System.Net;
+using System.Text;
-namespace APIJSON.NET
+const string _defaultCorsPolicyName = "localhost";
+var builder = WebApplication.CreateBuilder(args);
+
+// Add services to the container.
+
+builder.Services.AddControllers();
+// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
+builder.Services.AddEndpointsApiExplorer();
+
+builder.Services.Configure>(builder.Configuration.GetSection("RoleList"));
+builder.Services.Configure>(builder.Configuration.GetSection("tablempper"));
+builder.Services.Configure(tokenAuthConfig =>
{
- public class Program
+ tokenAuthConfig.SecurityKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(builder.Configuration["Authentication:JwtBearer:SecurityKey"]));
+ tokenAuthConfig.Issuer = builder.Configuration["Authentication:JwtBearer:Issuer"];
+ tokenAuthConfig.Audience = builder.Configuration["Authentication:JwtBearer:Audience"];
+ tokenAuthConfig.SigningCredentials = new SigningCredentials(tokenAuthConfig.SecurityKey, SecurityAlgorithms.HmacSha256);
+ tokenAuthConfig.Expiration = TimeSpan.FromDays(1);
+});
+AuthConfigurer.Configure(builder.Services, builder.Configuration);
+
+var origins = builder.Configuration.GetSection("CorsUrls").Value.Split(",");
+builder.Services.AddCors(options => options.AddPolicy(_defaultCorsPolicyName,
+ builder =>
+ builder.WithOrigins(origins)
+ .AllowAnyHeader()
+ .AllowAnyMethod().AllowCredentials()
+ ));
+builder.Services.AddControllers()
+ .AddNewtonsoftJson(options =>
{
- public static void Main(string[] args)
- {
- CreateWebHostBuilder(args).Build().Run();
- }
-
- public static IWebHostBuilder CreateWebHostBuilder(string[] args)
- {
- return WebHost.CreateDefaultBuilder(args).UseStartup();
- }
- }
+ options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
+ options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
+ }); ;
+builder.Services.AddSwaggerGen(c =>
+{
+ c.SwaggerDoc("v1", new OpenApiInfo { Title = "APIJSON.NET", Version = "v1" });
+});
+builder.Services.AddSingleton();
+builder.Services.AddSingleton();
+builder.Services.AddSingleton();
+builder.Services.AddSingleton();
+builder.Services.AddTransient();
+builder.Services.AddTransient();
+
+
+var app = builder.Build();
+
+// Configure the HTTP request pipeline.
+if (app.Environment.IsDevelopment())
+{
+ app.UseSwagger();
+ app.UseSwaggerUI(c =>
+ {
+ c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
+
+ });
}
+
+app.UseHttpsRedirection();
+app.UseStaticFiles();
+app.UseAuthorization();
+app.UseCors(_defaultCorsPolicyName);
+app.MapControllers();
+app.UseJwtTokenMiddleware();
+DbInit.Initialize(app);
+app.Run();
\ No newline at end of file
diff --git a/APIJSON.NET/APIJSON.NET/appsettings.json b/APIJSON.NET/APIJSON.NET/appsettings.json
index 3f3b41c..ac5a7c8 100644
--- a/APIJSON.NET/APIJSON.NET/appsettings.json
+++ b/APIJSON.NET/APIJSON.NET/appsettings.json
@@ -15,21 +15,21 @@
},
"RoleList": [
{
- "name": "role1", //Ȩ������ Ψһ
- "select": { //��ѯȨ��
- "table": [ "*" ], //�ɲ����ı�
- "column": [ "*" ], //�ɲ������ֶ�
+ "name": "role1", //Ȩ������ Ψһ
+ "select": { //��ѯȨ��
+ "table": [ "*" ], //�ɲ����ı�
+ "column": [ "*" ], //�ɲ������ֶ�
"where": []
},
- "update": { //��Ȩ��
+ "update": { //��Ȩ��
"table": [ "moment", "User", "Comment" ],
"column": [ "*", "*", "*" ]
},
- "insert": { //����Ȩ��
+ "insert": { //���Ȩ��
"table": [ "moment", "User", "Comment" ],
"column": [ "*", "*", "*" ]
},
- "delete": { //ɾ��Ȩ��
+ "delete": { //ɾ��Ȩ��
"table": [ "moment", "User", "Comment" ]
}
},
@@ -41,7 +41,7 @@
}
}
],
- "tablempper": //������ӳ��
+ "tablempper": //������ӳ��
{
"user": "apijson_user",
"org": "web_organization"
diff --git a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
index f6c0ce9..ba4928c 100644
--- a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
+++ b/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
@@ -20,9 +20,9 @@
-
-
-
+
+
+
From f80ed27717e289079e6816b52e833406c1e39542 Mon Sep 17 00:00:00 2001
From: liaozb <635990945@qq.com>
Date: Thu, 23 Jun 2022 17:14:28 +0800
Subject: [PATCH 2/5] =?UTF-8?q?#=E4=B9=B1=E7=A0=81=E4=BF=AE=E5=A4=8D#?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
APIJSON.NET/APIJSON.NET/appsettings.json | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/APIJSON.NET/APIJSON.NET/appsettings.json b/APIJSON.NET/APIJSON.NET/appsettings.json
index ac5a7c8..a088cc3 100644
--- a/APIJSON.NET/APIJSON.NET/appsettings.json
+++ b/APIJSON.NET/APIJSON.NET/appsettings.json
@@ -15,21 +15,21 @@
},
"RoleList": [
{
- "name": "role1", //Ȩ������ Ψһ
- "select": { //��ѯȨ��
- "table": [ "*" ], //�ɲ����ı�
- "column": [ "*" ], //�ɲ������ֶ�
+ "name": "role1", //权限名称 唯一
+ "select": { //查询权限
+ "table": [ "*" ], //可操作的表
+ "column": [ "*" ], //可操作的字段
"where": []
},
- "update": { //��Ȩ��
+ "update": { //修改权限
"table": [ "moment", "User", "Comment" ],
"column": [ "*", "*", "*" ]
},
- "insert": { //���Ȩ��
+ "insert": { //添加权限
"table": [ "moment", "User", "Comment" ],
"column": [ "*", "*", "*" ]
},
- "delete": { //ɾ��Ȩ��
+ "delete": { //删除权限
"table": [ "moment", "User", "Comment" ]
}
},
@@ -41,7 +41,7 @@
}
}
],
- "tablempper": //������ӳ��
+ "tablempper": //别名表映射
{
"user": "apijson_user",
"org": "web_organization"
From bd1f3dbed78537ea7fbbd461f37c489c966b89f6 Mon Sep 17 00:00:00 2001
From: liaozb <635990945@qq.com>
Date: Fri, 24 Jun 2022 10:11:39 +0800
Subject: [PATCH 3/5] =?UTF-8?q?#=E8=BF=90=E8=A1=8C=E9=94=99=E8=AF=AF?=
=?UTF-8?q?=E4=BF=AE=E5=A4=8D#?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../APIJSON.NET/Controllers/JsonController.cs | 3 ---
APIJSON.NET/APIJSON.NET/Data/DbContext.cs | 2 +-
APIJSON.NET/APIJSON.NET/Data/DbInit.cs | 2 +-
.../APIJSON.NET/{ => Data}/Models/Login.cs | 6 +++---
APIJSON.NET/APIJSON.NET/Program.cs | 18 +++++++++---------
APIJSON.NET/APIJSON.NET/appsettings.json | 4 ++--
6 files changed, 16 insertions(+), 19 deletions(-)
rename APIJSON.NET/APIJSON.NET/{ => Data}/Models/Login.cs (84%)
diff --git a/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs b/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
index 16dd406..d2edac2 100644
--- a/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
+++ b/APIJSON.NET/APIJSON.NET/Controllers/JsonController.cs
@@ -134,9 +134,6 @@ public ActionResult Add([FromBody]JObject jobject)
ht.Add("msg", "success");
try
{
-
-
-
foreach (var item in jobject)
{
string key = item.Key.Trim();
diff --git a/APIJSON.NET/APIJSON.NET/Data/DbContext.cs b/APIJSON.NET/APIJSON.NET/Data/DbContext.cs
index d3c8754..0756ffc 100644
--- a/APIJSON.NET/APIJSON.NET/Data/DbContext.cs
+++ b/APIJSON.NET/APIJSON.NET/Data/DbContext.cs
@@ -1,4 +1,4 @@
-using APIJSON.NET.Models;
+using APIJSON.NET.Data.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using SqlSugar;
diff --git a/APIJSON.NET/APIJSON.NET/Data/DbInit.cs b/APIJSON.NET/APIJSON.NET/Data/DbInit.cs
index b80bdd2..2b395c2 100644
--- a/APIJSON.NET/APIJSON.NET/Data/DbInit.cs
+++ b/APIJSON.NET/APIJSON.NET/Data/DbInit.cs
@@ -1,4 +1,4 @@
-using APIJSON.NET.Models;
+using APIJSON.NET.Data.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
diff --git a/APIJSON.NET/APIJSON.NET/Models/Login.cs b/APIJSON.NET/APIJSON.NET/Data/Models/Login.cs
similarity index 84%
rename from APIJSON.NET/APIJSON.NET/Models/Login.cs
rename to APIJSON.NET/APIJSON.NET/Data/Models/Login.cs
index c3f2be5..2c018e2 100644
--- a/APIJSON.NET/APIJSON.NET/Models/Login.cs
+++ b/APIJSON.NET/APIJSON.NET/Data/Models/Login.cs
@@ -1,13 +1,13 @@
using SqlSugar;
using System;
-namespace APIJSON.NET.Models
+namespace APIJSON.NET.Data.Models
{
public class Login
{
[SugarColumn(IsNullable = false, IsPrimaryKey = true)]
public int userId { get; set; }
- [SugarColumn(Length =100,ColumnDescription ="用户名")]
+ [SugarColumn(Length = 100, ColumnDescription = "用户名")]
public string userName { get; set; }
[SugarColumn(Length = 200, ColumnDescription = "密码")]
public string passWord { get; set; }
@@ -15,6 +15,6 @@ public class Login
public string passWordSalt { get; set; }
[SugarColumn(Length = 100, ColumnDescription = "权限组")]
public string roleCode { get; set; }
-
+
}
}
diff --git a/APIJSON.NET/APIJSON.NET/Program.cs b/APIJSON.NET/APIJSON.NET/Program.cs
index 47669b6..671614d 100644
--- a/APIJSON.NET/APIJSON.NET/Program.cs
+++ b/APIJSON.NET/APIJSON.NET/Program.cs
@@ -19,7 +19,11 @@
// Add services to the container.
-builder.Services.AddControllers();
+builder.Services.AddControllers().AddNewtonsoftJson(options =>
+{
+ options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
+ options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
+});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
@@ -42,23 +46,18 @@
.AllowAnyHeader()
.AllowAnyMethod().AllowCredentials()
));
-builder.Services.AddControllers()
- .AddNewtonsoftJson(options =>
- {
- options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
- options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
- }); ;
+
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "APIJSON.NET", Version = "v1" });
});
builder.Services.AddSingleton();
-builder.Services.AddSingleton();
+
builder.Services.AddSingleton();
builder.Services.AddSingleton();
builder.Services.AddTransient();
builder.Services.AddTransient();
-
+
var app = builder.Build();
@@ -74,6 +73,7 @@
}
app.UseHttpsRedirection();
+app.UseDefaultFiles();
app.UseStaticFiles();
app.UseAuthorization();
app.UseCors(_defaultCorsPolicyName);
diff --git a/APIJSON.NET/APIJSON.NET/appsettings.json b/APIJSON.NET/APIJSON.NET/appsettings.json
index a088cc3..94ff268 100644
--- a/APIJSON.NET/APIJSON.NET/appsettings.json
+++ b/APIJSON.NET/APIJSON.NET/appsettings.json
@@ -1,7 +1,7 @@
{
"ConnectionStrings": {
- "DbType": 0, //0:MySql,1:SqlServer,2:Sqlite
- "ConnectionString": "Server=192.168.2.25;Database=yunwei1.8;Uid=root;Pwd=xmjk;Port=3306;Character Set=utf8;"
+ "DbType": 1, //0:MySql,1:SqlServer,2:Sqlite
+ "ConnectionString": "Server=localhost;Database=APIJSON.NET;Uid=sa;Pwd=sa123qwe,;"
//"ConnectionString": "Server=119.29.9.25;Port=3306;Database=test;Uid=root;Pwd=1q,2w.3e?;CharSet=UTF8;"
},
"CorsUrls": "http://localhost:5000,http://localhost5001",
From 462977a356735ad19ad033e5d579dbc3cb1c18a6 Mon Sep 17 00:00:00 2001
From: liaozb <635990945@qq.com>
Date: Sun, 4 Feb 2024 15:51:35 +0800
Subject: [PATCH 4/5] =?UTF-8?q?#=E5=8D=87=E7=BA=A7=E5=88=B0.NET8#?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../APIJSON.Data.csproj} | 13 +-
.../APIJSON.Data/ApiJsonNetDataModule.cs | 16 +
APIJSON.NET/APIJSON.Data/Data/DbContext.cs | 41 +
APIJSON.NET/APIJSON.Data/FuncList.cs | 43 +
.../Infrastructure/SimpleStringCipher.cs | 134 ++
.../Infrastructure/StringExtensions.cs | 28 +
APIJSON.NET/APIJSON.Data/Models/DbOptions.cs | 15 +
APIJSON.NET/APIJSON.Data/Models/Login.cs | 19 +
APIJSON.NET/APIJSON.Data/Models/RoleItem.cs | 18 +
.../Properties/AssemblyInfo.cs | 0
APIJSON.NET/APIJSON.Data/SelectTable.cs | 827 +++++++++
.../APIJSON.Data/Services/IIdentityService.cs | 32 +
.../Services/ITableMapper.cs | 6 +-
.../APIJSON.Data/Services/TableMapper.cs | 26 +
.../APIJSON.NET.Test/APIJSON.NET.Test.csproj | 4 +-
APIJSON.NET/APIJSON.NET.Test/Program.cs | 69 +-
APIJSON.NET/APIJSON.NET.sln | 6 +-
APIJSON.NET/APIJSON.NET/APIJSON.NET.csproj | 48 +-
APIJSON.NET/APIJSON.NET/AppModule.cs | 123 ++
.../APIJSON.NET/Controllers/HomeController.cs | 13 +-
.../APIJSON.NET/Controllers/JsonController.cs | 439 +++--
.../Controllers/TokenController.cs | 160 +-
APIJSON.NET/APIJSON.NET/Data/DbContext.cs | 44 -
APIJSON.NET/APIJSON.NET/Data/Models/Login.cs | 20 -
APIJSON.NET/APIJSON.NET/Dockerfile | 25 +-
.../Infrastructure/JwtTokenMiddleware.cs | 26 -
.../Infrastructure/SimpleStringCipher.cs | 138 --
APIJSON.NET/APIJSON.NET/Logs/logs.txt | 1491 +++++++++++++++++
.../Models/TokenAuthConfiguration.cs | 18 -
APIJSON.NET/APIJSON.NET/Program.cs | 124 +-
.../AuthConfigurer.cs | 0
.../APIJSON.NET/{Data => Services}/DbInit.cs | 26 +-
.../APIJSON.NET/Services/IdentityService.cs | 6 +-
.../Services/JwtTokenMiddleware.cs | 24 +
.../Services/TokenAuthConfiguration.cs | 18 +
APIJSON.NET/APIJSON.NET/Startup.cs | 93 -
APIJSON.NET/APIJSON.NET/appsettings.json | 4 +-
.../APIJSONCommon/ApiJson.Common_461.csproj | 97 --
.../APIJSONCommon/ApiJson.Common_461.sln | 31 -
APIJSON.NET/APIJSONCommon/FuncList.cs | 44 -
.../Infrastructure/StringExtensions.cs | 29 -
APIJSON.NET/APIJSONCommon/Models/DbOptions.cs | 16 -
APIJSON.NET/APIJSONCommon/Models/RoleItem.cs | 19 -
APIJSON.NET/APIJSONCommon/SelectTable.cs | 829 ---------
.../Services/IIdentityService.cs | 33 -
.../APIJSONCommon/Services/TableMapper.cs | 26 -
APIJSON.NET/APIJSONCommon/app.config | 11 -
APIJSON.NET/APIJSONCommon/packages.config | 17 -
48 files changed, 3320 insertions(+), 1969 deletions(-)
rename APIJSON.NET/{APIJSONCommon/ApiJson.Common.csproj => APIJSON.Data/APIJSON.Data.csproj} (79%)
create mode 100644 APIJSON.NET/APIJSON.Data/ApiJsonNetDataModule.cs
create mode 100644 APIJSON.NET/APIJSON.Data/Data/DbContext.cs
create mode 100644 APIJSON.NET/APIJSON.Data/FuncList.cs
create mode 100644 APIJSON.NET/APIJSON.Data/Infrastructure/SimpleStringCipher.cs
create mode 100644 APIJSON.NET/APIJSON.Data/Infrastructure/StringExtensions.cs
create mode 100644 APIJSON.NET/APIJSON.Data/Models/DbOptions.cs
create mode 100644 APIJSON.NET/APIJSON.Data/Models/Login.cs
create mode 100644 APIJSON.NET/APIJSON.Data/Models/RoleItem.cs
rename APIJSON.NET/{APIJSONCommon => APIJSON.Data}/Properties/AssemblyInfo.cs (100%)
create mode 100644 APIJSON.NET/APIJSON.Data/SelectTable.cs
create mode 100644 APIJSON.NET/APIJSON.Data/Services/IIdentityService.cs
rename APIJSON.NET/{APIJSONCommon => APIJSON.Data}/Services/ITableMapper.cs (86%)
create mode 100644 APIJSON.NET/APIJSON.Data/Services/TableMapper.cs
create mode 100644 APIJSON.NET/APIJSON.NET/AppModule.cs
delete mode 100644 APIJSON.NET/APIJSON.NET/Data/DbContext.cs
delete mode 100644 APIJSON.NET/APIJSON.NET/Data/Models/Login.cs
delete mode 100644 APIJSON.NET/APIJSON.NET/Infrastructure/JwtTokenMiddleware.cs
delete mode 100644 APIJSON.NET/APIJSON.NET/Infrastructure/SimpleStringCipher.cs
create mode 100644 APIJSON.NET/APIJSON.NET/Logs/logs.txt
delete mode 100644 APIJSON.NET/APIJSON.NET/Models/TokenAuthConfiguration.cs
rename APIJSON.NET/APIJSON.NET/{Infrastructure => Services}/AuthConfigurer.cs (100%)
rename APIJSON.NET/APIJSON.NET/{Data => Services}/DbInit.cs (59%)
create mode 100644 APIJSON.NET/APIJSON.NET/Services/JwtTokenMiddleware.cs
create mode 100644 APIJSON.NET/APIJSON.NET/Services/TokenAuthConfiguration.cs
delete mode 100644 APIJSON.NET/APIJSON.NET/Startup.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/ApiJson.Common_461.csproj
delete mode 100644 APIJSON.NET/APIJSONCommon/ApiJson.Common_461.sln
delete mode 100644 APIJSON.NET/APIJSONCommon/FuncList.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/Infrastructure/StringExtensions.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/Models/DbOptions.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/Models/RoleItem.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/SelectTable.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/Services/IIdentityService.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/Services/TableMapper.cs
delete mode 100644 APIJSON.NET/APIJSONCommon/app.config
delete mode 100644 APIJSON.NET/APIJSONCommon/packages.config
diff --git a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj b/APIJSON.NET/APIJSON.Data/APIJSON.Data.csproj
similarity index 79%
rename from APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
rename to APIJSON.NET/APIJSON.Data/APIJSON.Data.csproj
index ba4928c..8a515d4 100644
--- a/APIJSON.NET/APIJSONCommon/ApiJson.Common.csproj
+++ b/APIJSON.NET/APIJSON.Data/APIJSON.Data.csproj
@@ -1,7 +1,7 @@
- netstandard2.1
+ net8.0
0.0.11
0.0.11 升级sqlSugarCore版本 解决如果查找字段是关键字(例如:key)时出错的问题
@@ -20,13 +20,12 @@
-
-
-
+
+
+
+
-
-
-
+
diff --git a/APIJSON.NET/APIJSON.Data/ApiJsonNetDataModule.cs b/APIJSON.NET/APIJSON.Data/ApiJsonNetDataModule.cs
new file mode 100644
index 0000000..8dbe0dc
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/ApiJsonNetDataModule.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Volo.Abp.Autofac;
+using Volo.Abp.Modularity;
+
+namespace APIJSON.Data;
+[DependsOn(
+ typeof(AbpAutofacModule))]
+public class ApiJsonNetDataModule : AbpModule
+{
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+
+ }
+}
diff --git a/APIJSON.NET/APIJSON.Data/Data/DbContext.cs b/APIJSON.NET/APIJSON.Data/Data/DbContext.cs
new file mode 100644
index 0000000..1f2ab40
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/Data/DbContext.cs
@@ -0,0 +1,41 @@
+using APIJSON.Data.Models;
+using Microsoft.Extensions.Configuration;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using Volo.Abp.DependencyInjection;
+namespace APIJSON.Data;
+
+public class DbContext:ISingletonDependency
+{
+ public DbContext(IConfiguration options)
+ {
+ Db = new SqlSugarClient(new ConnectionConfig()
+ {
+ ConnectionString = options.GetConnectionString("ConnectionString"),
+ DbType = (DbType)Enum.Parse(typeof(DbType), options.GetConnectionString("DbType")), InitKeyType= InitKeyType.Attribute,
+ IsAutoCloseConnection = true
+ });
+ Db.Aop.OnLogExecuted = (sql, pars) => //SQL执行完事件
+ {
+
+ };
+ Db.Aop.OnLogExecuting = (sql, pars) => //SQL执行前事件
+ {
+
+ };
+ }
+ public SqlSugarClient Db;
+ public DbSet LoginDb { get { return new DbSet(Db); } }
+}
+public class DbSet : SimpleClient where T : class, new()
+{
+ public DbSet(SqlSugarClient context) : base(context)
+ {
+
+ }
+ public List GetByIds(dynamic[] ids)
+ {
+ return Context.Queryable().In(ids).ToList(); ;
+ }
+}
diff --git a/APIJSON.NET/APIJSON.Data/FuncList.cs b/APIJSON.NET/APIJSON.Data/FuncList.cs
new file mode 100644
index 0000000..7acc119
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/FuncList.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Linq;
+
+namespace APIJSON.Data;
+
+///
+/// 自定义方法
+///
+public class FuncList
+{
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public string Merge(object a, object b)
+ {
+ return a.ToString() + b.ToString();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public object MergeObj(object a, object b)
+ {
+ return new { a, b };
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool isContain(object a, object b)
+ {
+ return a.ToString().Split(',').Contains(b);
+ }
+}
diff --git a/APIJSON.NET/APIJSON.Data/Infrastructure/SimpleStringCipher.cs b/APIJSON.NET/APIJSON.Data/Infrastructure/SimpleStringCipher.cs
new file mode 100644
index 0000000..43b09bc
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/Infrastructure/SimpleStringCipher.cs
@@ -0,0 +1,134 @@
+using System;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace APIJSON.Data;
+
+public class SimpleStringCipher
+{
+ public static SimpleStringCipher Instance { get; }
+
+ ///
+ /// This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
+ /// This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be
+ /// 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array.
+ ///
+ public byte[] InitVectorBytes;
+
+ ///
+ /// Default password to encrypt/decrypt texts.
+ /// It's recommented to set to another value for security.
+ /// Default value: "gsKnGZ041HLL4IM8"
+ ///
+ public static string DefaultPassPhrase { get; set; }
+
+ ///
+ /// Default value: Encoding.ASCII.GetBytes("jkE49230Tf093b42")
+ ///
+ public static byte[] DefaultInitVectorBytes { get; set; }
+
+ ///
+ /// Default value: Encoding.ASCII.GetBytes("hgt!16kl")
+ ///
+ public static byte[] DefaultSalt { get; set; }
+
+ ///
+ /// This constant is used to determine the keysize of the encryption algorithm.
+ ///
+ public const int Keysize = 256;
+
+ static SimpleStringCipher()
+ {
+ DefaultPassPhrase = "gsKnGZ041HLL4IM9";
+ DefaultInitVectorBytes = Encoding.ASCII.GetBytes("jkE49230Tf093b42");
+ DefaultSalt = Encoding.ASCII.GetBytes("hgt!11kl");
+ Instance = new SimpleStringCipher();
+ }
+
+ public SimpleStringCipher()
+ {
+ InitVectorBytes = DefaultInitVectorBytes;
+ }
+
+ public string Encrypt(string plainText, string passPhrase = null, byte[] salt = null)
+ {
+ if (plainText == null)
+ {
+ return null;
+ }
+
+ if (passPhrase == null)
+ {
+ passPhrase = DefaultPassPhrase;
+ }
+
+ if (salt == null)
+ {
+ salt = DefaultSalt;
+ }
+
+ var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
+ using (var password = new Rfc2898DeriveBytes(passPhrase, salt))
+ {
+ var keyBytes = password.GetBytes(Keysize / 8);
+ using (var symmetricKey = Aes.Create())
+ {
+ symmetricKey.Mode = CipherMode.CBC;
+ using (var encryptor = symmetricKey.CreateEncryptor(keyBytes, InitVectorBytes))
+ {
+ using (var memoryStream = new MemoryStream())
+ {
+ using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
+ {
+ cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
+ cryptoStream.FlushFinalBlock();
+ var cipherTextBytes = memoryStream.ToArray();
+ return Convert.ToBase64String(cipherTextBytes);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public string Decrypt(string cipherText, string passPhrase = null, byte[] salt = null)
+ {
+ if (string.IsNullOrEmpty(cipherText))
+ {
+ return null;
+ }
+
+ if (passPhrase == null)
+ {
+ passPhrase = DefaultPassPhrase;
+ }
+
+ if (salt == null)
+ {
+ salt = DefaultSalt;
+ }
+
+ var cipherTextBytes = Convert.FromBase64String(cipherText);
+ using (var password = new Rfc2898DeriveBytes(passPhrase, salt))
+ {
+ var keyBytes = password.GetBytes(Keysize / 8);
+ using (var symmetricKey = Aes.Create())
+ {
+ symmetricKey.Mode = CipherMode.CBC;
+ using (var decryptor = symmetricKey.CreateDecryptor(keyBytes, InitVectorBytes))
+ {
+ using (var memoryStream = new MemoryStream(cipherTextBytes))
+ {
+ using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
+ {
+ var plainTextBytes = new byte[cipherTextBytes.Length];
+ var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
+ return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/APIJSON.NET/APIJSON.Data/Infrastructure/StringExtensions.cs b/APIJSON.NET/APIJSON.Data/Infrastructure/StringExtensions.cs
new file mode 100644
index 0000000..240b92b
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/Infrastructure/StringExtensions.cs
@@ -0,0 +1,28 @@
+namespace APIJSON.Data;
+
+using System;
+using System.Text.RegularExpressions;
+public static class StringExtensions
+{
+
+ ///
+ /// 是否有值
+ ///
+ ///
+ ///
+ public static bool IsValue(this object str)
+ {
+ return str != null && !string.IsNullOrEmpty(str.ToString());
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string GetParamName(this string param)
+ {
+ return param + new Random().Next(1, 100);
+ }
+
+}
\ No newline at end of file
diff --git a/APIJSON.NET/APIJSON.Data/Models/DbOptions.cs b/APIJSON.NET/APIJSON.Data/Models/DbOptions.cs
new file mode 100644
index 0000000..c33da47
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/Models/DbOptions.cs
@@ -0,0 +1,15 @@
+namespace APIJSON.Data;
+
+using global::SqlSugar;
+public class DbOptions
+{
+ ///
+ ///
+ ///
+ public DbType DbType { get; set; }
+
+ ///
+ ///
+ ///
+ public string ConnectionString { get; set; }
+}
diff --git a/APIJSON.NET/APIJSON.Data/Models/Login.cs b/APIJSON.NET/APIJSON.Data/Models/Login.cs
new file mode 100644
index 0000000..0dcdf11
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/Models/Login.cs
@@ -0,0 +1,19 @@
+using SqlSugar;
+using System;
+
+namespace APIJSON.Data.Models;
+
+public class Login
+{
+ [SugarColumn(IsNullable = false, IsPrimaryKey = true)]
+ public int userId { get; set; }
+ [SugarColumn(Length = 100, ColumnDescription = "用户名")]
+ public string userName { get; set; }
+ [SugarColumn(Length = 200, ColumnDescription = "密码")]
+ public string passWord { get; set; }
+ [SugarColumn(Length = 100, ColumnDescription = "密码盐")]
+ public string passWordSalt { get; set; }
+ [SugarColumn(Length = 100, ColumnDescription = "权限组")]
+ public string roleCode { get; set; }
+
+}
diff --git a/APIJSON.NET/APIJSON.Data/Models/RoleItem.cs b/APIJSON.NET/APIJSON.Data/Models/RoleItem.cs
new file mode 100644
index 0000000..ba16bc6
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/Models/RoleItem.cs
@@ -0,0 +1,18 @@
+namespace APIJSON.Data.Models;
+
+public class RoleItem
+{
+ public string[] Table { get; set; }
+ public string[] Column { get; set; }
+ public string[] Filter { get; set; }
+}
+public class Role
+{
+ public string Name { get; set; }
+ public RoleItem Select { get; set; }
+ public RoleItem Update { get; set; }
+ public RoleItem Insert { get; set; }
+ public RoleItem Delete { get; set; }
+
+}
+
diff --git a/APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs b/APIJSON.NET/APIJSON.Data/Properties/AssemblyInfo.cs
similarity index 100%
rename from APIJSON.NET/APIJSONCommon/Properties/AssemblyInfo.cs
rename to APIJSON.NET/APIJSON.Data/Properties/AssemblyInfo.cs
diff --git a/APIJSON.NET/APIJSON.Data/SelectTable.cs b/APIJSON.NET/APIJSON.Data/SelectTable.cs
new file mode 100644
index 0000000..39838b7
--- /dev/null
+++ b/APIJSON.NET/APIJSON.Data/SelectTable.cs
@@ -0,0 +1,827 @@
+namespace APIJSON.Data;
+
+using AspectCore.Extensions.Reflection;
+using global::SqlSugar;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Dynamic;
+using System.Linq;
+using System.Text.RegularExpressions;
+
+///
+///
+///
+public class SelectTable
+{
+ private readonly IIdentityService _identitySvc;
+ private readonly ITableMapper _tableMapper;
+ private readonly SqlSugarClient db;
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public SelectTable(IIdentityService identityService, ITableMapper tableMapper, SqlSugarClient dbClient)
+ {
+ _identitySvc = identityService;
+ _tableMapper = tableMapper;
+ db = dbClient;
+ }
+ ///
+ /// 判断表名是否正确
+ ///
+ ///
+ ///
+ public virtual bool IsTable(string table)
+ {
+ return db.DbMaintenance.GetTableInfoList().Any(it => it.Name.Equals(table, StringComparison.CurrentCultureIgnoreCase));
+ }
+ ///
+ /// 判断表的列名是否正确
+ ///
+ ///
+ ///
+ ///
+ public virtual bool IsCol(string table, string col)
+ {
+ return db.DbMaintenance.GetColumnInfosByTableName(table).Any(it => it.DbColumnName.Equals(col, StringComparison.CurrentCultureIgnoreCase));
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual Tuple GetTableData(string subtable, int page, int count, int query, 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);
+ 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");
+ var tb = sugarQueryable(subtable, selectrole, values, dd);
+ if (query == 1)//1-总数
+ return new Tuple(new List