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 bb83d7c..4751ff2 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.25:8889"; +// public static final String API_URL = "http://192.168.2.19:8889"; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/entity/StuTrainingStepRecord.java b/src/main/java/com/sztzjy/financial_bigdata/entity/StuTrainingStepRecord.java index 02a57b1..915be62 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/entity/StuTrainingStepRecord.java +++ b/src/main/java/com/sztzjy/financial_bigdata/entity/StuTrainingStepRecord.java @@ -25,6 +25,16 @@ public class StuTrainingStepRecord { @ApiModelProperty("学生答案") private String stuAnswer; + private String threeId; + + public String getThreeId() { + return threeId; + } + + public void setThreeId(String threeId) { + this.threeId = threeId; + } + public String getRecordId() { return recordId; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/entity/resource_entity/TestTestSysCaseQuestionStepWithBLOBs.java b/src/main/java/com/sztzjy/financial_bigdata/entity/resource_entity/TestTestSysCaseQuestionStepWithBLOBs.java index 6637b0a..5373a80 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/entity/resource_entity/TestTestSysCaseQuestionStepWithBLOBs.java +++ b/src/main/java/com/sztzjy/financial_bigdata/entity/resource_entity/TestTestSysCaseQuestionStepWithBLOBs.java @@ -29,6 +29,16 @@ public class TestTestSysCaseQuestionStepWithBLOBs extends TestSysCaseQuestionSte @ApiModelProperty("练习答案原始数据") private String practiceAnswerOriginal; + private String threeId; + + public String getThreeId() { + return threeId; + } + + public void setThreeId(String threeId) { + this.threeId = threeId; + } + public String getPracticeAnswer() { return practiceAnswer; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CaseApi.java b/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CaseApi.java index e8734da..7516f40 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CaseApi.java +++ b/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CaseApi.java @@ -37,6 +37,7 @@ public class CaseApi { private final static String deleteCaseStep = Constant.API_URL + "/api/tea/CaseApi/deleteCaseStep"; private final static String selectCaseStepDetails = Constant.API_URL + "/api/tea/CaseApi/selectCaseStepDetails"; private final static String selectCaseStepListBatchByIdListAndSort = Constant.API_URL + "/api/tea/CaseApi/selectCaseStepListBatchByIdListAndSort"; + private final static String selectCaseStepListBatchByIdList = Constant.API_URL + "/api/tea/CaseApi/selectCaseStepListBatchByIdList"; private final static String selectAllStepBySystemOwner = Constant.API_URL + "/api/tea/CaseApi/selectAllStepBySystemOwner"; @@ -91,8 +92,8 @@ public class CaseApi { * local:案例题详情查询 * rsapi:案例题详情查询 */ - public static TestSysCaseQuestion selectCaseDetails(String caseId,String systemOwner) throws IOException { - String requestBody = "caseId=" + caseId+"&systemOwner="+systemOwner; + public static TestSysCaseQuestion selectCaseDetails(String caseId, String systemOwner) throws IOException { + String requestBody = "caseId=" + caseId + "&systemOwner=" + systemOwner; JSONObject object = HttpUtils.sendPost( selectCaseDetails, requestBody); @@ -145,7 +146,7 @@ public class CaseApi { * rsapi:根据二级Id查询案例题 */ public static List selectCaseByCourseId(String courseId, String systemOwner, String schoolId) throws IOException { - String requestBody = "courseId=" + courseId+"&systemOwner="+systemOwner+"&schoolId="+schoolId; + String requestBody = "courseId=" + courseId + "&systemOwner=" + systemOwner + "&schoolId=" + schoolId; JSONObject object = HttpUtils.sendPost( selectCaseByCourseId, requestBody); @@ -287,7 +288,7 @@ public class CaseApi { * local:根据章节 查询案例题步骤并排序 */ public static List selectCaseStepListBatchByIdListAndSort(String chapterId) throws IOException { - String requestBody="threeId="+chapterId; + String requestBody = "threeId=" + chapterId; JSONObject object = HttpUtils.sendPost( selectCaseStepListBatchByIdListAndSort, requestBody); @@ -300,6 +301,17 @@ public class CaseApi { return list; } + public static List selectCaseStepListBatchByIdList(List list) throws IOException { + Gson gson = new Gson(); + JSONObject object = HttpUtils.sendPost( + selectCaseStepListBatchByIdList, + gson.toJson(list), "application/json", null); + Type listType = new TypeToken>() { + }.getType(); + List resultList = gson.fromJson(object.get("respString").toString(), listType); + return resultList; + } + /** * 单独接口 * 展示案例题详细信息 @@ -323,10 +335,10 @@ public class CaseApi { * 单独接口 * 考试模式--成绩报告案例题questionOriginal所属章节,contentOriginal为考核点数量,Sort为序号 */ - public static List getGradeReportCase(List caseIdList, String schoolId,String systemOwner) throws IOException { + public static List getGradeReportCase(List caseIdList, String schoolId, String systemOwner) throws IOException { Gson gson = new Gson(); // 构建带有 schoolId 的 URL - String urlWithParams = getGradeReportCase + "?schoolId=" + URLEncoder.encode(schoolId, "UTF-8")+"&systemOwner="+ systemOwner; + String urlWithParams = getGradeReportCase + "?schoolId=" + URLEncoder.encode(schoolId, "UTF-8") + "&systemOwner=" + systemOwner; JSONObject object = HttpUtils.sendPost( urlWithParams, gson.toJson(caseIdList), "application/json", null); @@ -345,7 +357,7 @@ public class CaseApi { JSONObject object = HttpUtils.sendPost( selectAllStepBySystemOwner, requestBody); - if(object==null){ + if (object == null) { return null; } Gson gson = new GsonBuilder() 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 42f66fd..7e4c486 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 @@ -164,7 +164,7 @@ public class StuScoreServiceImpl implements StuScoreService { //3.记录表中所有ID得分之和 StuTrainingStepRecordExample example =new StuTrainingStepRecordExample(); - example.createCriteria().andCaseStepIdIn(stepIdList); + example.createCriteria().andCaseStepIdIn(stepIdList).andUserIdEqualTo(stuTrainingWithBLOBs.getUserId()); List stuTrainingStepRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); double stuTotalScore = stuTrainingStepRecords.stream() //学生总共得分 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 7ff3ae4..cc50333 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 @@ -7,7 +7,6 @@ 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.resource_entity.TestSysCaseQuestionStep; import com.sztzjy.financial_bigdata.entity.resource_entity.TestTestSysCaseQuestionStepWithBLOBs; import com.sztzjy.financial_bigdata.entity.stu_dto.StuTrainingDto; import com.sztzjy.financial_bigdata.entity.stu_dto.StuUserDto; @@ -114,24 +113,91 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { List stuClasses = classMapper.selectByExample(example); Map classIdToNameMap = stuClasses.stream().collect(Collectors.toMap(StuClass::getClassId, StuClass::getClassName)); - - //拿到权重 - SysWeightExample sysWeightExample = new SysWeightExample(); - sysWeightExample.createCriteria().andSchoolIdEqualTo(schoolId); - List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); - SysWeight sysWeight = sysWeights.get(0); - - // 批量获取实训记录 Set userIds = stuUsers.stream().map(StuUser::getUserid).collect(Collectors.toSet()); + ArrayList userIdList = new ArrayList<>(userIds); StuTrainingExample stuTrainingExample = new StuTrainingExample(); - stuTrainingExample.createCriteria().andUserIdIn(new ArrayList<>(userIds)); + stuTrainingExample.createCriteria().andUserIdIn(userIdList); List stuTrainingsWithBLOBs = trainingMapper.selectByExampleWithBLOBs(stuTrainingExample); if (stuTrainingsWithBLOBs.isEmpty()) { return Collections.emptyList(); } // 实训记录按用户ID分组 Map> userIdToTrainingsMap = stuTrainingsWithBLOBs.stream().collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId)); + List chapterIdList = new ArrayList<>(); + + + List sysTwoCatalogs = new ArrayList<>(); + try { + sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner, schoolId); + } catch (IOException e) { + e.printStackTrace(); + } + + for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) { + try { + List sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId); + List threeCatalogs = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList()); + chapterIdList.addAll(threeCatalogs); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //一次性取到所有案例题步骤,给实验实训算分用 + List stepList = new ArrayList<>(); + try { + stepList = CaseApi.selectCaseStepListBatchByIdList(chapterIdList); // + } catch (IOException e) { + e.printStackTrace(); + } + + Map> map1 = stepList.stream() //循环里算分方法调用 步骤分数 + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId, + Collectors.mapping(TestTestSysCaseQuestionStepWithBLOBs::getScore, Collectors.toList()))); + + Map> map = stepList.stream() //循环里算分方法调用,步骤ID + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId, + Collectors.mapping(TestTestSysCaseQuestionStepWithBLOBs::getCaseStepId, Collectors.toList()))); + + //3.记录表中所有ID得分之和 + StuTrainingStepRecordExample trainingStepRecordExample = new StuTrainingStepRecordExample(); + trainingStepRecordExample.createCriteria().andUserIdIn(userIdList); + List stuTrainingStepRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(trainingStepRecordExample); + for (StuTrainingStepRecord stuTrainingStepRecord : stuTrainingStepRecords) { + for (TestTestSysCaseQuestionStepWithBLOBs testTestSysCaseQuestionStepWithBLOBs : stepList) { + if (testTestSysCaseQuestionStepWithBLOBs.getCaseStepId().equals(stuTrainingStepRecord.getCaseStepId())) { + stuTrainingStepRecord.setThreeId(testTestSysCaseQuestionStepWithBLOBs.getThreeId()); + } + } + } + + // 假设您已经定义了 stuTrainingStepRecords 这个 List + Map> resultMap = new HashMap<>(); + + // 逐个处理每个记录 + for (StuTrainingStepRecord record : stuTrainingStepRecords) { + String userId = record.getUserId(); // 获取 userId + String threeId = record.getThreeId(); // 获取 threeId + String score = record.getScore(); // 获取 score + + // 确保 userId 的 Map 存在 + resultMap.putIfAbsent(userId, new HashMap<>()); + + // 获取用户的 inner Map + Map innerMap = resultMap.get(userId); + + // 累加分数 + if (innerMap.containsKey(threeId)) { + // 如果已经存在,则累加分数 + BigDecimal existingScore = innerMap.get(threeId); + BigDecimal newScore = existingScore.add(new BigDecimal(score)); + innerMap.put(threeId, newScore); // 更新分数 + } else { + // 如果不存在,则直接添加 + innerMap.put(threeId, new BigDecimal(score)); // 新的三维 ID,直接添加分数 + } + } // 批量获取报告分数 Set reportIds = stuTrainingsWithBLOBs.stream().map(StuTrainingWithBLOBs::getReportId).collect(Collectors.toSet()); @@ -144,6 +210,11 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } catch (IOException e) { return null; } + //拿到权重 + SysWeightExample sysWeightExample = new SysWeightExample(); + sysWeightExample.createCriteria().andSchoolIdEqualTo(schoolId); + List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); + SysWeight sysWeight = sysWeights.get(0); // 遍历用户,计算分数并封装DTO List list = new ArrayList<>(); @@ -152,7 +223,6 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { if (userTrainings.isEmpty()) { continue; } - TeaTrainingInfoDTO teaTrainingInfoDTO = new TeaTrainingInfoDTO(); teaTrainingInfoDTO.setClassName(classIdToNameMap.get(stuUser.getClassId())); teaTrainingInfoDTO.setStudentId(stuUser.getStudentId()); @@ -167,18 +237,17 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { if (reportId != null) { BigDecimal reportScore = reportIdToScoreMap.getOrDefault(reportId, BigDecimal.ZERO); if (BigDecimal.ZERO.compareTo(reportScore) != 0) { + reportScore = reportScore.multiply(sysWeight.getReportWeight().setScale(2, RoundingMode.HALF_UP)); totalScore = totalScore.add(reportScore); } } - //其他模块算分 - BigDecimal moduleScore = getModuleScore(training, sysWeight); + BigDecimal moduleScore = getModuleScore(training, sysWeight, map, map1, resultMap); totalScore = moduleScore.add(totalScore).setScale(2, RoundingMode.HALF_UP); } - - //这个综合得分的公式为 各个页面得分*权重 = 单个模块得分 所有模块得分之和/系统章节数 = 综合得分 + //综合得分 BigDecimal score = totalScore; - if (totalScore.compareTo(BigDecimal.ZERO) > 0) { - score = totalScore.divide(chapterNum, 2, RoundingMode.HALF_UP); + if (totalScore.compareTo(BigDecimal.ZERO) > 0) { //减一,资源中心查出来33,这里只查出来32, + score = totalScore.divide(chapterNum.subtract(BigDecimal.ONE), 2, RoundingMode.HALF_UP); } teaTrainingInfoDTO.setTotalScore(score); @@ -351,8 +420,9 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } } - //计算模块得分 - private BigDecimal getModuleScore(StuTrainingWithBLOBs stuTrainingWithBLOB, SysWeight sysWeight) { + //计算模块得分 章节下所有的案例步骤得分之和 / 章节下所有的案例步骤满分 + private BigDecimal getModuleScore(StuTrainingWithBLOBs stuTrainingWithBLOB, SysWeight sysWeight, + Map> map, Map> map1, Map> resultMap) { BigDecimal knowledgeSummaryWeight = sysWeight.getKnowledgeSummaryWeight(); BigDecimal resourceLearningWeight = sysWeight.getResourceLearningWeight(); BigDecimal learningEvalWeight = sysWeight.getLearningEvalWeight(); @@ -361,7 +431,6 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { BigDecimal knowledgeSummaryScore = Optional.ofNullable(stuTrainingWithBLOB.getKnowledgeSummaryScore()).orElse(BigDecimal.ZERO); BigDecimal resourceLearningScore = Optional.ofNullable(stuTrainingWithBLOB.getResourceLearningScore()).orElse(BigDecimal.ZERO); BigDecimal learningEvalScore = Optional.ofNullable(stuTrainingWithBLOB.getLearningEvalScore()).orElse(BigDecimal.ZERO); - BigDecimal expTrainingScore = Optional.ofNullable(stuTrainingWithBLOB.getExpTrainingScore()).orElse(BigDecimal.ZERO); knowledgeSummaryScore = knowledgeSummaryWeight.multiply(knowledgeSummaryScore).divide(BigDecimal.valueOf(100).setScale(2, RoundingMode.HALF_UP)); if (knowledgeSummaryScore.compareTo(knowledgeSummaryWeight) > 0) { @@ -378,36 +447,39 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { //实验实训 String chapterId = stuTrainingWithBLOB.getChapterId(); - //1.取出章节下的有所案例ID - List stepList = null; - try { - stepList = CaseApi.selectCaseStepListBatchByIdListAndSort(chapterId); - } catch (IOException e) { - throw new RuntimeException("资源中心根据根据案例题IDS批量查询失败"); - } - List stepIdList = stepList.stream().map(TestSysCaseQuestionStep::getCaseStepId).collect(Collectors.toList()); - - //2.步骤表中所有得分之和 - BigDecimal rightTotalScore = stepList.stream() - .map(TestTestSysCaseQuestionStepWithBLOBs::getScore) - .reduce(BigDecimal.ZERO, BigDecimal::add); - - //3.记录表中所有ID得分之和 - StuTrainingStepRecordExample example =new StuTrainingStepRecordExample(); - example.createCriteria().andCaseStepIdIn(stepIdList); - List stuTrainingStepRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); - - double stuTotalScore = stuTrainingStepRecords.stream() //学生总共得分 - .map(StuTrainingStepRecord::getScore) - .mapToDouble(Double::parseDouble) - .sum(); - - BigDecimal accuracy = BigDecimal.valueOf(stuTotalScore).divide(rightTotalScore,2,RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).multiply(expTrainingWeight.divide(BigDecimal.valueOf(100))); - - if (accuracy.compareTo(expTrainingWeight) > 0) { - accuracy = expTrainingWeight; + List stepIdList = map.get(chapterId); + List scoreList = map1.get(chapterId); + BigDecimal expTrainingScore = BigDecimal.ZERO; + if (stepIdList != null && !stepIdList.isEmpty()) { +// List stepIdList = stepList.stream().map(TestSysCaseQuestionStep::getCaseStepId).collect(Collectors.toList()); + //2.步骤表中所有得分之和 + BigDecimal rightTotalScore = scoreList.stream() + .reduce(BigDecimal.ZERO, BigDecimal::add); + + String userId = stuTrainingWithBLOB.getUserId(); + + //提出循环外了这段 +// StuTrainingStepRecordExample example = new StuTrainingStepRecordExample(); +// example.createCriteria().andCaseStepIdIn(stepIdList).andUserIdEqualTo(userId); +// List stuTrainingStepRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); +// double stuTotalScore = stuTrainingStepRecords.stream() //学生总共得分 +// .map(StuTrainingStepRecord::getScore) +// .mapToDouble(Double::parseDouble) +// .sum(); + + //3.记录表中所有ID得分之和 + Map scoreMap = resultMap.get(userId); + if (scoreMap != null && !scoreMap.isEmpty()) { + BigDecimal score = scoreMap.get(chapterId); + if (score != null) { + expTrainingScore = score.divide(rightTotalScore, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).multiply(expTrainingWeight.divide(BigDecimal.valueOf(100))); + if (expTrainingScore.compareTo(expTrainingWeight) > 0) { + expTrainingScore = expTrainingWeight; + } + } + } } - return knowledgeSummaryScore.add(resourceLearningScore).add(learningEvalScore).add(accuracy); + return knowledgeSummaryScore.add(resourceLearningScore).add(learningEvalScore).add(expTrainingScore); } @Override @@ -439,32 +511,11 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { @Override public PageInfo getTheoryInfo(Integer index, Integer size, String schoolId, String classId, String keyWord, String systemOwner) { PageHelper.startPage(index, size); -// List list = getStuTheoryRecordPageInfo(schoolId, classId, keyWord, systemOwner); List list = stuTheoryRecordMapper.selectConditions(schoolId, classId, keyWord, systemOwner); PageInfo pageInfo = new PageInfo<>(list); return pageInfo; } -// //查询方法 -// private List getStuTheoryRecordPageInfo(String schoolId, String classId, String keyWord, String systemOwner) { -// StuTheoryRecordExample s = new StuTheoryRecordExample(); -// StuTheoryRecordExample.Criteria criteria = s.createCriteria(); -// StuTheoryRecordExample.Criteria orCriteria = s.createCriteria(); -// criteria.andSchoolIdEqualTo(schoolId).andSystemOwnerEqualTo(systemOwner); -// orCriteria.andSchoolIdEqualTo(schoolId).andSystemOwnerEqualTo(systemOwner); -// if (StringUtils.isNotBlank(classId)) { -// criteria.andClassIdEqualTo(classId); -// orCriteria.andClassIdEqualTo(classId); -// } -// if (StringUtils.isNotBlank(keyWord)) { -// criteria.andStudentIdEqualTo(keyWord); -// orCriteria.andNameEqualTo(keyWord); -// } -// s.or(orCriteria); -// s.setOrderByClause("average_score ASC"); -// return stuTheoryRecordMapper.selectByExample(s); -// } - @Override public void exportTheoryExamInfo(HttpServletResponse response, String classId, String schoolId, String systemOwner) { @@ -602,6 +653,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } + //todo 原版代码 速度有点慢 private List getTeaTrainingInfoDTOS(String schoolId, String keyWord, String classId, String systemOwner) { List stuUsers = userMapper.getByNameAndStudentID(schoolId, keyWord, classId, systemOwner); @@ -622,14 +674,89 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { // 批量获取实训记录 Set userIds = stuUsers.stream().map(StuUser::getUserid).collect(Collectors.toSet()); + ArrayList userIdList = new ArrayList<>(userIds); StuTrainingExample stuTrainingExample = new StuTrainingExample(); - stuTrainingExample.createCriteria().andUserIdIn(new ArrayList<>(userIds)); + stuTrainingExample.createCriteria().andUserIdIn(userIdList); List stuTrainingsWithBLOBs = trainingMapper.selectByExampleWithBLOBs(stuTrainingExample); if (stuTrainingsWithBLOBs.isEmpty()) { return Collections.emptyList(); } // 实训记录按用户ID分组 Map> userIdToTrainingsMap = stuTrainingsWithBLOBs.stream().collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId)); + List chapterIdList = new ArrayList<>(); + + + List sysTwoCatalogs = new ArrayList<>(); + try { + sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner, schoolId); + } catch (IOException e) { + e.printStackTrace(); + } + + for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) { + try { + List sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId); + List threeCatalogs = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList()); + chapterIdList.addAll(threeCatalogs); + } catch (IOException e) { + e.printStackTrace(); + } + } + + //一次性取到所有案例题步骤,给实验实训算分用 + List stepList = new ArrayList<>(); + try { + stepList = CaseApi.selectCaseStepListBatchByIdList(chapterIdList); // + } catch (IOException e) { + e.printStackTrace(); + } + + Map> map1 = stepList.stream() //循环里算分方法调用 步骤分数 + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId, + Collectors.mapping(TestTestSysCaseQuestionStepWithBLOBs::getScore, Collectors.toList()))); + + Map> map = stepList.stream() //循环里算分方法调用,步骤ID + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId, + Collectors.mapping(TestTestSysCaseQuestionStepWithBLOBs::getCaseStepId, Collectors.toList()))); + + //3.记录表中所有ID得分之和 + StuTrainingStepRecordExample trainingStepRecordExample = new StuTrainingStepRecordExample(); + trainingStepRecordExample.createCriteria().andUserIdIn(userIdList); + List stuTrainingStepRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(trainingStepRecordExample); + for (StuTrainingStepRecord stuTrainingStepRecord : stuTrainingStepRecords) { + for (TestTestSysCaseQuestionStepWithBLOBs testTestSysCaseQuestionStepWithBLOBs : stepList) { + if (testTestSysCaseQuestionStepWithBLOBs.getCaseStepId().equals(stuTrainingStepRecord.getCaseStepId())) { + stuTrainingStepRecord.setThreeId(testTestSysCaseQuestionStepWithBLOBs.getThreeId()); + } + } + } + + // 假设您已经定义了 stuTrainingStepRecords 这个 List + Map> resultMap = new HashMap<>(); + + // 逐个处理每个记录 + for (StuTrainingStepRecord record : stuTrainingStepRecords) { + String userId = record.getUserId(); // 获取 userId + String threeId = record.getThreeId(); // 获取 threeId + String score = record.getScore(); // 获取 score + + // 确保 userId 的 Map 存在 + resultMap.putIfAbsent(userId, new HashMap<>()); + + // 获取用户的 inner Map + Map innerMap = resultMap.get(userId); + + // 累加分数 + if (innerMap.containsKey(threeId)) { + // 如果已经存在,则累加分数 + BigDecimal existingScore = innerMap.get(threeId); + BigDecimal newScore = existingScore.add(new BigDecimal(score)); + innerMap.put(threeId, newScore); // 更新分数 + } else { + // 如果不存在,则直接添加 + innerMap.put(threeId, new BigDecimal(score)); // 新的三维 ID,直接添加分数 + } + } // 批量获取报告分数 Set reportIds = stuTrainingsWithBLOBs.stream().map(StuTrainingWithBLOBs::getReportId).collect(Collectors.toSet()); @@ -655,8 +782,6 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { if (userTrainings.isEmpty()) { continue; } - - TeaTrainingInfoDTO teaTrainingInfoDTO = new TeaTrainingInfoDTO(); teaTrainingInfoDTO.setClassName(classIdToNameMap.get(stuUser.getClassId())); teaTrainingInfoDTO.setStudentId(stuUser.getStudentId()); @@ -675,13 +800,13 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { totalScore = totalScore.add(reportScore); } } - BigDecimal moduleScore = getModuleScore(training, sysWeight); + BigDecimal moduleScore = getModuleScore(training, sysWeight, map, map1, resultMap); totalScore = moduleScore.add(totalScore).setScale(2, RoundingMode.HALF_UP); } - + //综合得分 BigDecimal score = totalScore; - if (totalScore.compareTo(BigDecimal.ZERO) > 0) { - score = totalScore.divide(chapterNum, 2, RoundingMode.HALF_UP); + if (totalScore.compareTo(BigDecimal.ZERO) > 0) { //减一,资源中心查出来33,这里只查出来32, + score = totalScore.divide(chapterNum.subtract(BigDecimal.ONE), 2, RoundingMode.HALF_UP); } teaTrainingInfoDTO.setTotalScore(score);