修改考试页面查询接口,添加导出功能

master
xiaoCJ 3 months ago
parent ff476f9192
commit c99d1dba9c

@ -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";
}

@ -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 {

@ -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<List<StuTrainingDto>> getScoreInfo(@RequestParam String userId,
@RequestParam String schoolId,
@RequestParam String systemOwner) {
@RequestParam String systemOwner) throws IOException {
List<StuTrainingDto> list = new ArrayList<>();
List<SysTwoCatalog> sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner,schoolId);
List<SysThreeCatalog>allChapterId =new ArrayList<>();
for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) {
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId);
allChapterId.addAll(sysThreeCatalogs);
}
StuTrainingExample stuTrainingExample = new StuTrainingExample();
stuTrainingExample.createCriteria().andUserIdEqualTo(userId);
List<StuTrainingWithBLOBs> stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
Map<String, SysThreeCatalog> chapterMap = new HashMap<>();
Map<String, SysThreeCatalog> 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);

@ -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 Map<String,BigDecimal>map;
}

@ -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);
}

@ -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;
}

@ -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<TeaTrainingInfoDTO> getTrainingInfoDTOSNew(String schoolId, String systemOwner) {
List<TeaTrainingInfoDTO> 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<TeaTrainingInfoDTO> getTeaTrainingInfoDTOSNew(String schoolId, String systemOwner) {
StuUserExample example1 = new StuUserExample();
example1.createCriteria().andSchoolIdEqualTo(schoolId).andSystemOnwerEqualTo(systemOwner).andRoleIdEqualTo(4);
List<StuUser> stuUsers = userMapper.selectByExample(example1);
// 查询学生用户列表
if (stuUsers.isEmpty()) {
return Collections.emptyList();
}
// 批量获取班级信息
Set<String> classIds = stuUsers.stream().map(StuUser::getClassId).collect(Collectors.toSet());
StuClassExample example = new StuClassExample();
List<String> IDlist = new ArrayList<>(classIds);
example.createCriteria().andClassIdIn(IDlist).andSystemOwnerEqualTo(systemOwner);
List<StuClass> stuClasses = classMapper.selectByExample(example);
Map<String, String> classIdToNameMap = stuClasses.stream().collect(Collectors.toMap(StuClass::getClassId, StuClass::getClassName));
// 批量获取实训记录
Set<String> userIds = stuUsers.stream().map(StuUser::getUserid).collect(Collectors.toSet());
StuTrainingExample stuTrainingExample = new StuTrainingExample();
stuTrainingExample.createCriteria().andUserIdIn(new ArrayList<>(userIds));
List<StuTrainingWithBLOBs> stuTrainingsWithBLOBs = trainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
if (stuTrainingsWithBLOBs.isEmpty()) {
return Collections.emptyList();
}
// 实训记录按用户ID分组
Map<String, List<StuTrainingWithBLOBs>> userIdToTrainingsMap = stuTrainingsWithBLOBs.stream().collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId));
// 批量获取报告分数
Set<String> reportIds = stuTrainingsWithBLOBs.stream().map(StuTrainingWithBLOBs::getReportId).collect(Collectors.toSet());
List<TrainingReport> trainingReports = trainingReportMapper.selectByPrimaryKeys(reportIds);
Map<String, BigDecimal> 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<TeaTrainingInfoDTO> list = new ArrayList<>();
for (StuUser stuUser : stuUsers) {
List<StuTrainingWithBLOBs> 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<TeaTrainingInfoDTO> trainingInfoDTOSNew = getTrainingInfoDTOSNew(schoolId, systemOwner);
List<SysTwoCatalog> sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner,schoolId);
List<SysThreeCatalog>allChapterId =new ArrayList<>();
for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) {
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId);
allChapterId.addAll(sysThreeCatalogs);
}
Map<String, SysThreeCatalog> chapterIds = allChapterId.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, sysThreeCatalog -> sysThreeCatalog));
List<ExcelDto> 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<StuTrainingWithBLOBs> stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
LinkedHashMap<String,BigDecimal>map =new LinkedHashMap<>();
LinkedHashMap<String, SysThreeCatalog> 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<String> headerList = new ArrayList<>(Arrays.asList(headers)); // 将headers数组转换为List
for (Map.Entry<String, SysThreeCatalog> stringBigDecimalEntry : chapterIds.entrySet()) {
String name = stringBigDecimalEntry.getValue().getThreeName();
headerList.add(name);
}
headers = headerList.toArray(new String[0]); // 将List转回数组
//具体需要写入excel需要哪些字段这些字段取自UserReward类也就是上面的实际数据结果集的泛型
List<String> listColumn = Arrays.asList("rank", "name", "studentId", "className", "totalScore", "progress");
try {
FilePortUtil.exportExcelNew(response, title, headers, excelDtos, listColumn);
} catch (
Exception e) {
e.printStackTrace();
}
}
private List<TeaTrainingInfoDTO> getTeaTrainingInfoDTOS(String schoolId, String keyWord, String classId, String systemOwner) {
List<StuUser> stuUsers = userMapper.getByNameAndStudentID(schoolId, keyWord, classId, systemOwner);

@ -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 <T> void exportExcelNew(HttpServletResponse response, String title, String[] headers, List<T> list, List<String> 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<T> 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<String> list1 = Arrays.asList(headers);
LinkedHashMap<String, BigDecimal> map = (LinkedHashMap<String, BigDecimal>) mapField.get(t);
for (Map.Entry<String, BigDecimal> 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();
}
}
}
/**
*
*

@ -456,7 +456,7 @@
AND u.role_id = 4
AND u.school_id = #{schoolId}
<if test="keyWord != null and keyWord!=''">
AND student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%')
AND (student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%'))
</if>
<if test="classId != null and classId !=''">
AND u.class_id = #{classId}
@ -491,7 +491,7 @@
AND school_id = #{schoolId}
</if>
<if test="keyWord != null and keyWord != ''">
AND student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%')
AND (student_id like CONCAT ('%',#{keyWord},'%') or name like CONCAT ('%',#{keyWord},'%'))
</if>
</where>
</select>

Loading…
Cancel
Save