Skip to content

Commit

Permalink
fix:liukuo362573#170,modify for dynamic GetExpressionItems and add co…
Browse files Browse the repository at this point in the history
…de for expression
  • Loading branch information
bingtianyiyan committed Jun 22, 2024
1 parent 54a935b commit 5384454
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public async Task<TData<List<DepartmentEntity>>> GetList(DepartmentListParam par
List<UserEntity> userList = new List<UserEntity>();
if (obj.Data.Count > 0)
{
var userIdsArr = obj.Data.Where(p => p.PrincipalId > 0).Select(p => p.PrincipalId).ToArray();
if (userIdsArr.Length > 0)
var userIdsArr = obj.Data.Where(p => p.PrincipalId > 0).Select(p => p.PrincipalId.Value);
if (userIdsArr.Count() > 0)
{
userList = await userService.GetList(new UserListParam { UserIds = string.Join(",", userIdsArr) });
userList = await userService.GetList(new UserListParam { UserIds = userIdsArr.ToArray() });
}
}
foreach (DepartmentEntity entity in obj.Data)
Expand Down
88 changes: 48 additions & 40 deletions YiSha.Business/YiSha.Service/OrganizationManage/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,50 +166,58 @@ public async Task ChangeUser(UserEntity entity)
#region 私有方法
private Expression<Func<UserEntity, bool>> ListFilter(UserListParam param)
{
//****根据查询字段自动过滤条件****
var expression = LinqExtensions.GetExpressionItems<UserEntity,UserListParam>(param);

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


if (!string.IsNullOrEmpty(param.UserIds))
if (!string.IsNullOrEmpty(param.EndTime.ParseToString()))
{
long[] userIdList = TextHelper.SplitToArray<long>(param.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.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));
param.EndTime = param.EndTime.Value.Date.Add(new TimeSpan(23, 59, 59));
}
}
//****根据查询字段自动过滤条件****
var expression = LinqExtensions.GetExpressionItems<UserEntity,UserListParam>(param);

//if (param != null)
//{
// //if (param.UserStatus == -1)
// //{
// // param.UserStatus = null;
// //}

// //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(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));
// //}
//}
return expression;
}
#endregion
Expand Down
8 changes: 4 additions & 4 deletions YiSha.Entity/YiSha.Model/Param/DateTimeParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class DateTimeParam
/// <summary>
/// 搜索条件开始时间
/// </summary>
[LinqExpressionXAttribute(Name = "BaseModifyTime")]
public DateTime? StartTime { get; set; }
[QueryCompareAttribute(FieldName = "BaseModifyTime",Compare =CompareEnum.GreaterThanOrEquals)]
public virtual DateTime? StartTime { get; set; }

/// <summary>
/// 搜索条件结束时间
/// </summary>
[LinqExpressionXAttribute(Name = "BaseModifyTime")]
public DateTime? EndTime { get; set; }
[QueryCompareAttribute(FieldName = "BaseModifyTime", Compare = CompareEnum.LessThanOrEquals)]
public virtual DateTime? EndTime { get; set; }
}
}
10 changes: 5 additions & 5 deletions YiSha.Entity/YiSha.Model/Param/OrganizationManage/UserParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ namespace YiSha.Model.Param.OrganizationManage
public class UserListParam : DateTimeParam
{
public string UserName { get; set; }

[QueryCompareAttribute(Compare = CompareEnum.Equals)]
public string Mobile { get; set; }

[QueryCompareAttribute(Compare = CompareEnum.Equals)]
public int? UserStatus { get; set; }

public long? DepartmentId { get; set; }
[LinqExpressionXAttribute(IsIgnore = true)]
[QueryCompareAttribute(FieldName = "DepartmentId", Compare = CompareEnum.In)]
public List<long> ChildrenDepartmentIdList { get; set; }
[LinqExpressionXAttribute(IsIgnore = true)]
public string UserIds { get; set; }
[QueryCompareAttribute(FieldName ="Id",Compare = CompareEnum.In)]
public long[] UserIds { get; set; }
}

public class ChangePasswordParam
Expand Down
Loading

0 comments on commit 5384454

Please sign in to comment.