Skip to content

Commit

Permalink
Merge pull request #171 from joeries/YiShaAdmin-Net8
Browse files Browse the repository at this point in the history
1. 升级MySqlConnector和Pomelo.EntityFrameworkCore.MySql以解决启动时报错MissingMethodException; 2. UserService.ListFilter避免param为null,避免将非表字段属性直接加入Expression。
  • Loading branch information
liukuo362573 committed Jun 15, 2024
2 parents d1f1fbd + d0f9ad2 commit 39bc711
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 47 deletions.
81 changes: 47 additions & 34 deletions YiSha.Business/YiSha.Service/OrganizationManage/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ public async Task ChangeUser(UserEntity entity)
#region 私有方法
private Expression<Func<UserEntity, bool>> ListFilter(UserListParam param)
{
//新增/编辑部门时param为null,此时初始化默认实例以防异常
if (null == param)
{
param = new UserListParam();
}

//下面LinqExtensions.GetExpressionItems获取Expression时排除这些非表字段属性
var userIds = param.UserIds;
param.UserIds = null;
var startTime = param.StartTime;
param.StartTime = null;
var endTime = param.EndTime;
param.EndTime = null;
var childrenDepartmentIdList = param.ChildrenDepartmentIdList;
param.ChildrenDepartmentIdList = null;

//var expression = LinqExtensions.True<UserEntity>();

Expand All @@ -175,47 +190,45 @@ private Expression<Func<UserEntity, bool>> ListFilter(UserListParam param)
}

//****根据查询字段自动过滤条件****
var expression = LinqExtensions.GetExpressionItems<UserEntity,UserListParam>(param);
var expression = LinqExtensions.GetExpressionItems<UserEntity, UserListParam>(param);

if (param != null)
{
//if (!string.IsNullOrEmpty(param.UserName))
//{
// expression = expression.And(t => t.UserName.Contains(param.UserName));
//}
//if (!string.IsNullOrEmpty(param.UserName))
//{
// expression = expression.And(t => t.UserName.Contains(param.UserName));
//}


if (!string.IsNullOrEmpty(param.UserIds))
{
long[] userIdList = TextHelper.SplitToArray<long>(param.UserIds, ',');
expression = expression.And(t => userIdList.Contains(t.Id.Value));
}
if (!string.IsNullOrEmpty(userIds))
{
long[] userIdList = TextHelper.SplitToArray<long>(userIds, ',');
expression = expression.And(t => userIdList.Contains(t.Id.Value));
}

//if (!string.IsNullOrEmpty(param.Mobile))
//{
// expression = expression.And(t => t.Mobile.Contains(param.Mobile));
//}
//if (param.UserStatus > -1)
//{
// expression = expression.And(t => t.UserStatus == param.UserStatus);
//}
//if (!string.IsNullOrEmpty(param.Mobile))
//{
// expression = expression.And(t => t.Mobile.Contains(param.Mobile));
//}
//if (param.UserStatus > -1)
//{
// expression = expression.And(t => t.UserStatus == param.UserStatus);
//}

if (!string.IsNullOrEmpty(param.StartTime.ParseToString()))
{
expression = expression.And(t => t.BaseModifyTime >= param.StartTime);
}
if (!string.IsNullOrEmpty(param.EndTime.ParseToString()))
{
param.EndTime = param.EndTime.Value.Date.Add(new TimeSpan(23, 59, 59));
expression = expression.And(t => t.BaseModifyTime <= param.EndTime);
}
if (param.ChildrenDepartmentIdList != null && param.ChildrenDepartmentIdList.Count > 0)
{
expression = expression.And(t => param.ChildrenDepartmentIdList.Contains(t.DepartmentId.Value));
}
if (!string.IsNullOrEmpty(startTime.ParseToString()))
{
expression = expression.And(t => t.BaseModifyTime >= startTime);
}
if (!string.IsNullOrEmpty(endTime.ParseToString()))
{
endTime = endTime.Value.Date.Add(new TimeSpan(23, 59, 59));
expression = expression.And(t => t.BaseModifyTime <= endTime);
}
if (childrenDepartmentIdList != null && childrenDepartmentIdList.Count > 0)
{
expression = expression.And(t => childrenDepartmentIdList.Contains(t.DepartmentId.Value));
}

return expression;
}
#endregion
}
}
}
22 changes: 11 additions & 11 deletions YiSha.Data/YiSha.Data.EF/DbContextExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,40 +110,40 @@ public static void SetEntityDefaultValue(DbContext dbcontext)
prop.SetValue(entry.Entity, false);
break;
case "Char":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, '\0');
break;
case "SByte":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, (sbyte)0);
break;
case "Byte":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, (byte)0);
break;
case "Int16":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, (short)0);
break;
case "UInt16":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, (ushort)0);
break;
case "Int32":
prop.SetValue(entry.Entity, 0);
break;
case "UInt32":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, 0U);
break;
case "Int64":
prop.SetValue(entry.Entity, (Int64)0);
prop.SetValue(entry.Entity, 0L);
break;
case "UInt64":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, 0LU);
break;
case "Single":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, 0F);
break;
case "Double":
prop.SetValue(entry.Entity, 0);
prop.SetValue(entry.Entity, 0D);
break;
case "Decimal":
prop.SetValue(entry.Entity, (decimal)0);
prop.SetValue(entry.Entity, 0M);
break;
case "DateTime":
prop.SetValue(entry.Entity, GlobalConstant.DefaultTime);
Expand Down
2 changes: 1 addition & 1 deletion YiSha.Data/YiSha.Data.EF/YiSha.Data.EF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.120" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion YiSha.Data/YiSha.Data/YiSha.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="MySqlConnector" Version="2.3.1" />
<PackageReference Include="MySqlConnector" Version="2.3.7" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.120" />
</ItemGroup>

Expand Down

0 comments on commit 39bc711

Please sign in to comment.