From c99d1dba9c4c575e092891b2e79e1a4460e65212 Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Tue, 10 Dec 2024 17:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=80=83=E8=AF=95=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../financial_bigdata/config/Constant.java | 2 +- .../controller/stu/StuKnowledgeNote.java | 4 + .../tea/TeaGradeManageController.java | 42 +++-- .../financial_bigdata/entity/ExcelDto.java | 37 ++++ .../service/stu/impl/StuScoreServiceImpl.java | 10 + .../service/tea/ITeaGradeManageService.java | 2 + .../tea/impl/TeaGradeManageServiceImpl.java | 173 ++++++++++++++++++ .../util/excel/FilePortUtil.java | 79 +++++++- src/main/resources/mapper/StuUserMapper.xml | 4 +- 9 files changed, 334 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/sztzjy/financial_bigdata/entity/ExcelDto.java diff --git a/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java b/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java index 5b864c4..bb83d7c 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java +++ b/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java @@ -38,6 +38,6 @@ public class Constant { public static final String THEORY = "理论考试模块"; public static final String RESOURCE = "资源中心模块"; public static final String API_URL = "http://120.79.54.255:8889"; -// public static final String API_URL = "http://192.168.2.44:8889"; +// public static final String API_URL = "http://192.168.2.25:8889"; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuKnowledgeNote.java b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuKnowledgeNote.java index c125bac..a5c4efc 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuKnowledgeNote.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuKnowledgeNote.java @@ -165,6 +165,10 @@ public class StuKnowledgeNote { stuTraining.setTrainingId(uuid); stuTraining.setChapterId(chapterId); stuTraining.setUserId(userId); + stuTraining.setKnowledgeSummaryScore(BigDecimal.ZERO); + stuTraining.setResourceLearningScore(BigDecimal.ZERO); + stuTraining.setCaseStuScore(BigDecimal.ZERO); + stuTraining.setLearningEvalScore(BigDecimal.ZERO); stuTrainingMapper.insert(stuTraining); return new ResultEntity<>(uuid); } else { diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java index d9633e4..7bf3c74 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaGradeManageController.java @@ -78,6 +78,8 @@ public class TeaGradeManageController { private StuTrainingMapper stuTrainingMapper; @Autowired StuScoreService stuScoreService; + @Value("${file.path}") + private String filePath; @AnonymousAccess @@ -113,7 +115,7 @@ public class TeaGradeManageController { String userId = teaExamManage.getUserId(); StuUser stuUser = userMap.get(userId); - if (stuUser==null){ + if (stuUser == null) { continue; } copyexamManageWithBLOBs.setName(stuUser.getName()); //发布人 @@ -476,11 +478,21 @@ public class TeaGradeManageController { @RequestParam String schoolId, @RequestParam String systemOwner) { try { - iTeaGradeManageService.exportTrainingDetailsInfo(response, userId,schoolId,systemOwner); + iTeaGradeManageService.exportTrainingDetailsInfo(response, userId, schoolId, systemOwner); } catch (IOException e) { e.printStackTrace(); } + } + + //todo 新增的导出 + @AnonymousAccess + @GetMapping("/exportAllStuTrainingInfo") + @ApiOperation("***练习模式--页面导出") + public void exportAllStuTrainingInfo(HttpServletResponse response, + @RequestParam String schoolId, + @RequestParam String systemOwner) throws IOException { + iTeaGradeManageService.exportAllStuTrainingInfo(response, schoolId, systemOwner); } @@ -543,9 +555,6 @@ public class TeaGradeManageController { } - @Value("${file.path}") - private String filePath; - @GetMapping("/getReportByReportId") @ApiOperation("评阅--获取单个学生报告接口") @AnonymousAccess @@ -649,7 +658,7 @@ public class TeaGradeManageController { @ApiParam("不选择班级就是学习全部导出") @RequestParam(required = false) String classId, @RequestParam String schoolId, @RequestParam String systemOwner) { - iTeaGradeManageService.exportTheoryExamInfo(response, classId, schoolId,systemOwner); + iTeaGradeManageService.exportTheoryExamInfo(response, classId, schoolId, systemOwner); } @@ -701,28 +710,35 @@ public class TeaGradeManageController { @PostMapping("getScoreInfo") public ResultEntity> getScoreInfo(@RequestParam String userId, @RequestParam String schoolId, - @RequestParam String systemOwner) { + @RequestParam String systemOwner) throws IOException { List list = new ArrayList<>(); + List sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner,schoolId); + + ListallChapterId =new ArrayList<>(); + for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) { + List sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId); + allChapterId.addAll(sysThreeCatalogs); + } + StuTrainingExample stuTrainingExample = new StuTrainingExample(); stuTrainingExample.createCriteria().andUserIdEqualTo(userId); List stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample); - Map chapterMap = new HashMap<>(); + Map chapterIds = allChapterId.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, sysThreeCatalog -> sysThreeCatalog)); try { for (StuTrainingWithBLOBs stuTraining : stuTrainings) { String chapterId = stuTraining.getChapterId(); - SysThreeCatalog sysCourseChapter = chapterMap.get(chapterId); - if (sysCourseChapter == null) { - sysCourseChapter = CourseAPI.selectChapterByChapterId(chapterId); - chapterMap.put(chapterId, sysCourseChapter); + SysThreeCatalog sysCourseChapter = chapterIds.get(chapterId); + if (sysCourseChapter==null){ + continue; } StuTrainingDto stuTrainingDto = new StuTrainingDto(); stuTrainingDto.setTaskModule(sysCourseChapter.getThreeName()); list.add(stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, stuTrainingDto, sysCourseChapter)); } - } catch (IOException e) { + } catch (Exception e) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "资源中心根据章节ID查询章节信息失败"); } return new ResultEntity<>(list); diff --git a/src/main/java/com/sztzjy/financial_bigdata/entity/ExcelDto.java b/src/main/java/com/sztzjy/financial_bigdata/entity/ExcelDto.java new file mode 100644 index 0000000..18c879b --- /dev/null +++ b/src/main/java/com/sztzjy/financial_bigdata/entity/ExcelDto.java @@ -0,0 +1,37 @@ +package com.sztzjy.financial_bigdata.entity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +/** + * @Author xcj + * @Date 2024/12/10 + */ +@Data +@NoArgsConstructor +public class ExcelDto { + @ApiModelProperty("排名") + private int rank; + + @ApiModelProperty("姓名") + private String name; + + @ApiModelProperty("学号") + private String studentId; + + @ApiModelProperty("班级名称") + private String className; + + @ApiModelProperty("综合得分") + private BigDecimal totalScore; + + @ApiModelProperty("实训进度") + private BigDecimal progress; + + private Mapmap; +} diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/StuScoreServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/StuScoreServiceImpl.java index a8732d4..a4166a0 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/StuScoreServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/StuScoreServiceImpl.java @@ -149,18 +149,28 @@ public class StuScoreServiceImpl implements StuScoreService { BigDecimal totalScore = BigDecimal.ZERO; if (stuTrainingDto.getKnowledgeSummaryScore() != null) { totalScore = totalScore.add(stuTrainingDto.getKnowledgeSummaryScore()); + }else { + stuTrainingDto.setKnowledgeSummaryScore(BigDecimal.ZERO); } if (stuTrainingDto.getResourceLearningScore() != null) { totalScore = totalScore.add(stuTrainingDto.getResourceLearningScore()); + }else { + stuTrainingDto.setResourceLearningScore(BigDecimal.ZERO); } if (stuTrainingDto.getLearningEvalScore() != null) { totalScore = totalScore.add(stuTrainingDto.getLearningEvalScore()); + }else { + stuTrainingDto.setLearningEvalScore(BigDecimal.ZERO); } if (stuTrainingDto.getCaseStuScore() != null) { totalScore = totalScore.add(stuTrainingDto.getCaseStuScore()); + }else { + stuTrainingDto.setCaseStuScore(BigDecimal.ZERO); } if (stuTrainingDto.getReportScore() != null) { totalScore = totalScore.add(stuTrainingDto.getReportScore()); + }else { + stuTrainingDto.setReportScore(BigDecimal.ZERO); } stuTrainingDto.setModuleScore(totalScore); } diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/tea/ITeaGradeManageService.java b/src/main/java/com/sztzjy/financial_bigdata/service/tea/ITeaGradeManageService.java index c172e7f..80277bd 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/tea/ITeaGradeManageService.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/tea/ITeaGradeManageService.java @@ -34,4 +34,6 @@ public interface ITeaGradeManageService { void exportTheoryExamInfo(HttpServletResponse response, String classId, String schoolId,String systemOwner); SysWeight getSysWeightResultEntity(String courseId, String schoolId, String systemOwner); + + void exportAllStuTrainingInfo(HttpServletResponse response, String schoolId, String systemOwner) throws IOException; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java index 52ac944..9858810 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaGradeManageServiceImpl.java @@ -6,6 +6,7 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.financial_bigdata.entity.*; import com.sztzjy.financial_bigdata.entity.resource_entity.SysThreeCatalog; +import com.sztzjy.financial_bigdata.entity.resource_entity.SysTwoCatalog; import com.sztzjy.financial_bigdata.entity.stu_dto.StuTrainingDto; import com.sztzjy.financial_bigdata.entity.stu_dto.StuUserDto; import com.sztzjy.financial_bigdata.entity.tea_dto.StuTheoryRecordDto; @@ -27,6 +28,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -74,6 +76,105 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { return list; } + private List getTrainingInfoDTOSNew(String schoolId, String systemOwner) { + List list = getTeaTrainingInfoDTOSNew(schoolId, systemOwner); + assert !Objects.requireNonNull(list).isEmpty(); + list.sort(new TotalScoreComparator()); + int i = 0; + for (TeaTrainingInfoDTO teaTrainingInfoDTO : list) { + i++; + teaTrainingInfoDTO.setRank(i); + } + return list; + } + + + private List getTeaTrainingInfoDTOSNew(String schoolId, String systemOwner) { + StuUserExample example1 = new StuUserExample(); + example1.createCriteria().andSchoolIdEqualTo(schoolId).andSystemOnwerEqualTo(systemOwner).andRoleIdEqualTo(4); + List stuUsers = userMapper.selectByExample(example1); + + // 查询学生用户列表 + if (stuUsers.isEmpty()) { + return Collections.emptyList(); + } + + // 批量获取班级信息 + Set classIds = stuUsers.stream().map(StuUser::getClassId).collect(Collectors.toSet()); + + StuClassExample example = new StuClassExample(); + List IDlist = new ArrayList<>(classIds); + example.createCriteria().andClassIdIn(IDlist).andSystemOwnerEqualTo(systemOwner); + + List stuClasses = classMapper.selectByExample(example); + Map classIdToNameMap = stuClasses.stream().collect(Collectors.toMap(StuClass::getClassId, StuClass::getClassName)); + + // 批量获取实训记录 + Set userIds = stuUsers.stream().map(StuUser::getUserid).collect(Collectors.toSet()); + StuTrainingExample stuTrainingExample = new StuTrainingExample(); + stuTrainingExample.createCriteria().andUserIdIn(new ArrayList<>(userIds)); + List stuTrainingsWithBLOBs = trainingMapper.selectByExampleWithBLOBs(stuTrainingExample); + if (stuTrainingsWithBLOBs.isEmpty()) { + return Collections.emptyList(); + } + // 实训记录按用户ID分组 + Map> userIdToTrainingsMap = stuTrainingsWithBLOBs.stream().collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId)); + + // 批量获取报告分数 + Set reportIds = stuTrainingsWithBLOBs.stream().map(StuTrainingWithBLOBs::getReportId).collect(Collectors.toSet()); + List trainingReports = trainingReportMapper.selectByPrimaryKeys(reportIds); + Map reportIdToScoreMap = trainingReports.stream().collect(Collectors.toMap(TrainingReport::getReportId, TrainingReport::getTeacherScore)); + // 获取总模块数量 + BigDecimal chapterNum = null; + try { + chapterNum = BigDecimal.valueOf(CourseAPI.getTotalChapterCount(systemOwner)); + } catch (IOException e) { + return null; + } + + // 遍历用户,计算分数并封装DTO + List list = new ArrayList<>(); + for (StuUser stuUser : stuUsers) { + List userTrainings = userIdToTrainingsMap.getOrDefault(stuUser.getUserid(), Collections.emptyList()); + if (userTrainings.isEmpty()) { + continue; + } + + TeaTrainingInfoDTO teaTrainingInfoDTO = new TeaTrainingInfoDTO(); + teaTrainingInfoDTO.setClassName(classIdToNameMap.get(stuUser.getClassId())); + teaTrainingInfoDTO.setStudentId(stuUser.getStudentId()); + teaTrainingInfoDTO.setName(stuUser.getName()); + teaTrainingInfoDTO.setUserId(stuUser.getUserid()); + + BigDecimal allProgress = BigDecimal.ZERO; + BigDecimal totalScore = BigDecimal.ZERO; + for (StuTrainingWithBLOBs training : userTrainings) { + allProgress = allProgress.add(Optional.ofNullable(training.getProgress()).orElse(BigDecimal.ZERO)); + String reportId = training.getReportId(); + if (reportId != null) { + BigDecimal reportScore = reportIdToScoreMap.getOrDefault(reportId, BigDecimal.ZERO); + if (BigDecimal.ZERO.compareTo(reportScore) != 0) { + totalScore = totalScore.add(reportScore); + } + } + // 省略其他分数加法代码 + } + + BigDecimal score = totalScore; + if (totalScore.compareTo(BigDecimal.ZERO) > 0) { + score = totalScore.divide(chapterNum, 2, RoundingMode.HALF_UP); + } + teaTrainingInfoDTO.setTotalScore(score); + + BigDecimal progress = allProgress.divide(BigDecimal.valueOf(userTrainings.size()), 2, RoundingMode.HALF_UP); + teaTrainingInfoDTO.setProgress(progress); + + list.add(teaTrainingInfoDTO); + } + + return list; + } + /** * 进度字段类型为int 无法添加‘%’ @@ -362,6 +463,78 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } + //todo 新的导出 + @Override + public void exportAllStuTrainingInfo(HttpServletResponse response, String schoolId, String systemOwner) throws IOException { + List trainingInfoDTOSNew = getTrainingInfoDTOSNew(schoolId, systemOwner); + List sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner,schoolId); + ListallChapterId =new ArrayList<>(); + for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) { + List sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId); + allChapterId.addAll(sysThreeCatalogs); + } + Map chapterIds = allChapterId.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, sysThreeCatalog -> sysThreeCatalog)); + List excelDtos = new ArrayList<>(); + + for (TeaTrainingInfoDTO teaTrainingInfoDTO : trainingInfoDTOSNew) { + ExcelDto excelDto = new ExcelDto(); + excelDto.setProgress(teaTrainingInfoDTO.getProgress()); + excelDto.setName(teaTrainingInfoDTO.getName()); + excelDto.setStudentId(teaTrainingInfoDTO.getStudentId()); + excelDto.setRank(teaTrainingInfoDTO.getRank()); + excelDto.setTotalScore(teaTrainingInfoDTO.getTotalScore()); + + String userId = teaTrainingInfoDTO.getUserId(); + StuTrainingExample stuTrainingExample = new StuTrainingExample(); + stuTrainingExample.createCriteria().andUserIdEqualTo(userId); + List stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample); + + LinkedHashMapmap =new LinkedHashMap<>(); + LinkedHashMap chapterMap = new LinkedHashMap<>(); + + for (StuTrainingWithBLOBs stuTraining : stuTrainings) { + String chapterId = stuTraining.getChapterId(); + SysThreeCatalog sysCourseChapter = chapterMap.get(chapterId); + if (sysCourseChapter == null) { + sysCourseChapter = CourseAPI.selectChapterByChapterId(chapterId); + chapterMap.put(chapterId, sysCourseChapter); + } + StuTrainingDto stuTrainingDto = new StuTrainingDto(); + stuTrainingDto.setTaskModule(sysCourseChapter.getThreeName()); + + StuTrainingDto scoreByChapterId = stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, stuTrainingDto, sysCourseChapter); + + BigDecimal moduleScore = scoreByChapterId.getModuleScore(); + String taskModule = scoreByChapterId.getTaskModule(); + map.put(taskModule,moduleScore); + } + excelDto.setMap(map); + excelDtos.add(excelDto); + } + + //导出的表名 + String title = IdUtil.simpleUUID(); + //表中第一行表头字段 + String[] headers = {"排名", "姓名", "学号", "班级名称", "综合得分", "实训进度"}; + + List headerList = new ArrayList<>(Arrays.asList(headers)); // 将headers数组转换为List + for (Map.Entry stringBigDecimalEntry : chapterIds.entrySet()) { + String name = stringBigDecimalEntry.getValue().getThreeName(); + headerList.add(name); + } + headers = headerList.toArray(new String[0]); // 将List转回数组 + + //具体需要写入excel需要哪些字段,这些字段取自UserReward类,也就是上面的实际数据结果集的泛型 + List listColumn = Arrays.asList("rank", "name", "studentId", "className", "totalScore", "progress"); + try { + FilePortUtil.exportExcelNew(response, title, headers, excelDtos, listColumn); + } catch ( + Exception e) { + e.printStackTrace(); + } + } + + private List getTeaTrainingInfoDTOS(String schoolId, String keyWord, String classId, String systemOwner) { List stuUsers = userMapper.getByNameAndStudentID(schoolId, keyWord, classId, systemOwner); diff --git a/src/main/java/com/sztzjy/financial_bigdata/util/excel/FilePortUtil.java b/src/main/java/com/sztzjy/financial_bigdata/util/excel/FilePortUtil.java index cc80810..6f1c2c6 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/util/excel/FilePortUtil.java +++ b/src/main/java/com/sztzjy/financial_bigdata/util/excel/FilePortUtil.java @@ -3,6 +3,7 @@ package com.sztzjy.financial_bigdata.util.excel; import com.github.xiaoymin.knife4j.core.util.CollectionUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.poi.hssf.usermodel.*; +import org.geolatte.geom.M; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,9 +11,8 @@ import javax.servlet.http.HttpServletResponse; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.Date; -import java.util.Iterator; -import java.util.List; +import java.math.BigDecimal; +import java.util.*; /* * @author xcj @@ -83,6 +83,79 @@ public class FilePortUtil { } } + + public static void exportExcelNew(HttpServletResponse response, String title, String[] headers, List list, List containBean) throws Exception { + HSSFWorkbook workbook = null; + try { + workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet(title); + HSSFRow row = sheet.createRow(0); + /*创建第一行表头*/ + for (short i = 0; i < headers.length; i++) { + HSSFCell cell = row.createCell(i); + HSSFRichTextString text = new HSSFRichTextString(headers[i]); + cell.setCellValue(text); + } + Iterator it = list.iterator(); + int index = 0; + while (it.hasNext()) { + index++; + row = sheet.createRow(index); + T t = (T) it.next(); + /*反射得到字段*/ + Field[] fields = t.getClass().getDeclaredFields(); + /*如果需要匹配*/ + if (CollectionUtils.isNotEmpty(containBean)) { + for (int j = 0; j < containBean.size(); j++) { + for (int i = 0; i < fields.length; i++) { + Field field = fields[i]; + if (!field.getName().equals(containBean.get(j))) + continue; + /*给每一列set值*/ + setCellValue(t, field, row, j); + } + } + } else { + for (int i = 0; i < fields.length; i++) { + Field field = fields[i]; + setCellValue(t, field, row, i); + } + } + + Field mapField = t.getClass().getDeclaredField("map"); + mapField.setAccessible(true); + List list1 = Arrays.asList(headers); + LinkedHashMap map = (LinkedHashMap) mapField.get(t); + for (Map.Entry entry : map.entrySet()) { + BigDecimal moduleScore = entry.getValue(); + String key = entry.getKey(); + for (String header : list1) { + if (key.equals(header)){ + // 处理 moduleScore,例如将其写入Excel 中对应的单元格 + int i = list1.indexOf(header); + HSSFCell cell = row.createCell(i); + if (moduleScore != null) { + cell.setCellValue(moduleScore.doubleValue()); + } + } + } + } + headers = list1.toArray(new String[0]); // 将List转回数组 + } + /*application/vnd.ms-excel告诉浏览器要下载的是个excel*/ + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + /*请求头设置,Content-Disposition为下载标识,attachment标识以附件方式下载*/ + response.addHeader("Content-Disposition", "attachment;filename=" + new String((title).getBytes(), "ISO8859-1") + ".xls"); + workbook.write(response.getOutputStream()); + } finally { + if (workbook != null) { + workbook.close(); + } + } + } + + + /** * 设置每一行中的列 * diff --git a/src/main/resources/mapper/StuUserMapper.xml b/src/main/resources/mapper/StuUserMapper.xml index aa558c3..f574baf 100644 --- a/src/main/resources/mapper/StuUserMapper.xml +++ b/src/main/resources/mapper/StuUserMapper.xml @@ -456,7 +456,7 @@ AND u.role_id = 4 AND u.school_id = #{schoolId} - AND student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%') + AND (student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%')) AND u.class_id = #{classId} @@ -491,7 +491,7 @@ AND school_id = #{schoolId} - AND student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%') + AND (student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%'))