public HttpResponseMessage get_deptinfo([FromUri] GetDeptInfoRequest request) { request.pageSize = request.pageSize ?? ConstKeys.DEFAULT_PAGEINDEX; //默认继承全局每页显示的记录数,后期可以改这个参数 request.pageIndex = request.pageIndex ?? 1; //页码,从1开始 var model = _deptInfoService.GetDeptInfo(request); var list = new PageList <DeptInfoResponse>() { PageIndex = request.pageIndex.Value, PageSize = request.pageIndex.Value, TotalCount = model.TotalCount, TotalPages = model.TotalPages, Data = model.ToList() }; return(toListJson(list, OperatingState.Success, "获取成功")); }
/// <summary> /// 根据条件获取组织架构信息 /// </summary> /// <param name="request"></param> /// <returns></returns> public IPagedList <DeptInfoResponse> GetDeptInfo(GetDeptInfoRequest request) { if (request == null) { return(new PagedList <DeptInfoResponse>(new List <DeptInfoResponse>(), 0, request.pageSize.Value)); } try { Expression <Func <DeptInfo, bool> > wheres = c => c.DeletedState != (int)DeletedStates.Deleted; if (request.Id != null) { wheres = wheres.And(c => c.Id == request.Id); } if (request.EnterpriseID != null) { var dbEnterpriseInfo = _enterpriseInfoRepository.GetById(request?.EnterpriseID); if (dbEnterpriseInfo == null || dbEnterpriseInfo.DeletedState == (int)DeletedStates.Deleted) { return(new PagedList <DeptInfoResponse>(new List <DeptInfoResponse>(), 0, request.pageSize.Value)); } wheres = wheres.And(c => c.EnterpriseID == request.EnterpriseID); } if (request.ParentID != null) { wheres = wheres.And(c => c.ParentID == request.ParentID); } var result = (from d in _deptInfoRepository.Table.Where(wheres) join e in _enterpriseInfoRepository.Table.Where(t => t.DeletedState != (int)DeletedStates.Deleted) on d.EnterpriseID equals e.Id into eList join u in _userInfoRepository.Table.Where(t => t.DeletedState != (int)DeletedStates.Deleted) on d.CreateUserId equals u.Id into uList join d1 in _deptInfoRepository.Table.Where(t => t.DeletedState != (int)DeletedStates.Deleted) on d.ParentID equals d1.Id into dList select new DeptInfoResponse { Id = d.Id, Name = d.Name, EnterpriseID = d.EnterpriseID, EnterpriseName = eList.Any() ? eList.FirstOrDefault().Name : "", ParentID = d.ParentID, ParentName = dList.Any() ? dList.FirstOrDefault().Name : "", CreateUserId = d.CreateUserId, UserName = uList.Any() ? uList.FirstOrDefault().ChsName : "", CreateTime = d.CreateTime, }).OrderByDescending(T => T.CreateTime).ToList(); if (!string.IsNullOrWhiteSpace(request.keyWord)) { result = (from p in result where (p.Name != null && p.Name.Contains(request.keyWord)) || (p.ParentName != null && p.ParentName.Contains(request.keyWord)) || (p.EnterpriseName != null && p.EnterpriseName.Contains(request.keyWord)) || (p.UserName != null && p.UserName.Contains(request.keyWord)) select p).ToList(); } if (result.Count > 0) { var qiniu = EngineContext.Current.Resolve <IQiniuService>(); result.ForEach(t => t.ImgUrl = qiniu.DownLoadPrivateUrl(t.ImgUrl)); } return(new PagedList <DeptInfoResponse>(result, request.pageIndex.Value - 1, request.pageSize.Value)); } catch (Exception ex) { //var logger = EngineContext.Current.Resolve<ILogger>(); //logger.Error(ex.Message, ex); return(new PagedList <DeptInfoResponse>(new List <DeptInfoResponse>(), 0, 0)); } }