public async Task <IActionResult> GetCheckLetters(int draw, int start, int length, string deviceCode, DateTime beginTime, DateTime endTime) { var client = await _clientAppService.GetClient(deviceCode); var pageSearchDto = new PageSearchDetailModel { Take = length, Skip = start, UserId = CurrentUser.UserId, PlaceId = client.PlaceId, BeginTime = beginTime, EndTime = endTime }; var pagereslut = await _letterAppService.GetCheckLetters(pageSearchDto); var json = new { draw, recordsTotal = pagereslut.Total, recordsFiltered = pagereslut.Total, data = pagereslut.Rows }; return(Json(json)); }
public async Task <PageResultModel <LetterCheckListDto> > GetCheckLetters(PageSearchDetailModel pageSearch) { IQueryable <Letter> letters; var managePlace = await _placeWardenRepository.GetQueryable().FirstOrDefaultAsync(a => a.UserId == pageSearch.UserId); var place = await _placeRepository.GetQueryable().Include(a => a.Parent).FirstOrDefaultAsync(a => a.Id == pageSearch.PlaceId); if (managePlace.PlaceId == pageSearch.PlaceId) { var objectIds = await _objectSignerRepository.GetQueryable().Where(a => a.UserId == pageSearch.UserId) .Select(a => a.ExchangeObjectId).ToListAsync(); var receiveLogs = await _barcodeLogRepository.GetQueryable().Where(a => a.BarcodeStatus == EnumBarcodeStatus.已签收 && a.CurrentPlaceId == place.ParentId && a.OperationTime.Date >= pageSearch.BeginTime.Value.Date && a.OperationTime.Date <= pageSearch.EndTime.Value.Date && objectIds.Contains(a.CurrentObjectId)).Select(a => a.BarcodeNumber) .ToListAsync(); var sendLogs = await _barcodeLogRepository.GetQueryable().Where(a => a.BarcodeStatus == EnumBarcodeStatus.已投递 && a.CurrentPlaceId == pageSearch.PlaceId && a.OperationTime.Date >= pageSearch.BeginTime.Value.Date && a.OperationTime.Date <= pageSearch.EndTime.Value.Date && receiveLogs.Contains(a.BarcodeNumber)).Select(a => a.BarcodeNumber).ToListAsync(); var differentBarcodeNumbers = (from receive in receiveLogs select receive).Except (from send in sendLogs select send).ToList(); letters = _letterRepository.GetQueryable().Where(a => differentBarcodeNumbers.Contains(a.BarcodeNo)).OrderBy(a => a.Id); } else { var insideObjects = await _exchangeObjectRepository.GetQueryable() .Where(a => a.ObjectType == EnumObjectType.道).Select(a => a.Id).ToListAsync(); var receiveLogs = await _barcodeLogRepository.GetQueryable().Where(a => a.BarcodeStatus == EnumBarcodeStatus.已签收 && a.CurrentPlaceId == managePlace.PlaceId && a.OperationTime.Date >= pageSearch.BeginTime.Value.Date && a.OperationTime.Date <= pageSearch.EndTime.Value.Date && insideObjects.Contains(a.CurrentObjectId)).Select(a => a.BarcodeNumber) .ToListAsync(); var sendLogs = await _barcodeLogRepository.GetQueryable().Where(a => a.BarcodeStatus == EnumBarcodeStatus.已投递 && a.CurrentPlaceId == pageSearch.PlaceId && a.OperationTime.Date >= pageSearch.BeginTime.Value.Date && a.OperationTime.Date <= pageSearch.EndTime.Value.Date && receiveLogs.Contains(a.BarcodeNumber)).ToListAsync(); var differentBarcodeNumbers = (from receive in receiveLogs select receive).Except (from send in sendLogs select send.BarcodeNumber).ToList(); letters = _letterRepository.GetQueryable().Where(a => differentBarcodeNumbers.Contains(a.BarcodeNo)).OrderBy(a => a.Id); } var pageLetters = new PageResultModel <Letter> { Rows = await letters.Skip(pageSearch.Skip).Take(pageSearch.Take).ToListAsync(), Total = await letters.CountAsync() }; return(Mapper.Map <PageResultModel <LetterCheckListDto> >(pageLetters)); }