/// <summary> /// 获取QuestionRecord的分页列表信息 ///</summary> /// <param name="input"></param> /// <returns></returns> public async Task <PagedResultDto <QuestionRecordListDto> > GetPaged(GetQuestionRecordsInput input) { var query = _entityRepository.GetAll() .WhereIf(input.Quarter.HasValue, i => i.Quarter == input.Quarter.Value); // TODO:根据传入的参数添加过滤条件 var count = await query.CountAsync(); var entityList = await query .OrderBy(q => q.IsPublish).AsNoTracking() .PageBy(input) .ToListAsync(); // var entityListDtos = ObjectMapper.Map<List<QuestionRecordListDto>>(entityList); var entityListDtos = entityList.MapTo <List <QuestionRecordListDto> >(); //后台拼接字符串 foreach (var item in entityListDtos) { item.QuarterString = item.Year + "年" + item.Quarter; } return(new PagedResultDto <QuestionRecordListDto>(count, entityListDtos)); }
/// <summary> /// 通过零售户Id查询零售户问卷填写记录 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <PagedResultDto <RetailQuestionRecordListDto> > GetPagedByRetailerId(GetQuestionRecordsInput input) { if (input.RetailerId.HasValue) { var openId = await _weChatRepository.GetAll().Where(i => i.UserId == input.RetailerId).Select(i => i.OpenId).FirstOrDefaultAsync(); var answerRecords = _answerRepository.GetAll().Where(i => i.OpenId == openId); var questionRecordIds = answerRecords.Select(i => i.QuestionRecordId).Distinct().ToList(); var query = _entityRepository.GetAll().WhereIf(!string.IsNullOrWhiteSpace(input.Title), i => i.Title.Contains(input.Title)).Where(i => questionRecordIds.Contains(i.Id)); var results = await(from r in query select new RetailQuestionRecordListDto { Id = r.Id, Title = r.Title, QuarterString = r.Year + "年" + r.Quarter, CreationTime = r.CreationTime }).OrderByDescending(i => i.CreationTime).PageBy(input).ToListAsync(); foreach (var result in results) { result.WriteTime = await _answerRepository.GetAll().Where(a => a.QuestionRecordId == result.Id).Select(i => i.CreationTime).OrderByDescending(i => i).FirstOrDefaultAsync(); } var count = results.Count(); return(new PagedResultDto <RetailQuestionRecordListDto>(count, results)); } return(null); }