diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..1ff0c4230
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,63 @@
+###############################################################################
+# Set default behavior to automatically normalize line endings.
+###############################################################################
+* text=auto
+
+###############################################################################
+# Set default behavior for command prompt diff.
+#
+# This is need for earlier builds of msysgit that does not have it on by
+# default for csharp files.
+# Note: This is only used by command line
+###############################################################################
+#*.cs diff=csharp
+
+###############################################################################
+# Set the merge driver for project and solution files
+#
+# Merging from the command prompt will add diff markers to the files if there
+# are conflicts (Merging from VS is not affected by the settings below, in VS
+# the diff markers are never inserted). Diff markers may cause the following
+# file extensions to fail to load in VS. An alternative would be to treat
+# these files as binary and thus will always conflict and require user
+# intervention with every merge. To do so, just uncomment the entries below
+###############################################################################
+#*.sln merge=binary
+#*.csproj merge=binary
+#*.vbproj merge=binary
+#*.vcxproj merge=binary
+#*.vcproj merge=binary
+#*.dbproj merge=binary
+#*.fsproj merge=binary
+#*.lsproj merge=binary
+#*.wixproj merge=binary
+#*.modelproj merge=binary
+#*.sqlproj merge=binary
+#*.wwaproj merge=binary
+
+###############################################################################
+# behavior for image files
+#
+# image files are treated as binary by default.
+###############################################################################
+#*.jpg binary
+#*.png binary
+#*.gif binary
+
+###############################################################################
+# diff behavior for common document formats
+#
+# Convert binary document formats to text before diffing them. This feature
+# is only available from the command line. Turn it on by uncommenting the
+# entries below.
+###############################################################################
+#*.doc diff=astextplain
+#*.DOC diff=astextplain
+#*.docx diff=astextplain
+#*.DOCX diff=astextplain
+#*.dot diff=astextplain
+#*.DOT diff=astextplain
+#*.pdf diff=astextplain
+#*.PDF diff=astextplain
+#*.rtf diff=astextplain
+#*.RTF diff=astextplain
diff --git a/.gitignore b/.gitignore
index 9491a2fda..9d098c4ab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -360,4 +360,9 @@ MigrationBackup/
.ionide/
# Fody - auto-generated XML schema
-FodyWeavers.xsd
\ No newline at end of file
+FodyWeavers.xsd
+
+/src/*Pro*/
+/src/*Pro*
+/src/*pro*
+/src/*pro*/
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 1cb149fd6..000000000
--- a/.gitmodules
+++ /dev/null
@@ -1,4 +0,0 @@
-[submodule "Admin"]
- url = https://gitee.com/ThingsGateway/BlazorAdmin
- path = Admin
-
diff --git a/Admin b/Admin
deleted file mode 160000
index 3b73b7283..000000000
--- a/Admin
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 3b73b7283ac180a3a3bb2a0a1ecdd87a516b570a
diff --git a/README.md b/README.md
index 9728781da..a37b71a2b 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
## Introduction
-A cross-platform, high-performance edge data collection gateway based on net8, capable of handling millions of data points per.
+A cross-platform, high-performance edge data collection gateway based on net9.
## Documentation
diff --git a/README.zh-CN.md b/README.zh-CN.md
index da7bbf8a6..a1a412b67 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -2,7 +2,11 @@
## 介绍
-基于net8的跨平台高性能边缘采集网关,单机采集数据点位可达百万
+基于net9的跨平台高性能边缘采集网关
+
+最新版本分支:10.0
+
+稳定版分支:Release
## 文档
@@ -15,7 +19,7 @@
### 源码克隆
-注意因仓库包含子模块,直接下载zip包会导致子模块丢失,建议使用git clone命令
+建议使用git clone命令
``` shell
@@ -23,29 +27,6 @@ https://gitee.com/ThingsGateway/ThingsGateway.git
```
-### 源码更新
-
-在vs中打开powerShell窗口,执行以下命令,或根目录下的`git_pull.bat`脚本
-
-
-
-
-``` shell
-
-chcp 65001
-
-rem 更新主仓库
-git pull
-
-rem 初始化并更新所有子模块
-git submodule update --init
-
-pause
-
-```
-
-
-
### 插件列表
#### 采集插件
diff --git a/git_pull.bat b/git_pull.bat
deleted file mode 100644
index 439fe704a..000000000
--- a/git_pull.bat
+++ /dev/null
@@ -1,9 +0,0 @@
-chcp 65001
-
-rem 更新主仓库
-git pull
-
-rem 初始化并更新所有子模块
-git submodule update --init
-
-pause
\ No newline at end of file
diff --git a/src/Admin/README.md b/src/Admin/README.md
new file mode 100644
index 000000000..dd1f01fdc
--- /dev/null
+++ b/src/Admin/README.md
@@ -0,0 +1,21 @@
+
+
ThingsBlazor
+
权限管理框架
+
+
+### 🎁 框架介绍
+ 一个通用的AspNetCore小型权限框架,BlazorServer实现RBAC权限管理,在线会话管理。
+
+
+ ### 📙 衍生作品
+ - 👉[ThingsGateway](https://gitee.com/diego2098/ThingsGateway)
+ 跨平台边缘采集网关
+
+### 💐 特别鸣谢/源码参考(引用)
+ - 👉[Simple.Admin](https://gitee.com/zxzyjs/SimpleAdmin)
+ - 👉[Furion](https://gitee.com/dotnetchina/Furion)
+ - 👉[Bootstrap Blazor](https://www.blazor.zone/)
+
+### 🍎 联系作者
+ * QQ群:605534569
+ * 邮箱:2248356998@qq.com
\ No newline at end of file
diff --git a/src/Admin/README.zh-CN.md b/src/Admin/README.zh-CN.md
new file mode 100644
index 000000000..dd1f01fdc
--- /dev/null
+++ b/src/Admin/README.zh-CN.md
@@ -0,0 +1,21 @@
+
+
ThingsBlazor
+
权限管理框架
+
+
+### 🎁 框架介绍
+ 一个通用的AspNetCore小型权限框架,BlazorServer实现RBAC权限管理,在线会话管理。
+
+
+ ### 📙 衍生作品
+ - 👉[ThingsGateway](https://gitee.com/diego2098/ThingsGateway)
+ 跨平台边缘采集网关
+
+### 💐 特别鸣谢/源码参考(引用)
+ - 👉[Simple.Admin](https://gitee.com/zxzyjs/SimpleAdmin)
+ - 👉[Furion](https://gitee.com/dotnetchina/Furion)
+ - 👉[Bootstrap Blazor](https://www.blazor.zone/)
+
+### 🍎 联系作者
+ * QQ群:605534569
+ * 邮箱:2248356998@qq.com
\ No newline at end of file
diff --git a/src/Admin/ThingsGateway.Admin.Application/Aop/OperDescAttribute.cs b/src/Admin/ThingsGateway.Admin.Application/Aop/OperDescAttribute.cs
new file mode 100644
index 000000000..e638c3e51
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Aop/OperDescAttribute.cs
@@ -0,0 +1,164 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+
+using Rougamo;
+using Rougamo.Context;
+using Rougamo.Metadatas;
+
+using System.Collections.Concurrent;
+
+using ThingsGateway.Extension;
+using ThingsGateway.FriendlyException;
+using ThingsGateway.NewLife.Json.Extension;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// Aop拦截器
+///
+[Pointcut(AccessFlags.Public | AccessFlags.Method)]
+[Advice(Feature.OnException | Feature.OnSuccess)]
+public sealed class OperDescAttribute : MoAttribute
+{
+ ///
+ /// 日志消息队列(线程安全)
+ ///
+ private static readonly ConcurrentQueue _logMessageQueue = new();
+ private static readonly IAppService AppService;
+
+ static OperDescAttribute()
+ {
+ // 创建长时间运行的后台任务,并将日志消息队列中数据写入存储中
+ Task.Factory.StartNew(ProcessQueue, TaskCreationOptions.LongRunning);
+ AppService = App.RootServices.GetService();
+ }
+
+ public OperDescAttribute(string description, bool isRecordPar = true, object localizerType = null)
+ {
+ Description = description;
+ IsRecordPar = isRecordPar;
+ LocalizerType = (Type)localizerType;
+ }
+
+ ///
+ /// 说明,需配置本地化json文件
+ ///
+ public string Description { get; }
+
+ ///
+ /// 是否记录进出参数
+ ///
+ public bool IsRecordPar { get; }
+
+ public Type? LocalizerType { get; }
+
+ public override void OnException(MethodContext context)
+ {
+ //插入异常日志
+ SysOperateLog log = GetOperLog(LocalizerType, context);
+
+ log.Category = LogCateGoryEnum.Exception;//操作类型为异常
+ log.ExeStatus = false;//操作状态为失败
+ if (context.Exception is AppFriendlyException exception)
+ log.ExeMessage = exception?.Message;
+ else
+ log.ExeMessage = context.Exception?.ToString();
+
+ OperDescAttribute.WriteToQueue(log);
+ }
+
+ public override void OnSuccess(MethodContext context)
+ {
+ //插入操作日志
+ SysOperateLog log = GetOperLog(LocalizerType, context);
+ OperDescAttribute.WriteToQueue(log);
+ }
+
+ ///
+ /// 将日志消息写入数据库中
+ ///
+ private static async Task ProcessQueue()
+ {
+ var db = DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ var appLifetime = App.RootServices!.GetService()!;
+ while (!appLifetime.ApplicationStopping.IsCancellationRequested)
+ {
+ try
+ {
+ var data = _logMessageQueue.ToListWithDequeue(); // 从日志队列中获取数据
+ if (data.Count > 0)
+ {
+ await db.InsertableWithAttr(data).ExecuteCommandAsync(appLifetime.ApplicationStopping).ConfigureAwait(false);//入库
+ }
+ }
+ catch (Exception ex)
+ {
+ NewLife.Log.XTrace.WriteException(ex);
+ }
+ finally
+ {
+ await Task.Delay(3000, appLifetime.ApplicationStopping).ConfigureAwait(false);
+ }
+ }
+ }
+
+ private SysOperateLog GetOperLog(Type? localizerType, MethodContext context)
+ {
+ var methodBase = context.Method;
+ var clientInfo = AppService.ClientInfo;
+ string? paramJson = null;
+ if (IsRecordPar)
+ {
+ var args = context.Arguments;
+ var parametersInfo = methodBase.GetParameters();
+ var parametersDict = new Dictionary();
+
+ for (int i = 0; i < parametersInfo.Length; i++)
+ {
+ parametersDict[parametersInfo[i].Name!] = args[i];
+ }
+ paramJson = parametersDict.ToJsonNetString();
+ }
+ var result = context.ReturnValue;
+ var resultJson = IsRecordPar ? result?.ToJsonNetString() : null;
+ //操作日志表实体
+ var log = new SysOperateLog
+ {
+ Name = (localizerType == null ? App.CreateLocalizerByType(typeof(OperDescAttribute)) : App.CreateLocalizerByType(localizerType))![Description],
+ Category = LogCateGoryEnum.Operate,
+ ExeStatus = true,
+ OpIp = AppService?.RemoteIpAddress?.MapToIPv4()?.ToString() ?? string.Empty,
+ OpBrowser = clientInfo?.UA?.Family + clientInfo?.UA?.Major,
+ OpOs = clientInfo?.OS?.Family + clientInfo?.OS?.Major,
+ OpTime = DateTime.Now,
+ OpAccount = UserManager.UserAccount,
+ ReqUrl = null,
+ ReqMethod = "browser",
+ ResultJson = resultJson,
+ ClassName = methodBase.ReflectedType!.Name,
+ MethodName = methodBase.Name,
+ ParamJson = paramJson,
+ VerificatId = UserManager.VerificatId,
+ };
+ return log;
+ }
+
+ ///
+ /// 将日志消息写入队列中等待后台任务出队写入数据库
+ ///
+ /// 结构化日志消息
+ private static void WriteToQueue(SysOperateLog logMsg)
+ {
+ _logMessageQueue.Enqueue(logMsg);
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreExcelAttribute.cs b/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreExcelAttribute.cs
new file mode 100644
index 000000000..48c9d491c
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreExcelAttribute.cs
@@ -0,0 +1,19 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 忽略Excel导入导出
+///
+[AttributeUsage(AttributeTargets.Property)]
+public sealed class IgnoreExcelAttribute : Attribute
+{
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreRolePermissionAttribute.cs b/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreRolePermissionAttribute.cs
new file mode 100644
index 000000000..19045fbf1
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreRolePermissionAttribute.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 需要角色授权权限
+///
+[AttributeUsage(AttributeTargets.Class)]
+public sealed class RolePermissionAttribute : Attribute
+{
+}
+
+///
+/// 忽略角色授权权限
+///
+public sealed class IgnoreRolePermissionAttribute : Attribute
+{
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreSeedDataAttribute.cs b/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreSeedDataAttribute.cs
new file mode 100644
index 000000000..5f6751daf
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Attributes/IgnoreSeedDataAttribute.cs
@@ -0,0 +1,35 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 种子数据忽略新增
+///
+[AttributeUsage(AttributeTargets.Class)]
+public sealed class IgnoreSeedDataAddAttribute : Attribute
+{
+}
+
+///
+/// 种子数据忽略修改
+///
+[AttributeUsage(AttributeTargets.Class)]
+public sealed class IgnoreSeedDataUpdateAttribute : Attribute
+{
+}
+
+///
+/// 忽略初始化表
+///
+[AttributeUsage(AttributeTargets.Class)]
+public sealed class IgnoreInitTableAttribute : Attribute
+{
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Attributes/SuperAdminAttribute.cs b/src/Admin/ThingsGateway.Admin.Application/Attributes/SuperAdminAttribute.cs
new file mode 100644
index 000000000..7d90ba723
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Attributes/SuperAdminAttribute.cs
@@ -0,0 +1,27 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 管理员才能访问
+///
+[AttributeUsage(AttributeTargets.Class)]
+public sealed class SuperAdminAttribute : Attribute
+{
+}
+
+///
+/// 忽略超级管理员才能访问特性
+///
+[AttributeUsage(AttributeTargets.Method)]
+public sealed class IgnoreSuperAdminAttribute : Attribute
+{
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Const/CacheConst.cs b/src/Admin/ThingsGateway.Admin.Application/Const/CacheConst.cs
new file mode 100644
index 000000000..16f3da5a6
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Const/CacheConst.cs
@@ -0,0 +1,85 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public class CacheConst
+{
+ ///
+ /// Token表缓存Key
+ ///
+ public const string Cache_HardwareInfo = $"{CacheConst.Cache_Prefix_Admin}Cache_HardwareInfo:";
+
+ public const string Cache_Prefix_Admin = "ThingsGatewayAdmin:";
+
+ ///
+ /// 系统字典表缓存Key
+ ///
+ public const string Cache_SysDict = $"{CacheConst.Cache_Prefix_Admin}SysDict:";
+
+ ///
+ /// 关系表缓存Key
+ ///
+ public const string Cache_SysRelation = $"{CacheConst.Cache_Prefix_Admin}SysRelation:";
+
+ ///
+ /// 资源表缓存Key
+ ///
+ public const string Cache_SysResource = $"{CacheConst.Cache_Prefix_Admin}SysResource:";
+
+ ///
+ /// 角色表缓存Key
+ ///
+ public const string Cache_SysRole = $"{CacheConst.Cache_Prefix_Admin}SysRole:";
+
+ ///
+ /// 用户表缓存Key
+ ///
+ public const string Cache_SysUser = $"{CacheConst.Cache_Prefix_Admin}SysUser:";
+
+ ///
+ /// 用户账号关系缓存Key
+ ///
+ public const string Cache_SysUserAccount = $"{CacheConst.Cache_Prefix_Admin}SysUserAccount:";
+
+ ///
+ /// 职位表缓存Key
+ ///
+ public const string Cache_SysPosition = $"{CacheConst.Cache_Prefix_Admin}SysPosition:";
+
+ ///
+ /// 机构表缓存Key
+ ///
+ public const string Cache_SysOrg = $"{CacheConst.Cache_Prefix_Admin}SysOrg:";
+
+ ///
+ /// 公司表缓存Key
+ ///
+ public const string Cache_SysTenant = $"{CacheConst.Cache_Prefix_Admin}Tenant:";
+ ///
+ /// 公司表缓存Key
+ ///
+ public const string Cache_SysOrgTenant = $"{CacheConst.Cache_Prefix_Admin}OrgTenant:";
+
+ ///
+ /// Token表缓存Key
+ ///
+ public const string Cache_Token = $"{CacheConst.Cache_Prefix_Admin}Token:";
+
+ #region 登录错误次数
+
+ ///
+ /// 登录错误次数缓存Key
+ ///
+ public const string Cache_LoginErrorCount = $"{CacheConst.Cache_Prefix_Admin}LoginErrorCount:";
+
+ #endregion 登录错误次数
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Const/ClaimConst.cs b/src/Admin/ThingsGateway.Admin.Application/Const/ClaimConst.cs
new file mode 100644
index 000000000..f746ce60f
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Const/ClaimConst.cs
@@ -0,0 +1,50 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 授权用户常量
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public class ClaimConst
+{
+ ///
+ /// 账号
+ ///
+ public const string Account = "Account";
+
+ ///
+ /// SuperAdmin
+ ///
+ public const string SuperAdmin = "SuperAdmin";
+
+ ///
+ /// 用户Id
+ ///
+ public const string UserId = "UserId";
+
+ ///
+ /// 验证Id
+ ///
+ public const string VerificatId = "VerificatId";
+
+ ///
+ /// 组织Id
+ ///
+ public const string OrgId = "OrgId";
+
+ ///
+ /// 租户Id
+ ///
+ public const string TenantId = "TenantId";
+
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Const/ResourceConst.cs b/src/Admin/ThingsGateway.Admin.Application/Const/ResourceConst.cs
new file mode 100644
index 000000000..3152560fd
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Const/ResourceConst.cs
@@ -0,0 +1,28 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 资源表常量
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public class ResourceConst
+{
+ ///
+ /// 系统内置编码
+ ///
+ public const string System = "System";
+
+ ///
+ /// 系统管理内置ID 1
+ ///
+ public const long SystemId = 2;
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Const/RoleConst.cs b/src/Admin/ThingsGateway.Admin.Application/Const/RoleConst.cs
new file mode 100644
index 000000000..2ac3c3601
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Const/RoleConst.cs
@@ -0,0 +1,50 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 角色常量
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public class RoleConst
+{
+ ///
+ /// api角色
+ ///
+ public const string ApiRole = "ApiRole";
+
+ ///
+ /// 业务管理员
+ ///
+ public const string BizAdmin = "BizAdmin";
+
+ ///
+ /// 超级管理员
+ ///
+ public const string SuperAdmin = "SuperAdmin";
+
+ ///
+ /// 超级管理员Id
+ ///
+ public const long SuperAdminId = 212725263002001;
+ ///
+ /// 默认租户Id
+ ///
+ public const long DefaultTenantId = 252885263003720;
+ ///
+ /// 默认岗位Id
+ ///
+ public const long DefaultPositionId = 212725263003001;
+ ///
+ /// 超级管理员Id
+ ///
+ public const long SuperAdminRoleId = 212725263001001;
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Const/SqlSugarConst.cs b/src/Admin/ThingsGateway.Admin.Application/Const/SqlSugarConst.cs
new file mode 100644
index 000000000..6ef6796f2
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Const/SqlSugarConst.cs
@@ -0,0 +1,43 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// SqlSugar系统常量
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public class SqlSugarConst
+{
+ ///
+ /// DB_Admin
+ ///
+ public const string DB_Admin = "DB_Admin";
+
+ ///
+ /// DB_Custom
+ ///
+ public const string DB_Custom = "DB_Custom";
+
+ ///
+ /// DB_HardwareInfo
+ ///
+ public const string DB_HardwareInfo = "DB_HardwareInfo";
+
+ ///
+ /// DB_Log
+ ///
+ public const string DB_Log = "DB_Log";
+
+ ///
+ /// DB_TokenCache
+ ///
+ public const string DB_TokenCache = "DB_TokenCache";
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Controller/AuthController.cs b/src/Admin/ThingsGateway.Admin.Application/Controller/AuthController.cs
new file mode 100644
index 000000000..86f3eeb7d
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Controller/AuthController.cs
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace ThingsGateway.Admin.Application;
+
+[ApiDescriptionSettings(false)]
+[Route("api/auth")]
+[LoggingMonitor]
+public class AuthController : ControllerBase
+{
+ private readonly IAuthService _authService;
+
+ public AuthController(IAuthService authService)
+ {
+ _authService = authService;
+ }
+
+ [HttpPost("login")]
+ [AllowAnonymous]
+ public Task LoginAsync([FromBody] LoginInput input)
+ {
+ return _authService.LoginAsync(input);
+ }
+
+ [HttpPost("logout")]
+ [Authorize]
+ [IgnoreRolePermission]
+ public Task LogoutAsync()
+ {
+ return _authService.LoginOutAsync();
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Controller/CultureController.cs b/src/Admin/ThingsGateway.Admin.Application/Controller/CultureController.cs
new file mode 100644
index 000000000..2e2649d27
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Controller/CultureController.cs
@@ -0,0 +1,72 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Localization;
+using Microsoft.AspNetCore.Mvc;
+
+using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 文化 Controller
+///
+[ApiDescriptionSettings(false)]
+[Route("[controller]/[action]")]
+public class CultureController : Controller
+{
+ ///
+ /// 重置文化方法
+ ///
+ ///
+ ///
+ [HttpGet]
+ public IActionResult ResetCulture(string redirectUri)
+ {
+ HttpContext.Response.Cookies.Delete(CookieRequestCultureProvider.DefaultCookieName);
+
+ return LocalRedirect(redirectUri);
+ }
+
+ ///
+ /// 设置文化方法
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public IActionResult SetCulture(string culture, string redirectUri)
+ {
+ if (string.IsNullOrEmpty(culture))
+ {
+ HttpContext.Response.Cookies.Delete(CookieRequestCultureProvider.DefaultCookieName);
+ }
+ else
+ {
+ HttpContext.Response.Cookies.Append(
+ CookieRequestCultureProvider.DefaultCookieName,
+ CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture, culture)), new CookieOptions()
+ {
+ Expires = DateTimeOffset.Now.AddYears(1)
+ });
+
+ //更改全局文化,采集后台也会变化
+ //var cultureInfo = new CultureInfo(culture);
+ //CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
+ //CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
+
+ //CultureInfo.CurrentCulture = cultureInfo;
+ //CultureInfo.CurrentUICulture = cultureInfo;
+ }
+
+ return LocalRedirect(redirectUri);
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Controller/FileController.cs b/src/Admin/ThingsGateway.Admin.Application/Controller/FileController.cs
new file mode 100644
index 000000000..76f24947b
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Controller/FileController.cs
@@ -0,0 +1,50 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 文件下载
+///
+[ApiDescriptionSettings(false)]
+[Route("api/file")]
+public class FileController : ControllerBase
+{
+ ///
+ /// 下载wwwroot文件夹下的文件
+ ///
+ /// 相对路径
+ ///
+ [HttpGet("download")]
+ public IActionResult Download(string fileName)
+ {
+ // Validate the fileName to prevent path injection
+ if (string.IsNullOrEmpty(fileName))
+ {
+ return BadRequest("Invalid file name.");
+ }
+
+ var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", fileName);
+
+ if (!System.IO.File.Exists(filePath))
+ {
+ return NotFound();
+ }
+
+ var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+
+ Response.Headers.Append("Access-Control-Expose-Headers", "Content-Disposition");
+
+ return File(fileStream, "application/octet-stream", (fileName.Replace('/', '_')));
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Controller/OpenApiController.cs b/src/Admin/ThingsGateway.Admin.Application/Controller/OpenApiController.cs
new file mode 100644
index 000000000..eea51be0e
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Controller/OpenApiController.cs
@@ -0,0 +1,58 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Mapster;
+
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+using System.ComponentModel;
+
+namespace ThingsGateway.Admin.Application;
+
+
+///
+/// 登录
+///
+[ApiDescriptionSettings("ThingsGateway.OpenApi", Order = 200)]
+[Description("登录")]
+[Route("openapi/auth")]
+[Authorize(AuthenticationSchemes = "Bearer")]
+[LoggingMonitor]
+public class OpenApiController : ControllerBase
+{
+ private readonly IAuthService _authService;
+
+ public OpenApiController(IAuthService authService)
+ {
+ _authService = authService;
+ }
+
+ [HttpPost("login")]
+ [DisplayName("登录")]
+ [AllowAnonymous]
+ public async Task LoginAsync([FromBody] OpenApiLoginInput input)
+ {
+ var output = await _authService.LoginAsync(input.Adapt(), false).ConfigureAwait(false);
+
+ var openApiLoginOutput = output.Adapt();
+
+ return openApiLoginOutput;
+ }
+
+ [HttpPost("logout")]
+ [Authorize]
+ [DisplayName("登出")]
+ [IgnoreRolePermission]
+ public Task LogoutAsync()
+ {
+ return _authService.LoginOutAsync();
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Controller/TestController.cs b/src/Admin/ThingsGateway.Admin.Application/Controller/TestController.cs
new file mode 100644
index 000000000..1d6a74389
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Controller/TestController.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+//此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace ThingsGateway.Admin.Application;
+
+[Route("api/[controller]/[action]")]
+[RolePermission]
+[Authorize(AuthenticationSchemes = "Bearer")]
+public class TestController : ControllerBase
+{
+ [HttpPost]
+ public async Task Test(string data)
+ {
+ await Task.CompletedTask.ConfigureAwait(false);
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/BaseEntity.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/BaseEntity.cs
new file mode 100644
index 000000000..05720a4dd
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/BaseEntity.cs
@@ -0,0 +1,148 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+using System.Diagnostics.CodeAnalysis;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 主键id基类
+///
+public abstract class PrimaryIdEntity : IPrimaryIdEntity
+{
+ ///
+ /// 主键Id
+ ///
+ [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Visible = false, IsVisibleWhenEdit = false, IsVisibleWhenAdd = false, Sortable = true, DefaultSort = true, DefaultSortOrder = SortOrder.Asc)]
+ public virtual long Id { get; set; }
+}
+
+///
+/// 主键实体基类
+///
+public abstract class PrimaryKeyEntity : PrimaryIdEntity
+{
+ ///
+ /// 拓展信息
+ ///
+ [SugarColumn(ColumnDescription = "扩展信息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual string? ExtJson { get; set; }
+}
+
+public interface IBaseEntity
+{
+ DateTime? CreateTime { get; set; }
+ string? CreateUser { get; set; }
+ long CreateUserId { get; set; }
+ bool IsDelete { get; set; }
+ int? SortCode { get; set; }
+ DateTime? UpdateTime { get; set; }
+ string? UpdateUser { get; set; }
+ long? UpdateUserId { get; set; }
+}
+
+///
+/// 框架实体基类
+///
+public abstract class BaseEntity : PrimaryKeyEntity, IBaseEntity
+{
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(ColumnDescription = "创建时间", IsOnlyIgnoreUpdate = true, IsNullable = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public virtual DateTime? CreateTime { get; set; }
+
+ ///
+ /// 创建人
+ ///
+ [SugarColumn(ColumnDescription = "创建人", IsOnlyIgnoreUpdate = true, IsNullable = true)]
+ [IgnoreExcel]
+ [NotNull]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual string? CreateUser { get; set; }
+
+ ///
+ /// 创建者Id
+ ///
+ [SugarColumn(ColumnDescription = "创建者Id", IsOnlyIgnoreUpdate = true, IsNullable = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual long CreateUserId { get; set; }
+
+ ///
+ /// 软删除
+ ///
+ [SugarColumn(ColumnDescription = "软删除", IsNullable = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual bool IsDelete { get; set; } = false;
+
+
+ ///
+ /// 更新时间
+ ///
+ [SugarColumn(ColumnDescription = "更新时间", IsOnlyIgnoreInsert = true, IsNullable = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Visible = false, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public virtual DateTime? UpdateTime { get; set; }
+
+ ///
+ /// 更新人
+ ///
+ [SugarColumn(ColumnDescription = "更新人", IsOnlyIgnoreInsert = true, IsNullable = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual string? UpdateUser { get; set; }
+
+ ///
+ /// 修改者Id
+ ///
+ [SugarColumn(ColumnDescription = "修改者Id", IsOnlyIgnoreInsert = true, IsNullable = true)]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual long? UpdateUserId { get; set; }
+
+ ///
+ /// 排序码
+ ///
+ [SugarColumn(ColumnDescription = "排序码", IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Asc)]
+ [IgnoreExcel]
+ public int? SortCode { get; set; }
+}
+
+public interface IBaseDataEntity
+{
+ long CreateOrgId { get; set; }
+}
+
+///
+/// 业务数据实体基类(数据权限)
+///
+public abstract class BaseDataEntity : BaseEntity, IBaseDataEntity
+{
+ ///
+ /// 创建者部门Id
+ ///
+ [SugarColumn(ColumnDescription = "创建者部门Id", IsOnlyIgnoreUpdate = true, IsNullable = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ [IgnoreExcel]
+ public virtual long CreateOrgId { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysDict.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysDict.cs
new file mode 100644
index 000000000..98b4f9a99
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysDict.cs
@@ -0,0 +1,59 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+[SugarTable("sys_dict", TableDescription = "字典表")]
+[Tenant(SqlSugarConst.DB_Admin)]
+public class SysDict : BaseEntity
+{
+ ///
+ /// 类型
+ ///
+ [SugarColumn(ColumnDescription = "类型", Length = 200)]
+ [AutoGenerateColumn(Ignore = true, Filterable = true, Sortable = true)]
+ public virtual DictTypeEnum DictType { get; set; }
+
+ ///
+ /// 分类
+ ///
+ [SugarColumn(ColumnDescription = "分类", Length = 200)]
+ [Required]
+ [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)]
+ public string Category { get; set; }
+
+ ///
+ /// 名称
+ ///
+ [SugarColumn(ColumnDescription = "名称", Length = 200)]
+ [Required]
+ [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)]
+ public virtual string Name { get; set; }
+
+ ///
+ /// 代码
+ ///
+ [SugarColumn(ColumnDescription = "代码", ColumnDataType = StaticConfig.CodeFirst_BigString)]
+ [Required]
+ [AutoGenerateColumn(Searchable = true, Filterable = true, Sortable = true)]
+ public virtual string Code { get; set; }
+
+ ///
+ /// 描述
+ ///
+ [SugarColumn(ColumnDescription = "描述", Length = 200, IsNullable = true)]
+ public string Remark { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysOperateLog.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysOperateLog.cs
new file mode 100644
index 000000000..9e4be5eb1
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysOperateLog.cs
@@ -0,0 +1,136 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 操作日志表
+///
+[SugarTable("sys_operatelog", TableDescription = "操作日志表")]
+[Tenant(SqlSugarConst.DB_Log)]
+public class SysOperateLog
+{
+ ///
+ /// 日志分类
+ ///
+ [SugarColumn(ColumnDescription = "日志分类", Length = 200)]
+ [AutoGenerateColumn(Order = 1, Filterable = true, Sortable = true)]
+ public LogCateGoryEnum Category { get; set; }
+
+ ///
+ /// 日志名称
+ ///
+ [SugarColumn(ColumnDescription = "日志名称", Length = 200)]
+ [AutoGenerateColumn(Order = 2, Filterable = true, Sortable = true)]
+ public string Name { get; set; }
+
+ ///
+ /// 类名称
+ ///
+ [SugarColumn(ColumnDescription = "类名称", Length = 200)]
+ [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)]
+ public string ClassName { get; set; }
+
+ ///
+ /// 方法名称
+ ///
+ [SugarColumn(ColumnDescription = "方法名称", Length = 200)]
+ [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)]
+ public string MethodName { get; set; }
+
+ ///
+ /// 请求参数
+ ///
+ [SugarColumn(ColumnDescription = "请求参数", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
+ [AutoGenerateColumn(ShowTips = true, Filterable = true, Sortable = true)]
+ public string? ParamJson { get; set; }
+
+ ///
+ /// 请求方式
+ ///
+ [SugarColumn(ColumnDescription = "请求方式", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)]
+ public string? ReqMethod { get; set; }
+
+ ///
+ /// 请求地址
+ ///
+ [SugarColumn(ColumnDescription = "请求地址", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)]
+ public string? ReqUrl { get; set; }
+
+ ///
+ /// 返回结果
+ ///
+ [SugarColumn(ColumnDescription = "返回结果", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
+ [AutoGenerateColumn(ShowTips = true, Filterable = true, Sortable = true)]
+ public string? ResultJson { get; set; }
+
+ ///
+ /// 具体消息
+ ///
+ [SugarColumn(ColumnDescription = "具体消息", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
+ [AutoGenerateColumn(ShowTips = true, Filterable = true, Sortable = true)]
+ public string? ExeMessage { get; set; }
+
+ ///
+ /// 执行状态
+ ///
+ [SugarColumn(ColumnDescription = "执行状态")]
+ [AutoGenerateColumn(Filterable = true, Sortable = true)]
+ public bool ExeStatus { get; set; }
+
+ ///
+ /// 操作账号
+ ///
+ [SugarColumn(ColumnDescription = "操作账号", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Filterable = true, Sortable = true)]
+ public string? OpAccount { get; set; }
+
+ ///
+ /// 操作浏览器
+ ///
+ [SugarColumn(ColumnDescription = "操作浏览器", Length = 200)]
+ [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)]
+ public string OpBrowser { get; set; }
+
+ ///
+ /// 操作ip
+ ///
+ [SugarColumn(ColumnDescription = "操作ip", Length = 200)]
+ [AutoGenerateColumn(Filterable = true, Sortable = true)]
+ public string? OpIp { get; set; }
+
+ ///
+ /// 操作系统
+ ///
+ [SugarColumn(ColumnDescription = "操作系统", Length = 200)]
+ [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)]
+ public string OpOs { get; set; }
+
+ ///
+ /// 操作时间
+ ///
+ [SugarColumn(ColumnDescription = "操作时间")]
+ [AutoGenerateColumn(Visible = true, DefaultSort = true, Sortable = true, DefaultSortOrder = SortOrder.Desc)]
+ public DateTime OpTime { get; set; }
+
+ ///
+ /// 验证Id
+ ///
+ [SugarColumn(ColumnDescription = "验证Id")]
+ [IgnoreExcel]
+ [AutoGenerateColumn(Visible = false, Filterable = true, Sortable = true)]
+ public long VerificatId { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysOrg.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysOrg.cs
new file mode 100644
index 000000000..276378d03
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysOrg.cs
@@ -0,0 +1,81 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 组织表
+///
+[SugarTable("sys_org", TableDescription = "组织表")]
+[Tenant(SqlSugarConst.DB_Admin)]
+public class SysOrg : BaseEntity
+{
+ ///
+ /// 父id
+ ///
+ [SugarColumn(ColumnName = "ParentId", ColumnDescription = "父id")]
+ [AutoGenerateColumn(Ignore = true)]
+ public long ParentId { get; set; }
+
+ [SugarColumn(ColumnName = "ParentIdList", ColumnDescription = "父id列表", IsNullable = true, IsJson = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public List ParentIdList { get; set; } = new List();
+
+ ///
+ /// 主管ID
+ ///
+ [SugarColumn(ColumnName = "DirectorId", ColumnDescription = "主管ID", IsNullable = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public long? DirectorId { get; set; }
+
+ ///
+ /// 名称
+ ///
+ [SugarColumn(ColumnName = "Name", ColumnDescription = "名称", Length = 200)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ [Required]
+ public string Name { get; set; }
+
+ ///
+ /// 全称
+ ///
+ [SugarColumn(ColumnName = "Names", ColumnDescription = "全称", Length = 500)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public string Names { get; set; }
+
+ ///
+ /// 编码
+ ///
+ [SugarColumn(ColumnName = "Code", ColumnDescription = "编码", Length = 200)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public string Code { get; set; }
+
+ ///
+ /// 分类
+ ///
+ [SugarColumn(ColumnName = "Category", ColumnDescription = "分类")]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public OrgEnum Category { get; set; }
+
+
+ [SugarColumn(ColumnName = "Status", ColumnDescription = "启用")]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public bool Status { get; set; } = true;
+
+
+
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysPosition.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysPosition.cs
new file mode 100644
index 000000000..2ad2c57c8
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysPosition.cs
@@ -0,0 +1,61 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 职位表
+///
+[SugarTable("sys_position", TableDescription = "职位表")]
+[Tenant(SqlSugarConst.DB_Admin)]
+public class SysPosition : BaseEntity
+{
+ ///
+ /// 组织id
+ ///
+ [SugarColumn(ColumnName = "OrgId", ColumnDescription = "组织id")]
+ [AutoGenerateColumn(Ignore = true)]
+ [MinValue(1)]
+ public virtual long OrgId { get; set; }
+
+ ///
+ /// 名称
+ ///
+ [SugarColumn(ColumnName = "Name", ColumnDescription = "名称", Length = 200)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ [Required]
+ public virtual string Name { get; set; }
+
+ ///
+ /// 编码
+ ///
+ [SugarColumn(ColumnName = "Code", ColumnDescription = "编码", Length = 200)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public string Code { get; set; }
+
+
+ [SugarColumn(ColumnName = "Status", ColumnDescription = "启用")]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public bool Status { get; set; } = true;
+
+ ///
+ /// 分类
+ ///
+ [SugarColumn(ColumnName = "Category", ColumnDescription = "分类", Length = 200)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public virtual PositionCategoryEnum Category { get; set; }
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysRelation.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysRelation.cs
new file mode 100644
index 000000000..2971c0897
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysRelation.cs
@@ -0,0 +1,39 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using SqlSugar;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 系统关系表
+///
+[SugarTable("sys_relation", TableDescription = "系统关系表")]
+[Tenant(SqlSugarConst.DB_Admin)]
+public class SysRelation : PrimaryKeyEntity
+{
+ ///
+ /// 分类
+ ///
+ [SugarColumn(ColumnDescription = "分类", Length = 200)]
+ public RelationCategoryEnum Category { get; set; }
+
+ ///
+ /// 对象ID
+ ///
+ [SugarColumn(ColumnDescription = "对象ID")]
+ public long ObjectId { get; set; }
+
+ ///
+ /// 目标ID
+ ///
+ [SugarColumn(ColumnDescription = "目标ID", IsNullable = true)]
+ public string? TargetId { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysResource.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysResource.cs
new file mode 100644
index 000000000..2fb95059d
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysResource.cs
@@ -0,0 +1,101 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using Microsoft.AspNetCore.Components.Routing;
+
+using Newtonsoft.Json;
+
+using SqlSugar;
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 系统资源表
+///
+[SugarTable("sys_resource", TableDescription = "系统资源表")]
+[Tenant(SqlSugarConst.DB_Admin)]
+public class SysResource : BaseEntity
+{
+ ///
+ /// 父id
+ ///
+ [SugarColumn(ColumnDescription = "父id")]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual long ParentId { get; set; } = 0;
+
+ ///
+ /// 模块
+ ///
+ [SugarColumn(ColumnDescription = "模块")]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual long Module { get; set; }
+
+ ///
+ /// 标题
+ ///
+ [SugarColumn(ColumnDescription = "标题", Length = 200)]
+ [Required]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true, Searchable = true)]
+ public virtual string Title { get; set; }
+
+ ///
+ /// 图标
+ ///
+ [SugarColumn(ColumnDescription = "图标", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = true, Sortable = false, Filterable = false)]
+ public virtual string? Icon { get; set; }
+
+ ///
+ /// 编码
+ ///
+ [SugarColumn(ColumnDescription = "编码", Length = 200)]
+ [Required]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public virtual string Code { get; set; }
+
+ ///
+ /// 分类
+ ///
+ [SugarColumn(ColumnDescription = "分类")]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public ResourceCategoryEnum Category { get; set; } = ResourceCategoryEnum.Menu;
+
+ ///
+ /// 目标类型
+ ///
+ [SugarColumn(ColumnDescription = "目标类型", IsNullable = true)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public virtual TargetEnum? Target { get; set; }
+
+ ///
+ /// 菜单匹配类型
+ ///
+ [SugarColumn(ColumnDescription = "菜单匹配类型", IsNullable = true)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public virtual NavLinkMatch? NavLinkMatch { get; set; }
+
+ ///
+ /// 路径
+ ///
+ [SugarColumn(ColumnDescription = "路径", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true, Searchable = true)]
+ public virtual string Href { get; set; }
+
+ ///
+ /// 子节点
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public List? Children { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysRole.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysRole.cs
new file mode 100644
index 000000000..dc0082d70
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysRole.cs
@@ -0,0 +1,94 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 系统角色表
+///
+[SugarTable("sys_role", TableDescription = "系统角色表")]
+[Tenant(SqlSugarConst.DB_Admin)]
+public class SysRole : BaseEntity
+{
+ ///
+ /// 名称
+ ///
+ [SugarColumn(ColumnDescription = "名称", Length = 200)]
+ [Required]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public virtual string Name { get; set; }
+
+ ///
+ /// 编码
+ ///
+ [SugarColumn(ColumnDescription = "编码", Length = 200)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public string Code { get; set; }
+
+ ///
+ /// 分类
+ ///
+ [SugarColumn(ColumnDescription = "分类", Length = 200, IsNullable = false)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public virtual RoleCategoryEnum Category { get; set; }
+
+ ///
+ /// 组织id
+ ///
+ [SugarColumn(ColumnName = "OrgId", ColumnDescription = "组织id", IsNullable = false)]
+ [AutoGenerateColumn(Ignore = true)]
+ public long OrgId { get; set; }
+
+ ///
+ /// 默认数据范围
+ ///
+ [SugarColumn(ColumnName = "DefaultDataScope", ColumnDescription = "默认数据范围", IsJson = true, ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = false)]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual DefaultDataScope DefaultDataScope { get; set; } = new();
+
+ public override bool Equals(object? obj)
+ {
+ if (obj == null || !(obj is SysRole))
+ {
+ return false;
+ }
+
+ return Id == ((SysRole)obj).Id;
+ }
+
+ public override int GetHashCode()
+ {
+ return Id.GetHashCode();
+ }
+}
+
+
+
+///
+/// 默认数据范围
+///
+public class DefaultDataScope
+{
+ ///
+ /// 数据范围
+ ///
+ public DataScopeEnum ScopeCategory { get; set; }
+
+ ///
+ /// 自定义机构范围列表
+ ///
+ public List ScopeDefineOrgIdList { get; set; } = new List();
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/SysUser.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/SysUser.cs
new file mode 100644
index 000000000..b555a26cf
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/SysUser.cs
@@ -0,0 +1,253 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using Mapster;
+
+using SqlSugar;
+
+using System.ComponentModel.DataAnnotations;
+using System.Diagnostics.CodeAnalysis;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 系统用户表
+///
+[SugarTable("sys_user", TableDescription = "系统用户表")]
+[Tenant(SqlSugarConst.DB_Admin)]
+public class SysUser : BaseEntity
+{
+ ///
+ /// 头像
+ ///
+ [SugarColumn(ColumnDescription = "头像", ColumnDataType = StaticConfig.CodeFirst_BigString, IsNullable = true)]
+ [AutoGenerateColumn(Visible = true, Sortable = false, Filterable = false)]
+ [AdaptIgnore]
+ public virtual string? Avatar { get; set; }
+
+ ///
+ /// 账号
+ ///
+ [SugarColumn(ColumnDescription = "账号", Length = 200)]
+ [Required]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public virtual string Account { get; set; }
+
+ ///
+ /// 密码
+ ///
+ [SugarColumn(ColumnDescription = "密码", ColumnDataType = StaticConfig.CodeFirst_BigString)]
+ [AutoGenerateColumn(Ignore = true)]
+ public string Password { get; set; }
+
+ ///
+ /// 状态
+ ///
+ [SugarColumn(ColumnDescription = "状态")]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public bool Status { get; set; } = true;
+
+ ///
+ /// 手机
+ /// 这里使用了SM4自动加密解密
+ ///
+ [SugarColumn(ColumnDescription = "手机", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public string? Phone { get; set; }
+
+ ///
+ /// 邮箱
+ ///
+ [SugarColumn(ColumnDescription = "邮箱", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = true, Sortable = true, Filterable = true)]
+ public string? Email { get; set; }
+
+ ///
+ /// 上次登录ip
+ ///
+ [SugarColumn(ColumnDescription = "上次登录ip", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public string? LastLoginIp { get; set; }
+
+ ///
+ /// 上次登录设备
+ ///
+ [SugarColumn(ColumnDescription = "上次登录设备", IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public string? LastLoginDevice { get; set; }
+
+ ///
+ /// 上次登录时间
+ ///
+ [SugarColumn(ColumnDescription = "上次登录时间", IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public DateTime? LastLoginTime { get; set; }
+
+ ///
+ /// 上次登录地点
+ ///
+ [SugarColumn(ColumnDescription = "上次登录地点", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public string LastLoginAddress { get; set; }
+
+ ///
+ /// 最新登录ip
+ ///
+ [SugarColumn(ColumnDescription = "最新登录ip", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public string? LatestLoginIp { get; set; }
+
+ ///
+ /// 最新登录时间
+ ///
+ [SugarColumn(ColumnDescription = "最新登录时间", IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public DateTime? LatestLoginTime { get; set; }
+
+ ///
+ /// 最新登录设备
+ ///
+ [SugarColumn(ColumnDescription = "最新登录设备", IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public string? LatestLoginDevice { get; set; }
+
+ ///
+ /// 最新登录地点
+ ///
+ [SugarColumn(ColumnDescription = "最新登录地点", Length = 200, IsNullable = true)]
+ [AutoGenerateColumn(Visible = false, Sortable = true, Filterable = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false)]
+ public string LatestLoginAddress { get; set; }
+
+ ///
+ /// 机构id
+ ///
+ [SugarColumn(ColumnName = "OrgId", ColumnDescription = "机构id", IsNullable = false)]
+ [AutoGenerateColumn(Ignore = true)]
+ public virtual long OrgId { get; set; }
+
+ ///
+ /// 职位id
+ ///
+ [SugarColumn(ColumnName = "PositionId", ColumnDescription = "职位id", IsNullable = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ [Required]
+ [NotNull]
+ public virtual long? PositionId { get; set; }
+
+ ///
+ /// 主管id
+ ///
+ [SugarColumn(ColumnName = "DirectorId", ColumnDescription = "主管id", IsNullable = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public long? DirectorId { get; set; }
+
+ #region other
+ ///
+ /// 机构信息
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public string OrgName { get; set; }
+
+ ///
+ /// 机构信息全称
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public string OrgNames { get; set; }
+
+ ///
+ /// 职位信息
+ ///
+ [SugarColumn(IsIgnore = true)]
+ public string PositionName { get; set; }
+
+ ///
+ /// 组织和机构ID列表,组织ID从上到下最后是职位
+ ///
+ [SugarColumn(IsIgnore = true, IsJson = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public List OrgAndPosIdList { get; set; } = new List();
+
+ ///
+ /// 主管信息
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public UserSelectorOutput DirectorInfo { get; set; }
+
+ #endregion
+
+ #region other
+
+ ///
+ /// 按钮码集合
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public Dictionary> ButtonCodeList { get; set; } = new();
+
+ ///
+ /// 权限码集合
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public HashSet PermissionCodeList { get; set; } = new();
+
+ ///
+ /// 角色ID集合
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public HashSet RoleIdList { get; set; } = new();
+
+ ///
+ /// 机构及以下机构ID集合
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public HashSet ScopeOrgChildList { get; set; }
+
+ ///
+ /// 模块集合
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public List ModuleList { get; set; } = new();
+
+ ///
+ /// 租户Id
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public long? TenantId { get; set; }
+
+
+ ///
+ /// 全局用戶
+ ///
+ [SugarColumn(IsIgnore = true)]
+ [AutoGenerateColumn(Ignore = true)]
+ public bool IsGlobal { get; set; }
+
+ #endregion other
+}
+
+///
+/// 数据范围类
+///
+public class DataScope
+{
+ ///
+ /// API接口
+ ///
+ public string ApiUrl { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Entity/VerificatInfo.cs b/src/Admin/ThingsGateway.Admin.Application/Entity/VerificatInfo.cs
new file mode 100644
index 000000000..b886478bb
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Entity/VerificatInfo.cs
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+using ThingsGateway.List;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 会话信息
+///
+
+[SugarTable("verificatinfo", TableDescription = "验证缓存表")]
+[Tenant(SqlSugarConst.DB_TokenCache)]
+public class VerificatInfo : PrimaryIdEntity
+{
+ ///
+ /// 客户端ID列表
+ ///
+ [AutoGenerateColumn(Ignore = true)]
+ [SugarColumn(ColumnDescription = "客户端ID列表", IsNullable = true, IsJson = true)]
+ public ConcurrentList ClientIds { get; set; } = new();
+
+ ///
+ /// 验证Id
+ ///
+ [AutoGenerateColumn(Ignore = true)]
+ public long UserId { get; set; }
+
+ ///
+ /// 验证Id
+ ///
+ [AutoGenerateColumn(Filterable = true, Sortable = true)]
+ [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true)]
+ [IgnoreExcel]
+ public override long Id { get; set; }
+
+ ///
+ /// 登录IP
+ ///
+ [AutoGenerateColumn(Filterable = true, Sortable = true, Width = 200)]
+ public string LoginIp { get; set; }
+
+ ///
+ /// 登录时间
+ ///
+ [AutoGenerateColumn(Filterable = true, Sortable = true, Width = 200)]
+ public DateTime LoginTime { get; set; }
+
+ ///
+ /// 在线状态
+ ///
+ [Newtonsoft.Json.JsonIgnore]
+ [System.Text.Json.Serialization.JsonIgnore]
+ [AutoGenerateColumn(Filterable = true, Sortable = true, Width = 120)]
+ [SugarColumn(IsIgnore = true)]
+ public bool Online => ClientIds.Count > 0;
+
+ ///
+ /// 过期时间
+ ///
+ [AutoGenerateColumn(Filterable = true, Sortable = true)]
+ public int Expire { get; set; }
+
+ ///
+ /// verificat剩余有效期
+ ///
+ [AutoGenerateColumn(Filterable = true, Sortable = true)]
+ [SugarColumn(IsIgnore = true)]
+ [Newtonsoft.Json.JsonIgnore]
+ [System.Text.Json.Serialization.JsonIgnore]
+ public string VerificatRemain { get; set; }
+
+ ///
+ /// 超时时间
+ ///
+ [AutoGenerateColumn(Filterable = true, Sortable = true)]
+ public DateTime VerificatTimeout { get; set; }
+
+ ///
+ /// 登录设备
+ ///
+ [AutoGenerateColumn(Filterable = true, Sortable = true, Width = 100)]
+ public string Device { get; set; }
+
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/DataScopeEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/DataScopeEnum.cs
new file mode 100644
index 000000000..d25d2af40
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/DataScopeEnum.cs
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum DataScopeEnum
+{
+
+ ///
+ /// 仅自己
+ ///
+ SCOPE_SELF,
+
+ ///
+ /// 所有
+ ///
+ SCOPE_ALL,
+
+ ///
+ /// 仅所属组织
+ ///
+ SCOPE_ORG,
+
+ ///
+ /// 所属组织及以下
+ ///
+ SCOPE_ORG_CHILD,
+
+ ///
+ /// 自定义
+ ///
+ SCOPE_ORG_DEFINE,
+
+}
diff --git a/src/Foundation/ThingsGateway.Foundation/Channel/IAdapterObject.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/DictTypeEnum.cs
similarity index 73%
rename from src/Foundation/ThingsGateway.Foundation/Channel/IAdapterObject.cs
rename to src/Admin/ThingsGateway.Admin.Application/Enum/DictTypeEnum.cs
index 30f6466cb..66edf7525 100644
--- a/src/Foundation/ThingsGateway.Foundation/Channel/IAdapterObject.cs
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/DictTypeEnum.cs
@@ -8,16 +8,20 @@
// QQ群:605534569
//------------------------------------------------------------------------------
-namespace ThingsGateway.Foundation;
+namespace ThingsGateway.Admin.Application;
///
-/// 能对适配器做配置的客户端
+/// 字典表类型
///
-public interface IAdapterObject
+public enum DictTypeEnum
{
///
- /// 设置数据处理适配器
+ /// 系统使用
///
- /// 适配器
- void SetDataHandlingAdapter(DataHandlingAdapter adapter);
+ System,
+
+ ///
+ /// 用户自定义
+ ///
+ Define,
}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/LogCateGoryEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/LogCateGoryEnum.cs
new file mode 100644
index 000000000..b1c38244c
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/LogCateGoryEnum.cs
@@ -0,0 +1,19 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum LogCateGoryEnum
+{
+ Login,
+ Logout,
+ Operate,
+ Exception
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/OrgEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/OrgEnum.cs
new file mode 100644
index 000000000..31dd6794b
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/OrgEnum.cs
@@ -0,0 +1,17 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum OrgEnum
+{
+ DEPT,
+ COMPANY,
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/PositionCategoryEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/PositionCategoryEnum.cs
new file mode 100644
index 000000000..7e629aeef
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/PositionCategoryEnum.cs
@@ -0,0 +1,18 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum PositionCategoryEnum
+{
+ HIGH,
+ MIDDLE,
+ LOW,
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/RelationCategoryEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/RelationCategoryEnum.cs
new file mode 100644
index 000000000..e200a75e3
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/RelationCategoryEnum.cs
@@ -0,0 +1,25 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum RelationCategoryEnum
+{
+ UserHasRole,
+ UserHasResource,
+ UserHasPermission,
+ UserHasOpenApiPermission,
+ UserHasModule,
+ UserWorkbenchData,
+ RoleHasResource,
+ RoleHasPermission,
+ RoleHasOpenApiPermission,
+ RoleHasModule,
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/ResourceCategoryEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/ResourceCategoryEnum.cs
new file mode 100644
index 000000000..1f6e8ee24
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/ResourceCategoryEnum.cs
@@ -0,0 +1,18 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum ResourceCategoryEnum
+{
+ Module,
+ Menu,
+ Button,
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/RoleCategoryEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/RoleCategoryEnum.cs
new file mode 100644
index 000000000..436c63d4c
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/RoleCategoryEnum.cs
@@ -0,0 +1,17 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum RoleCategoryEnum
+{
+ Global = 0,
+ Org = 2,
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Enum/TargetEnum.cs b/src/Admin/ThingsGateway.Admin.Application/Enum/TargetEnum.cs
new file mode 100644
index 000000000..e7cc4eb30
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Enum/TargetEnum.cs
@@ -0,0 +1,19 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public enum TargetEnum
+{
+ _self,
+ _blank,
+ _parent,
+ _top
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Extensions/ApplicationBuilderExtensions.cs b/src/Admin/ThingsGateway.Admin.Application/Extensions/ApplicationBuilderExtensions.cs
new file mode 100644
index 000000000..f03975eb4
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Extensions/ApplicationBuilderExtensions.cs
@@ -0,0 +1,55 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Http;
+
+using System.Net;
+using System.Text.Json;
+
+namespace Microsoft.AspNetCore.Builder;
+
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public static class ApplicationBuilderExtensions
+{
+ public static IApplicationBuilder UseBootstrapBlazor(this IApplicationBuilder builder)
+ {
+ // 获得客户端 IP 地址
+ builder.UseWhen(context => context.Request.Path.StartsWithSegments("/ip.axd"), app => app.Run(async context =>
+ {
+ var ip = "";
+ var headers = context.Request.Headers;
+ if (headers.TryGetValue("X-Forwarded-For", out var value))
+ {
+ var ips = new List();
+ foreach (var xf in value)
+ {
+ if (!string.IsNullOrEmpty(xf))
+ {
+ ips.Add(xf);
+ }
+ }
+ ip = string.Join(";", ips);
+ }
+ else
+ {
+ ip = context.Connection.RemoteIpAddress.ToIPv4String();
+ }
+
+ context.Response.Headers.TryAdd("Content-Type", new Microsoft.Extensions.Primitives.StringValues("application/json; charset=utf-8"));
+ await context.Response.WriteAsync(JsonSerializer.Serialize(new { Id = context.TraceIdentifier, Ip = ip })).ConfigureAwait(false);
+ }));
+ return builder;
+ }
+ public static string ToIPv4String(this IPAddress? address)
+ {
+ var ipv4Address = (address ?? IPAddress.IPv6Loopback).ToString();
+ return ipv4Address.StartsWith("::ffff:") ? (address ?? IPAddress.IPv6Loopback).MapToIPv4().ToString() : ipv4Address;
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Extensions/CacheExtensions.cs b/src/Admin/ThingsGateway.Admin.Application/Extensions/CacheExtensions.cs
new file mode 100644
index 000000000..454a90081
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Extensions/CacheExtensions.cs
@@ -0,0 +1,88 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.StaticFiles;
+using Microsoft.AspNetCore.WebUtilities;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Net.Http.Headers;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public static class CacheExtensions
+{
+ private static int? _age;
+
+ private static List? _files;
+
+ public static void ProcessCache(this StaticFileResponseContext context, IConfiguration configuration)
+ {
+ if (context.CanCache(configuration, out var age))
+ {
+ context.Context.Response.Headers[HeaderNames.CacheControl] = $"public, max-age={age}";
+ }
+ }
+
+ private static bool CanCache(this StaticFileResponseContext context, IConfiguration configuration, out int age)
+ {
+ var ret = false;
+ age = 0;
+
+ var files = configuration.GetFiles();
+ if (files.Any(i => context.CanCache(i)))
+ {
+ ret = true;
+ age = configuration.GetAge();
+ }
+ return ret;
+ }
+
+ private static bool CanCache(this StaticFileResponseContext context, string file)
+ {
+ var ext = Path.GetExtension(context.File.PhysicalPath) ?? "";
+ bool ret = file.Equals(ext, StringComparison.OrdinalIgnoreCase);
+ if (ret && ext.Equals(".js", StringComparison.OrdinalIgnoreCase))
+ {
+ // process javascript file
+ ret = false;
+ if (context.Context.Request.QueryString.HasValue)
+ {
+ var paras = QueryHelpers.ParseQuery(context.Context.Request.QueryString.Value);
+ ret = paras.ContainsKey("v");
+ }
+ }
+ return ret;
+ }
+
+ private static int GetAge(this IConfiguration configuration)
+ {
+ _age ??= GetAge();
+ return _age.Value;
+
+ int GetAge()
+ {
+ var cacheSection = configuration.GetSection("Cache-Control");
+ return cacheSection.GetValue("Max-Age", 1000 * 60 * 10);
+ }
+ }
+
+ private static List GetFiles(this IConfiguration configuration)
+ {
+ _files ??= GetFiles();
+ return _files;
+
+ List GetFiles()
+ {
+ var cacheSection = configuration.GetSection("Cache-Control");
+ return cacheSection.GetSection("Files").Get>() ?? new();
+ }
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Extensions/ExportExcelExtensions.cs b/src/Admin/ThingsGateway.Admin.Application/Extensions/ExportExcelExtensions.cs
new file mode 100644
index 000000000..9e6bcb9d9
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Extensions/ExportExcelExtensions.cs
@@ -0,0 +1,120 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+
+using Mapster;
+
+using MiniExcelLibs;
+using MiniExcelLibs.Attributes;
+using MiniExcelLibs.OpenXml;
+
+using System.Data;
+using System.Reflection;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 导出excel扩展
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public static class ExportExcelExtensions
+{
+ ///
+ /// 导出excel
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static Dictionary ExportExcel(this IEnumerable? data, string sheetName)
+ {
+ //总数据
+ Dictionary sheets = new();
+ //通道页
+ List> valveLogExports = new();
+
+ #region 列名称
+
+ var type = typeof(T);
+ var propertyInfos = type.GetRuntimeProperties().Where(a => a.GetCustomAttribute() == null)
+ .OrderBy(
+ a =>
+ {
+ var order = a.GetCustomAttribute()?.Order ?? int.MaxValue; ;
+ if (order < 0)
+ {
+ order = order + 10000000;
+ }
+ else if (order == 0)
+ {
+ order = 10000000;
+ }
+ return order;
+ }
+ )
+ ;
+
+ #endregion 列名称
+
+ foreach (var device in data)
+ {
+ Dictionary valveLogExport = new();
+ foreach (var item in propertyInfos)
+ {
+ //描述
+ var desc = type.GetPropertyDisplayName(item.Name);
+ //数据源增加
+ valveLogExport.Add(desc ?? item.Name, item.GetValue(device)?.ToString());
+ }
+
+ //添加完整设备信息
+ valveLogExports.Add(valveLogExport);
+ }
+ //添加设备页
+ sheets.Add(sheetName, valveLogExports);
+ return sheets;
+ }
+
+
+ ///
+ /// 导出excel
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static async Task ExportExcel(this Stream stream, object input, bool isDynamicExcelColumn) where T : class
+ {
+ var config = new OpenXmlConfiguration();
+ if (isDynamicExcelColumn)
+ {
+ var type = typeof(T);
+ var data = type.GetRuntimeProperties();
+ List dynamicExcelColumns = new();
+ int index = 0;
+ foreach (var item in data)
+ {
+ var ignore = item.GetCustomAttribute() != null;
+ //描述
+ var desc = type.GetPropertyDisplayName(item.Name);
+ //数据源增加
+ dynamicExcelColumns.Add(new DynamicExcelColumn(item.Name) { Ignore = ignore, Index = index, Name = desc ?? item.Name, Width = 30 });
+ if (!ignore)
+ index++;
+ }
+ config.DynamicColumns = dynamicExcelColumns.ToArray();
+ }
+ config.TableStyles = TableStyles.None;
+ await MiniExcel.SaveAsAsync(stream, input, configuration: config).ConfigureAwait(false);
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Extensions/FileExtensions.cs b/src/Admin/ThingsGateway.Admin.Application/Extensions/FileExtensions.cs
new file mode 100644
index 000000000..1967ea67f
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Extensions/FileExtensions.cs
@@ -0,0 +1,44 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Components.Forms;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public static class FileExtensions
+{
+ ///
+ /// 存储本地文件
+ ///
+ /// 存储的第一层目录
+ ///
+ /// 文件全路径
+ public static async Task StorageLocal(this IBrowserFile file, string pPath = "imports")
+ {
+ string uploadFileFolder = App.WebHostEnvironment?.WebRootPath ?? "wwwroot"!;//赋值路径
+ var now = CommonUtils.GetSingleId();
+ var filePath = Path.Combine(uploadFileFolder, pPath);
+ if (!Directory.Exists(filePath))//如果不存在就创建文件夹
+ Directory.CreateDirectory(filePath);
+ //var fileSuffix = Path.GetExtension(file.Name).ToLower();// 文件后缀
+ var fileObjectName = $"{now}{file.Name}";//存储后的文件名
+ var fileName = Path.Combine(filePath, fileObjectName);//获取文件全路径
+ fileName = fileName.Replace("\\", "/");//格式化一系
+ //存储文件
+ using (var stream = File.Create(Path.Combine(filePath, fileObjectName)))
+ {
+ using var fs = file.OpenReadStream(1024 * 1024 * 500);
+ await fs.CopyToAsync(stream).ConfigureAwait(false);
+ }
+ return fileName;
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Extensions/QueryPageOptionsExtensions.cs b/src/Admin/ThingsGateway.Admin.Application/Extensions/QueryPageOptionsExtensions.cs
new file mode 100644
index 000000000..4ede1ebb3
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Extensions/QueryPageOptionsExtensions.cs
@@ -0,0 +1,97 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using SqlSugar;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public static class QueryPageOptionsExtensions
+{
+
+ public static IEnumerable GetData(this IEnumerable datas, QueryPageOptions option, FilterKeyValueAction where = null)
+ {
+ where ??= option.ToFilter();
+ if (where.HasFilters())
+ {
+ datas = datas.Where(where.GetFilterFunc());//name asc模式
+ }
+
+ if (option.SortList.Count > 0)
+ {
+ datas = datas.Sort(option.SortList);//name asc模式
+ }
+ if (option.AdvancedSortList.Count > 0)
+ {
+ datas = datas.Sort(option.AdvancedSortList);//name asc模式
+ }
+ if (option.SortOrder != SortOrder.Unset && !option.SortName.IsNullOrWhiteSpace())
+ {
+ datas = datas.Sort(option.SortName, option.SortOrder);
+ }
+ if (option.IsPage)
+ {
+ datas = datas.Skip((option.PageIndex - 1) * option.PageItems).Take(option.PageItems);
+ }
+ else if (option.IsVirtualScroll)
+ {
+ datas = datas.Skip((option.StartIndex) * option.PageItems).Take(option.PageItems);
+ }
+ return datas;
+ }
+
+ ///
+ /// 根据查询条件返回sqlsugar ISugarQueryable
+ ///
+ ///
+ ///
+ public static ISugarQueryable GetQuery(this SqlSugarClient db, QueryPageOptions option, ISugarQueryable? query = null, FilterKeyValueAction where = null)
+ {
+ query ??= db.Queryable();
+ where ??= option.ToFilter();
+
+ if (where.HasFilters())
+ {
+ query = query.Where(where.GetFilterLambda());//name asc模式
+ }
+
+ foreach (var item in option.SortList)
+ {
+ query = query.OrderByIF(!string.IsNullOrEmpty(item), $"{item}");//name asc模式
+ }
+ foreach (var item in option.AdvancedSortList)
+ {
+ query = query.OrderByIF(!string.IsNullOrEmpty(item), $"{item}");//name asc模式
+ }
+ query = query.OrderByIF(option.SortOrder != SortOrder.Unset, $"{option.SortName} {option.SortOrder}");
+ return query;
+ }
+
+ ///
+ /// 根据查询条件返回QueryData
+ ///
+ public static QueryData GetQueryData(this IEnumerable datas, QueryPageOptions option, FilterKeyValueAction where = null)
+ {
+ var ret = new QueryData()
+ {
+ IsSorted = option.SortOrder != SortOrder.Unset,
+ IsFiltered = option.Filters.Count > 0,
+ IsAdvanceSearch = option.AdvanceSearches.Count > 0 || option.CustomerSearches.Count > 0,
+ IsSearch = option.Searches.Count > 0
+ };
+ var items = datas.GetData(option, where);
+ ret.TotalCount = datas.Count();
+ ret.Items = items.ToList();
+ return ret;
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Extensions/SqlSugarExtensions.cs b/src/Admin/ThingsGateway.Admin.Application/Extensions/SqlSugarExtensions.cs
new file mode 100644
index 000000000..a2b766cef
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Extensions/SqlSugarExtensions.cs
@@ -0,0 +1,244 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using SqlSugar;
+
+using System.Linq.Expressions;
+using System.Reflection;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+[ThingsGateway.DependencyInjection.SuppressSniffer]
+public static class SqlSugarExtensions
+{
+ ///
+ public static ISugarQueryable ExportIgnoreColumns(this ISugarQueryable queryable)
+ {
+ return queryable.IgnoreColumns(
+ [
+ nameof(BaseEntity.Id),
+ nameof(BaseEntity.CreateTime),
+ nameof(BaseEntity.CreateUser),
+ nameof(BaseEntity.CreateUserId),
+ nameof(BaseDataEntity.CreateOrgId),
+ nameof(BaseEntity.ExtJson),
+ nameof(BaseEntity.IsDelete),
+ nameof(BaseEntity.UpdateTime),
+ nameof(BaseEntity.UpdateUser),
+ nameof(BaseEntity.UpdateUserId),
+ ]
+ );
+ }
+
+ ///
+ public static SqlSugarPagedList ToPagedList(this ISugarQueryable queryable, int current,
+ int size)
+ {
+ var total = 0;
+ var records = queryable.ToPageList(current, size, ref total);
+ var pages = (int)Math.Ceiling(total / (double)size);
+ return new SqlSugarPagedList
+ {
+ Current = current,
+ Size = size,
+ Records = records,
+ Total = total,
+ Pages = pages,
+ HasNextPages = current < pages,
+ HasPrevPages = current - 1 > 0
+ };
+ }
+
+ ///
+ /// SqlSugar分页扩展,查询出结果后再转换实体类
+ ///
+ public static SqlSugarPagedList ToPagedList(this ISugarQueryable queryable,
+ int current, int size)
+ {
+ var totalCount = 0;
+ var records = queryable.ToPageList(current, size, ref totalCount);
+ var totalPages = (int)Math.Ceiling(totalCount / (double)size);
+ return new SqlSugarPagedList
+ {
+ Current = current,
+ Size = size,
+ Records = records.Cast(),
+ Total = totalCount,
+ Pages = totalPages,
+ HasNextPages = current < totalPages,
+ HasPrevPages = current - 1 > 0
+ };
+ }
+
+ ///
+ /// SqlSugar分页扩展,查询前扩展转换实体类
+ ///
+ public static SqlSugarPagedList ToPagedList(this ISugarQueryable queryable, int pageIndex,
+ int pageSize, Expression> expression)
+ {
+ var totalCount = 0;
+ var items = queryable.ToPageList(pageIndex, pageSize, ref totalCount, expression);
+ var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
+ return new SqlSugarPagedList
+ {
+ Current = pageIndex,
+ Size = pageSize,
+ Records = items,
+ Total = totalCount,
+ Pages = totalPages,
+ HasNextPages = pageIndex < totalPages,
+ HasPrevPages = pageIndex - 1 > 0
+ };
+ }
+
+ ///
+ /// 分页查询
+ ///
+ ///
+ /// 数据列表
+ /// 参数
+ /// 不分页
+ /// 分页集合
+ public static SqlSugarPagedList ToPagedList(this IEnumerable list, BasePageInput basePageInput = null, bool isAll = false)
+ {
+ if (isAll)
+ {
+ list = Sort(list, basePageInput);
+ var data = new SqlSugarPagedList
+ {
+ Current = 1,
+ Size = list?.Count() ?? 0,
+ Records = list,
+ Total = list?.Count() ?? 0,
+ Pages = 1,
+ HasNextPages = false,
+ HasPrevPages = false
+ };
+ return data;
+ }
+
+ int _PageIndex = basePageInput.Current;
+ int _PageSize = basePageInput.Size;
+ var num = list.Count();
+ var pageConut = (double)num / _PageSize;
+ int PageConut = (int)Math.Ceiling(pageConut);
+ list = Sort(list, basePageInput);
+ if (PageConut >= _PageIndex)
+ {
+ list = list.Skip((_PageIndex - 1) * _PageSize).Take(_PageSize);
+ }
+ return new SqlSugarPagedList
+ {
+ Current = _PageIndex,
+ Size = _PageSize,
+ Records = list,
+ Total = num,
+ Pages = PageConut,
+ HasNextPages = _PageIndex < PageConut,
+ HasPrevPages = _PageIndex - 1 > 0
+ };
+ }
+
+ ///
+ /// SqlSugar分页扩展,查询前扩展转换实体类
+ ///
+ public static async Task> ToPagedListAsync(this ISugarQueryable queryable,
+ int current, int size)
+ {
+ RefAsync totalCount = 0;
+ var records = await queryable.ToPageListAsync(current, size, totalCount).ConfigureAwait(false);
+ var totalPages = (int)Math.Ceiling(totalCount / (double)size);
+ return new SqlSugarPagedList
+ {
+ Current = current,
+ Size = size,
+ Records = records,
+ Total = (int)totalCount,
+ Pages = totalPages,
+ HasNextPages = current < totalPages,
+ HasPrevPages = current - 1 > 0
+ };
+ }
+
+ ///
+ /// SqlSugar分页扩展,查询出结果后再转换实体类
+ ///
+ public static async Task> ToPagedListAsync(this ISugarQueryable queryable,
+ int current, int size)
+ {
+ RefAsync totalCount = 0;
+ var records = await queryable.ToPageListAsync(current, size, totalCount).ConfigureAwait(false);
+ var totalPages = (int)Math.Ceiling(totalCount / (double)size);
+ return new SqlSugarPagedList
+ {
+ Current = current,
+ Size = size,
+ Records = records.Cast(),
+ Total = (int)totalCount,
+ Pages = totalPages,
+ HasNextPages = current < totalPages,
+ HasPrevPages = current - 1 > 0
+ };
+ }
+
+ ///
+ /// SqlSugar分页扩展,查询前扩展转换实体类
+ ///
+ public static async Task> ToPagedListAsync(
+ this ISugarQueryable queryable, int pageIndex, int pageSize, Expression> expression)
+ {
+ RefAsync totalCount = 0;
+ var items = await queryable.ToPageListAsync(pageIndex, pageSize, totalCount, expression).ConfigureAwait(false);
+ var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
+ return new SqlSugarPagedList
+ {
+ Current = pageIndex,
+ Size = pageSize,
+ Records = items,
+ Total = (int)totalCount,
+ Pages = totalPages,
+ HasNextPages = pageIndex < totalPages,
+ HasPrevPages = pageIndex - 1 > 0
+ };
+ }
+
+ ///
+ public static async Task UpdateRangeAsync(this SqlSugarClient db, List updateObjs) where T : class, new()
+ {
+ return await db.Updateable(updateObjs).ExecuteCommandAsync().ConfigureAwait(false) > 0;
+ }
+
+ ///
+ public static async Task UpdateSetColumnsTrueAsync(this SqlSugarClient db, Expression> columns, Expression> whereExpression) where T : class, new()
+ {
+ return await db.Updateable().SetColumns(columns, appendColumnsByDataFilter: true).Where(whereExpression)
+ .ExecuteCommandAsync().ConfigureAwait(false) > 0;
+ }
+
+ private static IEnumerable Sort(this IEnumerable list, BasePageInput basePageInput)
+ {
+ if (basePageInput != null && basePageInput.SortField != null)
+ {
+ for (int i = 0; i < basePageInput.SortField.Count; i++)
+ {
+ var pro = typeof(T).GetRuntimeProperty(basePageInput.SortField[i]);
+ if (pro != null)
+ {
+ if (!basePageInput.SortDesc[i])
+ list = list.OrderBy(a => pro.GetValue(a));
+ else
+ list = list.OrderByDescending(a => pro.GetValue(a));
+ }
+ }
+ }
+ return list;
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/FodyWeavers.xml b/src/Admin/ThingsGateway.Admin.Application/FodyWeavers.xml
new file mode 100644
index 000000000..a6a2edf1b
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/FodyWeavers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/src/Admin/ThingsGateway.Admin.Application/GlobalUsings.cs b/src/Admin/ThingsGateway.Admin.Application/GlobalUsings.cs
new file mode 100644
index 000000000..12f87ac5d
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/GlobalUsings.cs
@@ -0,0 +1,12 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+global using ThingsGateway;
+global using ThingsGateway.NewLife.Extension;
\ No newline at end of file
diff --git a/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HardwareInfo.cs b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HardwareInfo.cs
new file mode 100644
index 000000000..a37759916
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HardwareInfo.cs
@@ -0,0 +1,60 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using ThingsGateway.NewLife;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+public class HardwareInfo
+{
+ ///
+ /// 当前磁盘信息
+ ///
+ public DriveInfo DriveInfo { get; set; }
+
+ ///
+ /// 硬件信息获取
+ ///
+ public MachineInfo? MachineInfo { get; set; }
+
+ ///
+ /// 主机环境
+ ///
+ public string Environment { get; set; }
+
+ ///
+ /// NET框架
+ ///
+ public string FrameworkDescription { get; set; }
+
+ ///
+ /// 系统架构
+ ///
+ public string OsArchitecture { get; set; }
+
+ ///
+ /// 唯一编码
+ ///
+ public string UUID { get; set; }
+
+ ///
+ /// 进程占用内存
+ ///
+ [AutoGenerateColumn(Ignore = true)]
+ public string WorkingSet { get; set; }
+
+ ///
+ /// 更新时间
+ ///
+ public string UpdateTime { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HardwareJob.cs b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HardwareJob.cs
new file mode 100644
index 000000000..da705e674
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HardwareJob.cs
@@ -0,0 +1,147 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Localization;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+
+using System.Runtime.InteropServices;
+
+using ThingsGateway.DataEncryption;
+using ThingsGateway.Extension;
+using ThingsGateway.NewLife;
+using ThingsGateway.NewLife.Threading;
+using ThingsGateway.Schedule;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 获取硬件信息作业任务
+///
+[JobDetail("hardware_log", Description = "获取硬件信息", GroupName = "Hardware", Concurrent = false)]
+[PeriodSeconds(30, TriggerId = "trigger_hardware", Description = "获取硬件信息", RunOnStart = true)]
+public class HardwareJob : IJob, IHardwareJob
+{
+ private readonly ILogger _logger;
+ private readonly IStringLocalizer _localizer;
+
+ ///
+ public HardwareJob(ILogger logger, IStringLocalizer localizer, IOptions options)
+ {
+ _logger = logger;
+ _localizer = localizer;
+ HardwareInfoOptions = options.Value;
+ }
+ #region 属性
+
+ ///
+ /// 运行信息获取
+ ///
+ public HardwareInfo HardwareInfo { get; } = new();
+
+ ///
+ public HardwareInfoOptions HardwareInfoOptions { get; private set; }
+
+ #endregion 属性
+
+ ///
+ public async Task> GetHistoryHardwareInfos()
+ {
+ using var db = DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ return await db.Queryable().ToListAsync().ConfigureAwait(false);
+ }
+
+ private bool error = false;
+ private DateTime hisInsertTime = default;
+
+ public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
+ {
+ if (HardwareInfoOptions.Enable)
+ {
+ try
+ {
+ if (HardwareInfo.MachineInfo == null)
+ {
+ await MachineInfo.RegisterAsync().ConfigureAwait(false);
+ HardwareInfo.MachineInfo = MachineInfo.Current;
+
+ string currentPath = Directory.GetCurrentDirectory();
+ DriveInfo drive = new(Path.GetPathRoot(currentPath));
+
+ HardwareInfoOptions.DaysAgo = Math.Min(Math.Max(HardwareInfoOptions.DaysAgo, 1), 7);
+ if (HardwareInfoOptions.HistoryInterval < 60000) HardwareInfoOptions.HistoryInterval = 60000;
+ HardwareInfo.DriveInfo = drive;
+ HardwareInfo.OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(); // 系统架构
+ HardwareInfo.FrameworkDescription = RuntimeInformation.FrameworkDescription; // NET框架
+ HardwareInfo.Environment = App.HostEnvironment.IsDevelopment() ? "Development" : "Production";
+ HardwareInfo.UUID = DESEncryption.Encrypt(HardwareInfo.MachineInfo.UUID + HardwareInfo.MachineInfo.Guid + HardwareInfo.MachineInfo.DiskID);
+
+ HardwareInfo.UpdateTime = TimerX.Now.ToDefaultDateTimeFormat();
+
+ }
+ }
+ catch
+ {
+ }
+ try
+ {
+ HardwareInfo.MachineInfo.Refresh();
+ HardwareInfo.UpdateTime = TimerX.Now.ToDefaultDateTimeFormat();
+ HardwareInfo.WorkingSet = (Environment.WorkingSet / 1024.0 / 1024.0).ToString("F2");
+ error = false;
+ }
+ catch (Exception ex)
+ {
+ if (!error)
+ _logger.LogWarning(ex, _localizer["GetHardwareInfoFail"]);
+ error = true;
+ }
+
+ try
+ {
+ if (HardwareInfoOptions.Enable)
+ {
+ if (DateTime.Now > hisInsertTime.Add(TimeSpan.FromMilliseconds(HardwareInfoOptions.HistoryInterval)))
+ {
+ hisInsertTime = DateTime.Now;
+ using var db = DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ {
+ var his = new HistoryHardwareInfo()
+ {
+ Date = TimerX.Now,
+ DriveUsage = (100 - (HardwareInfo.DriveInfo.TotalFreeSpace * 100.00 / HardwareInfo.DriveInfo.TotalSize)).ToString("F2"),
+ Battery = (HardwareInfo.MachineInfo.Battery * 100).ToString("F2"),
+ MemoryUsage = (100 - (HardwareInfo.MachineInfo.AvailableMemory * 100.00 / HardwareInfo.MachineInfo.Memory)).ToString("F2"),
+ CpuUsage = (HardwareInfo.MachineInfo.CpuRate * 100).ToString("F2"),
+ Temperature = (HardwareInfo.MachineInfo.Temperature).ToString("F2"),
+ };
+ await db.Insertable(his).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false);
+ }
+ var sevenDaysAgo = TimerX.Now.AddDays(-HardwareInfoOptions.DaysAgo);
+ //删除特定信息
+ await db.Deleteable(a => a.Date <= sevenDaysAgo).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false);
+ }
+ }
+ error = false;
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (Exception ex)
+ {
+ if (!error)
+ _logger.LogWarning(ex, _localizer["GetHardwareInfoFail"]);
+ error = true;
+ }
+ }
+ }
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HistoryHardwareInfo.cs b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HistoryHardwareInfo.cs
new file mode 100644
index 000000000..b11d11e20
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/HistoryHardwareInfo.cs
@@ -0,0 +1,43 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using SqlSugar;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+[SugarTable("his_hardwareinfo", TableDescription = "硬件信息历史表")]
+[Tenant(SqlSugarConst.DB_HardwareInfo)]
+public class HistoryHardwareInfo
+{
+ ///
+ [SugarColumn(ColumnDescription = "磁盘使用率")]
+ public string DriveUsage { get; set; }
+
+ ///
+ [SugarColumn(ColumnDescription = "内存使用率")]
+ public string MemoryUsage { get; set; }
+
+ ///
+ [SugarColumn(ColumnDescription = "CPU使用率")]
+ public string CpuUsage { get; set; }
+
+ ///
+ [SugarColumn(ColumnDescription = "温度")]
+ public string Temperature { get; set; }
+
+ ///
+ [SugarColumn(ColumnDescription = "电池")]
+ public string Battery { get; set; }
+
+ ///
+ [SugarColumn(ColumnDescription = "时间")]
+ public DateTime Date { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/IHardwareJob.cs b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/IHardwareJob.cs
new file mode 100644
index 000000000..6d20cefdb
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Job/Hardware/IHardwareJob.cs
@@ -0,0 +1,18 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public interface IHardwareJob
+{
+ HardwareInfo HardwareInfo { get; }
+ HardwareInfoOptions HardwareInfoOptions { get; }
+ Task> GetHistoryHardwareInfos();
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Job/JobPersistence.cs b/src/Admin/ThingsGateway.Admin.Application/Job/JobPersistence.cs
new file mode 100644
index 000000000..b048087b2
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Job/JobPersistence.cs
@@ -0,0 +1,76 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using ThingsGateway.Schedule;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 作业持久化(数据库)
+///
+public class JobPersistence : IJobPersistence
+{
+
+ ///
+ /// 作业调度服务启动时
+ ///
+ ///
+ ///
+ ///
+ public async Task> PreloadAsync(CancellationToken stoppingToken)
+ {
+ await Task.CompletedTask.ConfigureAwait(false);
+ // 获取所有定义的作业
+ var allJobs = App.EffectiveTypes.ScanToBuilders().ToList();
+ return allJobs;
+ }
+
+ ///
+ /// 作业计划初始化通知
+ ///
+ ///
+ ///
+ ///
+ public Task OnLoadingAsync(SchedulerBuilder builder, CancellationToken stoppingToken)
+ {
+ return Task.FromResult(builder);
+ }
+
+ ///
+ /// 作业计划Scheduler的JobDetail变化时
+ ///
+ ///
+ ///
+ public async Task OnChangedAsync(PersistenceContext context)
+ {
+ await Task.CompletedTask.ConfigureAwait(false);
+ }
+
+ ///
+ /// 作业计划Scheduler的触发器Trigger变化时
+ ///
+ ///
+ ///
+ public async Task OnTriggerChangedAsync(PersistenceTriggerContext context)
+ {
+ await Task.CompletedTask.ConfigureAwait(false);
+
+ }
+
+ ///
+ /// 作业触发器运行记录
+ ///
+ ///
+ ///
+ public async Task OnExecutionRecordAsync(PersistenceExecutionRecordContext context)
+ {
+ await Task.CompletedTask.ConfigureAwait(false);
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Job/LogJob/LogJob.cs b/src/Admin/ThingsGateway.Admin.Application/Job/LogJob/LogJob.cs
new file mode 100644
index 000000000..8f89f473c
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Job/LogJob/LogJob.cs
@@ -0,0 +1,33 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using ThingsGateway.Schedule;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 清理日志作业任务
+///
+[JobDetail("job_log", Description = "清理操作日志", GroupName = "Log", Concurrent = false)]
+[Daily(TriggerId = "trigger_log", Description = "清理操作日志", RunOnStart = true)]
+public class LogJob : IJob
+{
+ public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
+ {
+ var daysAgo = App.GetOptions()?.OperateLogDaysAgo ?? 7;
+ await LogJob.DeleteSysOperateLog(daysAgo, stoppingToken).ConfigureAwait(false);
+ }
+
+ private static async Task DeleteSysOperateLog(int daysAgo, CancellationToken stoppingToken)
+ {
+ using var db = DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ await db.DeleteableWithAttr().Where(u => u.OpTime < DateTime.Now.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken).ConfigureAwait(false); // 删除操作日志
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Locales/en-US.json b/src/Admin/ThingsGateway.Admin.Application/Locales/en-US.json
new file mode 100644
index 000000000..1a700b77a
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Locales/en-US.json
@@ -0,0 +1,464 @@
+{
+ "ThingsGateway.Admin.Application.SysUser": {
+ "Disable": "Disable",
+ "Enable": "Enable",
+ "GrantRole": "GrantRole",
+ "ExitVerificat": "You have been forcibly logged out",
+ "PasswordEdited": "Password changed, logged out",
+
+ "Avatar": "Avatar",
+ "Account": "Account",
+ "Account.Required": "Account.Required",
+ "Password": "Password",
+ "Status": "Status",
+ "Phone": "Phone",
+ "Email": "Email",
+ "LastLoginIp": "LastLoginIp",
+ "LastLoginDevice": "LastLoginDevice",
+ "LastLoginTime": "LastLoginTime",
+ "LastLoginAddress": "LastLoginAddress",
+ "LatestLoginIp": "LatestLoginIp",
+ "LatestLoginTime": "LatestLoginTime",
+ "LatestLoginDevice": "LatestLoginDevice",
+ "LatestLoginAddress": "LatestLoginAddress",
+ "SortCode": "SortCode",
+ "CreateTime": "CreateTime",
+ "UpdateTime": "UpdateTime",
+ "OrgNames": "Org",
+ "PositionName": "Position",
+ "OrgId": "Org",
+ "PositionId": "Position",
+ "DirectorId": "Director",
+
+ "CheckSelf": "Prohibit {0} yourself",
+ "CanotDeleteAdminUser": "Cannot delete built-in super admin user",
+ "CanotEditAdminUser": "Cannot edit super admin user",
+ "CanotGrantAdmin": "Cannot assign admins roles",
+ "EmailDup": "Duplicate email {0} exists",
+ "AccountDup": "Duplicate account {0} exists",
+ "CanotDeleteSelf": "Cannot delete yourself",
+ "EmailError": "Email format error {0}",
+ "PhoneError": "Phone number format error {0}",
+ "NoOrg": "The organization does not exist",
+ "DirectorSelf": "Cannot set oneself as the supervisor",
+
+ "DemoCanotUpdatePassword": "DEMO environment does not allow password modification",
+ "OldPasswordError": "Incorrect old password",
+ "ConfirmPasswordDiff": "Passwords entered twice are inconsistent",
+ "PasswordLengthLess": "Password length cannot be less than {0}",
+ "PasswordMustNum ": "Password must contain numbers",
+ "PasswordMustLow": "Password must contain lowercase letters",
+ "PasswordMustUpp": "Password must contain uppercase letters",
+ "PasswordMustSpecial": "Password must contain special characters"
+ },
+
+ "ThingsGateway.Admin.Application.SysRole": {
+ "Code": "Code",
+ "Name": "Name",
+ "Name.Required": "{0} is required",
+ "Category": "Category",
+ "SortCode": "Sort",
+ "CreateTime": "CreateTime",
+ "UpdateTime": "UpdateTime",
+ "OrgId": "Org",
+ "Global": "Global",
+ "Status": "Status",
+ "CanotDeleteAdmin": "Cannot delete built-in super admin role",
+ "CanotEditAdmin": "Cannot edit super admin role",
+ "CanotGrantAdmin": "Cannot assign admins roles",
+ "NameDup": "Duplicate role name {0}",
+
+ "OrgNotNull": "Organization cannot be null",
+ "SameOrgNameDup": "Duplicate role name exists: {0}",
+ "CannotRoleScopeAll": "Organization role cannot select global data scope",
+ "CodeDup": "Duplicate code exists: {0}"
+ },
+
+ "ThingsGateway.Admin.Application.RoleCategoryEnum": {
+ "Global": "Global",
+ "Org": "Org"
+ },
+ "ThingsGateway.Admin.Application.DataScopeEnum": {
+ "SCOPE_SELF": "Self",
+ "SCOPE_ALL": "All",
+ "SCOPE_ORG": "OnlyOrg",
+ "SCOPE_ORG_CHILD": "OrgChild",
+ "SCOPE_ORG_DEFINE": "Define"
+ },
+ "ThingsGateway.Admin.Application.DefaultDataScope": {
+ "ScopeCategory": "DataScope",
+ "ScopeDefineOrgIdList": "DefineOrgList"
+ },
+
+
+ "ThingsGateway.Admin.Application.SysResource": {
+ "Title": "Title",
+ "Module": "Module",
+ "Title.Required": "{0} is required",
+ "Href.Required": "{0} is required",
+ "Icon": "Icon",
+ "Href": "Path",
+ "Code": "Code",
+ "Category": "Category",
+ "Target": "Target",
+ "NavLinkMatch": "NavLinkMatch",
+ "SortCode": "Sort",
+ "CreateTime": "CreateTime",
+ "UpdateTime": "UpdateTime",
+ "ParentId": "Parent",
+ "ResourceDup": "Duplicate name {0} exists",
+ "ResourceParentChoiceSelf": "Parent cannot choose itself",
+ "ResourceParentNull": "Parent does not exist {0}",
+ "NotFoundResource": "System exception, menu not found",
+ "ModuleIdDiff": "Module is inconsistent with parent menu",
+ "CanotDeleteSystemResource": "Cannot delete system resource {0}",
+ "ResourceMenuHrefNotNull": "Menu href cannot null"
+ },
+ "ThingsGateway.Admin.Application.SysOrgCopyInput": {
+ "TargetId": "Target",
+ "ContainsChild": "ContainsChild",
+ "ContainsPosition": "ContainsPosition"
+ },
+
+ "ThingsGateway.Admin.Application.SysPosition": {
+ "Category.Required": "{0} is a required field",
+ "Name.Required": "{0} is a required field",
+ "Code.Required": "{0} is a required field",
+ "OrgId.MinValue": "{0} is a required field",
+ "Category": "Category",
+ "Name": "Name",
+ "Code": "Code",
+ "Status": "Status",
+ "OrgId": "Organization",
+ "Remark": "Remarks",
+ "SortCode": "SortCode",
+ "CreateTime": "CreateTime",
+ "UpdateTime": "UpdateTime",
+ "Dup": "Duplicate position exists with Category {0} and Name {1}",
+ "CodeDup": "Duplicate code {0} exists",
+ "NameDup": "Duplicate name {0} exists",
+ "CanotContainsSelf": "Cannot contain itself",
+ "TargetNameDup": "Target node has duplicate name {0}",
+ "ParentChoiceSelf": "Parent cannot be itself",
+ "ParentNull": "Parent does not exist {0}",
+ "DeleteUserFirst": "Please remove the users under the position first"
+ },
+
+ "ThingsGateway.Admin.Application.SysOrg": {
+ "Category.Required": "{0} is a required field",
+ "Name.Required": "{0} is a required field",
+ "Code.Required": "{0} is a required field",
+ "Category": "Category",
+ "Name": "Name",
+ "Code": "Code",
+ "Status": "Status",
+ "ParentId": "ParentOrg",
+ "Names": "Names",
+ "Remark": "Remarks",
+ "DirectorId": "Director",
+ "SortCode": "SortCode",
+ "CreateTime": "CreateTime",
+ "UpdateTime": "UpdateTime",
+ "Dup": "Duplicate organization exists with Category {0} and Name {1}",
+ "CodeDup": "Duplicate code {0} exists",
+ "NameDup": "Duplicate name {0} exists",
+ "CanotContainsSelf": "Cannot contain itself",
+ "TargetNameDup": "Target node has duplicate name {0}",
+ "ParentChoiceSelf": "Parent cannot be itself",
+ "ParentNull": "Parent does not exist {0}",
+ "DeleteUserFirst": "Please remove the users under the organization first",
+ "DeleteRoleFirst": "Please remove the roles under the organization first",
+ "DeletePositionFirst": "Please remove the positions under the organization first",
+ "RootOrg": "Unable to create top-level organization"
+ },
+
+ "ThingsGateway.Admin.Application.OrgEnum": {
+ "COMPANY": "Company",
+ "DEPT": "Dept"
+ },
+ "ThingsGateway.Admin.Application.PositionCategoryEnum": {
+ "HIGH": "High",
+ "MIDDLE": "Middle",
+ "LOW": "Low"
+ },
+ //controller
+ "ThingsGateway.Admin.Application.AuthController": {
+ //auth
+ "AuthController": "Login API",
+ "LoginAsync": "Login",
+ "LogoutAsync": "Logout"
+ },
+ "ThingsGateway.Admin.Application.TestController": {
+ //auth
+ "TestController": "Test API",
+ "Test": "Test"
+ },
+ "ThingsGateway.Admin.Application.OpenApiAuthController": {
+ //auth
+ "OpenApiAuthController": "Login API",
+ "LoginAsync": "Login",
+ "LogoutAsync": "Logout"
+ },
+
+ "ThingsGateway.Admin.Application.FileService": {
+ "FileNullError": "File cannot be empty",
+ "FileLengthError": "File size cannot exceed {0} M",
+ "FileTypeError": "Not supported format {0}"
+ },
+
+ "ThingsGateway.Admin.Application.UnifyResultProvider": {
+ "TokenOver": "Login has expired, please login again",
+ "NoPermission": "Access denied, no permission"
+ },
+
+ "ThingsGateway.Admin.Application.AuthService": {
+
+ "TenantNull": "The tenant does not exist",
+ "OrgDisable": "The affiliated company/department has been deactivated, please contact the administrator",
+
+ "SingleLoginWarn": "Your account is logged in elsewhere",
+ "UserNull": "User {0} does not exist",
+ "MustDesc": "Password needs to be encrypted with DESC before passing",
+ "PasswordError": "Too many password errors, please try again in {0} minutes",
+ "UserDisable": "Account {0} has been disabled",
+ "UserNoModule": "This account has not been assigned a module. Please contact the administrator",
+ "AuthErrorMax": "Account password error, will be locked for {1} minutes after exceeding {0} times, error count {2}"
+ },
+
+ "ThingsGateway.Admin.Application.HardwareInfo": {
+ "Environment": "HostEnvironment",
+ "FrameworkDescription": ".NETFramework",
+ "OsArchitecture": "System Architecture",
+ "UUID": "UUID",
+ "UpdateTime": "UpdateTime"
+ },
+ "ThingsGateway.Admin.Application.HistoryHardwareInfo": {
+ "DriveUsage": "Disk Usage",
+ "MemoryUsage": "Memory Usage",
+ "CpuUsage": "CPU Usage",
+ "Temperature": "Temperature",
+ "Battery": "Battery"
+ },
+
+
+ //oper
+ "ThingsGateway.Admin.Application.OperDescAttribute": {
+ //dict
+ "SaveDict": "Modify dictionary",
+ "DeleteDict": "Delete dictionary",
+ "EditLoginPolicy": "Modify login policy",
+ "EditPasswordPolicy": "Modify password policy",
+ "EditPagePolicy": "Modify page policy",
+ "EditWebsitePolicy": "Modify website settings",
+ //operlog
+ "DeleteOperLog": "Delete operation log",
+ "ExportOperLog": "Export operation log",
+
+ //resource
+ "SaveResource": "Modify resource",
+ "DeleteResource": "Delete resource",
+
+ //role
+ "SaveRole": "Modify role",
+ "DeleteRole": "Delete role",
+ "RoleGrantResource": "Role grant resource",
+ "RoleGrantUser": "Role grant user",
+ "RoleGrantApiPermission": "Role grant OpenApi",
+ "GrantApi": "GrantApi",
+ "GrantUser": "GrantUser",
+ "GrantRole": "GrantRole",
+ "GrantResource": "GrantResource",
+ //user
+ "SaveUser": "Modify user",
+ "DeleteuSER": "Delete user",
+ "ResetPassword": "Reset pw",
+ "UserGrantRole": "User grant role",
+ "UserGrantResource": "User grant resource",
+ "UserGrantApiPermission": "User grant OpenApi",
+
+ //usercenter
+ "UpdateUserInfo": "Update personal information",
+ "WorkbenchInfo": "Update personal workbench",
+ "UpdatePassword": "Update personal password",
+
+ //session
+ "ExitVerificat": "Force token off",
+ "ExitSession": "Force session off",
+
+
+ "CopyOrg": "Copy Organization",
+ "DeleteOrg": "Delete Organization",
+ "SaveOrg": "Save Organization",
+
+ "DeletePosition": "Delete Position",
+ "SavePosition": "Save Position",
+
+ "NoPermission": "No Permission",
+
+
+ "CopyResource": "CopyResource",
+ "ChangeParentResource": "ChangeParentResource"
+ },
+
+
+ //service
+
+ "ThingsGateway.Admin.Application.HardwareJob": {
+ "GetHardwareInfoFail": "Get Hardwareinfo Fail"
+ },
+
+ //dto
+ "ThingsGateway.Admin.Application.UserSelectorOutput": {
+ "Account": "Account",
+ "OrgId": "Org"
+ },
+ "ThingsGateway.Admin.Application.ResourceTableSearchModel": {
+ "Module": "Module",
+ "Href": "Path",
+ "Title": "Title"
+ },
+ "ThingsGateway.Admin.Application.WorkbenchInfo": {
+ "Razor": "Homepage",
+ "Shortcuts": "Shortcuts"
+ },
+ "ThingsGateway.Admin.Application.UpdatePasswordInput": {
+ "Password": "Password",
+ "NewPassword": "New password",
+ "ConfirmPassword": "Confirm password",
+ "Password.Required": "{0} is required",
+ "NewPassword.Required": "{0} is required",
+ "ConfirmPassword.Required": "{0} is required"
+ },
+
+ "ThingsGateway.Admin.Application.VerificatInfo": {
+ "Expire": "Expire(min)",
+ "Online": "Online",
+ "VerificatRemain": "VerificatRemain",
+ "VerificatTimeout": "VerificatTimeout",
+ "Device": "Device",
+ "LoginIp": "LoginIp",
+ "LoginTime": "LoginTime"
+ },
+
+ "ThingsGateway.Admin.Application.SessionOutput": {
+ "Account": "Account",
+ "Online": "Online status",
+ "LatestLoginIp": "Latest login IP",
+ "LatestLoginTime": "Latest login time",
+ "VerificatCount": "Token count"
+ },
+
+ "ThingsGateway.Admin.Application.SysDict": {
+ "Category.Required": "{0} is required",
+ "Name.Required": "{0} is required",
+ "Code.Required": "{0} is required",
+ "Category": "Category",
+ "Name": "Name",
+ "Code": "Code",
+ "Remark": "Remark",
+ "SortCode": "Sort",
+ "CreateTime": "CreateTime",
+ "UpdateTime": "UpdateTime",
+ "DemoCanotUpdateWebsitePolicy": "DEMO environment does not allow modifying website settings",
+ "DictDup": "Duplicate configuration exists, category {0}, name {1}"
+ },
+
+ "ThingsGateway.Admin.Application.SysOperateLog": {
+ "ClassName": "ClassName",
+ "ExeMessage": "ExeMessage",
+ "MethodName": "MethodName",
+ "ParamJson": "ParamJson",
+ "ReqMethod": "RequestMethod",
+ "ReqUrl": "RequestUrl",
+ "ResultJson": "ResultJson",
+ "Category": "Category",
+ "ExeStatus": "ExeStatus",
+ "Name": "Name",
+ "OpAccount": "OpAccount",
+ "OpBrowser": "OpBrowser",
+ "OpIp": "OpIp",
+ "OpOs": "OpOs",
+ "OpTime": "OpTime",
+ "VerificatId": "VerificatId"
+
+ },
+ "ThingsGateway.Admin.Application.OperateLogPageInput": {
+ "SearchDate": "SearchDate",
+ "Account": "Account",
+ "Category": "Category"
+ },
+ "ThingsGateway.Admin.Application.LoginInput": {
+ "Account": "Account",
+ "Password": "Password",
+ "Account.Required": "{0} is required",
+ "Password.Required": "{0} is required"
+ },
+ "ThingsGateway.Admin.Application.LogoutInput": {
+ "VerificatId.Required": "{0} is required"
+ },
+ "ThingsGateway.Admin.Application.AppConfig": {
+ "LoginPolicy": "LoginPolicy",
+ "PasswordPolicy": "PasswordPolicy",
+ "PagePolicy": "PagePolicy",
+ "WebsitePolicy": "WebsitePolicy"
+ },
+ "ThingsGateway.Admin.Application.LoginPolicy": {
+ "SingleOpen": "Single user login switch",
+ "ErrorLockTime": "Login error lock duration (min)",
+ "ErrorResetTime": "Login error count expiration duration (min)",
+ "ErrorCount": "Login error count lock threshold",
+ "VerificatExpireTime": "Login expiration time (min)",
+ "ErrorLockTime.MinValue": "{0} value is too small",
+ "ErrorResetTime.MinValue": "{0} value is too small",
+ "ErrorCount.MinValue": "{0} value is too small",
+ "VerificatExpireTime.MinValue": "{0} value is too small"
+ },
+ "ThingsGateway.Admin.Application.PagePolicy": {
+ "Shortcuts": "Default shortcuts",
+ "Razor": "Default homepage"
+ },
+ "ThingsGateway.Admin.Application.PasswordPolicy": {
+ "DefaultPassword": "Default user password",
+ "DefaultPassword.Required": "{0} is required",
+ "PasswordMinLen": "Minimum password length",
+ "PasswordMinLen.MinValue": "{0} value is too small",
+ "PasswordContainNum": "Contain numbers",
+ "PasswordContainLower": "Contain lowercase letters",
+ "PasswordContainUpper": "Contain uppercase letters",
+ "PasswordContainChar": "Contain special characters"
+ },
+ "ThingsGateway.Admin.Application.WebsitePolicy": {
+ "WebStatus": "WebStatus",
+ "CloseTip": "CloseTip",
+ "CloseTip.Required": "{0} is required"
+ },
+ //enum
+ "ThingsGateway.Admin.Application.ResourceCategoryEnum": {
+ "Module": "Module",
+ "Menu": "Menu",
+ "Button": "Button"
+ },
+
+ "ThingsGateway.Admin.Application.TargetEnum": {
+ "_self": "Current window",
+ "_blank": "New window",
+ "_parent": "Parent window",
+ "_top": "Top window"
+ },
+ "ThingsGateway.Admin.Application.DictTypeEnum": {
+ "System": "System",
+ "Define": "Business"
+ },
+
+ "ThingsGateway.Admin.Application.LogCateGoryEnum": {
+ "Login": "Login",
+ "Logout": "Logout",
+ "Operate": "Operation",
+ "Exception": "Exception"
+ },
+
+ "ThingsGateway.Admin.Application.LogEnum": {
+ "SUCCESS": "Success",
+ "FAIL": "Fail"
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Locales/zh-CN.json b/src/Admin/ThingsGateway.Admin.Application/Locales/zh-CN.json
new file mode 100644
index 000000000..9bb6ef174
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Locales/zh-CN.json
@@ -0,0 +1,466 @@
+{
+ "ThingsGateway.Admin.Application.SysUser": {
+ "Disable": "禁用",
+ "Enable": "启用",
+ "GrantRole": "分配角色",
+ "ExitVerificat": "您已被强制下线",
+ "PasswordEdited": "密码被修改,已退出登录",
+ "Avatar": "头像",
+ "Account": "账号",
+ "Account.Required": " {0} 是必填项",
+ "Password": "密码",
+ "Status": "状态",
+ "Phone": "手机",
+ "Email": "邮箱",
+ "LastLoginIp": "上次登录ip",
+ "LastLoginDevice": "上次登录设备",
+ "LastLoginTime": "上次登录时间",
+ "LastLoginAddress": "上次登录地点",
+ "LatestLoginIp": "最新登录ip",
+ "LatestLoginTime": "最新登录时间",
+ "LatestLoginDevice": "最新登录设备",
+ "LatestLoginAddress": "最新登录地点",
+ "SortCode": "排序",
+ "CreateTime": "创建时间",
+ "UpdateTime": "更新时间",
+ "OrgNames": "机构",
+ "PositionName": "职位",
+ "OrgId": "机构",
+ "PositionId": "职位",
+ "DirectorId": "主管",
+ "CheckSelf": "禁止 {0} 自己",
+ "CanotDeleteAdminUser": "不可删除系统内置超管用户",
+ "CanotEditAdminUser": "不可编辑超管用户",
+ "CanotGrantAdmin": "不能分配超管角色",
+ "EmailDup": "存在重复的邮箱 {0}",
+ "AccountDup": "存在重复的账号 {0}",
+ "CanotDeleteSelf": "不可删除自己",
+ "EmailError": "邮箱 {0} 格式错误",
+ "PhoneError": "手机号码 {0} 格式错误",
+ "NoOrg": "组织机构不存在",
+ "DirectorSelf": "不能设置自己为主管",
+
+
+ "DemoCanotUpdatePassword": "DEMO环境不允许修改密码",
+ "OldPasswordError": "原密码错误",
+ "ConfirmPasswordDiff": "两次输入的密码不一致",
+ "PasswordLengthLess": "密码长度不能小于 {0} ",
+ "PasswordMustNum ": "密码必须包含数字",
+ "PasswordMustLow": "密码必须包含小写字母",
+ "PasswordMustUpp": "密码必须包含大写字母",
+ "PasswordMustSpecial": "密码必须包含特殊字符"
+ },
+
+ "ThingsGateway.Admin.Application.SysRole": {
+ "Code": "编码",
+ "Name": "名称",
+ "Name.Required": " {0} 是必填项",
+ "Category": "分类",
+ "SortCode": "排序",
+ "Global": "全局",
+ "Status": "状态",
+ "OrgId": "机构",
+ "CreateTime": "创建时间",
+ "UpdateTime": "更新时间",
+
+ "CanotDeleteAdmin": "不可删除系统内置超管角色",
+ "CanotEditAdmin": "不可编辑超管角色",
+ "CanotGrantAdmin": "不能分配超管角色",
+
+ "NameDup": "存在重复的角色名称 {0}",
+ "OrgNotNull": "机构不能为空",
+ "SameOrgNameDup": "存在重复的角色名称 {0}",
+ "CannotRoleScopeAll": "机构角色不能选择全局数据范围",
+ "CodeDup": "存在重复的编码 {0}"
+ },
+ "ThingsGateway.Admin.Application.RoleCategoryEnum": {
+ "Global": "全局",
+ "Org": "机构"
+ },
+ "ThingsGateway.Admin.Application.DataScopeEnum": {
+ "SCOPE_SELF": "仅自己",
+ "SCOPE_ALL": "全部",
+ "SCOPE_ORG": "仅所属组织",
+ "SCOPE_ORG_CHILD": "所属组织及以下",
+ "SCOPE_ORG_DEFINE": "自定义"
+ },
+ "ThingsGateway.Admin.Application.DefaultDataScope": {
+ "ScopeCategory": "数据范围",
+ "ScopeDefineOrgIdList": "自定义列表"
+ },
+ "ThingsGateway.Admin.Application.SysResource": {
+ "Title": "标题",
+ "Module": "模块",
+ "Title.Required": "{0} 是必填项",
+ "Href.Required": "{0} 是必填项",
+ "Icon": "图标",
+ "Href": "路径",
+ "Code": "编码",
+ "Category": "分类",
+ "Target": "跳转类型",
+ "NavLinkMatch": "匹配类型",
+ "SortCode": "排序",
+ "ParentId": "上级菜单",
+ "CreateTime": "创建时间",
+ "UpdateTime": "更新时间",
+ "ResourceDup": "存在重复的名称 {0}",
+ "ResourceParentChoiceSelf": "父级不能选择自己",
+ "ResourceParentNull": "父级不存在 {0}",
+ "NotFoundResource": "系统异常,没找到该菜单",
+ "ModuleIdDiff": "模块与上级菜单不一致",
+ "CanotDeleteSystemResource": "不可删除系统资源 {0}",
+ "ResourceMenuHrefNotNull": "菜单的路径不能为空"
+ },
+
+ "ThingsGateway.Admin.Application.SysOrgCopyInput": {
+ "TargetId": "目标机构",
+ "ContainsChild": "包含下级",
+ "ContainsPosition": "包含职位"
+ },
+ "ThingsGateway.Admin.Application.SysPosition": {
+ "Category.Required": "{0} 是必填项",
+ "Name.Required": "{0} 是必填项",
+ "Code.Required": "{0} 是必填项",
+ "OrgId.MinValue": "{0} 是必填项",
+ "Category": "分类",
+ "Name": "名称",
+ "Code": "代码",
+ "Status": "状态",
+ "OrgId": "机构",
+ "Remark": "备注",
+ "SortCode": "排序",
+ "CreateTime": "创建时间",
+ "UpdateTime": "更新时间",
+ "Dup": "存在重复的岗位 分类 {0} 名称 {1}",
+ "CodeDup": "存在重复的编码 {0}",
+ "NameDup": "存在重复的名称 {0}",
+ "CanotContainsSelf": "不可包含自己",
+ "TargetNameDup": "目标节点存在重复的名称 {0}",
+ "ParentChoiceSelf": "父级不能选择自己",
+ "ParentNull": "父级不存在 {0}",
+ "DeleteUserFirst": "请先删除职位下的用户"
+
+ },
+
+ "ThingsGateway.Admin.Application.SysOrg": {
+ "Category.Required": "{0} 是必填项",
+ "Name.Required": "{0} 是必填项",
+ "Code.Required": "{0} 是必填项",
+ "Category": "分类",
+ "Name": "名称",
+ "Code": "代码",
+ "Status": "状态",
+ "ParentId": "上级机构",
+ "Names": "机构全称",
+ "Remark": "备注",
+ "DirectorId": "主管",
+ "SortCode": "排序",
+ "CreateTime": "创建时间",
+ "UpdateTime": "更新时间",
+ "Dup": "存在重复的机构 分类 {0} 名称 {1}",
+ "CodeDup": "存在重复的编码 {0}",
+ "NameDup": "存在重复的名称 {0}",
+ "CanotContainsSelf": "不可包含自己",
+ "TargetNameDup": "目标节点存在重复的名称 {0}",
+ "ParentChoiceSelf": "父级不能选择自己",
+ "ParentNull": "父级不存在 {0}",
+ "DeleteUserFirst": "请先删除机构下的用户",
+ "DeleteRoleFirst": "请先删除机构下的角色",
+ "DeletePositionFirst": "请先删除机构下的职位",
+ "RootOrg": "无法创建顶层机构"
+ },
+ "ThingsGateway.Admin.Application.OrgEnum": {
+ "COMPANY": "公司",
+ "DEPT": "部门"
+ },
+ "ThingsGateway.Admin.Application.PositionCategoryEnum": {
+ "HIGH": "高层",
+ "MIDDLE": "中层",
+ "LOW": "低层"
+ },
+
+ //controller
+ "ThingsGateway.Admin.Application.AuthController": {
+ //auth
+ "AuthController": "登录API",
+ "LoginAsync": "登录",
+ "LogoutAsync": "注销"
+ },
+ "ThingsGateway.Admin.Application.TestController": {
+ //auth
+ "TestController": "测试API",
+ "Test": "测试"
+ },
+ "ThingsGateway.Admin.Application.OpenApiAuthController": {
+ //auth
+ "OpenApiAuthController": "登录API",
+ "LoginAsync": "登录",
+ "LogoutAsync": "注销"
+ },
+
+
+
+
+ "ThingsGateway.Admin.Application.FileService": {
+ "FileNullError": "文件不能为空",
+ "FileLengthError": "文件大小不允许超过 {0} M",
+ "FileTypeError": "不支持 {0} 格式"
+ },
+
+ "ThingsGateway.Admin.Application.UnifyResultProvider": {
+ "TokenOver": "登录已过期,请重新登录",
+ "NoPermission": "禁止访问,没有权限"
+ },
+
+ "ThingsGateway.Admin.Application.AuthService": {
+ "TenantNull": "租户不存在",
+ "OrgDisable": "所属公司/部门已停用,请联系管理员",
+ "SingleLoginWarn": "您的账号已在别处登录",
+ "UserNull": "用户 {0} 不存在",
+ "PasswordError": "密码错误次数过多,请 {0} 分钟后再试",
+ "AuthErrorMax": "账号密码错误,超过 {0} 次后将锁定 {1} 分钟,错误次数 {2} ",
+ "UserDisable": "账号 {0} 已停用",
+ "MustDesc": "密码需要DESC加密后传入",
+ "UserNoModule": "该账号未分配模块,请联系管理员"
+ },
+
+
+ "ThingsGateway.Admin.Application.HardwareInfo": {
+ "Environment": "主机环境",
+ "FrameworkDescription": "NET框架",
+ "OsArchitecture": "系统架构",
+ "UUID": "唯一编码",
+ "UpdateTime": "更新时间"
+ },
+ "ThingsGateway.Admin.Application.HistoryHardwareInfo": {
+ "DriveUsage": "磁盘使用率",
+ "MemoryUsage": "内存使用率",
+ "CpuUsage": "CPU使用率",
+ "Temperature": "温度",
+ "Battery": "电池"
+ },
+
+ //oper
+ "ThingsGateway.Admin.Application.OperDescAttribute": {
+ //dict
+ "SaveDict": "修改字典",
+ "DeleteDict": "删除字典",
+ "EditLoginPolicy": "修改登录策略",
+ "EditPasswordPolicy": "修改密码策略",
+ "EditPagePolicy": "修改页面策略",
+ "EditWebsitePolicy": "修改网站设置",
+ //operlog
+ "DeleteOperLog": "删除操作日志",
+ "ExportOperLog": "导出操作日志",
+
+ //resource
+ "SaveResource": "修改资源",
+ "DeleteResource": "删除资源",
+
+ //role
+ "SaveRole": "修改角色",
+ "DeleteRole": "删除角色",
+ "RoleGrantResource": "角色授权资源",
+ "RoleGrantUser": "角色授权用户",
+ "RoleGrantApiPermission": "角色授权OpenApi",
+ "GrantApi": "API",
+ "GrantUser": "用户",
+ "GrantRole": "角色",
+ "GrantResource": "资源",
+ //user
+ "SaveUser": "修改用户",
+ "DeleteuSER": "删除用户",
+ "ResetPassword": "重置密码",
+ "UserGrantRole": "用户授权角色",
+ "UserGrantResource": "用户授权资源",
+ "UserGrantApiPermission": "用户授权OpenApi",
+
+ //usercenter
+ "UpdateUserInfo": "更新个人信息",
+ "WorkbenchInfo": "更新个人工作台",
+ "UpdatePassword": "更新个人密码",
+
+ //session
+ "ExitVerificat": "强退令牌",
+ "ExitSession": "强退会话",
+
+
+ "CopyOrg": "复制机构",
+ "DeleteOrg": "删除机构",
+ "SaveOrg": "保存机构",
+
+ "DeletePosition": "删除岗位",
+ "SavePosition": "保存岗位",
+
+ "NoPermission": "无权限操作",
+
+ "CopyResource": "复制资源",
+ "ChangeParentResource": "更改父节点"
+ },
+
+ //service
+
+ "ThingsGateway.Admin.Application.HardwareJob": {
+ "GetHardwareInfoFail": "获取硬件信息出错"
+ },
+
+ //dto
+ "ThingsGateway.Admin.Application.UserSelectorOutput": {
+ "Account": "账号",
+ "OrgId": "机构"
+ },
+ "ThingsGateway.Admin.Application.ResourceTableSearchModel": {
+ "Module": "模块",
+ "Href": "路径",
+ "Title": "标题"
+ },
+ "ThingsGateway.Admin.Application.WorkbenchInfo": {
+ "Razor": "主页",
+ "Shortcuts": "快捷方式"
+ },
+ "ThingsGateway.Admin.Application.UpdatePasswordInput": {
+ "Password": "密码",
+ "NewPassword": "新密码",
+ "ConfirmPassword": "确认密码",
+ "Password.Required": " {0} 是必填项",
+ "NewPassword.Required": " {0} 是必填项",
+ "ConfirmPassword.Required": " {0} 是必填项"
+ },
+
+
+ "ThingsGateway.Admin.Application.VerificatInfo": {
+ "Expire": "过期时间(分)",
+ "Online": "在线状态",
+ "VerificatRemain": "剩余有效期",
+ "VerificatTimeout": "超时时间",
+ "Device": "登录设备",
+ "LoginIp": "登录IP",
+ "LoginTime": "登录时间"
+ },
+
+ "ThingsGateway.Admin.Application.SessionOutput": {
+ "Account": "账号",
+ "Online": "在线状态",
+ "LatestLoginIp": "最新登录ip",
+ "LatestLoginTime": "最新登录时间",
+ "VerificatCount": "令牌数量"
+ },
+
+ "ThingsGateway.Admin.Application.SysDict": {
+ "Category.Required": "{0} 是必填项",
+ "Name.Required": "{0} 是必填项",
+ "Code.Required": "{0} 是必填项",
+ "Category": "分类",
+ "Name": "名称",
+ "Code": "代码",
+ "Remark": "备注",
+ "SortCode": "排序",
+ "CreateTime": "创建时间",
+ "UpdateTime": "更新时间",
+ "DictDup": "存在重复的配置 分类 {0} 名称 {1}",
+ "DemoCanotUpdateWebsitePolicy": "DEMO环境不允许修改网站设置"
+ },
+
+
+ "ThingsGateway.Admin.Application.SysOperateLog": {
+ "ClassName": "类名",
+ "ExeMessage": "具体消息",
+ "MethodName": "方法名称",
+ "ParamJson": "请求参数",
+ "ReqMethod": "请求方式",
+ "ReqUrl": "请求地址",
+ "ResultJson": "返回结果",
+ "Category": "日志分类",
+ "ExeStatus": "执行状态",
+ "Name": "日志名称",
+ "OpAccount": "账号",
+ "OpBrowser": "浏览器",
+ "OpIp": "ip",
+ "OpOs": "系统",
+ "OpTime": "操作时间",
+ "VerificatId": "验证Id"
+
+ },
+ "ThingsGateway.Admin.Application.OperateLogPageInput": {
+ "SearchDate": "时间范围",
+ "Account": "操作账号",
+ "Category": "分类"
+ },
+ "ThingsGateway.Admin.Application.LoginInput": {
+ "Account": "登录账号",
+ "Password": "登录密码",
+ "Account.Required": "{0} 是必填项",
+ "Password.Required": "{0} 是必填项"
+ },
+ "ThingsGateway.Admin.Application.LogoutInput": {
+ "VerificatId.Required": "{0} 是必填项"
+ },
+ "ThingsGateway.Admin.Application.AppConfig": {
+ "LoginPolicy": "登录策略",
+ "PasswordPolicy": "密码策略",
+ "PagePolicy": "页面设置",
+ "WebsitePolicy": "网站设置"
+ },
+ "ThingsGateway.Admin.Application.LoginPolicy": {
+ "SingleOpen": "单用户登录开关",
+ "ErrorLockTime": "登录错误锁定时长(分)",
+ "ErrorResetTime": "登录错误次数过期时长(分)",
+ "ErrorCount": "登录错误次数锁定阈值",
+ "VerificatExpireTime": "登录过期时间(分)",
+ "ErrorLockTime.MinValue": " {0} 值太小",
+ "ErrorResetTime.MinValue": " {0} 值太小",
+ "ErrorCount.MinValue": " {0} 值太小",
+ "VerificatExpireTime.MinValue": " {0} 值太小"
+ },
+ "ThingsGateway.Admin.Application.PagePolicy": {
+ "Shortcuts": "默认快捷方式",
+ "Razor": "默认主页"
+ },
+ "ThingsGateway.Admin.Application.PasswordPolicy": {
+ "DefaultPassword": "默认用户密码",
+ "DefaultPassword.Required": " {0} 是必填项",
+ "PasswordMinLen": "密码最小长度",
+ "PasswordMinLen.MinValue": " {0} 值太小",
+ "PasswordContainNum": "包含数字",
+ "PasswordContainLower": "包含小写字母",
+ "PasswordContainUpper": "包含大写字母",
+ "PasswordContainChar": "包含特殊字符"
+ },
+ "ThingsGateway.Admin.Application.WebsitePolicy": {
+ "WebStatus": "是否开放",
+ "CloseTip": "关闭提示",
+ "CloseTip.Required": " {0} 是必填项"
+ },
+
+
+
+ //enum
+ "ThingsGateway.Admin.Application.ResourceCategoryEnum": {
+ "Module": "模块",
+ "Menu": "菜单",
+ "Button": "按钮"
+ },
+
+ "ThingsGateway.Admin.Application.TargetEnum": {
+ "_self": "本窗口",
+ "_blank": "新窗口",
+ "_parent": "父级窗口",
+ "_top": "顶级窗口"
+ },
+ "ThingsGateway.Admin.Application.DictTypeEnum": {
+ "System": "系统配置",
+ "Define": "业务配置"
+ },
+
+ "ThingsGateway.Admin.Application.LogCateGoryEnum": {
+ "Login": "登录",
+ "Logout": "注销",
+ "Operate": "操作",
+ "Exception": "异常"
+ },
+
+ "ThingsGateway.Admin.Application.LogEnum": {
+ "SUCCESS": "成功",
+ "FAIL": "失败"
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Logging/DatabaseLoggingWriter.cs b/src/Admin/ThingsGateway.Admin.Application/Logging/DatabaseLoggingWriter.cs
new file mode 100644
index 000000000..212fc1a61
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Logging/DatabaseLoggingWriter.cs
@@ -0,0 +1,214 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using SqlSugar;
+
+using System.Collections.Concurrent;
+
+using ThingsGateway.Extension;
+using ThingsGateway.FriendlyException;
+using ThingsGateway.Logging;
+using ThingsGateway.NewLife.Json.Extension;
+using ThingsGateway.Razor;
+
+using UAParser;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 数据库写入器
+///
+public class DatabaseLoggingWriter : IDatabaseLoggingWriter
+{
+ ///
+ /// 日志消息队列(线程安全)
+ ///
+ private readonly ConcurrentQueue _operateLogMessageQueue = new();
+
+ private SqlSugarClient SqlSugarClient;
+
+ ///
+ /// 此方法只会写入经由MVCFilter捕捉的方法日志,对于BlazorServer的内部操作,由 执行
+ ///
+ ///
+ ///
+ public async Task WriteAsync(LogMessage logMsg, bool flush)
+ {
+ //获取请求json字符串
+ var jsonString = logMsg.Context.Get("loggingMonitor").ToString();
+ //转成实体
+ var loggingMonitor = jsonString.FromJsonNetString();
+ //日志时间赋值
+ loggingMonitor.LogDateTime = logMsg.LogDateTime;
+ // loggingMonitor.ReturnInformation.Value
+ //验证失败不记录日志
+ bool save = false;
+ if (loggingMonitor.Validation == null)
+ {
+ var operation = logMsg.Context.Get(LoggingConst.Operation).ToString();//获取操作名称
+ var client = (ClientInfo)logMsg.Context.Get(LoggingConst.Client);//获取客户端信息
+ var path = logMsg.Context.Get(LoggingConst.Path).ToString();//获取操作名称
+ var method = logMsg.Context.Get(LoggingConst.Method).ToString();//获取方法
+ //表示访问日志
+ if (path == "/api/auth/login" || path == "/api/auth/logout")
+ {
+ //如果没有异常信息
+ if (loggingMonitor.Exception == null)
+ {
+ save = await CreateVisitLog(operation, path, loggingMonitor, client, flush).ConfigureAwait(false);//添加到访问日志
+ }
+ else
+ {
+ //添加到异常日志
+ save = await CreateOperationLog(operation, path, loggingMonitor, client, flush).ConfigureAwait(false);
+ }
+ }
+ else
+ {
+ //只有定义了Title的POST方法才记录日志
+ if (!operation.IsNullOrWhiteSpace() && method == "POST")
+ {
+ //添加到操作日志
+ save = await CreateOperationLog(operation, path, loggingMonitor, client, flush).ConfigureAwait(false);
+ }
+ }
+ }
+ if (save)
+ {
+ await Task.Delay(1000).ConfigureAwait(false);
+ }
+ }
+
+ ///
+ /// 创建操作日志
+ ///
+ /// 操作名称
+ /// 请求地址
+ /// loggingMonitor
+ /// 客户端信息
+ ///
+ ///
+ private async Task CreateOperationLog(string operation, string path, LoggingMonitorJson loggingMonitor, ClientInfo clientInfo, bool flush)
+ {
+ //账号
+ var opAccount = loggingMonitor.AuthorizationClaims?.Where(it => it.Type == ClaimConst.Account).Select(it => it.Value).FirstOrDefault();
+
+ //获取参数json字符串,
+ var paramJson = loggingMonitor.Parameters == null || loggingMonitor.Parameters.Count == 0 ? null : loggingMonitor.Parameters[0].Value.ToJsonNetString();
+
+ //获取结果json字符串
+ var resultJson = string.Empty;
+ if (loggingMonitor.ReturnInformation != null)//如果有返回值
+ {
+ if (loggingMonitor.ReturnInformation.Value != null)//如果返回值不为空
+ {
+ resultJson = loggingMonitor.ReturnInformation.Value.ToJsonNetString();
+ }
+ }
+
+ //操作日志表实体
+ var sysLogOperate = new SysOperateLog
+ {
+ Name = operation,
+ Category = LogCateGoryEnum.Operate,
+ ExeStatus = true,
+ OpIp = loggingMonitor.RemoteIPv4,
+ OpBrowser = clientInfo?.UA?.Family + clientInfo?.UA?.Major,
+ OpOs = clientInfo?.OS?.Family + clientInfo?.OS?.Major,
+ OpTime = loggingMonitor.LogDateTime.LocalDateTime,
+ OpAccount = opAccount,
+ ReqMethod = loggingMonitor.HttpMethod,
+ ReqUrl = path,
+ ResultJson = resultJson,
+ ClassName = loggingMonitor.DisplayName,
+ MethodName = loggingMonitor.ActionName,
+ ParamJson = paramJson,
+ VerificatId = UserManager.VerificatId,
+ };
+ //如果异常不为空
+ if (loggingMonitor.Exception != null)
+ {
+ sysLogOperate.Category = LogCateGoryEnum.Exception;//操作类型为异常
+ sysLogOperate.ExeStatus = false;//操作状态为失败
+
+ if (loggingMonitor.Exception.Type == typeof(AppFriendlyException).ToString())
+ sysLogOperate.ExeMessage = loggingMonitor?.Exception.Message;
+ else
+ sysLogOperate.ExeMessage = $"{loggingMonitor.Exception.Type}:{loggingMonitor.Exception.Message}{Environment.NewLine}{loggingMonitor.Exception.StackTrace}";
+ }
+
+ _operateLogMessageQueue.Enqueue(sysLogOperate);
+
+ if (flush)
+ {
+ SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
+ return true;
+ }
+ return false;
+ }
+
+ ///
+ /// 创建访问日志
+ ///
+ /// 访问类型
+ ///
+ /// loggingMonitor
+ /// 客户端信息
+ ///
+ private async Task CreateVisitLog(string operation, string path, LoggingMonitorJson loggingMonitor, ClientInfo clientInfo, bool flush)
+ {
+ long verificatId = 0;//验证Id
+ var opAccount = "";//用户账号
+ if (path == "/api/auth/login")
+ {
+ //如果是登录,用户信息就从返回值里拿
+ var result = loggingMonitor.ReturnInformation?.Value?.ToJsonNetString();//返回值转json
+ var userInfo = result.FromJsonNetString>();//格式化成user表
+ opAccount = userInfo.Data.Account;//赋值账号
+ verificatId = userInfo.Data.VerificatId;
+ }
+ else
+ {
+ //如果是登录出,用户信息就从AuthorizationClaims里拿
+ opAccount = loggingMonitor.AuthorizationClaims.Where(it => it.Type == ClaimConst.Account).Select(it => it.Value).FirstOrDefault();
+ verificatId = loggingMonitor.AuthorizationClaims.Where(it => it.Type == ClaimConst.VerificatId).Select(it => it.Value).FirstOrDefault().ToLong();
+ }
+ //日志表实体
+ var sysLogVisit = new SysOperateLog
+ {
+ Name = operation,
+ Category = path == "/api/auth/login" ? LogCateGoryEnum.Login : LogCateGoryEnum.Logout,
+ ExeStatus = true,
+ OpIp = loggingMonitor.RemoteIPv4,
+ OpBrowser = clientInfo?.UA?.Family + clientInfo?.UA?.Major,
+ OpOs = clientInfo?.OS?.Family + clientInfo?.OS?.Major,
+ OpTime = loggingMonitor.LogDateTime.LocalDateTime,
+ VerificatId = verificatId,
+ OpAccount = opAccount,
+
+ ReqMethod = loggingMonitor.HttpMethod,
+ ReqUrl = path,
+ ResultJson = loggingMonitor.ReturnInformation?.Value?.ToJsonNetString(),
+ ClassName = loggingMonitor.DisplayName,
+ MethodName = loggingMonitor.ActionName,
+ ParamJson = loggingMonitor.Parameters?.ToJsonNetString(),
+ };
+ _operateLogMessageQueue.Enqueue(sysLogVisit);
+
+ if (flush)
+ {
+ SqlSugarClient ??= DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ await SqlSugarClient.InsertableWithAttr(_operateLogMessageQueue.ToListWithDequeue()).ExecuteCommandAsync().ConfigureAwait(false);//入库
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Logging/LoggingConst.cs b/src/Admin/ThingsGateway.Admin.Application/Logging/LoggingConst.cs
new file mode 100644
index 000000000..470676394
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Logging/LoggingConst.cs
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 日志常量
+///
+public class LoggingConst
+{
+ ///
+ /// 分类
+ ///
+ public const string CateGory = "CateGory";
+
+ ///
+ /// 客户端信息
+ ///
+ public const string Client = "Client";
+
+ ///
+ /// 请求方法:POST/GET
+ ///
+ public const string Method = "Method";
+
+ ///
+ /// 操作名称
+ ///
+ public const string Operation = "Operation";
+
+ ///
+ /// 请求地址
+ ///
+ public const string Path = "Path";
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Logging/LoggingMonitorJson.cs b/src/Admin/ThingsGateway.Admin.Application/Logging/LoggingMonitorJson.cs
new file mode 100644
index 000000000..72adcdfd6
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Logging/LoggingMonitorJson.cs
@@ -0,0 +1,187 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 认证信息
+///
+public class AuthorizationClaims
+{
+ ///
+ /// 类型
+ ///
+ public string Type { get; set; }
+
+ ///
+ /// 值
+ ///
+ public string Value { get; set; }
+}
+
+///
+/// 异常信息
+///
+public class LogException
+{
+ ///
+ /// 异常内容
+ ///
+ public string Message { get; set; }
+
+ ///
+ /// 堆栈信息
+ ///
+ public string StackTrace { get; set; }
+
+ ///
+ /// 异常类型
+ ///
+ public string Type { get; set; }
+}
+
+///
+/// 请求信息格式化
+///
+public class LoggingMonitorJson
+{
+ ///
+ /// 方法名称
+ ///
+ public string ActionName { get; set; }
+
+ ///
+ /// 认证信息
+ ///
+ public List AuthorizationClaims { get; set; }
+
+ ///
+ /// 控制器名
+ ///
+ public string ControllerName { get; set; }
+
+ ///
+ /// 类名称
+ ///
+ public string DisplayName { get; set; }
+
+ ///
+ /// 环境
+ ///
+ public string Environment { get; set; }
+
+ ///
+ /// 异常信息
+ ///
+ public LogException Exception { get; set; }
+
+ ///
+ /// 请求方法
+ ///
+ public string HttpMethod { get; set; }
+
+ ///
+ /// 服务端
+ ///
+ public string LocalIPv4 { get; set; }
+
+ ///
+ /// 日志时间
+ ///
+ public DateTimeOffset LogDateTime { get; set; }
+
+ ///
+ /// 系统架构
+ ///
+ public string OsArchitecture { get; set; }
+
+ ///
+ /// 系统名称
+ ///
+ public string OsDescription { get; set; }
+
+ ///
+ /// 参数列表
+ ///
+ public List Parameters { get; set; }
+
+ ///
+ /// 客户端IPV4地址
+ ///
+ public string RemoteIPv4 { get; set; }
+
+ ///
+ /// 认证信息
+ ///
+ public string RequestHeaderAuthorization { get; set; }
+
+ ///
+ /// 认证信息
+ ///
+ public string RequestHeaderCookies { get; set; }
+
+ ///
+ /// 请求地址
+ ///
+ public string RequestUrl { get; set; }
+
+ ///
+ /// 返回信息
+ ///
+ public ReturnInformation ReturnInformation { get; set; }
+
+ ///
+ /// 浏览器标识
+ ///
+ public string UserAgent { get; set; }
+
+ ///
+ /// 验证错误信息
+ ///
+ public Validation Validation { get; set; }
+}
+
+///
+/// 请求参数
+///
+public class Parameters
+{
+ ///
+ /// 参数名
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// 值
+ ///
+ public object Value { get; set; }
+}
+
+///
+/// 返回信息
+///
+public class ReturnInformation
+{
+ ///
+ /// 返回值
+ ///
+ public object Value { get; set; }
+}
+
+///
+/// 验证失败信息
+///
+public class Validation
+{
+ ///
+ /// 错误详情
+ ///
+ public string Message { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Options/AdminLogOptions.cs b/src/Admin/ThingsGateway.Admin.Application/Options/AdminLogOptions.cs
new file mode 100644
index 000000000..a5ff07f47
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Options/AdminLogOptions.cs
@@ -0,0 +1,21 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using ThingsGateway.ConfigurableOptions;
+
+namespace ThingsGateway.Admin.Application;
+
+
+public sealed class AdminLogOptions : IConfigurableOptions
+{
+
+ public int OperateLogDaysAgo { get; set; }
+
+}
\ No newline at end of file
diff --git a/src/Admin/ThingsGateway.Admin.Application/Options/EmailOptions.cs b/src/Admin/ThingsGateway.Admin.Application/Options/EmailOptions.cs
new file mode 100644
index 000000000..1f13e95f4
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Options/EmailOptions.cs
@@ -0,0 +1,60 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using ThingsGateway.ConfigurableOptions;
+
+namespace ThingsGateway.Admin.Application;
+
+
+///
+/// 邮件配置选项
+///
+public sealed class EmailOptions : IConfigurableOptions
+{
+ ///
+ /// 主机
+ ///
+ public string Host { get; set; }
+
+ ///
+ /// 端口
+ ///
+ public int Port { get; set; }
+
+ ///
+ /// 默认发件者邮箱
+ ///
+ public string DefaultFromEmail { get; set; }
+
+ ///
+ /// 默认接收人邮箱
+ ///
+ public string DefaultToEmail { get; set; }
+
+ ///
+ /// 启用SSL
+ ///
+ public bool EnableSsl { get; set; }
+
+ ///
+ /// 邮箱账号
+ ///
+ public string UserName { get; set; }
+
+ ///
+ /// 邮箱密码
+ ///
+ public string Password { get; set; }
+
+ ///
+ /// 默认邮件标题
+ ///
+ public string DefaultFromName { get; set; }
+}
\ No newline at end of file
diff --git a/src/Admin/ThingsGateway.Admin.Application/Options/HardwareInfoOptions.cs b/src/Admin/ThingsGateway.Admin.Application/Options/HardwareInfoOptions.cs
new file mode 100644
index 000000000..34aec8090
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Options/HardwareInfoOptions.cs
@@ -0,0 +1,34 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using ThingsGateway.ConfigurableOptions;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 历史硬件信息
+///
+public class HardwareInfoOptions : IConfigurableOptions
+{
+ ///
+ /// 启用
+ ///
+ public bool Enable { get; set; } = true;
+
+ ///
+ /// 历史保存间隔
+ ///
+ public int HistoryInterval { get; set; } = 60000;
+
+ ///
+ /// 历史保留天数
+ ///
+ public int DaysAgo { get; set; } = 7;
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Options/TenantOptions.cs b/src/Admin/ThingsGateway.Admin.Application/Options/TenantOptions.cs
new file mode 100644
index 000000000..c5dba59fa
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Options/TenantOptions.cs
@@ -0,0 +1,23 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using ThingsGateway.ConfigurableOptions;
+
+namespace ThingsGateway.Admin.Application;
+
+
+public sealed class TenantOptions : IConfigurableOptions
+{
+ ///
+ /// 启用
+ ///
+ public bool Enable { get; set; }
+
+}
\ No newline at end of file
diff --git a/src/Admin/ThingsGateway.Admin.Application/Provider/BlazorAuthenticationStateProvider.cs b/src/Admin/ThingsGateway.Admin.Application/Provider/BlazorAuthenticationStateProvider.cs
new file mode 100644
index 000000000..5e9560d64
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Provider/BlazorAuthenticationStateProvider.cs
@@ -0,0 +1,247 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Http;
+
+using System.Security.Claims;
+
+using ThingsGateway.Authorization;
+using ThingsGateway.DataEncryption;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+public class BlazorAuthenticationStateProvider : AppAuthorizeHandler
+{
+ private readonly ISysDictService _sysDictService;
+ private readonly ISysRoleService _sysRoleService;
+ private readonly ISysUserService _sysUserService;
+ private readonly IVerificatInfoService _verificatInfoService;
+
+ public BlazorAuthenticationStateProvider(IVerificatInfoService verificatInfoService, ISysUserService sysUserService, ISysRoleService sysRoleService, ISysDictService sysDictService)
+ {
+ _sysUserService = sysUserService;
+ _sysRoleService = sysRoleService;
+ _sysDictService = sysDictService;
+ _verificatInfoService = verificatInfoService;
+ }
+
+ ///
+ public override async Task HandleAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
+ {
+ var isAuthenticated = context.User.Identity?.IsAuthenticated;
+ if (isAuthenticated == true)
+ {
+ if (await CheckVerificatFromCacheAsync(context).ConfigureAwait(false))
+ {
+ await AuthorizeHandleAsync(context).ConfigureAwait(false);
+ }
+ else
+ {
+ if (App.HttpContext != null)
+ {
+ var identity = new ClaimsIdentity();
+ App.HttpContext.User = new ClaimsPrincipal(identity);
+ }
+ Fail(context);
+ }
+ }
+ else
+ {
+ Fail(context);// 授权失败
+ }
+
+ static void Fail(AuthorizationHandlerContext context)
+ {
+ context.Fail(); // 授权失败
+ DefaultHttpContext currentHttpContext = context.GetCurrentHttpContext();
+ if (currentHttpContext == null)
+ return;
+ currentHttpContext.Response.StatusCode = 401; //返回401给授权筛选器用
+ currentHttpContext.SignoutToSwagger();
+ currentHttpContext.SignOutAsync();
+ }
+ }
+
+ ///
+ public override async Task PipelineAsync(AuthorizationHandlerContext context, DefaultHttpContext httpContext)
+ {
+ var userId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.UserId)?.Value?.ToLong(0) ?? 0;
+
+ var user = await _sysUserService.GetUserByIdAsync(userId).ConfigureAwait(false);
+ if (context.Resource is Microsoft.AspNetCore.Components.RouteData routeData)
+ {
+ var roles = await _sysRoleService.GetRoleListByUserIdAsync(userId).ConfigureAwait(false);
+
+ //这里鉴别用户使能状态
+ if (user == null || !user.Status)
+ {
+ return false;
+ }
+
+ //超级管理员都能访问
+ var isSuperAdmin = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.SuperAdmin)?.Value.ToBoolean();
+ if (isSuperAdmin == true) return true;
+
+ // 获取超级管理员特性
+ var superAdminAttr = routeData.PageType.CustomAttributes.FirstOrDefault(x =>
+ x.AttributeType == typeof(SuperAdminAttribute));
+
+ if (superAdminAttr != null) //如果是超级管理员才能访问的接口
+ {
+ return false; //直接没权限
+ }
+ //获取角色授权特性
+ var isRolePermission = routeData.PageType.CustomAttributes.FirstOrDefault(x =>
+ x.AttributeType == typeof(RolePermissionAttribute));
+ if (isRolePermission != null)
+ {
+ //获取忽略角色授权特性
+ var isIgnoreRolePermission = routeData.PageType.CustomAttributes.FirstOrDefault(x =>
+ x.AttributeType == typeof(IgnoreRolePermissionAttribute));
+ if (isIgnoreRolePermission == null)
+ {
+ // 路由名称
+ var routeName = routeData.PageType.CustomAttributes.FirstOrDefault(x =>
+ x.AttributeType == typeof(RouteAttribute))?.ConstructorArguments?[0].Value as string;
+ if (routeName == null) return true;
+
+ if ((!user.PermissionCodeList.Contains(routeName.CutStart("/")) && !user.PermissionCodeList.Contains(routeName))) //如果当前路由信息不包含在角色授权路由列表中则认证失败
+ return false;
+ else
+ return true;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ else
+ {
+ return true;
+ }
+ }
+ else
+ {
+ //这里鉴别用户使能状态
+ if (user == null || !user.Status)
+ {
+ return false;
+ }
+
+ //超级管理员都能访问
+ var isSuperAdmin = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.SuperAdmin)?.Value?.ToBoolean();
+ if (isSuperAdmin == true) return true;
+
+ if (httpContext == null)
+ {
+ //非API请求
+ return true;
+ }
+
+ var superAdminAttr = httpContext.GetMetadata();
+
+ if (superAdminAttr != null) //如果是超级管理员才能访问的接口
+ {
+ //获取忽略超级管理员特性
+ var ignoreSpuerAdmin = httpContext.GetMetadata();
+ if (ignoreSpuerAdmin == null && isSuperAdmin != true) //如果只能超级管理员访问并且用户不是超级管理员
+ return false; //直接没权限
+ }
+
+ //获取角色授权特性
+ var isRolePermission = httpContext.GetMetadata();
+ if (isRolePermission != null)
+ {
+ //获取忽略角色授权特性
+ var ignoreRolePermission = httpContext.GetMetadata();
+ if (ignoreRolePermission == null)
+ {
+ // 路由名称
+ var routeName = httpContext.Request.Path.Value;
+ if (routeName == null) return true;
+ if ((!user.PermissionCodeList.Contains(routeName.CutStart("/")) && !user.PermissionCodeList.Contains(routeName))) //如果当前路由信息不包含在角色授权路由列表中则认证失败
+ return false;
+ else
+ {
+ return true; //没有用户信息则返回认证失败
+ }
+ }
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ return true;
+ }
+
+ ///
+ /// 检查 BearerToken/Cookie 有效性
+ ///
+ /// DefaultHttpContext
+ ///
+ private async Task CheckVerificatFromCacheAsync(AuthorizationHandlerContext context)
+ {
+ DefaultHttpContext currentHttpContext = context.GetCurrentHttpContext();
+ var userId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.UserId)?.Value?.ToLong();
+ var verificatId = context.User.Claims.FirstOrDefault(it => it.Type == ClaimConst.VerificatId)?.Value?.ToLong();
+ var expire = (await _sysDictService.GetAppConfigAsync().ConfigureAwait(false)).LoginPolicy.VerificatExpireTime;
+ if (currentHttpContext == null)
+ {
+ var verificatInfo = userId != null ? _verificatInfoService.GetOne(verificatId ?? 0) : null;//获取token信息
+
+ if (verificatInfo != null)
+ {
+ if (verificatInfo.VerificatTimeout < DateTime.Now.AddMinutes(5))
+ {
+ verificatInfo.VerificatTimeout = DateTime.Now.AddMinutes(30); //新的过期时间
+ _verificatInfoService.Update(verificatInfo); //更新tokne信息到cache
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if (await JWTEncryption.AutoRefreshToken(context, currentHttpContext, expire, expire * 2).ConfigureAwait(false))
+ {
+ //var token = JWTEncryption.GetJwtBearerToken(currentHttpContext); //获取当前token
+
+ var verificatInfo = userId != null ? _verificatInfoService.GetOne(verificatId ?? 0) : null;//获取token信息
+ if (verificatInfo != null)
+ {
+ if (verificatInfo.VerificatTimeout < DateTime.Now.AddMinutes(5))
+ {
+ verificatInfo.VerificatTimeout = DateTime.Now.AddMinutes(verificatInfo.Expire); //新的过期时间
+ _verificatInfoService.Update(verificatInfo); //更新tokne信息到cache
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ //失败
+ return false;
+ }
+ }
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Provider/UnifyResultProvider.cs b/src/Admin/ThingsGateway.Admin.Application/Provider/UnifyResultProvider.cs
new file mode 100644
index 000000000..b33aa403a
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Provider/UnifyResultProvider.cs
@@ -0,0 +1,102 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.Extensions.Localization;
+
+using ThingsGateway.DataValidation;
+using ThingsGateway.FriendlyException;
+using ThingsGateway.Razor;
+using ThingsGateway.UnifyResult;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 规范化RESTful风格返回值
+///
+[UnifyModel(typeof(UnifyResult<>))]
+public class UnifyResultProvider : IUnifyResultProvider
+{
+ private static IStringLocalizer Localizer = App.CreateLocalizerByType(typeof(UnifyResultProvider))!;
+
+ ///
+ /// 状态码响应拦截
+ ///
+ public async Task OnResponseStatusCodes(HttpContext context, int statusCode, UnifyResultSettingsOptions unifyResultSettings = null)
+ {
+ switch (statusCode)
+ {
+ // 处理 401 状态码
+ case StatusCodes.Status401Unauthorized:
+ await context.Response.WriteAsJsonAsync(RESTfulResult(statusCode, false, Localizer["TokenOver"].Value)).ConfigureAwait(false);
+ break;
+ // 处理 403 状态码
+ case StatusCodes.Status403Forbidden:
+ await context.Response.WriteAsJsonAsync(RESTfulResult(statusCode, false, default, Localizer["NoPermission"].Value)).ConfigureAwait(false);
+ break;
+
+ default: break;
+ }
+ }
+
+ ///
+ /// 成功返回
+ ///
+ ///
+ ///
+ ///
+ public IActionResult OnSucceeded(ActionExecutedContext context, object? data)
+ {
+ return new JsonResult(RESTfulResult(StatusCodes.Status200OK, true, data));
+ }
+
+
+
+ ///
+ /// 返回 RESTful 风格结果集
+ ///
+ /// 状态码
+ /// 是否成功
+ /// 数据
+ /// 错误信息
+ ///
+ private static UnifyResult RESTfulResult(int statusCode, bool succeeded = default, object? data = default, object? errors = default)
+ {
+ return new UnifyResult
+ {
+ Code = statusCode,
+ Msg = statusCode == StatusCodes.Status200OK ? "Success" : errors,
+ Data = data,
+ Time = DateTime.Now,
+ };
+ }
+
+ public IActionResult OnAuthorizeException(DefaultHttpContext context, ExceptionMetadata metadata)
+ {
+ return new JsonResult(RESTfulResult(metadata.StatusCode, data: metadata.Data, errors: metadata.Errors ?? metadata.Exception?.Message)
+ , UnifyContext.GetSerializerSettings(context));
+ }
+
+ public IActionResult OnException(ExceptionContext context, ExceptionMetadata metadata)
+ {
+ return new JsonResult(RESTfulResult(metadata.StatusCode, data: metadata.Data, errors: metadata.Errors ?? metadata.Exception?.Message)
+ , UnifyContext.GetSerializerSettings(context));
+ }
+
+ public IActionResult OnValidateFailed(ActionExecutingContext context, ValidationMetadata metadata)
+ {
+ return new JsonResult(RESTfulResult(metadata.StatusCode ?? StatusCodes.Status400BadRequest, data: metadata.Data, errors: metadata.ValidationResult) // 如果需要只显示第一条错误,修改为:errors: metadata.FirstErrorMessage
+ , UnifyContext.GetSerializerSettings(context));
+ }
+
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_dict.json b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_dict.json
new file mode 100644
index 000000000..f383841b5
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_dict.json
@@ -0,0 +1,124 @@
+{
+ "RECORDS": [
+ {
+ "Id": 252875263003121,
+ "DictType": "System",
+ "Category": "LoginPolicy",
+ "Name": "VerificatExpireTime",
+ "Code": "14400",
+ "Remark": "Verificat过期时间(分)",
+ "IsDelete": "0",
+ "SortCode": 9
+ },
+ {
+ "Id": 252875263003720,
+ "DictType": "System",
+ "Category": "PagePolicy",
+ "Name": "Shortcuts",
+ "Code": "[100]",
+ "Remark": "系统默认工作台数据",
+ "IsDelete": "0",
+ "SortCode": 1
+ },
+ {
+ "Id": 252875263003728,
+ "DictType": "System",
+ "Category": "PasswordPolicy",
+ "Name": "DefaultPassword",
+ "Code": "111111",
+ "Remark": "默认用户密码",
+ "IsDelete": "0",
+ "SortCode": 1
+ },
+ {
+ "Id": 364564896825413,
+ "DictType": "System",
+ "Category": "LoginPolicy",
+ "Name": "SingleOpen",
+ "Code": "False",
+ "Remark": "单用户登录开关",
+ "IsDelete": "0",
+ "SortCode": 1
+ },
+ {
+ "Id": 432079540875333,
+ "DictType": "System",
+ "Category": "LoginPolicy",
+ "Name": "ErrorCount",
+ "Code": "10",
+ "Remark": "登录错误次数",
+ "IsDelete": "0",
+ "SortCode": 99
+ },
+ {
+ "Id": 432079718375493,
+ "DictType": "System",
+ "Category": "LoginPolicy",
+ "Name": "ErrorResetTime",
+ "Code": "1",
+ "Remark": "错误重置时间",
+ "IsDelete": "0",
+ "SortCode": 99
+ },
+ {
+ "Id": 432079850803269,
+ "DictType": "System",
+ "Category": "LoginPolicy",
+ "Name": "ErrorLockTime",
+ "Code": "2",
+ "Remark": "登录错误锁定时长",
+ "IsDelete": "0",
+ "SortCode": 99
+ },
+ {
+ "Id": 432111701160005,
+ "DictType": "System",
+ "Category": "PasswordPolicy",
+ "Name": "PasswordMinLen",
+ "Code": "6",
+ "Remark": "密码最小长度",
+ "IsDelete": "0",
+ "SortCode": 99
+ },
+ {
+ "Id": 432112135159877,
+ "DictType": "System",
+ "Category": "PasswordPolicy",
+ "Name": "PasswordContainNum",
+ "Code": "False",
+ "Remark": "包含数字",
+ "IsDelete": "0",
+ "SortCode": 99
+ },
+ {
+ "Id": 432112321953861,
+ "DictType": "System",
+ "Category": "PasswordPolicy",
+ "Name": "PasswordContainLower",
+ "Code": "False",
+ "Remark": "包含小写字母",
+ "IsDelete": "0",
+ "SortCode": 99
+ },
+ {
+ "Id": 432112380907589,
+ "DictType": "System",
+ "Category": "PasswordPolicy",
+ "Name": "PasswordContainUpper",
+ "Code": "False",
+ "Remark": "包含大写字母",
+ "IsDelete": "0",
+ "SortCode": 99
+ },
+ {
+ "Id": 432112495247429,
+ "DictType": "System",
+ "Category": "PasswordPolicy",
+ "Name": "PasswordContainChar",
+ "Code": "False",
+ "Remark": "包含特殊字符",
+ "IsDelete": "0",
+ "SortCode": 99
+ }
+ ]
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_relation.json b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_relation.json
new file mode 100644
index 000000000..36b524092
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_relation.json
@@ -0,0 +1,11 @@
+{
+ "RECORDS": [
+ {
+ "Id": 503217527844933,
+ "Category": 0,
+ "ObjectId": 212725263002001,
+ "TargetId": "212725263001001",
+ "ExtJson": null
+ }
+ ]
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_resource.json b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_resource.json
new file mode 100644
index 000000000..394e9fad0
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_resource.json
@@ -0,0 +1,288 @@
+{
+ "RECORDS": [
+ {
+ "Id": 2,
+ "ParentId": 0,
+ "Title": "系统管理",
+ "Code": "System",
+ "Category": "MODULE",
+ "Target": "_self",
+ "Href": "",
+ "Icon": "fa-solid fa-house-user",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 100001,
+ "ParentId": 0,
+ "Module": 2,
+ "Title": "权限管理",
+ "Code": "System",
+ "NavLinkMatch": "All",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": null,
+ "Icon": "fa-solid fa-users-gear",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 100,
+ "ExtJson": null
+ },
+ {
+ "Id": 100002,
+ "ParentId": 0,
+ "Module": 2,
+ "Title": "系统运维",
+ "NavLinkMatch": "All",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": null,
+ "Icon": "fa-solid fa-file-circle-check",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 101,
+ "ExtJson": null
+ },
+ {
+ "Id": 100001001,
+ "Module": 2,
+ "ParentId": 100001,
+ "Title": "用户管理",
+ "NavLinkMatch": "All",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/user",
+ "Icon": "fa-solid fa-user-gear",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 100001005,
+ "Module": 2,
+ "ParentId": 100001,
+ "Title": "机构管理",
+ "NavLinkMatch": "All",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/org",
+ "Icon": "fa-solid fa-user-gear",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 100001004,
+ "Module": 2,
+ "ParentId": 100001,
+ "Title": "职位管理",
+ "NavLinkMatch": "All",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/position",
+ "Icon": "fa-solid fa-user-gear",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 100001002,
+ "Module": 2,
+ "ParentId": 100001,
+ "Title": "角色管理",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "NavLinkMatch": "All",
+ "Href": "/admin/role",
+ "Icon": "fa-solid fa-users-gear",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 2,
+ "ExtJson": null
+ },
+ {
+ "Id": 100001003,
+ "Module": 2,
+ "ParentId": 100001,
+ "Title": "菜单管理",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/resource",
+ "NavLinkMatch": "All",
+ "Icon": "fa-solid fa-bars",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ },
+ {
+ "Id": 100002001,
+ "ParentId": 100002,
+ "Module": 2,
+ "Title": "系统配置",
+ "Code": "System",
+ "Category": "MENU",
+ "NavLinkMatch": "All",
+ "Target": "_self",
+ "Href": "/admin/config",
+ "Icon": "fa-solid fa-gear",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 100002002,
+ "Module": 2,
+ "ParentId": 100002,
+ "Title": "字典管理",
+ "Code": "System",
+ "NavLinkMatch": "All",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/dict",
+ "Icon": "fa-solid fa-gear",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 100002003,
+ "Module": 2,
+ "ParentId": 100002,
+ "Title": "操作日志",
+ "NavLinkMatch": "All",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/oplog",
+ "Icon": "fa-solid fa-edit",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ },
+ {
+ "Id": 100002004,
+ "Module": 2,
+ "ParentId": 100002,
+ "Title": "会话管理",
+ "NavLinkMatch": "All",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/session",
+ "Icon": "fa-solid fa-person-circle-check",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 4,
+ "ExtJson": null
+ },
+ {
+ "Id": 100002005,
+ "Module": 2,
+ "ParentId": 100002,
+ "Title": "硬件信息",
+ "NavLinkMatch": "All",
+ "Code": "System",
+ "Category": "MENU",
+ "Target": "_self",
+ "Href": "/admin/hardwareinfo",
+ "Icon": "fas fa-server",
+
+ "CreateTime": null,
+ "CreateUser": null,
+ "CreateUserId": 0,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 4,
+ "ExtJson": null
+ }
+ ]
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_resourcebutton.json b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_resourcebutton.json
new file mode 100644
index 000000000..9ccdbea2b
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/Admin/seed_sys_resourcebutton.json
@@ -0,0 +1,845 @@
+{
+ "RECORDS": [
+ {
+ "Id": 501949744332869,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 502949744332869,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "新增",
+ "Code": "System",
+ "Category": "Button",
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 502949744332870,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "编辑",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 2,
+ "ExtJson": null
+ },
+ {
+ "Id": 502949744332871,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "删除",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ },
+ {
+ "Id": 502950809124933,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "重置密码",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:52:06.903",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502950980558917,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "授权角色",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:52:48.757",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502951076454469,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "授权资源",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:53:12.17",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": "11/1/2024 14:55:44.917",
+ "UpdateUser": "SuperAdmin",
+ "UpdateUserId": 212725263002001,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502951133163589,
+ "ParentId": 100001001,
+ "Module": 2,
+ "Title": "授权Api",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:53:26.017",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": "11/1/2024 15:01:16.98",
+ "UpdateUser": "SuperAdmin",
+ "UpdateUserId": 212725263002001,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 513951271813189,
+ "ParentId": 100001002,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:53:59.867",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+
+ {
+ "Id": 502951271813189,
+ "ParentId": 100001002,
+ "Module": 2,
+ "Title": "新增",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:53:59.867",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 502951271813190,
+ "ParentId": 100001002,
+ "Module": 2,
+ "Title": "编辑",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:53:59.867",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 2,
+ "ExtJson": null
+ },
+ {
+ "Id": 502951271813191,
+ "ParentId": 100001002,
+ "Module": 2,
+ "Title": "删除",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:53:59.867",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ },
+ {
+ "Id": 502951661793349,
+ "ParentId": 100001002,
+ "Module": 2,
+ "Title": "授权资源",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:55:35.077",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502952928694341,
+ "ParentId": 100001002,
+ "Module": 2,
+ "Title": "授权用户",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:00:44.377",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502952990781509,
+ "ParentId": 100001002,
+ "Module": 2,
+ "Title": "授权Api",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:00:59.537",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": "11/1/2024 15:01:10.2",
+ "UpdateUser": "SuperAdmin",
+ "UpdateUserId": 212725263002001,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 512953216376901,
+ "ParentId": 100001003,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:01:54.617",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+
+ {
+ "Id": 502953216376901,
+ "ParentId": 100001003,
+ "Module": 2,
+ "Title": "新增",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:01:54.617",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 502953216376902,
+ "ParentId": 100001003,
+ "Module": 2,
+ "Title": "编辑",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:01:54.617",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 2,
+ "ExtJson": null
+ },
+ {
+ "Id": 502953216376903,
+ "ParentId": 100001003,
+ "Module": 2,
+ "Title": "删除",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:01:54.617",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ },
+ {
+ "Id": 512953961062469,
+ "ParentId": 100002002,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:04:56.42",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+
+ {
+ "Id": 502953961062469,
+ "ParentId": 100002002,
+ "Module": 2,
+ "Title": "新增",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:04:56.42",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 502953961062470,
+ "ParentId": 100002002,
+ "Module": 2,
+ "Title": "编辑",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:04:56.42",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 2,
+ "ExtJson": null
+ },
+ {
+ "Id": 502953961062471,
+ "ParentId": 100002002,
+ "Module": 2,
+ "Title": "删除",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:04:56.42",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ },
+
+ {
+ "Id": 532953961062469,
+ "ParentId": 100002001,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:04:56.42",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+
+ {
+ "Id": 502954345615429,
+ "ParentId": 100002001,
+ "Module": 2,
+ "Code": "System",
+ "Title": "密码策略保存",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:06:30.307",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502954382938181,
+ "ParentId": 100002001,
+ "Module": 2,
+ "Code": "System",
+ "Title": "登录策略保存",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:06:39.417",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502954382931181,
+ "ParentId": 100002001,
+ "Module": 2,
+ "Code": "System",
+ "Title": "页面策略保存",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:06:39.417",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502954382931281,
+ "ParentId": 100002001,
+ "Module": 2,
+ "Title": "网站策略保存",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:06:39.417",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 505954686193733,
+ "ParentId": 100002003,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:07:53.453",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+
+ {
+ "Id": 502954686193733,
+ "ParentId": 100002003,
+ "Module": 2,
+ "Title": "日志清空",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:07:53.453",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 501954811879493,
+ "ParentId": 100002004,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:08:24.14",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 502954811879493,
+ "ParentId": 100002004,
+ "Module": 2,
+ "Title": "会话强退",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 15:08:24.14",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 0,
+ "ExtJson": null
+ },
+ {
+ "Id": 401949744332869,
+ "ParentId": 100001005,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 402949744332869,
+ "ParentId": 100001005,
+ "Module": 2,
+ "Title": "新增",
+ "Code": "System",
+ "Category": "Button",
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 402949744332870,
+ "ParentId": 100001005,
+ "Module": 2,
+ "Title": "编辑",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 2,
+ "ExtJson": null
+ },
+ {
+ "Id": 402949744332871,
+ "ParentId": 100001005,
+ "Module": 2,
+ "Title": "删除",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ },
+
+ {
+ "Id": 301949744332869,
+ "ParentId": 100001004,
+ "Module": 2,
+ "Title": "查询",
+ "Code": "System",
+ "Category": "Button",
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 302949744332869,
+ "ParentId": 100001004,
+ "Module": 2,
+ "Title": "新增",
+ "Code": "System",
+ "Category": "Button",
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 1,
+ "ExtJson": null
+ },
+ {
+ "Id": 302949744332870,
+ "ParentId": 100001004,
+ "Module": 2,
+ "Title": "编辑",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 2,
+ "ExtJson": null
+ },
+ {
+ "Id": 302949744332871,
+ "ParentId": 100001004,
+ "Module": 2,
+ "Title": "删除",
+ "Code": "System",
+ "Category": "Button",
+
+ "Href": null,
+ "Icon": null,
+
+ "CreateTime": "11/1/2024 14:47:46.973",
+ "CreateUser": "SuperAdmin",
+ "CreateUserId": 212725263002001,
+ "IsDelete": "0",
+ "UpdateTime": null,
+ "UpdateUser": null,
+ "UpdateUserId": null,
+ "SortCode": 3,
+ "ExtJson": null
+ }
+ ]
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/SysDictSeedData.cs b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysDictSeedData.cs
new file mode 100644
index 000000000..ff7d0e794
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysDictSeedData.cs
@@ -0,0 +1,28 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 系统配置种子数据
+///
+public class SysDictSeedData : ISqlSugarEntitySeedData
+{
+ ///
+ public IEnumerable SeedData()
+ {
+ var data = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_dict.json"));
+
+ var assembly = GetType().Assembly;
+ return SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_dict.json")).Concat(data);
+ }
+
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/SysOrgSeedData.cs b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysOrgSeedData.cs
new file mode 100644
index 000000000..3b30b1ae6
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysOrgSeedData.cs
@@ -0,0 +1,42 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 职位表种子数据
+///
+public class SysOrgSeedData : ISqlSugarEntitySeedData
+{
+ ///
+ public IEnumerable SeedData()
+ {
+ var data = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_org.json"));
+
+ var assembly = GetType().Assembly;
+ return new List()
+ {
+ new SysOrg()
+ {
+ Id=RoleConst.DefaultTenantId,
+ Status=true,
+ IsDelete=false,
+ DirectorId=RoleConst.SuperAdminId,
+ Name="Default",
+ Code="Diego",
+ Category=OrgEnum.COMPANY,
+ CreateUserId=RoleConst.SuperAdminId,
+ Names="Default",
+ SortCode=0
+ }
+ }.Concat(SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_org.json")).Concat(data));
+
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/SysPositionSeedData.cs b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysPositionSeedData.cs
new file mode 100644
index 000000000..201c2759a
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysPositionSeedData.cs
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 职位表种子数据
+///
+public class SysPositionSeedData : ISqlSugarEntitySeedData
+{
+ ///
+ public IEnumerable SeedData()
+ {
+ var data = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_position.json"));
+
+ var assembly = GetType().Assembly;
+ return new List()
+ {
+ new SysPosition()
+ {
+ Id=RoleConst.DefaultPositionId,
+ Status=true,
+ IsDelete=false,
+ Name="管理员",
+ OrgId=RoleConst.DefaultTenantId,
+ Code="ThingsGateway",
+ Category=PositionCategoryEnum.HIGH,
+ CreateUserId=RoleConst.SuperAdminId,
+ SortCode=0
+ }
+ }.Concat(SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_position.json")).Concat(data));
+
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/SysRelationSeedData.cs b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysRelationSeedData.cs
new file mode 100644
index 000000000..0a32706d1
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysRelationSeedData.cs
@@ -0,0 +1,28 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 关系表种子数据
+///
+public class SysRelationSeedData : ISqlSugarEntitySeedData
+{
+ ///
+ public IEnumerable SeedData()
+ {
+ var db = DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ if (db.Queryable().Any(a => a.ObjectId == RoleConst.SuperAdminId))
+ return Enumerable.Empty();
+ var data = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_relation.json"));
+ var assembly = GetType().Assembly;
+ return SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_relation.json")).Concat(data);
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/SysResourceSeedData.cs b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysResourceSeedData.cs
new file mode 100644
index 000000000..e5f9097da
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysResourceSeedData.cs
@@ -0,0 +1,36 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 资源表种子数据
+///
+public class SysResourceSeedData : ISqlSugarEntitySeedData
+{
+ ///
+ public IEnumerable SeedData()
+ {
+ var data1 = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_resource.json"));
+ var data2 = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_resourcebutton.json"));
+ var data3 = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_biz_resource.json"));
+
+ var assembly = GetType().Assembly;
+ return SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_resource.json"))
+ .Concat(SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_resourcebutton.json")))
+ .Concat(SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_biz_resource.json")))
+
+ .Concat(data1)
+ .Concat(data2)
+ .Concat(data3)
+ ;
+
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/SysRoleSeedData.cs b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysRoleSeedData.cs
new file mode 100644
index 000000000..53637659f
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysRoleSeedData.cs
@@ -0,0 +1,37 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 角色种子数据
+///
+public class SysRoleSeedData : ISqlSugarEntitySeedData
+{
+ ///
+ public IEnumerable SeedData()
+ {
+ var data = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_role.json"));
+ var assembly = GetType().Assembly;
+ return new List()
+ {
+ new SysRole()
+ {
+ Id=RoleConst.SuperAdminRoleId,
+ Code=RoleConst.SuperAdmin,
+ Name="超级管理员",
+ Category=RoleCategoryEnum.Global,
+ DefaultDataScope=new(),
+ IsDelete=false,
+ SortCode=0
+ }
+ }.Concat(SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_role.json")).Concat(data));
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/SeedData/SysUserSeedData.cs b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysUserSeedData.cs
new file mode 100644
index 000000000..b9fb6f92e
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/SeedData/SysUserSeedData.cs
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 用户表种子数据
+///
+public class SysUserSeedData : ISqlSugarEntitySeedData
+{
+ ///
+ public IEnumerable SeedData()
+ {
+ var data = SeedDataUtil.GetSeedData(PathExtensions.CombinePathWithOs("SeedData", "Admin", "seed_sys_user.json"));
+ var assembly = GetType().Assembly;
+ return new List()
+ {
+ new SysUser()
+ {
+ Id=RoleConst.SuperAdminId,
+ Account=RoleConst.SuperAdmin,
+ Password="7DA385A25A98388E",
+ OrgId=RoleConst.DefaultTenantId,
+ PositionId=RoleConst.DefaultPositionId,
+ Status=true,
+ IsDelete=false,
+ SortCode=0
+ }
+ }.Concat(SeedDataUtil.GetSeedDataByJson(SeedDataUtil.GetManifestResourceStream(assembly, "SeedData.Admin.seed_sys_user.json"))).Concat(data);
+ }
+
+
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/ApiPermission/ApiPermissionService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/ApiPermission/ApiPermissionService.cs
new file mode 100644
index 000000000..7f25f690d
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/ApiPermission/ApiPermissionService.cs
@@ -0,0 +1,194 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+
+using BootstrapBlazor.Components;
+
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc.ApiExplorer;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.Extensions.Options;
+
+using Swashbuckle.AspNetCore.SwaggerGen;
+
+using System.Globalization;
+using System.Reflection;
+
+using ThingsGateway.Extension;
+using ThingsGateway.SpecificationDocument;
+
+namespace ThingsGateway.Admin.Application;
+
+internal sealed class ApiPermissionService : IApiPermissionService
+{
+ private readonly IApiDescriptionGroupCollectionProvider _apiDescriptionGroupCollectionProvider;
+ private readonly SwaggerGeneratorOptions _generatorOptions;
+
+ public ApiPermissionService(
+ IOptions generatorOptions,
+ IApiDescriptionGroupCollectionProvider apiDescriptionGroupCollectionProvider)
+ {
+ _generatorOptions = generatorOptions.Value;
+ _apiDescriptionGroupCollectionProvider = apiDescriptionGroupCollectionProvider;
+ }
+ private IEnumerable GetDocumentNames()
+ {
+ return _generatorOptions.SwaggerDocs.Keys;
+ }
+
+ ///
+ public List ApiPermissionTreeSelector()
+ {
+ var cacheKey = $"{nameof(ApiPermissionTreeSelector)}-{CultureInfo.CurrentUICulture.Name}";
+ var permissions = App.CacheService.Get>(cacheKey);
+ if (permissions == null)
+ {
+ permissions = new();
+
+ Dictionary groupOpenApis = new();
+ foreach (var item in GetDocumentNames())
+ {
+ OpenApiPermissionTreeSelector openApiPermissionTreeSelector = new() { ApiName = item ?? "Default" };
+ groupOpenApis.TryAdd(openApiPermissionTreeSelector.ApiName, openApiPermissionTreeSelector);
+ }
+ var apiDescriptions = _apiDescriptionGroupCollectionProvider.ApiDescriptionGroups.Items;
+
+ // 获取所有需要数据权限的控制器
+ var controllerTypes =
+ App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(RolePermissionAttribute), false));
+
+ foreach (var groupOpenApi in groupOpenApis)
+ {
+
+ foreach (var apiDescriptionGroup in apiDescriptions)
+ {
+
+
+ var routes = apiDescriptionGroup.Items.Where(api => api.ActionDescriptor is ControllerActionDescriptor);
+
+ OpenApiPermissionTreeSelector openApiPermissionTreeSelector = groupOpenApi.Value;
+
+ Dictionary openApiPermissionTreeSelectorDict = new();
+
+ foreach (var route in routes)
+ {
+ if (!SpecificationDocumentBuilder.CheckApiDescriptionInCurrentGroup(groupOpenApi.Key, route))
+ {
+ continue;
+ }
+
+ var actionDesc = (ControllerActionDescriptor)route.ActionDescriptor;
+ if (!actionDesc.ControllerTypeInfo.CustomAttributes.Any(a => a.AttributeType == typeof(RolePermissionAttribute)))
+ continue;
+ var controllerDescription = actionDesc.ControllerTypeInfo.GetTypeDisplayName();
+
+ if (openApiPermissionTreeSelectorDict.TryGetValue(actionDesc.ControllerName, out var openApiControllerGroup))
+ {
+
+ }
+ else
+ {
+ openApiControllerGroup = new() { ApiName = controllerDescription, ApiRoute = actionDesc.ControllerName };
+
+ openApiPermissionTreeSelectorDict.Add(actionDesc.ControllerName, openApiControllerGroup);
+ }
+
+ var ignoreRolePermission = actionDesc.MethodInfo.CustomAttributes.Any(a => a.AttributeType == typeof(IgnoreRolePermissionAttribute));
+ if (ignoreRolePermission)
+ continue;
+ var routePath = route.RelativePath;
+ var methodDesc = actionDesc.MethodInfo.DeclaringType.GetMethodDisplayName(actionDesc.MethodInfo.Name);
+
+ //添加到权限列表
+ openApiControllerGroup.Children ??= new();
+ openApiControllerGroup.Children.Add(new OpenApiPermissionTreeSelector
+ {
+ ApiName = methodDesc,
+ ApiRoute = routePath,
+ });
+ }
+
+
+ openApiPermissionTreeSelector.Children.AddRange(openApiPermissionTreeSelectorDict.Values);
+
+ if (openApiPermissionTreeSelector.Children.Any(a => a.Children.Count > 0))
+ permissions.Add(openApiPermissionTreeSelector);
+
+ }
+
+ }
+
+ App.CacheService.Set(cacheKey, permissions);
+ }
+ return permissions;
+ }
+
+
+ ///
+ /// 获取路由地址名称
+ ///
+ /// 控制器地址
+ /// 路由名称
+ ///
+ public string GetRouteName(string controllerName, string template)
+ {
+ if (!template.StartsWith('/'))
+ template = "/" + template;//如果路由名称不是/开头则加上/防止控制器没写
+ if (template.Contains("[controller]"))
+ {
+ controllerName = controllerName.Replace("Controller", "");//去掉Controller
+ controllerName = controllerName.ToLowerCamelCase();//转首字母小写写
+ template = template.Replace("[controller]", controllerName);//替换[controller]
+ }
+
+ return template;
+ }
+
+ ///
+ public IEnumerable PermissionTreeSelector(IEnumerable routes)
+ {
+ List permissions = PermissionTreeSelector();
+ return permissions.Where(a => routes.ToHashSet().Contains(a.ApiRoute));
+ }
+
+ ///
+ public List PermissionTreeSelector()
+ {
+ var cacheKey = $"{nameof(PermissionTreeSelector)}-{CultureInfo.CurrentUICulture.Name}";
+ var permissions = App.CacheService.GetOrAdd(cacheKey, entry =>
+ {
+ List permissions = new();//权限列表
+
+ // 获取所有需要数据权限的控制器
+ var controllerTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass
+ && u.IsDefined(typeof(AuthorizeAttribute), false)
+ && u.IsDefined(typeof(Microsoft.AspNetCore.Components.RouteAttribute), false));
+
+ foreach (var controller in controllerTypes)
+ {
+ //获取数据权限特性
+ var route = controller.GetCustomAttributes().FirstOrDefault();
+ if (route == null) continue;
+ var apiRoute = GetRouteName(controller.Name, route.Template);//赋值路由名称
+
+ var desc = controller.GetTypeDisplayName();
+ //添加到权限列表
+ permissions.Add(new PermissionTreeSelector
+ {
+ ApiName = desc,
+ ApiRoute = apiRoute,
+ });
+ }
+ return permissions;
+ });
+
+ return permissions;
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/ApiPermission/IApiPermissionService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/ApiPermission/IApiPermissionService.cs
new file mode 100644
index 000000000..c4b1a7209
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/ApiPermission/IApiPermissionService.cs
@@ -0,0 +1,24 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+
+using ThingsGateway.Admin.Application;
+
+public interface IApiPermissionService
+{
+ ///
+ /// 获取API树
+ ///
+ ///
+ public List ApiPermissionTreeSelector();
+ string GetRouteName(string controllerName, string template);
+ List PermissionTreeSelector();
+ IEnumerable PermissionTreeSelector(IEnumerable routes);
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/AppService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/AppService.cs
new file mode 100644
index 000000000..184fd64ff
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/AppService.cs
@@ -0,0 +1,77 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authentication.Cookies;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.WebUtilities;
+
+using System.Net;
+using System.Reflection;
+using System.Security.Claims;
+
+using UAParser;
+
+namespace ThingsGateway.Admin.Application;
+
+public class AppService : IAppService
+{
+ public string GetReturnUrl(string returnUrl)
+ {
+ var url = QueryHelpers.AddQueryString(CookieAuthenticationDefaults.LoginPath, new Dictionary
+ {
+ ["ReturnUrl"] = returnUrl
+ });
+ return url;
+ }
+
+ public async Task LoginOutAsync()
+ {
+ try
+ {
+ await App.HttpContext!.SignOutAsync().ConfigureAwait(false);
+ App.HttpContext!.SignoutToSwagger();
+ }
+ catch
+ {
+ }
+ }
+
+ public ClientInfo? ClientInfo
+ {
+ get
+ {
+ var str = App.HttpContext?.Request?.Headers?.UserAgent;
+ ClientInfo? clientInfo = null;
+ if (!string.IsNullOrEmpty(str))
+ {
+ clientInfo = Parser.GetDefault().Parse(str);
+ }
+ return clientInfo;
+ }
+ }
+
+ public async Task LoginAsync(ClaimsIdentity identity)
+ {
+ var diffTime = DateTime.MaxValue;
+ //var diffTime = DateTime.Now.AddMinutes(expire);
+ await App.HttpContext!.SignInAsync(Assembly.GetEntryAssembly().GetName().Name, new ClaimsPrincipal(identity), new AuthenticationProperties()
+ {
+ IsPersistent = true,
+ AllowRefresh = true,
+ ExpiresUtc = diffTime,
+ }).ConfigureAwait(false);
+ }
+ public ClaimsPrincipal? User => App.User;
+
+ public IPAddress? RemoteIpAddress => App.HttpContext?.Connection?.RemoteIpAddress;
+
+ public int LocalPort => App.HttpContext.Connection.LocalPort;
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/AppService/IAppService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/IAppService.cs
new file mode 100644
index 000000000..09e577a01
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/AppService/IAppService.cs
@@ -0,0 +1,58 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+
+using System.Net;
+using System.Security.Claims;
+
+using UAParser;
+
+namespace ThingsGateway.Admin.Application;
+
+public interface IAppService
+{
+ ///
+ /// ClientInfo
+ ///
+ public ClientInfo? ClientInfo { get; }
+
+ ///
+ /// ClaimsPrincipal
+ ///
+ public ClaimsPrincipal? User { get; }
+
+ ///
+ /// RemoteIpAddress
+ ///
+ public IPAddress? RemoteIpAddress { get; }
+
+ ///
+ /// GetReturnUrl
+ ///
+ ///
+ ///
+ public string GetReturnUrl(string returnUrl);
+
+ ///
+ /// LoginOutAsync
+ ///
+ public Task LoginOutAsync();
+
+ ///
+ /// LoginAsync
+ ///
+ ///
+ public Task LoginAsync(ClaimsIdentity claimsIdentity);
+
+
+
+}
+
+
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthRazorService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthRazorService.cs
new file mode 100644
index 000000000..e94833281
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthRazorService.cs
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using ThingsGateway.NewLife.Json.Extension;
+using ThingsGateway.Razor;
+
+
+namespace ThingsGateway.Admin.Application;
+
+internal sealed class AuthRazorService : IAuthRazorService
+{
+
+ private AjaxService AjaxService { get; set; }
+ public AuthRazorService(AjaxService ajaxService)
+ {
+ AjaxService = ajaxService;
+ }
+ ///
+ /// 用户登录
+ ///
+ public async Task> LoginAsync(LoginInput input)
+ {
+ var ajaxOption = new AjaxOption
+ {
+ Url = "/api/auth/login",
+ Method = "POST",
+ Data = input,
+ };
+ var str = await AjaxService.InvokeAsync(ajaxOption).ConfigureAwait(false);
+ if (str != null)
+ {
+ var ret = str.RootElement.GetRawText().FromJsonNetString>();
+ return ret;
+ }
+ else
+ {
+ throw new ArgumentNullException();
+ }
+ }
+
+ ///
+ /// 注销当前用户
+ ///
+ public async Task> LoginOutAsync()
+ {
+ var ajaxOption = new AjaxOption
+ {
+ Url = "/api/auth/logout",
+ Method = "POST",
+ };
+ using var str = await AjaxService.InvokeAsync(ajaxOption).ConfigureAwait(false);
+ if (str != null)
+ {
+ var ret = str.RootElement.GetRawText().FromJsonNetString>();
+ return ret;
+ }
+ else
+ {
+ throw new ArgumentNullException();
+ }
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthService.cs
new file mode 100644
index 000000000..37b2dda28
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/AuthService.cs
@@ -0,0 +1,409 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Authentication.Cookies;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Localization;
+
+using SqlSugar;
+
+using System.Security.Claims;
+
+using ThingsGateway.DataEncryption;
+using ThingsGateway.FriendlyException;
+
+namespace ThingsGateway.Admin.Application;
+
+public class AuthService : IAuthService
+{
+ private readonly ISysDictService _configService;
+ private readonly ISysResourceService _sysResourceService;
+ private readonly IUserCenterService _userCenterService;
+ private readonly ISysUserService _sysUserService;
+ private readonly ISysOrgService _sysOrgService;
+ private IStringLocalizer _localizer;
+ private IVerificatInfoService _verificatInfoService;
+ private IAppService _appService;
+
+ public AuthService(ISysDictService configService, ISysResourceService sysResourceService,
+ ISysUserService userService, IUserCenterService userCenterService,
+ ISysOrgService sysOrgService,
+ IVerificatInfoService verificatInfoService, IAppService appService,
+ IStringLocalizer localizer)
+ {
+ _sysOrgService = sysOrgService;
+ _configService = configService;
+ _appService = appService;
+ _sysUserService = userService;
+ _sysResourceService = sysResourceService;
+ _userCenterService = userCenterService;
+ _localizer = localizer;
+ _verificatInfoService = verificatInfoService;
+ }
+
+ ///
+ /// 登录
+ ///
+ /// 登录参数
+ /// cookie方式登录
+ /// 登录输出
+ public async Task LoginAsync(LoginInput input, bool isCookie = true)
+ {
+ var appConfig = await _configService.GetAppConfigAsync().ConfigureAwait(false);
+
+ //判断是否开启web访问
+ if (!appConfig.WebsitePolicy.WebStatus
+ && input.Account != RoleConst.SuperAdmin)//如果禁用了网站并且不是超级管理员
+ {
+ throw Oops.Bah(appConfig.WebsitePolicy.CloseTip);
+ }
+ string? password = input.Password;
+ if (isCookie) //openApi登录不再需要解密
+ {
+ try
+ {
+ password = DESEncryption.Decrypt(input.Password);//解密
+ }
+ catch (Exception)
+ {
+ throw Oops.Bah(_localizer["MustDesc"]);
+ }
+ }
+
+ await BeforeLoginAsync(appConfig, input).ConfigureAwait(false);//登录前校验
+
+ var userInfo = await _sysUserService.GetUserByAccountAsync(input.Account, input.TenantId).ConfigureAwait(false);//获取用户信息
+ if (userInfo == null)
+ throw Oops.Bah(_localizer["UserNull", input.Account]);//用户不存在
+
+ if (userInfo.Password != password)
+ {
+ LoginError(appConfig.LoginPolicy, input.Account);//登录错误操作
+ }
+ var result = await ExecLogin(appConfig.LoginPolicy, input, userInfo, isCookie).ConfigureAwait(false);// 执行登录
+ return result;
+ }
+
+ ///
+ /// 注销当前用户
+ ///
+ public async Task LoginOutAsync()
+ {
+ if (UserManager.UserId == 0)
+ return;
+ var verificatId = UserManager.UserId;
+ //获取用户信息
+ var userinfo = await _sysUserService.GetUserByAccountAsync(UserManager.UserAccount, UserManager.TenantId).ConfigureAwait(false);
+ if (userinfo != null)
+ {
+ var loginEvent = new LoginEvent
+ {
+ Ip = _appService.RemoteIpAddress?.MapToIPv4()?.ToString(),
+ SysUser = userinfo,
+ VerificatId = verificatId
+ };
+ RemoveTokenFromCache(loginEvent);//移除verificat
+ }
+ await _appService.LoginOutAsync().ConfigureAwait(false);
+ }
+
+ #region 方法
+
+ ///
+ /// 登录之前执行的方法
+ ///
+ /// 配置
+ /// input
+ private async Task BeforeLoginAsync(AppConfig appConfig, LoginInput input)
+ {
+ var tenantEnable = App.GetOptions()?.Enable ?? false;
+
+ if (tenantEnable)
+ {
+ //如果租户ID为空表示用域名登录
+ if (input.TenantId == null)
+ {
+ //获取域名
+ var origin = App.HttpContext.Request.Headers["Origin"].ToString();
+ // 如果Origin头不存在,可以尝试使用Referer头作为备选
+ if (string.IsNullOrEmpty(origin))
+ origin = App.HttpContext.Request.Headers["Referer"].ToString();
+ //根据域名获取二级域名
+ var domain = origin.Split("//")[1].Split(".")[0];
+ //根据二级域名获取租户
+ var tenantList = await _sysOrgService.GetTenantListAsync().ConfigureAwait(false);
+ var tenant = tenantList.FirstOrDefault(x => x.Code.Equals(domain, StringComparison.OrdinalIgnoreCase));//获取租户默认是机构编码
+ if (tenant != null)
+ input.TenantId = tenant.Id;
+ else
+ input.TenantId = RoleConst.DefaultTenantId;
+ }
+ }
+ else
+ {
+ input.TenantId = RoleConst.DefaultTenantId;
+ }
+
+ var key = CacheConst.Cache_LoginErrorCount + input.Account + input.TenantId;//获取登录错误次数Key值
+ var errorCountCache = App.CacheService.Get(key);//获取登录错误次数
+
+ if (errorCountCache >= appConfig.LoginPolicy.ErrorCount)
+ {
+ App.CacheService.SetExpire(key, TimeSpan.FromMinutes(appConfig.LoginPolicy.ErrorLockTime));//设置缓存
+ throw Oops.Bah(_localizer["PasswordError", appConfig.LoginPolicy.ErrorLockTime]);
+ }
+ }
+
+ ///
+ /// 执行登录
+ ///
+ /// 登录策略
+ /// 用户登录参数
+ /// 用户信息
+ /// cookie方式登录
+ /// 登录输出结果
+ private async Task ExecLogin(LoginPolicy loginPolicy, LoginInput input, SysUser sysUser, bool isCookie = true)
+ {
+ if (sysUser.Status == false)
+ throw Oops.Bah(_localizer["UserDisable", sysUser.Account]);//账号已停用
+
+ var verificatId = CommonUtils.GetSingleId();
+ var expire = loginPolicy.VerificatExpireTime;
+ string accessToken = string.Empty;
+ string refreshToken = string.Empty;
+ if (!isCookie)
+ {
+ #region Token
+
+ //生成Token
+ accessToken = JWTEncryption.Encrypt(new Dictionary
+ {
+ {
+ ClaimConst.UserId, sysUser.Id
+ },
+ {
+ ClaimConst.Account, sysUser.Account
+ },
+ {
+ ClaimConst.SuperAdmin, sysUser.RoleIdList.Contains(RoleConst.SuperAdminRoleId)
+ },
+ {
+ ClaimConst.VerificatId, verificatId
+ },
+ {
+ ClaimConst.OrgId, sysUser.OrgId
+ },
+ {
+ ClaimConst.TenantId, input.TenantId
+ }
+ });
+ // 生成刷新Token令牌
+ refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, expire * 2);
+ // 设置Swagger自动登录
+ App.HttpContext?.SigninToSwagger(accessToken);
+ // 设置响应报文头
+ App.HttpContext?.SetTokensOfResponseHeaders(accessToken, refreshToken);
+
+ #endregion Token
+ }
+ else
+ {
+ if (sysUser.ModuleList.Count == 0)
+ throw Oops.Bah(_localizer["UserNoModule"]);//未分配模块
+ var org = await _sysOrgService.GetSysOrgByIdAsync(sysUser.OrgId).ConfigureAwait(false);//获取机构
+ if (!org.Status) throw Oops.Bah(_localizer["OrgDisable"]);//机构冻结
+ #region cookie
+
+ var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
+ identity.AddClaim(new Claim(ClaimConst.VerificatId, verificatId.ToString()));
+ identity.AddClaim(new Claim(ClaimConst.UserId, sysUser.Id.ToString()));
+ identity.AddClaim(new Claim(ClaimConst.Account, sysUser.Account));
+ identity.AddClaim(new Claim(ClaimConst.SuperAdmin, sysUser.RoleIdList.Contains(RoleConst.SuperAdminRoleId).ToString()));
+ identity.AddClaim(new Claim(ClaimConst.OrgId, sysUser.OrgId.ToString()));
+ identity.AddClaim(new Claim(ClaimConst.TenantId, input.TenantId?.ToString() ?? "0"));
+
+ await _appService.LoginAsync(identity).ConfigureAwait(false);
+
+ #endregion cookie
+ }
+ //登录事件参数
+ var logingEvent = new LoginEvent
+ {
+ Ip = _appService.RemoteIpAddress?.MapToIPv4()?.ToString(),
+ Device = input.Device?.ToString(),
+ Expire = expire,
+ SysUser = sysUser,
+ VerificatId = verificatId
+ };
+ await WriteTokenToCache(loginPolicy, logingEvent).ConfigureAwait(false);//写入verificat到cache
+ await UpdateUser(logingEvent).ConfigureAwait(false);
+ if (sysUser.Account == RoleConst.SuperAdmin)
+ {
+ var modules = (await _sysResourceService.GetAllAsync().ConfigureAwait(false)).Where(a => a.Category == ResourceCategoryEnum.Module);//获取模块列表
+ sysUser.ModuleList = modules.ToList();//模块列表赋值给用户
+ }
+ //返回结果
+ return new LoginOutput
+ {
+ VerificatId = verificatId,
+ Account = sysUser.Account,
+ Id = sysUser.Id,
+ ModuleList = sysUser.ModuleList,
+ AccessToken = accessToken,
+ RefreshToken = refreshToken
+ };
+ }
+
+ ///
+ /// 登录错误反馈
+ ///
+ /// 登录策略
+ /// 用户名称
+ private void LoginError(LoginPolicy loginPolicy, string userName)
+ {
+ var key = CacheConst.Cache_LoginErrorCount + userName;//获取登录错误次数Key值
+ App.CacheService.Increment(key, 1);// 登录错误次数+1
+ App.CacheService.SetExpire(key, TimeSpan.FromMinutes(loginPolicy.ErrorResetTime));//设置过期时间
+ var errorCountCache = App.CacheService.Get(key);//获取登录错误次数
+ throw Oops.Bah(_localizer["AuthErrorMax", loginPolicy.ErrorCount, loginPolicy.ErrorLockTime, errorCountCache]);//账号密码错误
+ }
+
+ ///
+ /// 从cache删除用户verificat
+ ///
+ /// 登录事件参数
+ private void RemoveTokenFromCache(LoginEvent loginEvent)
+ {
+ //更新verificat列表
+ _verificatInfoService.Delete(loginEvent.VerificatId);
+ }
+
+ ///
+ /// 单用户登录通知用户下线
+ ///
+ /// 用户Id
+ private async Task SingleLogin(long userId)
+ {
+ var clientIds = _verificatInfoService.GetClientIdListByUserId(userId);
+ await NoticeUtil.UserLoginOut(new UserLoginOutEvent
+ {
+ Message = _localizer["SingleLoginWarn"],
+ ClientIds = clientIds,
+ }).ConfigureAwait(false);
+ }
+
+ ///
+ /// 登录事件
+ ///
+ ///
+ ///
+ private async Task UpdateUser(LoginEvent loginEvent)
+ {
+ var sysUser = loginEvent.SysUser;
+
+ #region 登录/密码策略
+
+ var key = CacheConst.Cache_LoginErrorCount + sysUser.Account;//获取登录错误次数Key值
+ App.CacheService.Remove(key);//移除登录错误次数
+
+ //获取用户verificat列表
+ var userToken = _verificatInfoService.GetOne(loginEvent.VerificatId);
+
+ #endregion 登录/密码策略
+
+ #region 重新赋值属性,设置本次登录信息为最新的信息
+
+ sysUser.LastLoginIp = sysUser.LatestLoginIp;
+ sysUser.LastLoginTime = sysUser.LatestLoginTime;
+ sysUser.LatestLoginIp = loginEvent.Ip;
+ sysUser.LatestLoginTime = loginEvent.DateTime;
+
+ #endregion 重新赋值属性,设置本次登录信息为最新的信息
+
+ using var db = DbContext.Db.GetConnectionScopeWithAttr().CopyNew();
+ //更新用户登录信息
+ if (await db.Updateable(sysUser).UpdateColumns(it => new
+ {
+ it.LastLoginIp,
+ it.LastLoginTime,
+ it.LatestLoginIp,
+ it.LatestLoginTime,
+ }).ExecuteCommandAsync().ConfigureAwait(false) > 0)
+ App.CacheService.HashAdd(CacheConst.Cache_SysUser, sysUser.Id.ToString(), sysUser);//更新Cache信息
+ }
+
+ ///
+ /// 写入用户verificat到cache
+ ///
+ /// 登录策略
+ /// 登录事件参数
+ private async Task WriteTokenToCache(LoginPolicy loginPolicy, LoginEvent loginEvent)
+ {
+ //获取verificat列表
+ var tokenTimeout = loginEvent.DateTime.AddMinutes(loginEvent.Expire);
+ //生成verificat信息
+ var verificatInfo = new VerificatInfo
+ {
+ Device = loginEvent.Device,
+ Expire = loginEvent.Expire,
+ VerificatTimeout = tokenTimeout,
+ Id = loginEvent.VerificatId,
+ UserId = loginEvent.SysUser.Id,
+ LoginIp = loginEvent.Ip,
+ LoginTime = loginEvent.DateTime
+ };
+ //判断是否单用户登录
+ if (loginPolicy.SingleOpen)
+ {
+ await SingleLogin(loginEvent.SysUser.Id).ConfigureAwait(false);//单用户登录方法
+ }
+
+ //添加到verificat列表
+ _verificatInfoService.Add(verificatInfo);
+ }
+
+ #endregion 方法
+}
+
+///
+/// 登录事件参数
+///
+public class LoginEvent
+{
+ ///
+ /// 时间
+ ///
+ public DateTime DateTime = DateTime.Now;
+
+ ///
+ /// 过期时间
+ ///
+ public int Expire { get; set; }
+
+ ///
+ /// Ip地址
+ ///
+ public string? Ip { get; set; }
+
+ ///
+ /// 用户信息
+ ///
+ public SysUser SysUser { get; set; }
+
+ ///
+ /// VerificatId
+ ///
+ public long VerificatId { get; set; }
+
+ ///
+ /// 登录设备
+ ///
+ public string Device { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/Dto/AuthInput.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/Dto/AuthInput.cs
new file mode 100644
index 000000000..1bdd277aa
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/Dto/AuthInput.cs
@@ -0,0 +1,72 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 登录输入参数
+///
+public class OpenApiLoginInput
+{
+ ///
+ /// 账号
+ ///
+ /// SuperAdmin
+ [Required]
+ public string Account { get; set; }
+
+ ///
+ /// 密码
+ ///
+ ///111111
+ [Required]
+ public string Password { get; set; }
+
+
+ ///
+ /// 租户Id
+ ///
+ ///252885263003720
+ [Required]
+ public long TenantId { get; set; }
+}
+
+///
+/// 登录输入参数
+///
+public class LoginInput
+{
+ ///
+ /// 账号
+ ///
+ /// SuperAdmin
+ [Required]
+ public string Account { get; set; }
+
+ ///
+ /// 密码
+ ///
+ ///111111
+ [Required]
+ public string Password { get; set; }
+ ///
+ /// 租户ID
+ ///
+ ///252885263003720
+ public long? TenantId { get; set; } = RoleConst.DefaultTenantId;
+
+ ///
+ /// 设备类型,默认PC
+ ///
+ /// 0
+ public string Device { get; set; } = "PC";
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/Dto/AuthOutput.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/Dto/AuthOutput.cs
new file mode 100644
index 000000000..1bade499e
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/Dto/AuthOutput.cs
@@ -0,0 +1,72 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public class OpenApiLoginOutput
+{
+ ///
+ /// 令牌Token
+ ///
+ public string AccessToken { get; set; }
+
+ ///
+ /// 账号
+ ///
+ public string Account { get; set; }
+
+ ///
+ /// 用户Id
+ ///
+ public long Id { get; set; }
+
+ ///
+ /// 刷新Token
+ ///
+ public string RefreshToken { get; set; }
+
+ ///
+ /// 验证ID
+ ///
+ public long VerificatId { get; set; }
+}
+
+public class LoginOutput
+{
+ ///
+ /// 令牌Token
+ ///
+ public string AccessToken { get; set; }
+
+ ///
+ /// 账号
+ ///
+ public string Account { get; set; }
+
+ ///
+ /// 用户Id
+ ///
+ public long Id { get; set; }
+
+ ///
+ /// 模块列表
+ ///
+ public IEnumerable ModuleList { get; set; } = Enumerable.Empty();
+
+ ///
+ /// 刷新Token
+ ///
+ public string RefreshToken { get; set; }
+
+ ///
+ /// 验证ID
+ ///
+ public long VerificatId { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/IAuthRazorService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/IAuthRazorService.cs
new file mode 100644
index 000000000..768d6a237
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/IAuthRazorService.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using ThingsGateway.Razor;
+
+namespace ThingsGateway.Admin.Application;
+
+public interface IAuthRazorService
+{
+ ///
+ /// 用户登录
+ ///
+ Task> LoginAsync(LoginInput input);
+
+ ///
+ /// 注销当前用户
+ ///
+ Task> LoginOutAsync();
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Auth/IAuthService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/IAuthService.cs
new file mode 100644
index 000000000..e305d1728
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Auth/IAuthService.cs
@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 定义身份验证服务的接口
+///
+public interface IAuthService
+{
+ ///
+ /// 用户登录
+ ///
+ /// 登录参数
+ /// 是否使用 cookie 登录方式
+ /// 登录输出
+ Task LoginAsync(LoginInput input, bool isCookie = true);
+
+ ///
+ /// 注销当前用户
+ ///
+ Task LoginOutAsync();
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/AppConfig.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/AppConfig.cs
new file mode 100644
index 000000000..ee3319a20
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/AppConfig.cs
@@ -0,0 +1,31 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public class AppConfig
+{
+ ///
+ /// 登录策略
+ ///
+ public LoginPolicy LoginPolicy { get; set; }
+
+ ///
+ /// 页面策略
+ ///
+ public PagePolicy PagePolicy { get; set; }
+
+ ///
+ /// 密码策略
+ ///
+ public PasswordPolicy PasswordPolicy { get; set; }
+
+ public WebsitePolicy WebsitePolicy { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/LoginPolicy.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/LoginPolicy.cs
new file mode 100644
index 000000000..fd4378d1a
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/LoginPolicy.cs
@@ -0,0 +1,43 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public class LoginPolicy
+{
+ ///
+ /// 登录错误次数锁定阈值
+ ///
+ [MinValue(3)]
+ public int ErrorCount { get; set; }
+
+ ///
+ /// 登录错误锁定时间(分)
+ ///
+ [MinValue(1)]
+ public int ErrorLockTime { get; set; }
+
+ ///
+ /// 登录错误次数过期时间(分)
+ ///
+ [MinValue(1)]
+ public int ErrorResetTime { get; set; }
+
+ ///
+ /// 单用户登录开关
+ ///
+ public bool SingleOpen { get; set; }
+
+ ///
+ /// 登录过期时间(分)
+ ///
+ [MinValue(1)]
+ public int VerificatExpireTime { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/PagePolicy.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/PagePolicy.cs
new file mode 100644
index 000000000..d0e74e519
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/PagePolicy.cs
@@ -0,0 +1,19 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+public class PagePolicy
+{
+ ///
+ /// 系统默认快捷方式菜单ID列表
+ ///
+ public List Shortcuts { get; set; } = new();
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/PasswordPolicy.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/PasswordPolicy.cs
new file mode 100644
index 000000000..8ee7269b8
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/PasswordPolicy.cs
@@ -0,0 +1,48 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+public class PasswordPolicy
+{
+ ///
+ /// 默认用户密码
+ ///
+ [Required]
+ public string DefaultPassword { get; set; }
+
+ ///
+ /// 包含特殊字符
+ ///
+ public bool PasswordContainChar { get; set; }
+
+ ///
+ /// 包含小写字母
+ ///
+ public bool PasswordContainLower { get; set; }
+
+ ///
+ /// 包含数字
+ ///
+ public bool PasswordContainNum { get; set; }
+
+ ///
+ /// 包含大写字母
+ ///
+ public bool PasswordContainUpper { get; set; }
+
+ ///
+ /// 密码最小长度
+ ///
+ [MinValue(1)]
+ public int PasswordMinLen { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/WebsitePolicy.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/WebsitePolicy.cs
new file mode 100644
index 000000000..30c9ad1f2
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/Dto/WebsitePolicy.cs
@@ -0,0 +1,27 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using System.ComponentModel.DataAnnotations;
+
+namespace ThingsGateway.Admin.Application;
+
+public class WebsitePolicy
+{
+ ///
+ /// 关闭提示
+ ///
+ [Required]
+ public string CloseTip { get; set; }
+
+ ///
+ /// 是否开放
+ ///
+ public bool WebStatus { get; set; }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Dict/ISysDictService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/ISysDictService.cs
new file mode 100644
index 000000000..749705012
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/ISysDictService.cs
@@ -0,0 +1,92 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 系统字典服务接口,提供对系统字典的操作
+///
+public interface ISysDictService
+{
+ ///
+ /// 删除业务配置
+ ///
+ /// 待删除配置项的ID列表
+ /// 是否成功删除
+ Task DeleteDictAsync(IEnumerable ids);
+
+ ///
+ /// 修改登录策略
+ ///
+ /// 登录策略
+ Task EditLoginPolicyAsync(LoginPolicy input);
+
+ ///
+ /// 修改页面策略
+ ///
+ /// 页面策略
+ Task EditPagePolicyAsync(PagePolicy input);
+
+ ///
+ /// 修改密码策略
+ ///
+ /// 密码策略
+ Task EditPasswordPolicyAsync(PasswordPolicy input);
+
+ ///
+ /// 修改网站设置
+ ///
+ /// 网站设置
+ Task EditWebsitePolicyAsync(WebsitePolicy input);
+
+ ///
+ /// 获取系统配置
+ ///
+ /// 系统配置信息
+ Task GetAppConfigAsync();
+
+ ///
+ /// 根据分类和名称获取系统字典项
+ ///
+ /// 分类
+ /// 名称
+ /// 系统字典项
+ Task GetByKeyAsync(string category, string name);
+
+
+ ///
+ /// 从缓存/数据库获取自定义配置列表
+ ///
+ /// 自定义配置列表
+ Task> GetDefineConfigAsync();
+
+ ///
+ /// 从缓存/数据库获取系统配置列表
+ ///
+ /// 系统配置列表
+ Task> GetSystemConfigAsync();
+
+ ///
+ /// 表格查询
+ ///
+ /// 查询选项
+ /// 查询结果
+ Task> PageAsync(QueryPageOptions option);
+
+ ///
+ /// 修改业务配置
+ ///
+ /// 配置项
+ /// 保存类型
+ /// 是否成功保存
+ Task SaveDictAsync(SysDict input, ItemChangedType type);
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Dict/SysDictService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/SysDictService.cs
new file mode 100644
index 000000000..5e0fefe38
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Dict/SysDictService.cs
@@ -0,0 +1,336 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using BootstrapBlazor.Components;
+
+using ThingsGateway.FriendlyException;
+using ThingsGateway.NewLife.Json.Extension;
+using ThingsGateway.Razor;
+
+namespace ThingsGateway.Admin.Application;
+
+internal sealed class SysDictService : BaseService, ISysDictService
+{
+ ///
+ /// 删除业务配置
+ ///
+ /// id列表
+ [OperDesc("DeleteDict")]
+ public async Task DeleteDictAsync(IEnumerable ids)
+ {
+ var result = await base.DeleteAsync(ids).ConfigureAwait(false);
+ if (result)
+ RefreshCache(DictTypeEnum.Define);
+ return result;
+ }
+
+ ///
+ /// 修改登录策略
+ ///
+ /// 登录策略
+ [OperDesc("EditLoginPolicy")]
+ public async Task EditLoginPolicyAsync(LoginPolicy input)
+ {
+ using var db = GetDB();
+ //更新数据
+ List dicts = new List()
+ {
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(LoginPolicy), Name = nameof(LoginPolicy.SingleOpen), Code = input.SingleOpen.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(LoginPolicy), Name = nameof(LoginPolicy.ErrorCount), Code = input.ErrorCount.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(LoginPolicy), Name = nameof(LoginPolicy.ErrorLockTime), Code = input.ErrorLockTime.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(LoginPolicy), Name = nameof(LoginPolicy.ErrorResetTime), Code = input.ErrorResetTime.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(LoginPolicy), Name = nameof(LoginPolicy.VerificatExpireTime), Code = input.VerificatExpireTime.ToString() },
+ };
+ var storageable = await db.Storageable(dicts).WhereColumns(it => new { it.DictType, it.Category, it.Name }).ToStorageAsync().ConfigureAwait(false);
+
+ //事务
+ var result = await db.UseTranAsync(async () =>
+ {
+ await storageable.AsUpdateable.UpdateColumns(it => new { it.Code }).ExecuteCommandAsync().ConfigureAwait(false);
+ await storageable.AsInsertable.ExecuteCommandAsync().ConfigureAwait(false);
+ }).ConfigureAwait(false);
+ if (result.IsSuccess)//如果成功了
+ {
+ RefreshCache(DictTypeEnum.System);//刷新缓存
+ }
+ else
+ {
+ throw new(result.ErrorMessage, result.ErrorException);
+ }
+ }
+
+ ///
+ /// 修改页面策略
+ ///
+ /// 页面策略
+ [OperDesc("EditPagePolicy")]
+ public async Task EditPagePolicyAsync(PagePolicy input)
+ {
+ using var db = GetDB();
+ //更新数据
+ List dicts = new List()
+ {
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(PagePolicy), Name = nameof(PagePolicy.Shortcuts), Code = input.Shortcuts.ToJsonNetString() },
+ };
+ var storageable = await db.Storageable(dicts).WhereColumns(it => new { it.DictType, it.Category, it.Name }).ToStorageAsync().ConfigureAwait(false);
+
+ //事务
+ var result = await db.UseTranAsync(async () =>
+ {
+ await storageable.AsUpdateable.UpdateColumns(it => new { it.Code }).ExecuteCommandAsync().ConfigureAwait(false);
+ await storageable.AsInsertable.ExecuteCommandAsync().ConfigureAwait(false);
+ }).ConfigureAwait(false);
+ if (result.IsSuccess)//如果成功了
+ {
+ RefreshCache(DictTypeEnum.System);//刷新缓存
+ }
+ else
+ {
+ throw new(result.ErrorMessage, result.ErrorException);
+ }
+ }
+
+ ///
+ /// 修改密码策略
+ ///
+ /// 密码策略
+ [OperDesc("EditPasswordPolicy")]
+ public async Task EditPasswordPolicyAsync(PasswordPolicy input)
+ {
+ using var db = GetDB();
+ //更新数据
+ List dicts = new List()
+ {
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(PasswordPolicy), Name = nameof(PasswordPolicy.PasswordContainLower), Code = input.PasswordContainLower.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(PasswordPolicy), Name = nameof(PasswordPolicy.DefaultPassword), Code = input.DefaultPassword.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(PasswordPolicy), Name = nameof(PasswordPolicy.PasswordContainChar), Code = input.PasswordContainChar.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(PasswordPolicy), Name = nameof(PasswordPolicy.PasswordContainUpper), Code = input.PasswordContainUpper.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(PasswordPolicy), Name = nameof(PasswordPolicy.PasswordMinLen), Code = input.PasswordMinLen.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(PasswordPolicy), Name = nameof(PasswordPolicy.PasswordContainNum), Code = input.PasswordContainNum.ToString() },
+ };
+ var storageable = await db.Storageable(dicts).WhereColumns(it => new { it.DictType, it.Category, it.Name }).ToStorageAsync().ConfigureAwait(false);
+
+ //事务
+ var result = await db.UseTranAsync(async () =>
+ {
+ await storageable.AsUpdateable.UpdateColumns(it => new { it.Code }).ExecuteCommandAsync().ConfigureAwait(false);
+ await storageable.AsInsertable.ExecuteCommandAsync().ConfigureAwait(false);
+ }).ConfigureAwait(false);
+ if (result.IsSuccess)//如果成功了
+ {
+ RefreshCache(DictTypeEnum.System);//刷新缓存
+ }
+ else
+ {
+ throw new(result.ErrorMessage, result.ErrorException);
+ }
+ }
+
+ ///
+ /// 修改网站设置
+ ///
+ ///
+ [OperDesc("EditWebsitePolicy")]
+ public async Task EditWebsitePolicyAsync(WebsitePolicy input)
+ {
+ var websiteOptions = App.GetOptions()!;
+ if (websiteOptions.Demo)
+ {
+ throw Oops.Bah(Localizer["DemoCanotUpdateWebsitePolicy"]);
+ }
+
+ using var db = GetDB();
+ //更新数据
+ List dicts = new List()
+ {
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(WebsitePolicy), Name = nameof(WebsitePolicy.WebStatus), Code = input.WebStatus.ToString() },
+ new SysDict() { DictType = DictTypeEnum.System, Category = nameof(WebsitePolicy), Name = nameof(WebsitePolicy.CloseTip), Code = input.CloseTip },
+ };
+ var storageable = await db.Storageable(dicts).WhereColumns(it => new { it.DictType, it.Category, it.Name }).ToStorageAsync().ConfigureAwait(false);
+
+ //事务
+ var result = await db.UseTranAsync(async () =>
+ {
+ await storageable.AsUpdateable.UpdateColumns(it => new { it.Code }).ExecuteCommandAsync().ConfigureAwait(false);
+ await storageable.AsInsertable.ExecuteCommandAsync().ConfigureAwait(false);
+ }).ConfigureAwait(false);
+ if (result.IsSuccess)//如果成功了
+ {
+ RefreshCache(DictTypeEnum.System);//刷新缓存
+ }
+ else
+ {
+ throw new(result.ErrorMessage, result.ErrorException);
+ }
+ }
+
+ ///
+ /// 获取系统配置
+ ///
+ public async Task GetAppConfigAsync()
+ {
+ var key = $"{CacheConst.Cache_SysDict}{DictTypeEnum.System}{nameof(AppConfig)}";//系统配置key
+ var appConfig = App.CacheService.Get(key);
+ if (appConfig == null)
+ {
+ List sysDicts = await GetSystemConfigAsync().ConfigureAwait(false);
+
+ appConfig = new AppConfig() { LoginPolicy = new(), PasswordPolicy = new(), PagePolicy = new(), WebsitePolicy = new() };
+ //登录策略
+ appConfig.LoginPolicy.ErrorCount = sysDicts.FirstOrDefault(a => a.Category == nameof(LoginPolicy) && a.Name == nameof(LoginPolicy.ErrorCount))?.Code.ToInt() ?? 3;
+ appConfig.LoginPolicy.ErrorLockTime = sysDicts.FirstOrDefault(a => a.Category == nameof(LoginPolicy) && a.Name == nameof(LoginPolicy.ErrorLockTime))?.Code.ToInt() ?? 1;
+ appConfig.LoginPolicy.ErrorResetTime = sysDicts.FirstOrDefault(a => a.Category == nameof(LoginPolicy) && a.Name == nameof(LoginPolicy.ErrorResetTime))?.Code.ToInt() ?? 1;
+ appConfig.LoginPolicy.SingleOpen = sysDicts.FirstOrDefault(a => a.Category == nameof(LoginPolicy) && a.Name == nameof(LoginPolicy.SingleOpen))?.Code.ToBoolean() ?? false;
+ appConfig.LoginPolicy.VerificatExpireTime = sysDicts.FirstOrDefault(a => a.Category == nameof(LoginPolicy) && a.Name == nameof(LoginPolicy.VerificatExpireTime))?.Code.ToInt() ?? 14400;
+ //密码策略
+ appConfig.PasswordPolicy.PasswordContainChar = sysDicts.FirstOrDefault(a => a.Category == nameof(PasswordPolicy) && a.Name == nameof(PasswordPolicy.PasswordContainChar))?.Code.ToBoolean() ?? false;
+ appConfig.PasswordPolicy.PasswordContainNum = sysDicts.FirstOrDefault(a => a.Category == nameof(PasswordPolicy) && a.Name == nameof(PasswordPolicy.PasswordContainNum))?.Code.ToBoolean() ?? false;
+ appConfig.PasswordPolicy.PasswordContainLower = sysDicts.FirstOrDefault(a => a.Category == nameof(PasswordPolicy) && a.Name == nameof(PasswordPolicy.PasswordContainLower))?.Code.ToBoolean() ?? false;
+ appConfig.PasswordPolicy.PasswordMinLen = sysDicts.FirstOrDefault(a => a.Category == nameof(PasswordPolicy) && a.Name == nameof(PasswordPolicy.PasswordMinLen))?.Code.ToInt() ?? 6;
+ appConfig.PasswordPolicy.PasswordContainUpper = sysDicts.FirstOrDefault(a => a.Category == nameof(PasswordPolicy) && a.Name == nameof(PasswordPolicy.PasswordContainUpper))?.Code.ToBoolean() ?? false;
+ appConfig.PasswordPolicy.DefaultPassword = sysDicts.FirstOrDefault(a => a.Category == nameof(PasswordPolicy) && a.Name == nameof(PasswordPolicy.DefaultPassword))?.Code ?? "111111";
+
+ //页面策略
+ appConfig.PagePolicy.Shortcuts = sysDicts.FirstOrDefault(a => a.Category == nameof(PagePolicy) && a.Name == nameof(PagePolicy.Shortcuts))?.Code.FromJsonNetString>() ?? new List();
+
+ //网站设置
+ appConfig.WebsitePolicy.WebStatus = sysDicts.FirstOrDefault(a => a.Category == nameof(WebsitePolicy) && a.Name == nameof(WebsitePolicy.WebStatus))?.Code.ToBoolean() ?? true;
+ appConfig.WebsitePolicy.CloseTip = sysDicts.FirstOrDefault(a => a.Category == nameof(WebsitePolicy) && a.Name == nameof(WebsitePolicy.CloseTip))?.Code ?? "";
+ App.CacheService.Set(key, appConfig);
+ }
+
+ return appConfig;
+ }
+
+ ///
+ /// 根据分类从缓存/数据库获取列表
+ ///
+ /// 分类
+ /// 名称
+ /// 配置列表
+ public async Task GetByKeyAsync(string category, string name)
+ {
+ var key = CacheConst.Cache_SysDict + DictTypeEnum.Define;
+ var field = $"{category}:sysdict:{name}";
+ var sysDict = App.CacheService.HashGetOne(key, field);
+ if (sysDict == null)
+ {
+ using var db = GetDB();
+ sysDict = await db.Queryable().FirstAsync(a => a.DictType == DictTypeEnum.Define && a.Category == category && a.Name == name).ConfigureAwait(false);
+ App.CacheService.HashAdd(key, field, sysDict);
+ }
+ return sysDict;
+ }
+
+ ///
+ /// 从缓存/数据库获取系统配置列表
+ ///
+ ///
+ public async Task> GetDefineConfigAsync()
+ {
+ var key = $"{CacheConst.Cache_SysDict}{DictTypeEnum.Define}";//系统配置key
+ var sysDicts = App.CacheService.HashGetAll(key);
+ if (sysDicts.Count == 0)
+ {
+ using var db = GetDB();
+ sysDicts = (await db.Queryable().Where(a => a.DictType == DictTypeEnum.Define).ToListAsync().ConfigureAwait(false)).ToDictionary(a =>
+ $"{a.Category}:sysdict:{a.Name}", a => a);
+ App.CacheService.Set(key, sysDicts);
+ }
+
+ return sysDicts;
+ }
+
+
+ ///
+ /// 从缓存/数据库获取系统配置列表
+ ///
+ ///
+ public async Task> GetSystemConfigAsync()
+ {
+ var key = $"{CacheConst.Cache_SysDict}{DictTypeEnum.System}";//系统配置key
+ var sysDicts = App.CacheService.Get>(key);
+ if (sysDicts == null)
+ {
+ using var db = GetDB();
+ sysDicts = await db.Queryable().Where(a => a.DictType == DictTypeEnum.System).ToListAsync().ConfigureAwait(false);
+ App.CacheService.Set(key, sysDicts);
+ }
+
+ return sysDicts;
+ }
+
+
+ ///
+ /// 表格查询
+ ///
+ ///
+ ///
+ public Task> PageAsync(QueryPageOptions option)
+ {
+ return QueryAsync(option,
+ a => a.Where(it => it.DictType == DictTypeEnum.Define)
+ .WhereIF(!option.SearchText.IsNullOrWhiteSpace(), a => a.Category.Contains(option.SearchText!)));
+ }
+
+ ///
+ /// 修改业务配置
+ ///
+ /// 配置项
+ /// 保存类型
+ [OperDesc("SaveDict")]
+ public async Task SaveDictAsync(SysDict input, ItemChangedType type)
+ {
+ await CheckInput(input).ConfigureAwait(false);//检查参数
+ var reuslt = await base.SaveAsync(input, type).ConfigureAwait(false);
+ if (reuslt)
+ RefreshCache(DictTypeEnum.Define);
+
+ return reuslt;
+ }
+
+ #region 方法
+
+ ///
+ /// 检查输入参数
+ ///
+ /// 配置项
+ private async Task CheckInput(SysDict input)
+ {
+
+ //设置类型为业务
+ input.DictType = DictTypeEnum.Define;
+
+ var dict = await GetByKeyAsync(input.Category, input.Name).ConfigureAwait(false);//获取全部字典
+
+ //判断是否从存在重复
+
+ if (dict != null && dict.Id != input.Id)
+ {
+ throw Oops.Bah(Localizer["DictDup", input.Category, input.Name]);
+ }
+
+ }
+
+ ///
+ /// 刷新缓存
+ ///
+ /// 类型
+ ///
+ private void RefreshCache(DictTypeEnum define)
+ {
+ App.CacheService.Remove($"{CacheConst.Cache_SysDict}{define}");
+ if (define == DictTypeEnum.System)
+ App.CacheService.Remove($"{CacheConst.Cache_SysDict}{define}{nameof(AppConfig)}");
+ }
+
+
+ #endregion 方法
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Event/EventService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Event/EventService.cs
new file mode 100644
index 000000000..ee224a5cf
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Event/EventService.cs
@@ -0,0 +1,48 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+using System.Collections.Concurrent;
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 内存推送事件服务
+///
+///
+public class EventService : IEventService
+{
+ private ConcurrentDictionary> Cache { get; } = new();
+
+ public void Dispose()
+ {
+ Cache.Clear();
+ }
+
+ ///
+ public async Task Publish(string key, TEntry payload)
+ {
+ if (Cache.TryGetValue(key, out var func))
+ {
+ await func(payload).ConfigureAwait(false);
+ }
+ }
+
+ ///
+ public void Subscribe(string key, Func callback)
+ {
+ Cache.TryAdd(key, callback);
+ }
+
+ ///
+ public void UnSubscribe(string key)
+ {
+ Cache.Remove(key);
+ }
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/Event/IEventService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/Event/IEventService.cs
new file mode 100644
index 000000000..44409e1c2
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/Event/IEventService.cs
@@ -0,0 +1,37 @@
+// ------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+// ------------------------------------------------------------------------------
+
+namespace ThingsGateway.Admin.Application;
+
+///
+/// 推送事件服务
+///
+///
+public interface IEventService : IDisposable
+{
+ ///
+ /// 发布
+ ///
+ ///
+ ///
+ ///
+ Task Publish(string key, TEntry payload);
+ ///
+ /// 订阅
+ ///
+ ///
+ ///
+ void Subscribe(string key, Func callback);
+ ///
+ /// 取消订阅
+ ///
+ ///
+ void UnSubscribe(string key);
+}
diff --git a/src/Admin/ThingsGateway.Admin.Application/Services/File/FileService.cs b/src/Admin/ThingsGateway.Admin.Application/Services/File/FileService.cs
new file mode 100644
index 000000000..b6f1a95f7
--- /dev/null
+++ b/src/Admin/ThingsGateway.Admin.Application/Services/File/FileService.cs
@@ -0,0 +1,96 @@
+//------------------------------------------------------------------------------
+// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
+// 此代码版权(除特别声明外的代码)归作者本人Diego所有
+// 源代码使用协议遵循本仓库的开源协议及附加协议
+// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
+// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
+// 使用文档:https://thingsgateway.cn/
+// QQ群:605534569
+//------------------------------------------------------------------------------
+
+using Microsoft.AspNetCore.Components.Forms;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Localization;
+
+using System.Text;
+using System.Web;
+
+using ThingsGateway.FriendlyException;
+
+namespace ThingsGateway.Admin.Application;
+
+internal sealed class FileService : IFileService
+{
+ private IStringLocalizer _localizer;
+ public FileService(
+ IStringLocalizer localizer)
+ {
+ _localizer = localizer;
+
+ }
+ ///