From c673532021697e44115a0e03035d4cb0b00ac988 Mon Sep 17 00:00:00 2001
From: NoahLan <6995syu@163.com>
Date: Mon, 5 Feb 2024 17:45:58 +0800
Subject: [PATCH] first commit.
---
.idea/.idea.NPin/.idea/.gitignore | 13 +
.idea/.idea.NPin/.idea/encodings.xml | 4 +
.idea/.idea.NPin/.idea/indexLayout.xml | 8 +
.idea/.idea.NPin/.idea/vcs.xml | 6 +
.../NPin.Framework.Core/Enums/FileTypeEnum.cs | 32 ++
.../NPin.Framework.Core/Enums/OrderByEnum.cs | 14 +
.../Extensions/HttpContextExtensions.cs | 6 +
.../Helper/ReflectHelper.cs | 57 +++
.../NPin.Framework.Core.csproj | 19 +
.../NPinFrameworkCoreModule.cs | 7 +
.../MapsterAutoObjectMappingProvider.cs | 18 +
.../MapsterObjectMapper.cs | 18 +
.../NPin.Framework.Mapster.csproj | 18 +
.../NPinFrameworkMapsterModule.cs | 16 +
.../DbConnOptions.cs | 105 +++++
.../ISqlSugarDbConnectionCreator.cs | 19 +
.../ISqlSugarDbContext.cs | 27 ++
.../ISqlSugarRepository.cs | 87 ++++
.../ISugarDbContextProvider.cs | 6 +
.../IgnoreCodeFirstAttribute.cs | 6 +
.../MasterTenantAttribute.cs | 6 +
...Framework.SqlSugarCore.Abstractions.csproj | 18 +
...FrameworkSqlSugarCoreAbstractionsModule.cs | 9 +
.../AsyncLocalDbContextAccessor.cs | 21 +
.../NPin.Framework.SqlSugarCore.csproj | 18 +
.../NPinFrameworkSqlSugarCoreModule.cs | 95 ++++
.../Repositories/SqlSugarRepository.cs | 430 ++++++++++++++++++
.../SqlSugarCoreExtensions.cs | 33 ++
.../SqlSugarDbConnectionCreator.cs | 111 +++++
.../SqlSugarDbContext.cs | 238 ++++++++++
.../SqlSugarDbContextCreationContext.cs | 28 ++
.../Uow/SqlSugarDatabaseApi.cs | 14 +
.../Uow/SqlSugarTransactionApi.cs | 33 ++
.../UnitOfWorkSqlSugarDbContextProvider.cs | 195 ++++++++
NPin.sln | 51 +++
src/NPin.Web/.dockerignore | 25 +
src/NPin.Web/Dockerfile | 20 +
src/NPin.Web/NPin.Web.csproj | 17 +
src/NPin.Web/NPin.http | 6 +
src/NPin.Web/Program.cs | 44 ++
src/NPin.Web/Properties/launchSettings.json | 41 ++
src/NPin.Web/appsettings.Development.json | 8 +
src/NPin.Web/appsettings.json | 9 +
43 files changed, 1956 insertions(+)
create mode 100644 .idea/.idea.NPin/.idea/.gitignore
create mode 100644 .idea/.idea.NPin/.idea/encodings.xml
create mode 100644 .idea/.idea.NPin/.idea/indexLayout.xml
create mode 100644 .idea/.idea.NPin/.idea/vcs.xml
create mode 100644 Framework/NPin.Framework.Core/Enums/FileTypeEnum.cs
create mode 100644 Framework/NPin.Framework.Core/Enums/OrderByEnum.cs
create mode 100644 Framework/NPin.Framework.Core/Extensions/HttpContextExtensions.cs
create mode 100644 Framework/NPin.Framework.Core/Helper/ReflectHelper.cs
create mode 100644 Framework/NPin.Framework.Core/NPin.Framework.Core.csproj
create mode 100644 Framework/NPin.Framework.Core/NPinFrameworkCoreModule.cs
create mode 100644 Framework/NPin.Framework.Mapster/MapsterAutoObjectMappingProvider.cs
create mode 100644 Framework/NPin.Framework.Mapster/MapsterObjectMapper.cs
create mode 100644 Framework/NPin.Framework.Mapster/NPin.Framework.Mapster.csproj
create mode 100644 Framework/NPin.Framework.Mapster/NPinFrameworkMapsterModule.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/ISqlSugarDbConnectionCreator.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/ISqlSugarDbContext.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/ISqlSugarRepository.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/ISugarDbContextProvider.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/IgnoreCodeFirstAttribute.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/MasterTenantAttribute.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/NPin.Framework.SqlSugarCore.Abstractions.csproj
create mode 100644 Framework/NPin.Framework.SqlSugarCore.Abstractions/NPinFrameworkSqlSugarCoreAbstractionsModule.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/AsyncLocalDbContextAccessor.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/NPin.Framework.SqlSugarCore.csproj
create mode 100644 Framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/SqlSugarCoreExtensions.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/SqlSugarDbContext.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/SqlSugarDbContextCreationContext.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/Uow/SqlSugarDatabaseApi.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/Uow/SqlSugarTransactionApi.cs
create mode 100644 Framework/NPin.Framework.SqlSugarCore/Uow/UnitOfWorkSqlSugarDbContextProvider.cs
create mode 100644 NPin.sln
create mode 100644 src/NPin.Web/.dockerignore
create mode 100644 src/NPin.Web/Dockerfile
create mode 100644 src/NPin.Web/NPin.Web.csproj
create mode 100644 src/NPin.Web/NPin.http
create mode 100644 src/NPin.Web/Program.cs
create mode 100644 src/NPin.Web/Properties/launchSettings.json
create mode 100644 src/NPin.Web/appsettings.Development.json
create mode 100644 src/NPin.Web/appsettings.json
diff --git a/.idea/.idea.NPin/.idea/.gitignore b/.idea/.idea.NPin/.idea/.gitignore
new file mode 100644
index 0000000..6ea7a0a
--- /dev/null
+++ b/.idea/.idea.NPin/.idea/.gitignore
@@ -0,0 +1,13 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/contentModel.xml
+/.idea.NPin.iml
+/modules.xml
+/projectSettingsUpdater.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/.idea.NPin/.idea/encodings.xml b/.idea/.idea.NPin/.idea/encodings.xml
new file mode 100644
index 0000000..df87cf9
--- /dev/null
+++ b/.idea/.idea.NPin/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.NPin/.idea/indexLayout.xml b/.idea/.idea.NPin/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.NPin/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.NPin/.idea/vcs.xml b/.idea/.idea.NPin/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/.idea.NPin/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Framework/NPin.Framework.Core/Enums/FileTypeEnum.cs b/Framework/NPin.Framework.Core/Enums/FileTypeEnum.cs
new file mode 100644
index 0000000..dac82cb
--- /dev/null
+++ b/Framework/NPin.Framework.Core/Enums/FileTypeEnum.cs
@@ -0,0 +1,32 @@
+namespace NPin.Framework.Core.Enums;
+
+///
+/// 文件类型
+///
+public enum FileTypeEnum
+{
+ ///
+ /// 普通文件
+ ///
+ File,
+
+ ///
+ /// 图片
+ ///
+ Image,
+
+ ///
+ /// 缩略图
+ ///
+ Thumbnail,
+
+ ///
+ /// Excel
+ ///
+ Excel,
+
+ ///
+ /// 临时文件
+ ///
+ Temp
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.Core/Enums/OrderByEnum.cs b/Framework/NPin.Framework.Core/Enums/OrderByEnum.cs
new file mode 100644
index 0000000..681701e
--- /dev/null
+++ b/Framework/NPin.Framework.Core/Enums/OrderByEnum.cs
@@ -0,0 +1,14 @@
+namespace NPin.Framework.Core.Enums;
+
+public enum OrderByEnum
+{
+ ///
+ /// 升序
+ ///
+ Asc,
+
+ ///
+ /// 降序
+ ///
+ Desc,
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.Core/Extensions/HttpContextExtensions.cs b/Framework/NPin.Framework.Core/Extensions/HttpContextExtensions.cs
new file mode 100644
index 0000000..97329f1
--- /dev/null
+++ b/Framework/NPin.Framework.Core/Extensions/HttpContextExtensions.cs
@@ -0,0 +1,6 @@
+namespace NPin.Framework.Core.Extensions;
+
+public static class HttpContextExtensions
+{
+ // public static void FileInlineHandle(this HttpContext)
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.Core/Helper/ReflectHelper.cs b/Framework/NPin.Framework.Core/Helper/ReflectHelper.cs
new file mode 100644
index 0000000..0f47b84
--- /dev/null
+++ b/Framework/NPin.Framework.Core/Helper/ReflectHelper.cs
@@ -0,0 +1,57 @@
+namespace NPin.Framework.Core.Helper;
+
+public static class ReflectHelper
+{
+ ///
+ /// 反射获取对象属性值(string)
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string? GetModelValue(string fieldName, object obj)
+ {
+ try
+ {
+ var typ = obj.GetType();
+ object o = typ.GetProperty(fieldName).GetValue(obj, null);
+ if (o == null)
+ {
+ return null;
+ }
+
+ var value = Convert.ToString(o);
+ if (string.IsNullOrEmpty(value))
+ {
+ return null;
+ }
+
+ return value;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ }
+
+ ///
+ /// 反射设置对象属性值
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static bool SetModelValue(string fieldName, object value, object obj)
+ {
+ try
+ {
+ var typ = obj.GetType();
+ typ.GetProperty(fieldName)?.SetValue(obj, value, null);
+ return true;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.Core/NPin.Framework.Core.csproj b/Framework/NPin.Framework.Core/NPin.Framework.Core.csproj
new file mode 100644
index 0000000..3cf2969
--- /dev/null
+++ b/Framework/NPin.Framework.Core/NPin.Framework.Core.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net8.0
+ enable
+ enable
+ Lan.Framework.Core
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Framework/NPin.Framework.Core/NPinFrameworkCoreModule.cs b/Framework/NPin.Framework.Core/NPinFrameworkCoreModule.cs
new file mode 100644
index 0000000..c66e187
--- /dev/null
+++ b/Framework/NPin.Framework.Core/NPinFrameworkCoreModule.cs
@@ -0,0 +1,7 @@
+using Volo.Abp.Modularity;
+
+namespace NPin.Framework.Core;
+
+public class NPinFrameworkCoreModule : AbpModule
+{
+}
diff --git a/Framework/NPin.Framework.Mapster/MapsterAutoObjectMappingProvider.cs b/Framework/NPin.Framework.Mapster/MapsterAutoObjectMappingProvider.cs
new file mode 100644
index 0000000..adc1265
--- /dev/null
+++ b/Framework/NPin.Framework.Mapster/MapsterAutoObjectMappingProvider.cs
@@ -0,0 +1,18 @@
+using Mapster;
+using Volo.Abp.ObjectMapping;
+
+namespace NPin.Framework.Mapster;
+
+public class MapsterAutoObjectMappingProvider: IAutoObjectMappingProvider
+{
+ public TDestination Map(object source)
+ {
+ // var sss = typeof(TDestination).Name;
+ return source.Adapt();
+ }
+
+ public TDestination Map(TSource source, TDestination destination)
+ {
+ return source.Adapt(destination);
+ }
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.Mapster/MapsterObjectMapper.cs b/Framework/NPin.Framework.Mapster/MapsterObjectMapper.cs
new file mode 100644
index 0000000..31a064d
--- /dev/null
+++ b/Framework/NPin.Framework.Mapster/MapsterObjectMapper.cs
@@ -0,0 +1,18 @@
+using Volo.Abp.ObjectMapping;
+
+namespace NPin.Framework.Mapster;
+
+public class MapsterObjectMapper : IObjectMapper
+{
+ public IAutoObjectMappingProvider AutoObjectMappingProvider => throw new NotImplementedException();
+
+ public TDestination Map(TSource source)
+ {
+ throw new NotImplementedException();
+ }
+
+ public TDestination Map(TSource source, TDestination destination)
+ {
+ throw new NotImplementedException();
+ }
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.Mapster/NPin.Framework.Mapster.csproj b/Framework/NPin.Framework.Mapster/NPin.Framework.Mapster.csproj
new file mode 100644
index 0000000..489f7d3
--- /dev/null
+++ b/Framework/NPin.Framework.Mapster/NPin.Framework.Mapster.csproj
@@ -0,0 +1,18 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Framework/NPin.Framework.Mapster/NPinFrameworkMapsterModule.cs b/Framework/NPin.Framework.Mapster/NPinFrameworkMapsterModule.cs
new file mode 100644
index 0000000..3e83c80
--- /dev/null
+++ b/Framework/NPin.Framework.Mapster/NPinFrameworkMapsterModule.cs
@@ -0,0 +1,16 @@
+using Microsoft.Extensions.DependencyInjection;
+using NPin.Framework.Core;
+using Volo.Abp.Modularity;
+using Volo.Abp.ObjectMapping;
+
+namespace NPin.Framework.Mapster;
+
+[DependsOn(typeof(NPinFrameworkCoreModule), typeof(AbpObjectMappingModule))]
+public class NPinFrameworkMapsterModule : AbpModule
+{
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ // 注入 MapsterAutoObjectMappingProvider
+ context.Services.AddTransient();
+ }
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs b/Framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
new file mode 100644
index 0000000..9e17cd0
--- /dev/null
+++ b/Framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
@@ -0,0 +1,105 @@
+using SqlSugar;
+
+namespace NPin.Framework.SqlSugarCore.Abstractions;
+
+public class DbConnOptions
+{
+ ///
+ /// 连接字符串 必填
+ ///
+ public string? Url { get; set; }
+
+ ///
+ /// 数据库类型
+ ///
+ public DbType? DbType { get; set; }
+
+ ///
+ /// 开启种子数据
+ ///
+ public bool EnabledDbSeed { get; set; } = false;
+
+ ///
+ /// 开启 CodeFirst 自动化表结构
+ ///
+ public bool EnabledCodeFirst { get; set; } = false;
+
+ ///
+ /// 开启sql日志
+ ///
+ public bool EnabledSqlLog { get; set; } = true;
+
+ ///
+ /// 实体程序集
+ ///
+ public List? EntityAssembly { get; set; }
+
+ ///
+ /// 开启读写分离
+ ///
+ public bool EnabledReadWrite { get; set; } = false;
+
+ ///
+ /// 读写分离
+ ///
+ public List? ReadUrl { get; set; }
+
+ ///
+ /// 开启Saas多租户
+ ///
+ public bool EnabledSaasMultiTenancy { get; set; } = false;
+
+
+ ///
+ /// 默认租户库连接,如果不填,那就是默认库的地址
+ ///
+ public string? MasterSaasMultiTenancyUrl { get; set; }
+
+
+ ///
+ /// Saas租户连接
+ ///
+ public List? SaasMultiTenancy { get; set; }
+
+ public static string MasterTenantDbDefaultName = "Master";
+ public static string TenantDbDefaultName = "Default";
+
+ public SaasMultiTenancyOptions GetDefaultSaasMultiTenancy()
+ {
+ return new SaasMultiTenancyOptions { Name = TenantDbDefaultName, Url = Url };
+ }
+
+ public SaasMultiTenancyOptions? GetDefaultMasterSaasMultiTenancy()
+ {
+ if (EnabledSaasMultiTenancy == false)
+ {
+ return null;
+ }
+
+ if (string.IsNullOrEmpty(MasterSaasMultiTenancyUrl))
+ {
+ return new SaasMultiTenancyOptions { Name = MasterTenantDbDefaultName, Url = Url };
+ }
+ else
+ {
+ return new SaasMultiTenancyOptions()
+ {
+ Name = MasterTenantDbDefaultName,
+ Url = MasterSaasMultiTenancyUrl
+ };
+ }
+ }
+}
+
+public class SaasMultiTenancyOptions
+{
+ ///
+ /// 租户名称标识
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// 连接Url
+ ///
+ public string Url { get; set; }
+}
\ No newline at end of file
diff --git a/Framework/NPin.Framework.SqlSugarCore.Abstractions/ISqlSugarDbConnectionCreator.cs b/Framework/NPin.Framework.SqlSugarCore.Abstractions/ISqlSugarDbConnectionCreator.cs
new file mode 100644
index 0000000..3e35021
--- /dev/null
+++ b/Framework/NPin.Framework.SqlSugarCore.Abstractions/ISqlSugarDbConnectionCreator.cs
@@ -0,0 +1,19 @@
+using System.Reflection;
+using SqlSugar;
+
+namespace NPin.Framework.SqlSugarCore.Abstractions;
+
+public interface ISqlSugarDbConnectionCreator
+{
+ DbConnOptions Options { get; }
+
+ Action OnSqlSugarClientConfig { get; set; }
+ Action