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