diff --git a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.dll b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.dll index 473704a..a62cc26 100644 Binary files a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.dll and b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.dll differ diff --git a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.pdb b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.pdb index 6d7a9c3..5ae3984 100644 Binary files a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.pdb and b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Business.pdb differ diff --git a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll index 13958c3..ec97308 100644 Binary files a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll and b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll differ diff --git a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb index c50464a..7017da6 100644 Binary files a/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb and b/Sln.Iot.Business/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb differ diff --git a/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.csproj.AssemblyReference.cache b/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.csproj.AssemblyReference.cache index b9db106..9c21cf7 100644 Binary files a/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.csproj.AssemblyReference.cache and b/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.csproj.AssemblyReference.cache differ diff --git a/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.dll b/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.dll index 473704a..a62cc26 100644 Binary files a/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.dll and b/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.dll differ diff --git a/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.pdb b/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.pdb index 6d7a9c3..5ae3984 100644 Binary files a/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.pdb and b/Sln.Iot.Business/obj/Debug/netstandard2.1/Sln.Iot.Business.pdb differ diff --git a/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll b/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll index 13958c3..ec97308 100644 Binary files a/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll and b/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.dll differ diff --git a/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb b/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb index c50464a..7017da6 100644 Binary files a/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb and b/Sln.Iot.Repository/bin/Debug/netstandard2.1/Sln.Iot.Repository.pdb differ diff --git a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.AssemblyReference.cache b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.AssemblyReference.cache index bdb6bb8..801912b 100644 Binary files a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.AssemblyReference.cache and b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.AssemblyReference.cache differ diff --git a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.CoreCompileInputs.cache b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.CoreCompileInputs.cache index 344a085..d3ec618 100644 --- a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.CoreCompileInputs.cache +++ b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -38cea589c6583306e028f7802e4cb060ec1ca7f6 +93cff6037311b0410aec40b449d81c076811b5b7 diff --git a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.dll b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.dll index 13958c3..ec97308 100644 Binary files a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.dll and b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.dll differ diff --git a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.pdb b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.pdb index c50464a..7017da6 100644 Binary files a/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.pdb and b/Sln.Iot.Repository/obj/Debug/netstandard2.1/Sln.Iot.Repository.pdb differ diff --git a/Sln.Iot.Repository/service/Impl/RecordIotEnvInstantServiceImpl.cs b/Sln.Iot.Repository/service/Impl/RecordIotEnvInstantServiceImpl.cs index ec1a2d2..46a527c 100644 --- a/Sln.Iot.Repository/service/Impl/RecordIotEnvInstantServiceImpl.cs +++ b/Sln.Iot.Repository/service/Impl/RecordIotEnvInstantServiceImpl.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using Sln.Iot.Model.dao; using Sln.Iot.Repository.service.@base; +using Sln.Iot.Repository.service.split; namespace Sln.Iot.Repository.service.Impl { @@ -54,7 +55,12 @@ namespace Sln.Iot.Repository.service.Impl { // _rep.AsTenant().BeginTran(); - insertIds = _rep.Context.Insertable(list).SplitTable().ExecuteReturnSnowflakeIdList(); + + var sqlSugarClient = _rep.Context; + //加载指定分表策略 + //sqlSugarClient.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new MonitorIdToSplitService(); + insertIds = sqlSugarClient.Insertable(list).SplitTable().ExecuteReturnSnowflakeIdList(); + // _rep.AsTenant().CommitTran(); return true; } diff --git a/Sln.Iot.Repository/service/split/MonitorIdToSplitService.cs b/Sln.Iot.Repository/service/split/MonitorIdToSplitService.cs new file mode 100644 index 0000000..fbe1db9 --- /dev/null +++ b/Sln.Iot.Repository/service/split/MonitorIdToSplitService.cs @@ -0,0 +1,97 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2025 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Iot.Repository.service.split +* 唯一标识:2D1DE17A-79B9-48D8-BB98-60E89BEC711A +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2025-04-27 10:10:14 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using SqlSugar; + +namespace Sln.Iot.Repository.service.split +{ + /// + /// 自定义分表策略:根据传感器 ID 进行分表 + /// + public class MonitorIdToSplitService:ISplitTableService + { + /// + /// 返回数据库中所有分表 + /// + /// + /// + /// + /// + public List GetAllTables(ISqlSugarClient db, EntityInfo EntityInfo, List tableInfos) + { + List result = new List(); + foreach (var item in tableInfos) + { + if (item.Name.Contains("record_iotenv_instant")) //区分标识如果不用正则符复杂一些,防止找错表 + { + SplitTableInfo data = new SplitTableInfo() + { + TableName = item.Name //要用item.name不要写错了 + }; + result.Add(data); + } + } + return result.OrderBy(it=>it.TableName).ToList();//打断点看一下有没有查出所有分表 + } + + /// + /// 获取分表字段的值 + /// + /// + /// + /// + /// + /// + public object GetFieldValue(ISqlSugarClient db, EntityInfo entityInfo, SplitType splitType, object entityValue) + { + var splitColumn = entityInfo.Columns.FirstOrDefault(it => it.PropertyInfo.GetCustomAttribute() != null); + var value = splitColumn.PropertyInfo.GetValue(entityValue, null); + return value; + } + /// + /// 默认表名 + /// + /// + /// + /// + public string GetTableName(ISqlSugarClient db, EntityInfo entityInfo) + { + return entityInfo.DbTableName; + } + + public string GetTableName(ISqlSugarClient db, EntityInfo entityInfo, SplitType type) + { + return entityInfo.DbTableName;//目前模式少不需要分类(自带的有 日、周、月、季、年等进行区分) + } + + public string GetTableName(ISqlSugarClient db, EntityInfo entityInfo, SplitType splitType, object fieldValue) + { + return entityInfo.DbTableName + "_"+fieldValue; //根据值按首字母 + } + } +} \ No newline at end of file diff --git a/Sln.Iot.sln.DotSettings.user b/Sln.Iot.sln.DotSettings.user index 00ad177..35274b5 100644 --- a/Sln.Iot.sln.DotSettings.user +++ b/Sln.Iot.sln.DotSettings.user @@ -5,5 +5,6 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file diff --git a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.dll b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.dll index 473704a..a62cc26 100644 Binary files a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.dll and b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.dll differ diff --git a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.pdb b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.pdb index 6d7a9c3..5ae3984 100644 Binary files a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.pdb and b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Business.pdb differ diff --git a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.dll b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.dll index 13958c3..ec97308 100644 Binary files a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.dll and b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.dll differ diff --git a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.pdb b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.pdb index c50464a..7017da6 100644 Binary files a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.pdb and b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.Repository.pdb differ diff --git a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.dll b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.dll index 35fcbe8..0794617 100644 Binary files a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.dll and b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.dll differ diff --git a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.pdb b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.pdb index 9f4afc0..1f7251a 100644 Binary files a/Sln.Iot/bin/Debug/net6.0/Sln.Iot.pdb and b/Sln.Iot/bin/Debug/net6.0/Sln.Iot.pdb differ diff --git a/Sln.Iot/obj/Debug/net6.0/Sln.Iot.csproj.AssemblyReference.cache b/Sln.Iot/obj/Debug/net6.0/Sln.Iot.csproj.AssemblyReference.cache index 18f94ba..c62e479 100644 Binary files a/Sln.Iot/obj/Debug/net6.0/Sln.Iot.csproj.AssemblyReference.cache and b/Sln.Iot/obj/Debug/net6.0/Sln.Iot.csproj.AssemblyReference.cache differ diff --git a/Sln.Iot/obj/Debug/net6.0/Sln.Iot.dll b/Sln.Iot/obj/Debug/net6.0/Sln.Iot.dll index 35fcbe8..0794617 100644 Binary files a/Sln.Iot/obj/Debug/net6.0/Sln.Iot.dll and b/Sln.Iot/obj/Debug/net6.0/Sln.Iot.dll differ diff --git a/Sln.Iot/obj/Debug/net6.0/Sln.Iot.pdb b/Sln.Iot/obj/Debug/net6.0/Sln.Iot.pdb index 9f4afc0..1f7251a 100644 Binary files a/Sln.Iot/obj/Debug/net6.0/Sln.Iot.pdb and b/Sln.Iot/obj/Debug/net6.0/Sln.Iot.pdb differ