public async Task <PageResultModel <Letter> > GetManagerReceiveLetters(LetterPageSerchModel pageSearch)
        {
            var query = _dbContext.Letters.Include(a => a.SendDepartment).Include(a => a.ReceiveDepartment).Include(a => a.CreateUser).Where(a => a.LetterType == EnumLetterType.收信);

            if (pageSearch.BeginTime != null)
            {
                query = query.Where(a => a.CreateTime >= pageSearch.BeginTime.Value);
            }

            if (pageSearch.EndTime != null)
            {
                query = query.Where(a => a.CreateTime <= pageSearch.EndTime.Value);
            }

            if (!string.IsNullOrWhiteSpace(pageSearch.LetterNo))
            {
                query = query.Where(a => a.LetterNo.Contains(pageSearch.LetterNo));
            }

            if (pageSearch.SendDepartmentId != 0)
            {
                query = query.Where(a => a.SendDepartmentId == pageSearch.SendDepartmentId);
            }
            if (!string.IsNullOrWhiteSpace(pageSearch.ShiJiNo))
            {
                query = query.Where(a => a.ShiJiCode.Contains(pageSearch.ShiJiNo));
            }
            return(new PageResultModel <Letter>
            {
                Rows = await query.OrderByDescending(a => a.Id).Skip(pageSearch.Skip).Take(pageSearch.Take).ToListAsync(),
                Total = await query.CountAsync()
            });
        }
        public async Task <IActionResult> GetSearchList(int draw, int start, int length)
        {
            var pageSearchDto = new LetterPageSerchModel
            {
                Take = length,
                Skip = start
            };

            pageSearchDto.SetTimeValue(Request.Query["beginTime"], Request.Query["endTime"]);
            if (!string.IsNullOrWhiteSpace(Request.Query["sendDepartmentId"]))
            {
                pageSearchDto.SendDepartmentId = Convert.ToInt32(Request.Query["sendDepartmentId"]);
            }

            if (!string.IsNullOrWhiteSpace(Request.Query["receiveDepartmentId"]))
            {
                pageSearchDto.ReceiveDepartmentId = Convert.ToInt32(Request.Query["receiveDepartmentId"]);
            }

            pageSearchDto.ShiJiNo  = Request.Query["shiJiNo"];
            pageSearchDto.LetterNo = Request.Query["letterNo"];
            var pagereslut = await _letterAppService.GetSearchLetters(pageSearchDto);

            var json = new
            {
                draw,
                recordsTotal    = pagereslut.Total,
                recordsFiltered = pagereslut.Total,
                data            = pagereslut.Rows
            };

            return(Json(json));
        }
        public async Task <PageResultModel <Letter> > GetReceiveLetters(LetterPageSerchModel pageSearch)
        {
            //父级单位可以查询子单位的信件
            var query = _dbContext.Letters.Include(a => a.SendDepartment).Include(a => a.ReceiveDepartment)
                        .Include(a => a.CreateUser)
                        .Join(_dbContext.BarcodeLogs, l => l.ReceiveDepartmentId, bl => bl.DepartmentId, (l, bl) => new { l, bl })
                        .Where(a => a.bl.BarcodeStatus == EnumBarcodeStatus.已签收);

            if (pageSearch.BeginTime != null)
            {
                query = query.Where(a => a.bl.OperationTime >= pageSearch.BeginTime.Value);
            }

            if (pageSearch.EndTime != null)
            {
                query = query.Where(a => a.bl.OperationTime <= pageSearch.EndTime.Value);
            }

            if (!string.IsNullOrWhiteSpace(pageSearch.LetterNo))
            {
                query = query.Where(a => a.l.LetterNo.Contains(pageSearch.LetterNo));
            }

            if (pageSearch.SendDepartmentId != 0)
            {
                query = query.Where(a => a.l.SendDepartmentId == pageSearch.SendDepartmentId);
            }
            if (!string.IsNullOrWhiteSpace(pageSearch.ShiJiNo))
            {
                query = query.Where(a => a.l.ShiJiCode.Contains(pageSearch.ShiJiNo));
            }
            var newQuery = query.Select(a => a.l);

            return(new PageResultModel <Letter>
            {
                Rows = await newQuery.Skip(pageSearch.Skip).Take(pageSearch.Take).ToListAsync(),
                Total = await newQuery.CountAsync()
            });
        }
        public async Task <PageResultModel <LetterSendListDto> > GetSendLetters(LetterPageSerchModel pageSearchModel)
        {
            var letters = await _letterRepository.GetSendLetters(pageSearchModel);

            return(Mapper.Map <PageResultModel <LetterSendListDto> >(letters));
        }
        public async Task <PageResultModel <LetterReceiveListDto> > GetReceiveLetters(LetterPageSerchModel pageSearchModel)
        {
            PageResultModel <Letter> letters;

            if (_commonSettings.Value.ReceiveDepartmentId == pageSearchModel.ReceiveDepartmentId)
            {
                letters = await _letterRepository.GetManagerReceiveLetters(pageSearchModel);
            }
            else
            {
                letters = await _letterRepository.GetReceiveLetters(pageSearchModel);
            }

            return(Mapper.Map <PageResultModel <LetterReceiveListDto> >(letters));
        }