public async Task <CommonSearchResponse <List <ArchivesSearchResult> > > SearchArchives(ArchivesSearchRequest request)
        {
            var response = new CommonSearchResponse <List <ArchivesSearchResult> >();

            try
            {
                var query = _db.ArchivesInfo.AsNoTracking().Where(c => !c.Deleted);
                if (!string.IsNullOrEmpty(request.Keyword))
                {
                    query = query.Where(c => c.Title.Contains(request.Keyword.Trim()) || c.ProjectName.Contains(request.Keyword.Trim()));
                }
                if (!string.IsNullOrEmpty(request.Label))
                {
                    var projectNames = request.Label.Split(',', StringSplitOptions.RemoveEmptyEntries);
                    query = query.Where(c => projectNames.Contains(c.ProjectName));
                }
                if (request.ShowBorrowed.HasValue)
                {
                    if (!request.ShowBorrowed.Value)
                    {
                        query = query.Where(c => c.Status != ArchivesStatus.Borrowed);
                    }
                }
                var list = await query.OrderBy(c => c.ArchivesNumber)
                           .Skip(request.PageNumber * request.PageSize)
                           .Take(request.PageSize)
                           .Select(c => new ArchivesSearchResult
                {
                    Id             = c.Id,
                    ArchivesNumber = c.ArchivesNumber,
                    CategoryId     = c.CategoryId,
                    FileNumber     = c.FileNumber,
                    ProjectName    = c.ProjectName,
                    Title          = c.Title,
                    OrderNumber    = c.OrderNumber,
                    Status         = c.Status,
                }).ToListAsync();

                var total = await query.CountAsync();

                response.Data       = list;
                response.TotalPage  = total.GetPages(request.PageSize);
                response.TotalCount = total;
                response.Success    = true;
                response.SEcho      = request.SEcho;
            }
            catch (Exception ex)
            {
                response.Message = "获取案档列表发生异常";
                ApplicationLog.Error("SearchArchives", ex);
            }

            return(response);
        }
