修改部分成绩和导出相关接口

master
xiaoCJ 2 months ago
parent d1b0807e0c
commit 9abf4d343d

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

@ -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<StuTrainingDto> 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<String> reportIds = stuTrainings.stream().map(StuTraining::getReportId).collect(Collectors.toList());
TrainingReportExample trainingReportExample =new TrainingReportExample();
trainingReportExample.createCriteria().andReportIdIn(reportIds);
List<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample);
//提前查出所有report对象
Map<String, TrainingReport> trainingReportMap = trainingReports.stream()
.collect(Collectors.toMap(TrainingReport::getReportId, Function.identity()));
//提前查出权重
SysWeightExample sysWeightExample = new SysWeightExample();
sysWeightExample.createCriteria().andCourseIdEqualTo(sysCourseChapter.getTwoId())
.andSchoolIdEqualTo(schoolId)
.andSystemOwnerEqualTo(systemOwner);
List<SysWeight> sysWeights = sysWeightMapper.selectByExample(sysWeightExample);
Map<String, SysWeight> weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity()));
//查步骤集合
List<String>ids =new ArrayList<>();
ids.add(chapterId);
List<TestTestSysCaseQuestionStepWithBLOBs> list = CaseApi.selectCaseStepByThreeIds(ids);
Map<String, List<TestTestSysCaseQuestionStepWithBLOBs>> 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<StuTrainingStepRecord> allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example);
Map<String, List<StuTrainingStepRecord>> 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>(stuTrainingDto);
}

