/// <summary> /// 查询列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <List <GetStudentByIdDto> > QueryStudentsByClassNo(GetStudentByIdInput input) { var students = _IStudentRepository.FindList(null, true).ToList(); if (input.ClassNo > 0) { students = _IStudentRepository.FindList(t => t.ClassNo == input.ClassNo, true).ToList(); } var list = students.MapTo <Tb_Student, GetStudentByIdDto>(); return(await Task.FromResult(list)); }
public async Task <List <GetStudentByIdDto> > QuerysByClassNo(GetStudentByIdInput input) { var key = "QuerysByClassNo-" + input.ClassNo; if (MemoryCacheHelper.Exists(key)) { var list = MemoryCacheHelper.Get(key); return((List <GetStudentByIdDto>)list); } else { var students = await _studentService.QueryStudentsByClassNo(input); MemoryCacheHelper.Set(key, students, TimeSpan.FromMinutes(1)); return(students); } }
public IActionResult DownloadOrders() { var input = new GetStudentByIdInput(); var list = _studentService.QueryStudentsByClassNo(input).Result; var path = "./UploadFile/Export/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path += "student.xlsx"; using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write)) { IWorkbook workbook = new XSSFWorkbook(); var sheet = workbook.CreateSheet("orders"); var header = sheet.CreateRow(0); header.CreateCell(0).SetCellValue("ID"); header.CreateCell(1).SetCellValue("Name"); header.CreateCell(2).SetCellValue("CreateTime"); var index = 1; foreach (var item in list) { var datarow = sheet.CreateRow(index); datarow.CreateCell(0).SetCellValue(item.ID); datarow.CreateCell(1).SetCellValue(item.Name); datarow.CreateCell(2).SetCellValue(item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")); index++; } workbook.Write(fs); } var memory = new MemoryStream(); using (var stream = new FileStream(path, FileMode.Open)) { stream.CopyTo(memory); } memory.Position = 0; return(File(memory, "application/vnd.ms-excel", "order.xlsx")); }