导出班级学员成绩

This commit is contained in:
wuchunlei
2025-05-06 14:11:39 +08:00
parent f0202bbc47
commit dab1ae8202
2 changed files with 157 additions and 0 deletions

View File

@@ -17,6 +17,9 @@ import com.peanut.modules.medical.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.transaction.annotation.Transactional;
@@ -25,8 +28,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -395,6 +402,65 @@ public class ClassController {
return R.ok().put("result",classEntityService.userScoreList(params));
}
//导出学员成绩
@RequestMapping("/exportUserScore")
public void exportUserScore(HttpServletResponse response,@RequestBody Map<String,Object> params){
List<Map<String,Object>> userScoreList = classEntityService.userScoreList(params);
XSSFWorkbook wb = new XSSFWorkbook();
//创建一张表
Sheet sheet = wb.createSheet("Student");
//创建第一行起始为0
Row titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("姓名");
titleRow.createCell(1).setCellValue("电话");
titleRow.createCell(2).setCellValue("邮箱");
titleRow.createCell(3).setCellValue("任务");
titleRow.createCell(4).setCellValue("医案");
titleRow.createCell(5).setCellValue("心得");
titleRow.createCell(6).setCellValue("思考题");
titleRow.createCell(7).setCellValue("考试");
titleRow.createCell(8).setCellValue("总成绩");
//序号默认为1
int cell = 1;
//遍历
for (Map<String,Object> map : userScoreList) {
Row row = sheet.createRow(cell);
MyUserEntity user = (MyUserEntity)map.get("user");
row.createCell(0).setCellValue(user.getName());
row.createCell(1).setCellValue(user.getTel());
row.createCell(2).setCellValue(user.getEmail());
row.createCell(3).setCellValue(map.get("task0Score").toString());
row.createCell(4).setCellValue(map.get("task1Score").toString());
row.createCell(5).setCellValue(map.get("experienceScore").toString());
row.createCell(6).setCellValue(map.get("questionScore").toString());
row.createCell(7).setCellValue(map.get("examScore").toString());
row.createCell(8).setCellValue(map.get("userScore").toString());
//序号自增
cell++;
}
String fileName = "学生成绩.xlsx";
OutputStream outputStream =null;
try {
//文件名编码格式
fileName = URLEncoder.encode(fileName,"UTF-8");
//设置ContentType请求信息格式
response.setContentType("application/vnd.ms-excel");
//设置标头
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
outputStream = response.getOutputStream();
wb.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//结班
@RequestMapping("/closeClass")
@Transactional