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 4751ff2..c61ec3a 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java +++ b/src/main/java/com/sztzjy/financial_bigdata/config/Constant.java @@ -37,7 +37,7 @@ public class Constant { public static final String SHIZHAN = "实战考核模块"; 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.19:8889"; +// public static final String API_URL = "http://120.79.54.255:8889"; + public static final String API_URL = "http://192.168.2.19:8889"; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuScoreController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuScoreController.java index 6b4986b..a94103b 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuScoreController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/StuScoreController.java @@ -4,10 +4,13 @@ import cn.hutool.core.util.IdUtil; import com.sztzjy.financial_bigdata.annotation.AnonymousAccess; import com.sztzjy.financial_bigdata.entity.*; import com.sztzjy.financial_bigdata.entity.resource_entity.SysThreeCatalog; +import com.sztzjy.financial_bigdata.entity.resource_entity.TestTestSysCaseQuestionStepWithBLOBs; import com.sztzjy.financial_bigdata.entity.stu_dto.StuTrainingDto; import com.sztzjy.financial_bigdata.mapper.StuTrainingMapper; +import com.sztzjy.financial_bigdata.mapper.StuTrainingStepRecordMapper; import com.sztzjy.financial_bigdata.mapper.SysWeightMapper; import com.sztzjy.financial_bigdata.mapper.TrainingReportMapper; +import com.sztzjy.financial_bigdata.resourceCenterAPI.CaseApi; import com.sztzjy.financial_bigdata.resourceCenterAPI.CourseAPI; import com.sztzjy.financial_bigdata.service.stu.StuScoreService; import com.sztzjy.financial_bigdata.service.tea.ITeaGradeManageService; @@ -26,8 +29,12 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; /** * @Author xcj @@ -49,7 +56,8 @@ public class StuScoreController { private ITeaGradeManageService gradeManageService; @Autowired private StuScoreService stuScoreService; - + @Autowired + private StuTrainingStepRecordMapper trainingStepRecordMapper; @AnonymousAccess @ApiOperation("***得分情况展示") @@ -57,7 +65,7 @@ public class StuScoreController { public ResultEntity getScoreInfo(@RequestParam String userId, @RequestParam String chapterId, @RequestParam String schoolId, - @RequestParam String systemOwner){ + @RequestParam String systemOwner) throws IOException { StuTrainingDto stuTrainingDto = new StuTrainingDto(); StuTrainingExample stuTrainingExample = new StuTrainingExample(); @@ -70,9 +78,44 @@ public class StuScoreController { } catch (IOException e) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "资源中心根据章节ID查询章节信息失败"); } + + List reportIds = stuTrainings.stream().map(StuTraining::getReportId).collect(Collectors.toList()); + TrainingReportExample trainingReportExample =new TrainingReportExample(); + trainingReportExample.createCriteria().andReportIdIn(reportIds); + List trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample); + + //提前查出所有report对象 + Map trainingReportMap = trainingReports.stream() + .collect(Collectors.toMap(TrainingReport::getReportId, Function.identity())); + + //提前查出权重 + SysWeightExample sysWeightExample = new SysWeightExample(); + sysWeightExample.createCriteria().andCourseIdEqualTo(sysCourseChapter.getTwoId()) + .andSchoolIdEqualTo(schoolId) + .andSystemOwnerEqualTo(systemOwner); + + List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); + Map weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity())); + + //查步骤集合 + Listids =new ArrayList<>(); + ids.add(chapterId); + List list = CaseApi.selectCaseStepByThreeIds(ids); + Map> groupedIds = list.stream() + .filter(step -> step.getThreeId() != null) // 过滤掉 threeId 为 null 的对象 + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId)); // 按 threeId 分组 + + //一次查出所有的记录表 + StuTrainingStepRecordExample example = new StuTrainingStepRecordExample(); + example.createCriteria().andUserIdEqualTo(userId); // 批量查询用户记录 + List allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); + Map> allRecordsMap = allRecords.stream() + .collect(Collectors.groupingBy(StuTrainingStepRecord::getUserId)); // 按 threeId 分组 + if (!stuTrainings.isEmpty()) { StuTrainingWithBLOBs stuTrainingWithBLOBs = stuTrainings.get(0); - stuTrainingDto = stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTrainingWithBLOBs, stuTrainingDto, sysCourseChapter); + stuTrainingDto = stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTrainingWithBLOBs, stuTrainingDto, + sysCourseChapter,trainingReportMap,weightMap,groupedIds,allRecordsMap); } return new ResultEntity(stuTrainingDto); } 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 cbf7418..371f686 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 @@ -80,6 +80,10 @@ public class TeaGradeManageController { StuScoreService stuScoreService; @Value("${file.path}") private String filePath; + @Autowired + private TrainingReportMapper trainingReportMapper; + @Autowired + private StuTrainingStepRecordMapper trainingStepRecordMapper; @AnonymousAccess @@ -191,7 +195,6 @@ public class TeaGradeManageController { } - @AnonymousAccess @PostMapping("/getCountChart") @ApiOperation("考试模式--图表统计接口") @@ -654,7 +657,6 @@ public class TeaGradeManageController { } - @AnonymousAccess @ApiOperation("老师端/练习模式得分详情展示") @PostMapping("getScoreInfo") @@ -663,30 +665,61 @@ public class TeaGradeManageController { @RequestParam String systemOwner) throws IOException { List list = new ArrayList<>(); - List sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner,schoolId); + List sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner, schoolId); + List twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList()); - ListallChapterId =new ArrayList<>(); - for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) { - List sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId); - allChapterId.addAll(sysThreeCatalogs); - } + List allChapterId = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId); + List ids = allChapterId.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList()); StuTrainingExample stuTrainingExample = new StuTrainingExample(); stuTrainingExample.createCriteria().andUserIdEqualTo(userId); List stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample); + List reportIds = stuTrainings.stream().map(StuTraining::getReportId).collect(Collectors.toList()); + TrainingReportExample trainingReportExample = new TrainingReportExample(); + trainingReportExample.createCriteria().andReportIdIn(reportIds); + List trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample); + + + //提前查出所有report对象 + Map trainingReportMap = trainingReports.stream() + .collect(Collectors.toMap(TrainingReport::getReportId, Function.identity())); + Map chapterIds = allChapterId.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, sysThreeCatalog -> sysThreeCatalog)); + //提前查出权重 + SysWeightExample sysWeightExample = new SysWeightExample(); + sysWeightExample.createCriteria().andCourseIdIn(twoIds) + .andSchoolIdEqualTo(schoolId) + .andSystemOwnerEqualTo(systemOwner); + + //一次查出所有章节下的案例步骤 + List lists = CaseApi.selectCaseStepByThreeIds(ids); + Map> groupedIds = lists.stream() + .filter(step -> step.getThreeId() != null) // 过滤掉 threeId 为 null 的对象 + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId)); // 按 threeId 分组 + + List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); + Map weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity())); + + + //一次查出所有的记录表 + StuTrainingStepRecordExample example = new StuTrainingStepRecordExample(); + example.createCriteria().andUserIdEqualTo(userId); // 批量查询用户记录 + List allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); + Map> allRecordsMap = allRecords.stream() + .collect(Collectors.groupingBy(StuTrainingStepRecord::getUserId)); // 按 threeId 分组 try { for (StuTrainingWithBLOBs stuTraining : stuTrainings) { String chapterId = stuTraining.getChapterId(); SysThreeCatalog sysCourseChapter = chapterIds.get(chapterId); - if (sysCourseChapter==null){ + if (sysCourseChapter == null) { continue; } StuTrainingDto stuTrainingDto = new StuTrainingDto(); stuTrainingDto.setTaskModule(sysCourseChapter.getThreeName()); - list.add(stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, stuTrainingDto, sysCourseChapter)); + list.add(stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, stuTrainingDto, + sysCourseChapter, trainingReportMap, weightMap, groupedIds,allRecordsMap)); } } catch (Exception e) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "资源中心根据章节ID查询章节信息失败"); 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 7516f40..b08fbdd 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CaseApi.java +++ b/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CaseApi.java @@ -12,6 +12,8 @@ import com.sztzjy.financial_bigdata.entity.tea_dto.TrainingDto; import com.sztzjy.financial_bigdata.util.HttpUtils; import com.sztzjy.financial_bigdata.util.ResultEntity; import org.apache.commons.lang3.StringUtils; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.springframework.web.bind.annotation.RequestParam; import java.io.IOException; @@ -37,6 +39,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 selectCaseStepByThreeIds = Constant.API_URL + "/api/tea/CaseApi/selectCaseStepByThreeIds"; private final static String selectCaseStepListBatchByIdList = Constant.API_URL + "/api/tea/CaseApi/selectCaseStepListBatchByIdList"; private final static String selectAllStepBySystemOwner = Constant.API_URL + "/api/tea/CaseApi/selectAllStepBySystemOwner"; @@ -301,6 +304,24 @@ public class CaseApi { return list; } + + public static List selectCaseStepByThreeIds(List chapterIds) throws IOException { + // 使用 Gson 将 List 转换为 JSON 字符串 + String requestBody = new Gson().toJson(chapterIds); + + JSONObject object = HttpUtils.sendPostNew( + selectCaseStepByThreeIds, + requestBody); + + Gson gson = new GsonBuilder() + .registerTypeAdapter(Date.class, new DateTypeAdapter()) + .create(); + + Type listType = new TypeToken>() {}.getType(); // 正确的解析类型 + List steps = gson.fromJson(object.get("respString").toString(), listType); + return steps; + } + public static List selectCaseStepListBatchByIdList(List list) throws IOException { Gson gson = new Gson(); JSONObject object = HttpUtils.sendPost( diff --git a/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CourseAPI.java b/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CourseAPI.java index b5618b7..c4143ee 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CourseAPI.java +++ b/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/CourseAPI.java @@ -2,26 +2,31 @@ package com.sztzjy.financial_bigdata.resourceCenterAPI; import cn.hutool.json.JSONObject; -import com.google.gson.Gson; import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.sztzjy.financial_bigdata.config.Constant; -import com.sztzjy.financial_bigdata.entity.SysCourseChapter; 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.TestTestSysCaseQuestionStepWithBLOBs; import com.sztzjy.financial_bigdata.util.HttpUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.springframework.web.bind.annotation.RequestParam; import java.io.IOException; import java.lang.reflect.Type; import java.util.Date; import java.util.List; -import java.util.Map; public class CourseAPI { private final static String getAllTwoCatalogList = Constant.API_URL + "/api/sys/courseApi/getAllTwoCatalogList"; private final static String selectThreeCatalogListByTwoId = Constant.API_URL + "/api/sys/courseApi/selectThreeCatalogListByTwoId"; + private final static String selectThreeCatalogListByTwoIdList = Constant.API_URL + "/api/sys/courseApi/selectThreeCatalogListByTwoIdList"; private final static String insertSysTwoCatalog = Constant.API_URL + "/api/sys/courseApi/insertSysTwoCatalog"; private final static String deleteTwoCatalog = Constant.API_URL + "/api/sys/courseApi/deleteTwoCatalog"; private final static String insertSysThreeCatalog = Constant.API_URL + "/api/sys/courseApi/insertSysThreeCatalog"; @@ -32,21 +37,23 @@ public class CourseAPI { private final static String selectChapterByChapterId = Constant.API_URL + "/api/sys/courseApi/selectChapterByChapterId"; private final static String selectNameByCourseID = Constant.API_URL + "/api/sys/courseApi/selectNameByCourseID"; private final static String getModuleBySchoolId = Constant.API_URL + "/api/sys/courseApi/getModuleBySchoolId"; + private final static String selectChapterByIdList = Constant.API_URL + "/api/sys/courseApi/selectChapterByIdList"; /** * local:查看课程 * rsapi:查看二级目录 */ - public static List selectCourseList(String systemOwner,String schoolId) throws IOException { - String requestBody="systemOwner="+systemOwner+"&schoolId="+schoolId; + public static List selectCourseList(String systemOwner, String schoolId) throws IOException { + String requestBody = "systemOwner=" + systemOwner + "&schoolId=" + schoolId; JSONObject object = HttpUtils.sendPost( getAllTwoCatalogList, requestBody); Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new DateTypeAdapter()) .create(); - Type listType = new TypeToken>() {}.getType(); + Type listType = new TypeToken>() { + }.getType(); List twoCatalogList = gson.fromJson(object.get("respString").toString(), listType); return twoCatalogList; } @@ -55,34 +62,56 @@ public class CourseAPI { * local:查询课程下的所有章节 * rsapi:根据二级目录ID查寻所有三级目录信息 */ - public static List selectThreeCatalogListByTwoId(String twoId,String schoolId) throws IOException { - String requestBody="twoId="+twoId+"&schoolId="+schoolId; + public static List selectThreeCatalogListByTwoId(String twoId, String schoolId) throws IOException { + String requestBody = "twoId=" + twoId + "&schoolId=" + schoolId; JSONObject object = HttpUtils.sendPost( selectThreeCatalogListByTwoId, requestBody); Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new DateTypeAdapter()) .create(); - Type listType = new TypeToken>() {}.getType(); + Type listType = new TypeToken>() { + }.getType(); List threeCatalogList = gson.fromJson(object.get("respString").toString(), listType); return threeCatalogList; } + + public static List callSelectThreeCatalogList(List twoIds, String schoolId) throws IOException { + // 使用 Gson 将 List 转换为 JSON 字符串 + String requestBody = new Gson().toJson(twoIds); + // 构建URL + String url = selectThreeCatalogListByTwoIdList + "?schoolId=" + schoolId; + JSONObject object = HttpUtils.sendPostNew( + url, + requestBody); + + Gson gson = new GsonBuilder() + .registerTypeAdapter(Date.class, new DateTypeAdapter()) + .create(); + + Type listType = new TypeToken>() { + }.getType(); // 正确的解析类型 + List sysThreeCatalogs = gson.fromJson(object.get("respString").toString(), listType); + return sysThreeCatalogs; + } + + /** * local:增加课程 * rsapi:增加二级目录 */ - public static Boolean insertSysTwoCatalog(SysTwoCatalog twoCatalog,String systemOwner,String schoolId) throws IOException { + public static Boolean insertSysTwoCatalog(SysTwoCatalog twoCatalog, String systemOwner, String schoolId) throws IOException { twoCatalog.setOneId(systemOwner); twoCatalog.setCreator(schoolId); Gson gson = new Gson(); JSONObject object = HttpUtils.sendPost( insertSysTwoCatalog, - gson.toJson(twoCatalog),"application/json",null); + gson.toJson(twoCatalog), "application/json", null); String respString = object.get("respString").toString(); - if("true".equals(respString)){ + if ("true".equals(respString)) { return true; - }else { + } else { return false; } } @@ -92,14 +121,14 @@ public class CourseAPI { * rsapi:删除二级目录 */ public static Boolean deleteTwoCatalog(String courseId) throws IOException { - String requestBody="twoId="+courseId; + String requestBody = "twoId=" + courseId; JSONObject object = HttpUtils.sendPost( deleteTwoCatalog, requestBody); String respString = object.get("respString").toString(); - if("true".equals(respString)){ + if ("true".equals(respString)) { return true; - }else { + } else { return false; } } @@ -115,11 +144,11 @@ public class CourseAPI { Gson gson = new Gson(); JSONObject object = HttpUtils.sendPost( insertSysThreeCatalog, - gson.toJson(threeCatalog),"application/json",null); + gson.toJson(threeCatalog), "application/json", null); String respString = object.get("respString").toString(); - if("true".equals(respString)){ + if ("true".equals(respString)) { return true; - }else { + } else { return false; } } @@ -129,14 +158,14 @@ public class CourseAPI { * rsapi:删除三级目录 */ public static Boolean deleteThreeCatalog(String threeId) throws IOException { - String requestBody="threeId="+threeId; + String requestBody = "threeId=" + threeId; JSONObject object = HttpUtils.sendPost( deleteThreeCatalog, requestBody); String respString = object.get("respString").toString(); - if("true".equals(respString)){ + if ("true".equals(respString)) { return true; - }else { + } else { return false; } } @@ -145,14 +174,15 @@ public class CourseAPI { * 获取内置课程 并排序ASC */ public static List selectTwoCataLogByInnerAndAsc(String systemOwner) throws IOException { - String requestBody="systemOwner="+systemOwner; + String requestBody = "systemOwner=" + systemOwner; JSONObject object = HttpUtils.sendPost( selectTwoCataLogByInnerAndAsc, requestBody); Gson gson = new GsonBuilder() .registerTypeAdapter(Date.class, new DateTypeAdapter()) .create(); - Type listType = new TypeToken>() {}.getType(); + Type listType = new TypeToken>() { + }.getType(); List twoCatalogList = gson.fromJson(object.get("respString").toString(), listType); return twoCatalogList; } @@ -169,7 +199,7 @@ public class CourseAPI { JSONObject object = HttpUtils.sendPost( urlWithParams, gson.toJson(courseIds), "application/json", null); - if(object==null){ + if (object == null) { return null; } Type listType = new TypeToken>() { @@ -182,7 +212,7 @@ public class CourseAPI { * 查询总章节数量 */ public static Integer getTotalChapterCount(String systemOwner) throws IOException { - String requestBody="systemOwner="+systemOwner; + String requestBody = "systemOwner=" + systemOwner; JSONObject object = HttpUtils.sendPost( getTotalChapterCount, requestBody); @@ -195,7 +225,7 @@ public class CourseAPI { * 根据章节ID查询章节信息 */ public static SysThreeCatalog selectChapterByChapterId(String chapterId) throws IOException { - String requestBody = "chapterId="+chapterId; + String requestBody = "chapterId=" + chapterId; JSONObject object = HttpUtils.sendPost( selectChapterByChapterId, requestBody); @@ -208,13 +238,35 @@ public class CourseAPI { return step; } + /** + * 根据章节ID查询章节信息 + */ + public static List selectChapterByIdList(List chapterIds) throws IOException { + // 使用 Gson 将 List 转换为 JSON 字符串 + String requestBody = new Gson().toJson(chapterIds); + + JSONObject object = HttpUtils.sendPostNew( + selectChapterByIdList, + requestBody); + + Gson gson = new GsonBuilder() + .registerTypeAdapter(Date.class, new DateTypeAdapter()) + .create(); + + Type listType = new TypeToken>() { + }.getType(); // 正确的解析类型 + List steps = gson.fromJson(object.get("respString").toString(), listType); + + return steps; + } + /** * 单独接口 * 查询章节名称集合 */ - public static List selectNameByCourseID(String schoolId,String systemOwner) throws IOException { - String requestBody = "schoolId="+schoolId+"&systemOwner="+systemOwner; + public static List selectNameByCourseID(String schoolId, String systemOwner) throws IOException { + String requestBody = "schoolId=" + schoolId + "&systemOwner=" + systemOwner; JSONObject object = HttpUtils.sendPost( selectNameByCourseID, requestBody); diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/StuScoreService.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/StuScoreService.java index 87af010..06a8a10 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/StuScoreService.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/StuScoreService.java @@ -1,16 +1,25 @@ package com.sztzjy.financial_bigdata.service.stu; +import com.sztzjy.financial_bigdata.entity.StuTrainingStepRecord; import com.sztzjy.financial_bigdata.entity.StuTrainingWithBLOBs; +import com.sztzjy.financial_bigdata.entity.SysWeight; +import com.sztzjy.financial_bigdata.entity.TrainingReport; import com.sztzjy.financial_bigdata.entity.resource_entity.SysThreeCatalog; +import com.sztzjy.financial_bigdata.entity.resource_entity.TestTestSysCaseQuestionStepWithBLOBs; import com.sztzjy.financial_bigdata.entity.stu_dto.StuTrainingDto; import java.io.IOException; import java.util.List; +import java.util.Map; /** * @Author xcj * @Date 2024/11/22 */ public interface StuScoreService { - StuTrainingDto getScoreByChapterId(String schoolId, String systemOwner,StuTrainingWithBLOBs stuTrainingWithBLOBs, StuTrainingDto stuTrainingDto, SysThreeCatalog sysCourseChapter); + StuTrainingDto getScoreByChapterId(String schoolId, String systemOwner, StuTrainingWithBLOBs stuTrainingWithBLOBs, + StuTrainingDto stuTrainingDto, SysThreeCatalog sysCourseChapter, + Map trainingReportMap,Map weightMap, + Map> groupedIds, + Map> allRecordsMap); } 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 7e4c486..3d61a0d 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 @@ -21,7 +21,9 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @Author xcj @@ -125,15 +127,12 @@ public class StuScoreServiceImpl implements StuScoreService { @Override - public StuTrainingDto getScoreByChapterId(String schoolId, String systemOwner, StuTrainingWithBLOBs stuTrainingWithBLOBs, StuTrainingDto stuTrainingDto, SysThreeCatalog sysCourseChapter){ - SysWeightExample sysWeightExample = new SysWeightExample(); - sysWeightExample.createCriteria().andCourseIdEqualTo(sysCourseChapter.getTwoId()) - .andSchoolIdEqualTo(schoolId) - .andSystemOwnerEqualTo(systemOwner); - - List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); - if (!sysWeights.isEmpty()) { - SysWeight sysWeight = sysWeights.get(0); + public StuTrainingDto getScoreByChapterId(String schoolId, String systemOwner, StuTrainingWithBLOBs stuTrainingWithBLOBs, + StuTrainingDto stuTrainingDto, SysThreeCatalog sysCourseChapter, Map trainingReportMap, + Map weightMap, Map> groupedIds, + Map> allRecordsMap) { + SysWeight sysWeight = weightMap.get(sysCourseChapter.getTwoId()); + if (sysWeight!=null) { BeanUtils.copyProperties(sysWeight, stuTrainingDto); // 提取权重数据 } else { setDefaultWeights(stuTrainingDto); @@ -147,25 +146,19 @@ public class StuScoreServiceImpl implements StuScoreService { if (stuTrainingDto.getCaseStuScore() == null) { stuTrainingDto.setCaseStuScore(BigDecimal.ZERO); } else { - //1.取出章节下的有所案例ID - List stepList = null; - try { - stepList = CaseApi.selectCaseStepListBatchByIdListAndSort(sysCourseChapter.getThreeId()); - } catch (IOException e) { - throw new RuntimeException("资源中心根据根据案例题IDS批量查询失败"); - } - List stepIdList = stepList.stream().map(TestSysCaseQuestionStep::getCaseStepId).collect(Collectors.toList()); + List stepList = groupedIds.get(sysCourseChapter.getThreeId()); + List stepIdList = stepList.stream().map(TestTestSysCaseQuestionStepWithBLOBs::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).andUserIdEqualTo(stuTrainingWithBLOBs.getUserId()); - List stuTrainingStepRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); + // 3.根据 stepIdList 筛选记录 + List stuTrainingStepRecords = allRecordsMap.get(stuTrainingWithBLOBs.getUserId()) + .stream().filter(record -> stepIdList.contains(record.getCaseStepId())).collect(Collectors.toList()); + double stuTotalScore = stuTrainingStepRecords.stream() //学生总共得分 .map(StuTrainingStepRecord::getScore) @@ -174,8 +167,8 @@ public class StuScoreServiceImpl implements StuScoreService { BigDecimal expTrainingWeight = stuTrainingDto.getExpTrainingWeight(); //实验实训权重 - 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){ + 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; } //这里返回正确率 模块得分/模块案例满分*100*权重 @@ -189,7 +182,7 @@ public class StuScoreServiceImpl implements StuScoreService { BigDecimal learningEvalScore = stuTrainingDto.getLearningEvalScore(); BigDecimal learningEvalWeight = stuTrainingDto.getLearningEvalWeight(); BigDecimal weightLearningEvalScore = learningEvalWeight.multiply(learningEvalScore).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); - if (weightLearningEvalScore.compareTo(learningEvalWeight)>0){ + if (weightLearningEvalScore.compareTo(learningEvalWeight) > 0) { weightLearningEvalScore = learningEvalWeight; } stuTrainingDto.setLearningEvalScore(weightLearningEvalScore); @@ -197,13 +190,13 @@ public class StuScoreServiceImpl implements StuScoreService { //学习资源 - if (stuTrainingDto.getResourceLearningScore()==null){ + if (stuTrainingDto.getResourceLearningScore() == null) { stuTrainingDto.setResourceLearningScore(BigDecimal.ZERO); - }else { + } else { BigDecimal resourceLearningScore = stuTrainingDto.getResourceLearningScore(); BigDecimal resourceLearningWeight = stuTrainingDto.getResourceLearningWeight(); BigDecimal weightresourceLearningScore = resourceLearningWeight.multiply(resourceLearningScore).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); - if (weightresourceLearningScore.compareTo(resourceLearningWeight)>0){ + if (weightresourceLearningScore.compareTo(resourceLearningWeight) > 0) { weightresourceLearningScore = resourceLearningWeight; } stuTrainingDto.setResourceLearningScore(weightresourceLearningScore); @@ -216,7 +209,7 @@ public class StuScoreServiceImpl implements StuScoreService { BigDecimal knowledgeSummaryScore = stuTrainingDto.getKnowledgeSummaryScore(); BigDecimal knowledgeSummaryWeight = stuTrainingDto.getKnowledgeSummaryWeight(); BigDecimal weightKnowledgeSummaryScore = knowledgeSummaryWeight.multiply(knowledgeSummaryScore).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); - if (weightKnowledgeSummaryScore.compareTo(knowledgeSummaryWeight)>0){ + if (weightKnowledgeSummaryScore.compareTo(knowledgeSummaryWeight) > 0) { weightKnowledgeSummaryScore = knowledgeSummaryWeight; } stuTrainingDto.setKnowledgeSummaryScore(weightKnowledgeSummaryScore); @@ -224,7 +217,7 @@ public class StuScoreServiceImpl implements StuScoreService { // 设置报告相关数据 - TrainingReport trainingReport = trainingReportMapper.selectByPrimaryKey(stuTrainingWithBLOBs.getReportId()); + TrainingReport trainingReport = trainingReportMap.get(stuTrainingWithBLOBs.getReportId()); if (trainingReport == null) { stuTrainingDto.setReportCompleteStatus("未提交"); stuTrainingDto.setReportScore(BigDecimal.ZERO); @@ -232,7 +225,7 @@ public class StuScoreServiceImpl implements StuScoreService { BigDecimal reportScore = trainingReport.getTeacherScore(); BigDecimal reportWeight = stuTrainingDto.getReportWeight(); BigDecimal weightReportScore = reportScore.multiply(reportWeight).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); - if (weightReportScore.compareTo(reportWeight)>0){ + if (weightReportScore.compareTo(reportWeight) > 0) { weightReportScore = reportWeight; } stuTrainingDto.setReportScore(weightReportScore); 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 cc50333..2b4ee8f 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 @@ -30,6 +30,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; /** @@ -80,7 +81,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { return list; } - private List getTrainingInfoDTOSNew(String schoolId, String systemOwner) { + private List getTrainingInfoDTOSNew(String schoolId, String systemOwner) throws IOException { List list = getTeaTrainingInfoDTOSNew(schoolId, systemOwner); assert !Objects.requireNonNull(list).isEmpty(); list.sort(new TotalScoreComparator()); @@ -93,7 +94,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } - private List getTeaTrainingInfoDTOSNew(String schoolId, String systemOwner) { + private List getTeaTrainingInfoDTOSNew(String schoolId, String systemOwner) throws IOException { StuUserExample example1 = new StuUserExample(); example1.createCriteria().andSchoolIdEqualTo(schoolId).andSystemOnwerEqualTo(systemOwner).andRoleIdEqualTo(4); List stuUsers = userMapper.selectByExample(example1); @@ -124,8 +125,6 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } // 实训记录按用户ID分组 Map> userIdToTrainingsMap = stuTrainingsWithBLOBs.stream().collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId)); - List chapterIdList = new ArrayList<>(); - List sysTwoCatalogs = new ArrayList<>(); try { @@ -134,15 +133,9 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { 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 towIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList()); + List sysThreeCatalogs = CourseAPI.callSelectThreeCatalogList(towIds, schoolId); + List chapterIdList = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList()); //一次性取到所有案例题步骤,给实验实训算分用 List stepList = new ArrayList<>(); @@ -215,7 +208,10 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { sysWeightExample.createCriteria().andSchoolIdEqualTo(schoolId); List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); SysWeight sysWeight = sysWeights.get(0); - + BigDecimal knowledgeSummaryWeight = sysWeight.getKnowledgeSummaryWeight(); + BigDecimal resourceLearningWeight = sysWeight.getResourceLearningWeight(); + BigDecimal learningEvalWeight = sysWeight.getLearningEvalWeight(); + BigDecimal expTrainingWeight = sysWeight.getExpTrainingWeight(); // 遍历用户,计算分数并封装DTO List list = new ArrayList<>(); for (StuUser stuUser : stuUsers) { @@ -241,7 +237,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { totalScore = totalScore.add(reportScore); } } - BigDecimal moduleScore = getModuleScore(training, sysWeight, map, map1, resultMap); + BigDecimal moduleScore = getModuleScore(training, knowledgeSummaryWeight, resourceLearningWeight, learningEvalWeight, expTrainingWeight, map, map1, resultMap); totalScore = moduleScore.add(totalScore).setScale(2, RoundingMode.HALF_UP); } //综合得分 @@ -393,15 +389,57 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { @Override - public List getTrainingDetailsInfo(String userId, String schoolId, String systemOwner) { + public List getTrainingDetailsInfo(String userId, String schoolId, String systemOwner) throws IOException { List list = new ArrayList<>(); + List sysTwoCatalogs = null; + try { + sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner, schoolId); + } catch (IOException e) { + e.printStackTrace(); + } + StuTrainingExample stuTrainingExample = new StuTrainingExample(); stuTrainingExample.createCriteria().andUserIdEqualTo(userId); List stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample); Map chapterMap = new HashMap<>(); + List reportIds = stuTrainings.stream().map(StuTraining::getReportId).collect(Collectors.toList()); + TrainingReportExample trainingReportExample = new TrainingReportExample(); + trainingReportExample.createCriteria().andReportIdIn(reportIds); + List trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample); + + //提前查出所有report对象 + Map trainingReportMap = trainingReports.stream() + .collect(Collectors.toMap(TrainingReport::getReportId, Function.identity())); + + List twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList()); + + //提前查出权重 + SysWeightExample sysWeightExample = new SysWeightExample(); + sysWeightExample.createCriteria().andCourseIdIn(twoIds) + .andSchoolIdEqualTo(schoolId) + .andSystemOwnerEqualTo(systemOwner); + + List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); + Map weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity())); + + //一次查出所有章节下的案例步骤 + List allChapterId = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId); + List ids = allChapterId.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList()); + List stepList = CaseApi.selectCaseStepByThreeIds(ids); + Map> groupedIds = stepList.stream() + .filter(step -> step.getThreeId() != null) // 过滤掉 threeId 为 null 的对象 + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId)); // 按 threeId 分组 + + //一次查出所有的记录表 + StuTrainingStepRecordExample example = new StuTrainingStepRecordExample(); + example.createCriteria().andUserIdEqualTo(userId); // 批量查询用户记录 + List allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); + Map> allRecordsMap = allRecords.stream() + .collect(Collectors.groupingBy(StuTrainingStepRecord::getUserId)); // 按 threeId 分组 + try { for (StuTrainingWithBLOBs stuTraining : stuTrainings) { String chapterId = stuTraining.getChapterId(); @@ -412,7 +450,8 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } StuTrainingDto stuTrainingDto = new StuTrainingDto(); stuTrainingDto.setTaskModule(sysCourseChapter.getThreeName()); - list.add(stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, stuTrainingDto, sysCourseChapter)); + list.add(stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, stuTrainingDto, sysCourseChapter, + trainingReportMap, weightMap, groupedIds, allRecordsMap)); } return list; } catch (Exception e) { @@ -421,13 +460,9 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { } //计算模块得分 章节下所有的案例步骤得分之和 / 章节下所有的案例步骤满分 - private BigDecimal getModuleScore(StuTrainingWithBLOBs stuTrainingWithBLOB, SysWeight sysWeight, + private BigDecimal getModuleScore(StuTrainingWithBLOBs stuTrainingWithBLOB, BigDecimal knowledgeSummaryWeight, BigDecimal resourceLearningWeight, + BigDecimal learningEvalWeight, BigDecimal expTrainingWeight, Map> map, Map> map1, Map> resultMap) { - BigDecimal knowledgeSummaryWeight = sysWeight.getKnowledgeSummaryWeight(); - BigDecimal resourceLearningWeight = sysWeight.getResourceLearningWeight(); - BigDecimal learningEvalWeight = sysWeight.getLearningEvalWeight(); - BigDecimal expTrainingWeight = sysWeight.getExpTrainingWeight(); - 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); @@ -585,14 +620,72 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { public void exportAllStuTrainingInfo(HttpServletResponse response, String schoolId, String systemOwner) throws IOException { List trainingInfoDTOSNew = getTrainingInfoDTOSNew(schoolId, systemOwner); List sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner, schoolId); - List allChapterId = new ArrayList<>(); - for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) { - List sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId); - allChapterId.addAll(sysThreeCatalogs); - } + List twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList()); + List allChapterId = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId); + Map chapterIds = allChapterId.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, sysThreeCatalog -> sysThreeCatalog)); List excelDtos = new ArrayList<>(); + // 1. 提取所有的 userId + Set userIds = trainingInfoDTOSNew.stream() + .map(TeaTrainingInfoDTO::getUserId) + .collect(Collectors.toSet()); + + // 2. 基于 userId 查询所有的 StuTrainingWithBLOBs + StuTrainingExample stuTrainingExample = new StuTrainingExample(); + stuTrainingExample.createCriteria().andUserIdIn(new ArrayList<>(userIds)); + List stuTrainingsByUser = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample); + + // 3. 将 stuTrainings 按照 userId 分组 + Map> trainingsByUserId = stuTrainingsByUser.stream() + .collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId)); + + //提前查出权重 + + SysWeightExample sysWeightExample = new SysWeightExample(); + sysWeightExample.createCriteria().andCourseIdIn(twoIds) + .andSchoolIdEqualTo(schoolId) + .andSystemOwnerEqualTo(systemOwner); + + List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); + Map weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity())); + + + // 4. 提前收集所有的 reportId + Set allReportIds = new HashSet<>(); + for (List stuTrainings : trainingsByUserId.values()) { + List reportIds = stuTrainings.stream().map(StuTraining::getReportId).collect(Collectors.toList()); + allReportIds.addAll(reportIds); + } + + // 5. 基于 reportId 查询所有的 TrainingReport + TrainingReportExample trainingReportExample = new TrainingReportExample(); + trainingReportExample.createCriteria().andReportIdIn(new ArrayList<>(allReportIds)); + List trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample); + + // 6. 将 trainingReports 按照 reportId 分组 + Map trainingReportMap = trainingReports.stream() + .collect(Collectors.toMap(TrainingReport::getReportId, Function.identity())); + + + //一次查出所有三级目录 + List ids = allChapterId.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList()); + List sysThreeCatalogs = CourseAPI.selectChapterByIdList(ids); + Map sysThreeCatalogsMap = sysThreeCatalogs.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, Function.identity())); + + //一次查出所有章节下的案例步骤 + List list = CaseApi.selectCaseStepByThreeIds(ids); + Map> groupedIds = list.stream() + .filter(step -> step.getThreeId() != null) // 过滤掉 threeId 为 null 的对象 + .collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId)); // 按 threeId 分组 + + //一次查出所有的记录表 + StuTrainingStepRecordExample example = new StuTrainingStepRecordExample(); + example.createCriteria().andUserIdIn(new ArrayList<>(userIds)); // 批量查询用户记录 + List allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example); + Map> allRecordsMap = allRecords.stream() + .collect(Collectors.groupingBy(StuTrainingStepRecord::getUserId)); // 按 threeId 分组 + for (TeaTrainingInfoDTO teaTrainingInfoDTO : trainingInfoDTOSNew) { ExcelDto excelDto = new ExcelDto(); excelDto.setProgress(teaTrainingInfoDTO.getProgress()); @@ -602,25 +695,19 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { excelDto.setTotalScore(teaTrainingInfoDTO.getTotalScore()); String userId = teaTrainingInfoDTO.getUserId(); - StuTrainingExample stuTrainingExample = new StuTrainingExample(); - stuTrainingExample.createCriteria().andUserIdEqualTo(userId); - List stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample); + // 根据 userId 获取对应的 StuTrainingWithBLOBs 列表 + List stuTrainings = trainingsByUserId.get(userId); LinkedHashMap map = 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); - } + SysThreeCatalog sysThreeCatalog = sysThreeCatalogsMap.get(chapterId); StuTrainingDto stuTrainingDto = new StuTrainingDto(); - stuTrainingDto.setTaskModule(sysCourseChapter.getThreeName()); + stuTrainingDto.setTaskModule(sysThreeCatalog.getThreeName()); - StuTrainingDto scoreByChapterId = stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, stuTrainingDto, sysCourseChapter); + StuTrainingDto scoreByChapterId = stuScoreService.getScoreByChapterId(schoolId, systemOwner, stuTraining, + stuTrainingDto, sysThreeCatalog, trainingReportMap, weightMap, groupedIds, allRecordsMap); BigDecimal moduleScore = scoreByChapterId.getModuleScore(); String taskModule = scoreByChapterId.getTaskModule(); @@ -693,14 +780,13 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { 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 twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList()); + + try { + List sysThreeCatalogs = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId); + chapterIdList = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList()); + } catch (IOException e) { + e.printStackTrace(); } //一次性取到所有案例题步骤,给实验实训算分用 @@ -775,6 +861,11 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { List sysWeights = sysWeightMapper.selectByExample(sysWeightExample); SysWeight sysWeight = sysWeights.get(0); + BigDecimal knowledgeSummaryWeight = sysWeight.getKnowledgeSummaryWeight(); + BigDecimal resourceLearningWeight = sysWeight.getResourceLearningWeight(); + BigDecimal learningEvalWeight = sysWeight.getLearningEvalWeight(); + BigDecimal expTrainingWeight = sysWeight.getExpTrainingWeight(); + // 遍历用户,计算分数并封装DTO List list = new ArrayList<>(); for (StuUser stuUser : stuUsers) { @@ -800,7 +891,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService { totalScore = totalScore.add(reportScore); } } - BigDecimal moduleScore = getModuleScore(training, sysWeight, map, map1, resultMap); + BigDecimal moduleScore = getModuleScore(training, knowledgeSummaryWeight, resourceLearningWeight, learningEvalWeight, expTrainingWeight, map, map1, resultMap); totalScore = moduleScore.add(totalScore).setScale(2, RoundingMode.HALF_UP); } //综合得分 diff --git a/src/main/java/com/sztzjy/financial_bigdata/util/HttpUtils.java b/src/main/java/com/sztzjy/financial_bigdata/util/HttpUtils.java index a48ad8d..d09d722 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/util/HttpUtils.java +++ b/src/main/java/com/sztzjy/financial_bigdata/util/HttpUtils.java @@ -60,6 +60,54 @@ public class HttpUtils { return response.toString(); } + + + public static JSONObject sendPostNew(String url, String paramStr) throws IOException { + try { + JSONObject ret = new JSONObject(); + HttpPost method = new HttpPost(url); + + // 使用 UTF-8 编码 + StringEntity entity = new StringEntity(paramStr, "utf-8"); + entity.setContentType("application/json"); // 直接设置为 JSON 类型 + method.setEntity(entity); + + // 设置请求超时 + int timeout = 60000; + RequestConfig requestConfig = RequestConfig.custom() + .setSocketTimeout(timeout) + .setConnectTimeout(timeout) + .build(); + method.setConfig(requestConfig); + + // 创建 HttpClient + HttpClient client = HttpClients.createDefault(); + HttpResponse resp = client.execute(method); + int statusCode = resp.getStatusLine().getStatusCode(); + + if (statusCode != HttpStatus.SC_OK) { + log.info("接口请求失败,返回码:" + statusCode + ",失败原因:" + resp.getStatusLine().getReasonPhrase()); + return null; + } + + // 读取响应内容 + String respString = EntityUtils.toString(resp.getEntity(), "UTF-8"); + ret.put("statusCode", statusCode); + + if (StringUtils.isNotEmpty(respString)) { + ret.put("respString", respString); + } + + return ret; + } catch (Exception e) { + e.printStackTrace(); + log.info("接口请求失败,失败原因:" + e.getMessage()); + } + + return null; + } + + // 发送POST请求 public static JSONObject sendPost(String url, String paramStr) throws IOException { try {