Skip to content

Commit

Permalink
fix:liukuo362573#170 for query bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bingtianyiyan committed Jun 19, 2024
1 parent 6623717 commit 54a935b
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 130 deletions.
13 changes: 11 additions & 2 deletions YiSha.Business/YiSha.Business/OrganizationManage/DepartmentBLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using YiSha.Util.Model;
using YiSha.Util.Extension;
using YiSha.Web.Code;
using NPOI.SS.Formula.Functions;

namespace YiSha.Business.OrganizationManage
{
Expand All @@ -32,10 +33,18 @@ public async Task<TData<List<DepartmentEntity>>> GetList(DepartmentListParam par
List<long> childrenDepartmentIdList = await GetChildrenDepartmentIdList(obj.Data, operatorInfo.DepartmentId.Value);
obj.Data = obj.Data.Where(p => childrenDepartmentIdList.Contains(p.Id.Value)).ToList();
}
List<UserEntity> userList = await userService.GetList(new UserListParam { UserIds = string.Join(",", obj.Data.Select(p => p.PrincipalId).ToArray()) });
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)
{
userList = await userService.GetList(new UserListParam { UserIds = string.Join(",", userIdsArr) });
}
}
foreach (DepartmentEntity entity in obj.Data)
{
if (entity.PrincipalId > 0)
if (entity.PrincipalId > 0 && userList.Count > 0 )
{
entity.PrincipalName = userList.Where(p => p.Id == entity.PrincipalId).Select(p => p.RealName).FirstOrDefault();
}
Expand Down
30 changes: 13 additions & 17 deletions YiSha.Business/YiSha.Service/OrganizationManage/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,15 @@ public async Task ChangeUser(UserEntity entity)
#region 私有方法
private Expression<Func<UserEntity, bool>> ListFilter(UserListParam param)
{

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

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

//****根据查询字段自动过滤条件****
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));
Expand All @@ -200,15 +196,15 @@ private Expression<Func<UserEntity, bool>> ListFilter(UserListParam param)
// 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 (!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));
Expand Down
3 changes: 3 additions & 0 deletions YiSha.Entity/YiSha.Model/Param/DateTimeParam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiSha.Util.Extension;

namespace YiSha.Model.Param
{
Expand All @@ -11,11 +12,13 @@ public class DateTimeParam
/// <summary>
/// 搜索条件开始时间
/// </summary>
[LinqExpressionXAttribute(Name = "BaseModifyTime")]
public DateTime? StartTime { get; set; }

/// <summary>
/// 搜索条件结束时间
/// </summary>
[LinqExpressionXAttribute(Name = "BaseModifyTime")]
public DateTime? EndTime { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using YiSha.Entity.OrganizationManage;
using YiSha.Util.Extension;

namespace YiSha.Model.Param.OrganizationManage
{
Expand All @@ -13,9 +14,9 @@ public class UserListParam : DateTimeParam
public int? UserStatus { get; set; }

public long? DepartmentId { get; set; }

[LinqExpressionXAttribute(IsIgnore = true)]
public List<long> ChildrenDepartmentIdList { get; set; }

[LinqExpressionXAttribute(IsIgnore = true)]
public string UserIds { get; set; }
}

Expand Down
Loading

0 comments on commit 54a935b

Please sign in to comment.