Update split bug

This commit is contained in:
sunkaixuan
2022-02-27 20:04:19 +08:00
parent b4ddeeebe6
commit a2f8457d43
2 changed files with 11 additions and 18 deletions

View File

@@ -899,27 +899,20 @@ namespace SqlSugar
var columnName = this.SqlBuilder.GetTranslationColumnName(splitColumn.DbColumnName); var columnName = this.SqlBuilder.GetTranslationColumnName(splitColumn.DbColumnName);
var sqlParameterKeyWord = this.SqlBuilder.SqlParameterKeyWord; var sqlParameterKeyWord = this.SqlBuilder.SqlParameterKeyWord;
return this.Where($" {columnName}>={sqlParameterKeyWord}spBeginTime AND {columnName}<= {sqlParameterKeyWord}spEndTime",new { spBeginTime = beginTime , spEndTime = endTime}).SplitTable(tas => { return this.Where($" {columnName}>={sqlParameterKeyWord}spBeginTime AND {columnName}<= {sqlParameterKeyWord}spEndTime",new { spBeginTime = beginTime , spEndTime = endTime}).SplitTable(tas => {
var result = tas;
var dateNull = DateTime.MinValue; var type= this.EntityInfo.Type.GetCustomAttribute<SplitTableAttribute>();
var min = tas.Where(it => it.Date <= beginTime.Date).Select(it=>it.Date).OrderByDescending(it=>it.Date).FirstOrDefault(); if (SplitType.Month == type.SplitType)
var max = tas.Where(it => it.Date >= endTime.Date).Select(it => it.Date).OrderBy(it => it.Date).FirstOrDefault();
if (max == dateNull && min == dateNull)
{ {
return tas.Take(1); result = result.Where(y => y.Date >= beginTime.ToString("yyyy-MM").ObjToDate() && y.Date <= endTime.Date.ToString("yyyy-MM").ObjToDate().AddMonths(1).AddDays(-1)).ToList();
} }
if (max == dateNull) else if (SplitType.Month == type.SplitType)
{ {
max = tas.Where(it => it.Date <= endTime).Select(it => it.Date).OrderByDescending(it => it.Date).FirstOrDefault(); result = result.Where(y => y.Date.Year >= beginTime.Year && y.Date.Year <= endTime.Year).ToList();
} }
if (max == dateNull) else
{ {
max = min; result = result.Where(y => y.Date >= beginTime.Date && y.Date <= endTime.Date).ToList();
} }
if (min == dateNull)
{
min = max;
}
var result= tas.Where(y => y.Date >= min && y.Date <= max);
return result; return result;
}); });
} }

View File

@@ -388,9 +388,9 @@ namespace SqlSugar
InstanceFactory.CustomDllName = SugarCompatible.IsFramework?"SqlSugar.Access": "SqlSugar.AccessCore"; InstanceFactory.CustomDllName = SugarCompatible.IsFramework?"SqlSugar.Access": "SqlSugar.AccessCore";
break; break;
case DbType.Custom: case DbType.Custom:
Check.Exception(InstanceFactory.CustomDbName==null , "DbType.Custom: InstanceFactory.CustomDbName is not null "); Check.Exception(InstanceFactory.CustomDbName.IsNullOrEmpty() , "DbType.Custom: InstanceFactory.CustomDbName is not null ");
Check.Exception(InstanceFactory.CustomNamespace == null, "DbType.Custom: InstanceFactory.CustomNamespace is not null "); Check.Exception(InstanceFactory.CustomNamespace.IsNullOrEmpty(), "DbType.Custom: InstanceFactory.CustomNamespace is not null ");
Check.Exception(InstanceFactory.CustomDllName == null, "DbType.Custom: InstanceFactory.CustomDllName is not null "); Check.Exception(InstanceFactory.CustomDllName.IsNullOrEmpty(), "DbType.Custom: InstanceFactory.CustomDllName is not null ");
break; break;
default: default:
throw new Exception("ConnectionConfig.DbType is null"); throw new Exception("ConnectionConfig.DbType is null");