@ -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")
@ -664,18 +666,48 @@ public class TeaGradeManageController {
List<StuTrainingDto> list = new ArrayList<>();
List<SysTwoCatalog> sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner, schoolId);
List<String> twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList());
List<SysThreeCatalog>allChapterId =new ArrayList<>();
for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) {
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId);
allChapterId.addAll(sysThreeCatalogs);
}
List<SysThreeCatalog> allChapterId = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId);
List<String> ids = allChapterId.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList());
StuTrainingExample stuTrainingExample = new StuTrainingExample();
stuTrainingExample.createCriteria().andUserIdEqualTo(userId);
List<StuTrainingWithBLOBs> stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
List<String> reportIds = stuTrainings.stream().map(StuTraining::getReportId).collect(Collectors.toList());
TrainingReportExample trainingReportExample = new TrainingReportExample();
trainingReportExample.createCriteria().andReportIdIn(reportIds);
List<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample);
//提前查出所有report对象
Map<String, TrainingReport> trainingReportMap = trainingReports.stream()
.collect(Collectors.toMap(TrainingReport::getReportId, Function.identity()));
Map<String, SysThreeCatalog> chapterIds = allChapterId.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, sysThreeCatalog -> sysThreeCatalog));
//提前查出权重
SysWeightExample sysWeightExample = new SysWeightExample();
sysWeightExample.createCriteria().andCourseIdIn(twoIds)
.andSchoolIdEqualTo(schoolId)
.andSystemOwnerEqualTo(systemOwner);
//一次查出所有章节下的案例步骤
List<TestTestSysCaseQuestionStepWithBLOBs> lists = CaseApi.selectCaseStepByThreeIds(ids);
Map<String, List<TestTestSysCaseQuestionStepWithBLOBs>> groupedIds = lists.stream()
.filter(step -> step.getThreeId() != null) // 过滤掉 threeId 为 null 的对象
.collect(Collectors.groupingBy(TestTestSysCaseQuestionStepWithBLOBs::getThreeId)); // 按 threeId 分组
List<SysWeight> sysWeights = sysWeightMapper.selectByExample(sysWeightExample);
Map<String, SysWeight> weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity()));
//一次查出所有的记录表
StuTrainingStepRecordExample example = new StuTrainingStepRecordExample();
example.createCriteria().andUserIdEqualTo(userId); // 批量查询用户记录
List<StuTrainingStepRecord> allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example);
Map<String, List<StuTrainingStepRecord>> allRecordsMap = allRecords.stream()
.collect(Collectors.groupingBy(StuTrainingStepRecord::getUserId)); // 按 threeId 分组
try {
for (StuTrainingWithBLOBs stuTraining : stuTrainings) {
@ -686,7 +718,8 @@ public class TeaGradeManageController {
}
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查询章节信息失败");

@ -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<TestTestSysCaseQuestionStepWithBLOBs> selectCaseStepByThreeIds(List<String> 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<List<TestTestSysCaseQuestionStepWithBLOBs>>() {}.getType(); // 正确的解析类型
List<TestTestSysCaseQuestionStepWithBLOBs> steps = gson.fromJson(object.get("respString").toString(), listType);
return steps;
}
public static List<TestTestSysCaseQuestionStepWithBLOBs> selectCaseStepListBatchByIdList(List<String> list) throws IOException {
Gson gson = new Gson();
JSONObject object = HttpUtils.sendPost(

@ -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,6 +37,7 @@ 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";
/**
@ -46,7 +52,8 @@ public class CourseAPI {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateTypeAdapter())
.create();
Type listType = new TypeToken<List<SysTwoCatalog>>() {}.getType();
Type listType = new TypeToken<List<SysTwoCatalog>>() {
}.getType();
List<SysTwoCatalog> twoCatalogList = gson.fromJson(object.get("respString").toString(), listType);
return twoCatalogList;
}
@ -63,11 +70,33 @@ public class CourseAPI {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateTypeAdapter())
.create();
Type listType = new TypeToken<List<SysThreeCatalog>>() {}.getType();
Type listType = new TypeToken<List<SysThreeCatalog>>() {
}.getType();
List<SysThreeCatalog> threeCatalogList = gson.fromJson(object.get("respString").toString(), listType);
return threeCatalogList;
}
public static List<SysThreeCatalog> callSelectThreeCatalogList(List<String> 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<List<SysThreeCatalog>>() {
}.getType(); // 正确的解析类型
List<SysThreeCatalog> sysThreeCatalogs = gson.fromJson(object.get("respString").toString(), listType);
return sysThreeCatalogs;
}
/**
* local:
* rsapi:
@ -152,7 +181,8 @@ public class CourseAPI {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateTypeAdapter())
.create();
Type listType = new TypeToken<List<SysTwoCatalog>>() {}.getType();
Type listType = new TypeToken<List<SysTwoCatalog>>() {
}.getType();
List<SysTwoCatalog> twoCatalogList = gson.fromJson(object.get("respString").toString(), listType);
return twoCatalogList;
}
@ -208,6 +238,28 @@ public class CourseAPI {
return step;
}
/**
* ID
*/
public static List<SysThreeCatalog> selectChapterByIdList(List<String> 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<List<SysThreeCatalog>>() {
}.getType(); // 正确的解析类型
List<SysThreeCatalog> steps = gson.fromJson(object.get("respString").toString(), listType);
return steps;
}
/**
*

@ -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<String, TrainingReport> trainingReportMap,Map<String, SysWeight> weightMap,
Map<String, List<TestTestSysCaseQuestionStepWithBLOBs>> groupedIds,
Map<String, List<StuTrainingStepRecord>> allRecordsMap);
}

@ -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<SysWeight> 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<String, TrainingReport> trainingReportMap,
Map<String, SysWeight> weightMap, Map<String, List<TestTestSysCaseQuestionStepWithBLOBs>> groupedIds,
Map<String, List<StuTrainingStepRecord>> 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<TestTestSysCaseQuestionStepWithBLOBs> stepList = null;
try {
stepList = CaseApi.selectCaseStepListBatchByIdListAndSort(sysCourseChapter.getThreeId());
} catch (IOException e) {
throw new RuntimeException("资源中心根据根据案例题IDS批量查询失败");
}
List<String> stepIdList = stepList.stream().map(TestSysCaseQuestionStep::getCaseStepId).collect(Collectors.toList());
List<TestTestSysCaseQuestionStepWithBLOBs> stepList = groupedIds.get(sysCourseChapter.getThreeId());
List<String> 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<StuTrainingStepRecord> stuTrainingStepRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example);
// 3.根据 stepIdList 筛选记录
List<StuTrainingStepRecord> stuTrainingStepRecords = allRecordsMap.get(stuTrainingWithBLOBs.getUserId())
.stream().filter(record -> stepIdList.contains(record.getCaseStepId())).collect(Collectors.toList());
double stuTotalScore = stuTrainingStepRecords.stream() //学生总共得分
.map(StuTrainingStepRecord::getScore)
@ -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);

@ -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<TeaTrainingInfoDTO> getTrainingInfoDTOSNew(String schoolId, String systemOwner) {
private List<TeaTrainingInfoDTO> getTrainingInfoDTOSNew(String schoolId, String systemOwner) throws IOException {
List<TeaTrainingInfoDTO> list = getTeaTrainingInfoDTOSNew(schoolId, systemOwner);
assert !Objects.requireNonNull(list).isEmpty();
list.sort(new TotalScoreComparator());
@ -93,7 +94,7 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService {
}
private List<TeaTrainingInfoDTO> getTeaTrainingInfoDTOSNew(String schoolId, String systemOwner) {
private List<TeaTrainingInfoDTO> getTeaTrainingInfoDTOSNew(String schoolId, String systemOwner) throws IOException {
StuUserExample example1 = new StuUserExample();
example1.createCriteria().andSchoolIdEqualTo(schoolId).andSystemOnwerEqualTo(systemOwner).andRoleIdEqualTo(4);
List<StuUser> stuUsers = userMapper.selectByExample(example1);
@ -124,8 +125,6 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService {
}
// 实训记录按用户ID分组
Map<String, List<StuTrainingWithBLOBs>> userIdToTrainingsMap = stuTrainingsWithBLOBs.stream().collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId));
List<String> chapterIdList = new ArrayList<>();
List<SysTwoCatalog> sysTwoCatalogs = new ArrayList<>();
try {
@ -134,15 +133,9 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService {
e.printStackTrace();
}
for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) {
try {
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId);
List<String> threeCatalogs = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList());
chapterIdList.addAll(threeCatalogs);
} catch (IOException e) {
e.printStackTrace();
}
}
List<String> towIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList());
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.callSelectThreeCatalogList(towIds, schoolId);
List<String> chapterIdList = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList());
//一次性取到所有案例题步骤,给实验实训算分用
List<TestTestSysCaseQuestionStepWithBLOBs> stepList = new ArrayList<>();
@ -215,7 +208,10 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService {
sysWeightExample.createCriteria().andSchoolIdEqualTo(schoolId);
List<SysWeight> 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<TeaTrainingInfoDTO> 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<StuTrainingDto> getTrainingDetailsInfo(String userId, String schoolId, String systemOwner) {
public List<StuTrainingDto> getTrainingDetailsInfo(String userId, String schoolId, String systemOwner) throws IOException {
List<StuTrainingDto> list = new ArrayList<>();
List<SysTwoCatalog> sysTwoCatalogs = null;
try {
sysTwoCatalogs = CourseAPI.selectCourseList(systemOwner, schoolId);
} catch (IOException e) {
e.printStackTrace();
}
StuTrainingExample stuTrainingExample = new StuTrainingExample();
stuTrainingExample.createCriteria().andUserIdEqualTo(userId);
List<StuTrainingWithBLOBs> stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
Map<String, SysThreeCatalog> chapterMap = new HashMap<>();
List<String> reportIds = stuTrainings.stream().map(StuTraining::getReportId).collect(Collectors.toList());
TrainingReportExample trainingReportExample = new TrainingReportExample();
trainingReportExample.createCriteria().andReportIdIn(reportIds);
List<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample);
//提前查出所有report对象
Map<String, TrainingReport> trainingReportMap = trainingReports.stream()
.collect(Collectors.toMap(TrainingReport::getReportId, Function.identity()));
List<String> twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList());
//提前查出权重
SysWeightExample sysWeightExample = new SysWeightExample();
sysWeightExample.createCriteria().andCourseIdIn(twoIds)
.andSchoolIdEqualTo(schoolId)
.andSystemOwnerEqualTo(systemOwner);
List<SysWeight> sysWeights = sysWeightMapper.selectByExample(sysWeightExample);
Map<String, SysWeight> weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity()));
//一次查出所有章节下的案例步骤
List<SysThreeCatalog> allChapterId = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId);
List<String> ids = allChapterId.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList());
List<TestTestSysCaseQuestionStepWithBLOBs> stepList = CaseApi.selectCaseStepByThreeIds(ids);
Map<String, List<TestTestSysCaseQuestionStepWithBLOBs>> 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<StuTrainingStepRecord> allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example);
Map<String, List<StuTrainingStepRecord>> 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<String, List<String>> map, Map<String, List<BigDecimal>> map1, Map<String, Map<String, BigDecimal>> 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<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);
}
List<String> twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList());
List<SysThreeCatalog> allChapterId = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId);
Map<String, SysThreeCatalog> chapterIds = allChapterId.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, sysThreeCatalog -> sysThreeCatalog));
List<ExcelDto> excelDtos = new ArrayList<>();
// 1. 提取所有的 userId
Set<String> userIds = trainingInfoDTOSNew.stream()
.map(TeaTrainingInfoDTO::getUserId)
.collect(Collectors.toSet());
// 2. 基于 userId 查询所有的 StuTrainingWithBLOBs
StuTrainingExample stuTrainingExample = new StuTrainingExample();
stuTrainingExample.createCriteria().andUserIdIn(new ArrayList<>(userIds));
List<StuTrainingWithBLOBs> stuTrainingsByUser = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
// 3. 将 stuTrainings 按照 userId 分组
Map<String, List<StuTrainingWithBLOBs>> trainingsByUserId = stuTrainingsByUser.stream()
.collect(Collectors.groupingBy(StuTrainingWithBLOBs::getUserId));
//提前查出权重
SysWeightExample sysWeightExample = new SysWeightExample();
sysWeightExample.createCriteria().andCourseIdIn(twoIds)
.andSchoolIdEqualTo(schoolId)
.andSystemOwnerEqualTo(systemOwner);
List<SysWeight> sysWeights = sysWeightMapper.selectByExample(sysWeightExample);
Map<String, SysWeight> weightMap = sysWeights.stream().collect(Collectors.toMap(SysWeight::getCourseId, Function.identity()));
// 4. 提前收集所有的 reportId
Set<String> allReportIds = new HashSet<>();
for (List<StuTrainingWithBLOBs> stuTrainings : trainingsByUserId.values()) {
List<String> 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<TrainingReport> trainingReports = trainingReportMapper.selectByExampleWithBLOBs(trainingReportExample);
// 6. 将 trainingReports 按照 reportId 分组
Map<String, TrainingReport> trainingReportMap = trainingReports.stream()
.collect(Collectors.toMap(TrainingReport::getReportId, Function.identity()));
//一次查出所有三级目录
List<String> ids = allChapterId.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList());
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.selectChapterByIdList(ids);
Map<String, SysThreeCatalog> sysThreeCatalogsMap = sysThreeCatalogs.stream().collect(Collectors.toMap(SysThreeCatalog::getThreeId, Function.identity()));
//一次查出所有章节下的案例步骤
List<TestTestSysCaseQuestionStepWithBLOBs> list = CaseApi.selectCaseStepByThreeIds(ids);
Map<String, List<TestTestSysCaseQuestionStepWithBLOBs>> 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<StuTrainingStepRecord> allRecords = trainingStepRecordMapper.selectByExampleWithBLOBs(example);
Map<String, List<StuTrainingStepRecord>> 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<StuTrainingWithBLOBs> stuTrainings = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample);
// 根据 userId 获取对应的 StuTrainingWithBLOBs 列表
List<StuTrainingWithBLOBs> stuTrainings = trainingsByUserId.get(userId);
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);
}
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,15 +780,14 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService {
e.printStackTrace();
}
for (SysTwoCatalog sysTwoCatalog : sysTwoCatalogs) {
List<String> twoIds = sysTwoCatalogs.stream().map(SysTwoCatalog::getTwoId).collect(Collectors.toList());
try {
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.selectThreeCatalogListByTwoId(sysTwoCatalog.getTwoId(), schoolId);
List<String> threeCatalogs = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList());
chapterIdList.addAll(threeCatalogs);
List<SysThreeCatalog> sysThreeCatalogs = CourseAPI.callSelectThreeCatalogList(twoIds, schoolId);
chapterIdList = sysThreeCatalogs.stream().map(SysThreeCatalog::getThreeId).collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
}
}
//一次性取到所有案例题步骤,给实验实训算分用
List<TestTestSysCaseQuestionStepWithBLOBs> stepList = new ArrayList<>();
@ -775,6 +861,11 @@ public class TeaGradeManageServiceImpl implements ITeaGradeManageService {
List<SysWeight> 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<TeaTrainingInfoDTO> 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);
}
//综合得分

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

Loading…
Cancel
Save