Beispiel #2
0
        public async Task <CommonSearchResponse <List <SearchBorrowRegisterResult> > > SearchBorrowRegister(SearchBorrowRegisterRequest request)
        {
            var response = new CommonSearchResponse <List <SearchBorrowRegisterResult> >();

            try
            {
                var query = _db.BorrowRegister.AsNoTracking().Where(c => !c.Deleted);
                if (!request.ShowRegistered)
                {
                    query = query.Where(c => c.Status != BorrowRegisterStatus.Registered);
                }
                if (!string.IsNullOrEmpty(request.Keyword))
                {
                    query = query.Where(c => c.Phone.Contains(request.Keyword.Trim()) || c.Borrower.Contains(request.Keyword.Trim()) || c.Company.Contains(request.Keyword.Trim()) || c.Department.Contains(request.Keyword.Trim()));
                }
                if (request.StartDate.HasValue)
                {
                    query = query.Where(c => c.CreateTime > request.StartDate.Value);
                }
                if (request.EndDate.HasValue)
                {
                    query = query.Where(c => c.CreateTime < request.EndDate.Value.AddDays(1));
                }
                if (request.iSortCol_0 == "0")
                {
                    if (request.sSortDir_0 == "asc")
                    {
                        query = query.OrderBy(c => c.CreateTime);
                    }
                    else
                    {
                        query = query.OrderByDescending(c => c.CreateTime);
                    }
                }
                else if (request.iSortCol_0 == "5")
                {
                    if (request.sSortDir_0 == "asc")
                    {
                        query = query.OrderBy(c => c.ReturnDate);
                    }
                    else
                    {
                        query = query.OrderByDescending(c => c.ReturnDate);
                    }
                }
                else
                {
                    query = query.OrderByDescending(c => c.CreateTime);
                }
                var list = await query.Skip(request.PageNumber *request.PageSize)
                           .Take(request.PageSize)
                           .Select(c => new SearchBorrowRegisterResult
                {
                    Id            = c.Id,
                    Borrower      = c.Borrower,
                    Company       = c.Company,
                    Department    = c.Department,
                    Phone         = c.Phone,
                    ReturnDate    = c.ReturnDate,
                    SignPhoto     = c.SignPhoto,
                    Status        = c.Status,
                    CreateTime    = c.CreateTime,
                    CreateTimeStr = c.CreateTime.ToString("yyyy-MM-dd"),
                    Receiver      = c.Receiver,
                    Remark        = c.Remark
                }).ToListAsync();

                var ids = list.Select(c => c.Id);

                var archivesList = await _db.BorrowRegisterDetail.AsNoTracking().Where(brd => ids.Contains(brd.BorrowRegisterId)).ToListAsync();

                list.ForEach(c =>
                {
                    var arlist      = archivesList.Where(j => j.BorrowRegisterId == c.Id);
                    c.ArchivesStr   = string.Join(",", arlist.Select(j => $"{j.ArchivesNumber}/{j.CategoryNumber}/{j.FileNumber}/{j.OrderNumber}"));
                    c.ReturnDateStr = c.ReturnDate.ToString("yyyy-MM-dd");
                    c.ProjectName   = string.Join(",", arlist.Select(j => j.ProjectName));
                });

                var total = await query.CountAsync();

                response.Data       = list;
                response.TotalPage  = total.GetPages(request.PageSize);
                response.TotalCount = total;
                response.Success    = true;

                //response.Data = list;
                //response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = "获取借阅列表失败";
                ApplicationLog.Error("SearchBorrowRegister", ex);
            }

            return(response);
        }
        public async Task <CommonSearchResponse <List <SearchBorrowRegisterResult> > > SearchBorrowRegister(SearchBorrowRegisterRequest request)
        {
            var response = new CommonSearchResponse <List <SearchBorrowRegisterResult> >();

            try
            {
                var query = _db.BorrowRegister.AsNoTracking().Where(c => !c.Deleted);
                if (!string.IsNullOrEmpty(request.Keyword))
                {
                    query = query.Where(c => c.Phone.Contains(request.Keyword.Trim()) || c.Borrower.Contains(request.Keyword.Trim()) || c.Company.Contains(request.Keyword.Trim()) || c.Department.Contains(request.Keyword.Trim()));
                }
                var list = await query.OrderBy(c => c.Status).ThenBy(c => c.Id)
                           .Skip(request.PageNumber * request.PageSize)
                           .Take(request.PageSize)
                           .Select(c => new SearchBorrowRegisterResult
                {
                    Id            = c.Id,
                    Borrower      = c.Borrower,
                    Company       = c.Company,
                    Department    = c.Company,
                    Phone         = c.Phone,
                    ReturnDate    = c.ReturnDate,
                    SignPhoto     = c.SignPhoto,
                    Status        = c.Status,
                    CreateTime    = c.CreateTime,
                    CreateTimeStr = c.CreateTime.ToString("yyyy-MM-dd")
                }).ToListAsync();

                var ids = list.Select(c => c.Id);

                var archivesList = await(from brd in _db.BorrowRegisterDetail.AsNoTracking()
                                         join a in _db.ArchivesInfo.AsNoTracking() on brd.ArchivesId equals a.Id
                                         where ids.Contains(brd.BorrowRegisterId)
                                         select new ArchivesSimple
                {
                    BorrowRegisterId = brd.BorrowRegisterId,
                    ArchivesNumber   = a.ArchivesNumber,
                    CatalogNumber    = a.CatalogNumber,
                    CategoryId       = a.CategoryId,
                    FileNumber       = a.FileNumber,
                    OrderNumber      = a.OrderNumber
                }).ToListAsync();

                list.ForEach(c =>
                {
                    var arlist      = archivesList.Where(j => j.BorrowRegisterId == c.Id).ToList();
                    c.ArchivesList  = arlist;
                    c.ArchivesStr   = string.Join(",", arlist.Select(j => $"{j.ArchivesNumber}/{j.FileNumber}/{j.OrderNumber}"));
                    c.ReturnDateStr = c.ReturnDate.ToString("yyyy-MM-dd");
                });

                response.Data    = list;
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = "获取借阅列表失败";
                ApplicationLog.Error("SearchBorrowRegister", ex);
            }

            return(response);
        }