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 1/2] =?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