修改部分bug

newBigdata
yz 11 months ago
parent de46df8e38
commit 7edc6fe017

@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@RestController
@ -31,6 +32,8 @@ public class ExamController {
TeaExamManageMapper manageMapper;
@Autowired
StuStudentExamMapper studentExamMapper;
@Autowired
TeaExamManageMapper examManageMapper;
//实战考核基础知识题目展示(开始考试)
@ -40,9 +43,14 @@ public class ExamController {
public ResultEntity<List<SysObjectiveQuestion>> basicKnowledge(@ApiParam("考试管理id") @RequestParam String examManageId,
@RequestParam String userId,
@RequestParam String classId) {
//判断考试时间是否已经超过
TeaExamManageWithBLOBs teaExamManageWithBLOBs = examManageMapper.selectByPrimaryKey(examManageId);
if(teaExamManageWithBLOBs.getEndTime().before(new Date())){
return new ResultEntity<>(HttpStatus.OK, "考试已结束");
}
List<SysObjectiveQuestion> list=examService.basicKnowledge(examManageId,userId,classId);
if(list==null){
return new ResultEntity<>(HttpStatus.OK, "考试已结束");
return new ResultEntity<>(HttpStatus.OK, "考试已完成");
}
for (int i = 0; i < list.size(); i++) {
list.get(i).setSchoolId(String.valueOf(i+1));

@ -5,18 +5,16 @@ import com.sztzjy.financial_bigdata.annotation.AnonymousAccess;
import com.sztzjy.financial_bigdata.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.python.core.CompileMode;
import org.python.core.Py;
import org.python.core.PyCode;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@RestController
@Api(tags = "python接口")
@ -27,82 +25,104 @@ public class PythonController {
@ApiOperation("代码检验")
@AnonymousAccess
public ResultEntity validatePythonCode(@RequestBody JSONObject upCodeJson) {
String upCode = upCodeJson.getString("code");
// 对 Python 代码进行检验
String head="# -- coding: utf-8 --\n";
String code=head+upCode;
PythonInterpreter interpreter = new PythonInterpreter();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
System.out.println(upCodeJson);
String pythonCode = upCodeJson.getString("code");
try {
InputStream stream = new ByteArrayInputStream(code.getBytes());
PyCode pyCode = Py.compile(stream, "<string>", CompileMode.exec);
// 创建一个新的进程来执行Python代码
// Process process = Runtime.getRuntime().exec("python");
Process process = Runtime.getRuntime().exec("/usr/bin/python3");
// 获取进程的输入流
BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
// 获取进程的输出流
BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// 重定向输出到 outputStream
interpreter.setOut(outputStream);
// 向进程的输入流写入Python代码
process.getOutputStream().write(pythonCode.getBytes());
process.getOutputStream().flush();
process.getOutputStream().close();
// 读取Python代码的输出
String line;
StringBuilder output = new StringBuilder();
while ((line = inputStream.readLine()) != null) {
output.append(line).append("\n");
}
interpreter.exec(pyCode);
// 读取Python代码的错误信息
StringBuilder errors = new StringBuilder();
while ((line = errorStream.readLine()) != null) {
errors.append(line).append("\n");
}
// 获取运行结果
String result = outputStream.toString();
// 等待进程执行完成
int exitCode = process.waitFor();
return new ResultEntity<>(HttpStatus.OK, result);
} catch (Exception e) {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "语法有误", e.getMessage());
} finally {
interpreter.close();
if (exitCode == 0) {
// 执行成功输出Python代码的结果
System.out.println("Python code output:\n" + output.toString());
return new ResultEntity(HttpStatus.OK,output.toString());
} else {
// 执行失败,输出错误信息
System.err.println("Error executing Python code:\n" + errors.toString());
return new ResultEntity(HttpStatus.BAD_REQUEST,errors.toString());
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
return new ResultEntity(HttpStatus.BAD_REQUEST,e);
}
}
public static void main(String[] args) {
String pythonCode = "num=100\na=2\nb=2\nc=a+b\nprint(c)\n";
try {
// 构建Python命令和代码
String pythonCommand = "python";
String pythonCode = "#读取数据\n" +
"import pandas as pd\n" +
"df = pd.read_excel('IT行业收入表.xlsx')#读取excel表\n" +
"df.head()#使用函数,显示前几行数据\n" +
"\n" +
"# 此时的工龄为自变量,薪水为因变量,通过如下代码进行自变量、因变量选取\n" +
"X = df[['工龄']]\n" +
"Y = df['薪水']\n" +
"\n" +
"# 通过如下代码可以将此时的散点图绘制出来:\n" +
"from matplotlib import pyplot as plt\n" +
"%matplotlib inline\n" +
"plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签\n" +
"plt.scatter(X,Y)#绘制散点图\n" +
"plt.xlabel('工龄')#设置x轴标签\n" +
"plt.ylabel('薪水')#设置y轴标签\n" +
"plt.show()";
// 创建进程构建器
ProcessBuilder processBuilder = new ProcessBuilder(pythonCommand);
// 启动进程
Process process = processBuilder.start();
// 获取标准输入流
InputStream inputStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
// 将Python代码写入标准输入流
// 创建一个新的进程来执行Python代码
Process process = Runtime.getRuntime().exec("python");
// 获取进程的输入流
BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
// 获取进程的输出流
BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// 向进程的输入流写入Python代码
process.getOutputStream().write(pythonCode.getBytes());
process.getOutputStream().flush();
process.getOutputStream().close();
// 读取和打印Python解释器的输出
// 读取Python代码的输出
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
StringBuilder output = new StringBuilder();
while ((line = inputStream.readLine()) != null) {
output.append(line).append("\n");
}
// 读取Python代码的错误信息
StringBuilder errors = new StringBuilder();
while ((line = errorStream.readLine()) != null) {
errors.append(line).append("\n");
}
// 等待进程执行完成
int exitCode = process.waitFor();
System.out.println("Exit Code: " + exitCode);
if (exitCode == 0) {
// 执行成功输出Python代码的结果
System.out.println("Python code output:\n" + output.toString());
} else {
// 执行失败,输出错误信息
System.err.println("Error executing Python code:\n" + errors.toString());
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}

@ -4,12 +4,15 @@ package com.sztzjy.financial_bigdata.controller.stu;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sztzjy.financial_bigdata.annotation.AnonymousAccess;
import com.sztzjy.financial_bigdata.config.Constant;
import com.sztzjy.financial_bigdata.entity.*;
import com.sztzjy.financial_bigdata.entity.stu_dto.ObjQuestionCountDto;
import com.sztzjy.financial_bigdata.entity.stu_dto.StuTheoryExamDetailDto;
import com.sztzjy.financial_bigdata.entity.stu_dto.StuTheoryTestDto;
import com.sztzjy.financial_bigdata.entity.stu_dto.StuTheoryTestRecordDto;
import com.sztzjy.financial_bigdata.mapper.StuTheoryRecordMapper;
import com.sztzjy.financial_bigdata.mapper.StuUserMapper;
import com.sztzjy.financial_bigdata.mapper.SysObjectiveQuestionMapper;
import com.sztzjy.financial_bigdata.service.stu.ITheoryTestService;
import com.sztzjy.financial_bigdata.util.ResultEntity;
import io.swagger.annotations.Api;
@ -19,6 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -32,6 +37,8 @@ public class TheoryTestController {
StuTheoryRecordMapper recordMapper;
@Autowired
StuUserMapper userMapper;
@Autowired
SysObjectiveQuestionMapper objectiveQuestionMapper;
//开始考试 选择 35道单选每题2分5道多选每题4分10道判断每题1分
@GetMapping("startTheoryTest")
@ -124,6 +131,14 @@ public class TheoryTestController {
@ApiOperation("获取理论考试记录数据")
@AnonymousAccess
public ResultEntity<StuTheoryTestRecordDto> getTheoryRecord(String userId){
//先根据userid查询是否有记录 没有记录返回null
StuTheoryRecord record = recordMapper.selectByPrimaryKey(userId);
if(record==null){
StuTheoryTestRecordDto stuTheoryRecordDto = new StuTheoryTestRecordDto();
stuTheoryRecordDto.setExamCount(0);
stuTheoryRecordDto.setAverageScore(BigDecimal.ZERO);
return new ResultEntity<>(HttpStatus.OK, "暂无理论考试记录",stuTheoryRecordDto);
}
StuUser stuUser = userMapper.selectByPrimaryKey(userId);
String schoolId = stuUser.getSchoolId();
//查询该学校下的所有平均分 按高低排序
@ -132,8 +147,13 @@ public class TheoryTestController {
example.setOrderByClause("average_score desc");
List<StuTheoryRecord> stuTheoryRecords = recordMapper.selectByExample(example);
Integer paiming=null;
if(stuTheoryRecords==null){
return null;
if(stuTheoryRecords.size()==0){
StuTheoryTestRecordDto stuTheoryRecordDto = new StuTheoryTestRecordDto();
stuTheoryRecordDto.setExamCount(0);
stuTheoryRecordDto.setAverageScore(BigDecimal.ZERO);
stuTheoryRecordDto.setRank(0);
return new ResultEntity<>(HttpStatus.OK, "获取理论考试记录数据成功",stuTheoryRecordDto);
}else {
for (int i = 0; i < stuTheoryRecords.size(); i++) {
if(stuTheoryRecords.get(i).getUserId().equals(userId)){
@ -150,4 +170,50 @@ public class TheoryTestController {
return new ResultEntity<>(HttpStatus.OK, "获取理论考试记录数据成功",stuTheoryRecordDto);
}
//获取题库全部数据
@GetMapping("getObjQuestionCount")
@ApiOperation("获取客观题库数量")
@AnonymousAccess
public ResultEntity<ObjQuestionCountDto> getObjQuestionCount(@RequestParam String schoolId){
SysObjectiveQuestionExample singleExample = new SysObjectiveQuestionExample();
if(Constant.BUILT_IN_SCHOOL_ID.equals(schoolId)){
singleExample.createCriteria().andSchoolIdEqualTo(schoolId).andTypeEqualTo(Constant.OBJECTIVE_TYPE_SINGLE);
}else {
ArrayList<String> list = new ArrayList<>();
list.add(schoolId);
list.add(Constant.BUILT_IN_SCHOOL_ID);
singleExample.createCriteria().andSchoolIdIn(list).andTypeEqualTo(Constant.OBJECTIVE_TYPE_SINGLE);
}
long single = objectiveQuestionMapper.countByExample(singleExample);
SysObjectiveQuestionExample manyExample = new SysObjectiveQuestionExample();
if(Constant.BUILT_IN_SCHOOL_ID.equals(schoolId)){
manyExample.createCriteria().andSchoolIdEqualTo(schoolId).andTypeEqualTo(Constant.OBJECTIVE_TYPE_Many);
}else {
ArrayList<String> list = new ArrayList<>();
list.add(schoolId);
list.add(Constant.BUILT_IN_SCHOOL_ID);
manyExample.createCriteria().andSchoolIdIn(list).andTypeEqualTo(Constant.OBJECTIVE_TYPE_Many);
}
long many = objectiveQuestionMapper.countByExample(manyExample);
SysObjectiveQuestionExample judgeExample = new SysObjectiveQuestionExample();
if(Constant.BUILT_IN_SCHOOL_ID.equals(schoolId)){
judgeExample.createCriteria().andSchoolIdEqualTo(schoolId).andTypeEqualTo(Constant.OBJECTIVE_TYPE_JUDGE);
}else {
ArrayList<String> list = new ArrayList<>();
list.add(schoolId);
list.add(Constant.BUILT_IN_SCHOOL_ID);
judgeExample.createCriteria().andSchoolIdIn(list).andTypeEqualTo(Constant.OBJECTIVE_TYPE_JUDGE);
}
long judge = objectiveQuestionMapper.countByExample(judgeExample);
ObjQuestionCountDto objQuestionCountDto = new ObjQuestionCountDto();
objQuestionCountDto.setSingle(single);
objQuestionCountDto.setMany(many);
objQuestionCountDto.setJudge(judge);
return new ResultEntity<>(HttpStatus.OK, "获取客观题库数量成功",objQuestionCountDto);
}
}

@ -1,8 +1,10 @@
package com.sztzjy.financial_bigdata.controller.tea;
import com.sztzjy.financial_bigdata.annotation.AnonymousAccess;
import com.sztzjy.financial_bigdata.entity.TeaResourceCenter;
import com.sztzjy.financial_bigdata.entity.TeaResourceCenterExample;
import com.sztzjy.financial_bigdata.entity.*;
import com.sztzjy.financial_bigdata.entity.sys_dto.SysCourseDto;
import com.sztzjy.financial_bigdata.mapper.SysCourseChapterMapper;
import com.sztzjy.financial_bigdata.mapper.SysCourseMapper;
import com.sztzjy.financial_bigdata.mapper.TeaResourceCenterMapper;
import com.sztzjy.financial_bigdata.service.tea.ITeaResourceCenterService;
import com.sztzjy.financial_bigdata.util.ResultEntity;
@ -39,6 +41,10 @@ public class TeaResourceCenterController {
TeaResourceCenterMapper resourceCenterMapper;
@Value("${file.path}")
private String filePath;
@Autowired
private SysCourseMapper sysCourseMapper;
@Autowired
private SysCourseChapterMapper courseChapterMapper;
//上传资源文件

@ -0,0 +1,17 @@
package com.sztzjy.financial_bigdata.entity.stu_dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class ObjQuestionCountDto {
@ApiModelProperty("单选题数据量")
private long single;
@ApiModelProperty("多选题数据量")
private long many;
@ApiModelProperty("判断题数据量")
private long judge;
}

@ -57,4 +57,6 @@ public interface SysObjectiveQuestionMapper {
Map<Integer, BigDecimal> selectByList(@Param("list") List<String> list);
List<SysObjectiveQuestion> selectObjectivityByType(@Param("type")String type, @Param("schoolId")String schoolId);
List<SysObjectiveQuestion> selectBatchByIdList(@Param("idList") List<String> idList);
}

@ -33,12 +33,6 @@ public class ExamServiceImpl implements IExamService {
// 如果结束考试状态为true,则直接回显题目和考生的答题记录
@Override
public List<SysObjectiveQuestion> basicKnowledge(String examManageId, String userId,String classId) {
//判断考试时间是否已经超过
TeaExamManageWithBLOBs teaExamManageWithBLOBs = examManageMapper.selectByPrimaryKey(examManageId);
if(teaExamManageWithBLOBs.getEndTime().before(new Date())){
return null;
}
//查询学生考试记录
StuStudentExamExample example = new StuStudentExamExample();
example.createCriteria().andUseridEqualTo(userId).andExamManageIdEqualTo(examManageId);
@ -87,22 +81,16 @@ public class ExamServiceImpl implements IExamService {
String singleIds = teaExamManageWithBLOBs.getSingleIdlist();
String manyIds = teaExamManageWithBLOBs.getManyIdlist();
String judgeIds = teaExamManageWithBLOBs.getJudgeIdlist();
List<String> singleIdList = Arrays.asList(singleIds.substring(0, singleIds.length() ).split(","));
List<String> manyIdList = Arrays.asList(manyIds.substring(0, manyIds.length()).split(","));
List<String> judgeIdList = Arrays.asList(judgeIds.substring(0, judgeIds.length()).split(","));
List<String> singleIdList = Arrays.asList(singleIds.split(","));
List<String> manyIdList = Arrays.asList(manyIds.split(","));
List<String> judgeIdList = Arrays.asList(judgeIds.split(","));
List<SysObjectiveQuestion> objectiveQuestionList=new ArrayList<>();
for (int i = 0; i < singleIdList.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(singleIdList.get(i));
objectiveQuestionList.add(objectiveQuestion);
}
for (int i = 0; i < manyIdList.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(manyIdList.get(i));
objectiveQuestionList.add(objectiveQuestion);
}
for (int i = 0; i < judgeIdList.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(judgeIdList.get(i));
objectiveQuestionList.add(objectiveQuestion);
}
List<SysObjectiveQuestion> singleObjectiveQuestionList = objectiveQuestionMapper.selectBatchByIdList(singleIdList);;
objectiveQuestionList.addAll(singleObjectiveQuestionList);
List<SysObjectiveQuestion> manyObjectiveQuestionList = objectiveQuestionMapper.selectBatchByIdList(manyIdList);;
objectiveQuestionList.addAll(manyObjectiveQuestionList);
List<SysObjectiveQuestion> judgeObjectiveQuestionList = objectiveQuestionMapper.selectBatchByIdList(judgeIdList);;
objectiveQuestionList.addAll(judgeObjectiveQuestionList);
return objectiveQuestionList;
}

@ -9,6 +9,7 @@ import com.sztzjy.financial_bigdata.mapper.StuTrainingMapper;
import com.sztzjy.financial_bigdata.mapper.SysObjectiveQuestionMapper;
import com.sztzjy.financial_bigdata.service.stu.IExerciseService;
import com.sztzjy.financial_bigdata.service.tea.ITeaObjectiveService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -52,7 +53,7 @@ public class ExerciseServiceImpl implements IExerciseService {
return dtos;
}else {
StuTrainingWithBLOBs bloBs = stuTrainingWithBLOBs.get(0);
if (bloBs==null || bloBs.getLearningEvalIdlist().isEmpty()) {
if (bloBs==null) {
List<SysObjectiveQuestion> objectiveQuestionList = objectiveService.selectObjectQuestionListByChapterId(chapterId);
for (int i = 0; i < objectiveQuestionList.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionList.get(i);
@ -66,8 +67,8 @@ public class ExerciseServiceImpl implements IExerciseService {
trainingMapper.updateByPrimaryKey(bloBs);
return dtos;
}else {
if(bloBs.getLearningEvalAnswer()==null){ //判断是否提交过 未提交
List<String> learningEvalIdlist = Arrays.asList(bloBs.getLearningEvalIdlist().substring(1, bloBs.getLearningEvalIdlist().length() - 1).split(","));
if(StringUtils.isBlank(bloBs.getLearningEvalAnswer())){ //判断是否提交过 未提交
List<String> learningEvalIdlist = Arrays.asList(bloBs.getLearningEvalIdlist().substring(1, bloBs.getLearningEvalIdlist().length() - 1).split(", "));
for (int i = 0; i < learningEvalIdlist.size(); i++) {
String objectiveId = learningEvalIdlist.get(i);
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(objectiveId);
@ -76,8 +77,8 @@ public class ExerciseServiceImpl implements IExerciseService {
}
return dtos;
}else { //提交
List<String> learningEvalAnswerList = Arrays.asList(bloBs.getLearningEvalAnswer().substring(1, bloBs.getLearningEvalAnswer().length() - 1).split(","));
List<String> learningEvalIdlist = Arrays.asList(bloBs.getLearningEvalIdlist().substring(1, bloBs.getLearningEvalIdlist().length() - 1).split(","));
List<String> learningEvalAnswerList = Arrays.asList(bloBs.getLearningEvalAnswer().substring(1, bloBs.getLearningEvalAnswer().length() - 1).split(", "));
List<String> learningEvalIdlist = Arrays.asList(bloBs.getLearningEvalIdlist().substring(1, bloBs.getLearningEvalIdlist().length() - 1).split(", "));
for (int i = 0; i < learningEvalIdlist.size(); i++) {
String objectiveId = learningEvalIdlist.get(i);
String stuAnswer = learningEvalAnswerList.get(i);

@ -58,20 +58,14 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
String singleIds = stuTheoryExam.getSingleIds();
String multipleIds = stuTheoryExam.getMultipleIds();
String judgeIds = stuTheoryExam.getJudgeIds();
List<String> singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(","));
List<String> multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(","));
List<String> judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(","));
List<String> singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(", "));
List<String> multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(", "));
List<String> judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(", "));
List<String> idlist=new ArrayList<>();
idlist.addAll(singleIdList);
idlist.addAll(multipleIdList);
idlist.addAll(judgeIdList);
List<SysObjectiveQuestion> returnQuestionList = new ArrayList();
for (int i = 0; i < idlist.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(idlist.get(i));
returnQuestionList.add(objectiveQuestion);
}
// List<SysObjectiveQuestion> returnQuestionList = objectiveQuestionMapper.selectBatchByIdList(idlist);
List<SysObjectiveQuestion> returnQuestionList = objectiveQuestionMapper.selectBatchByIdList(idlist);
return returnQuestionList;
}
}
@ -122,9 +116,11 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
Integer examCount = record.getExamCount();
BigDecimal averageScore = record.getAverageScore();
BigDecimal multiply = averageScore.multiply(BigDecimal.valueOf(examCount));
multiply.add(score).divide(BigDecimal.valueOf(examCount).add(BigDecimal.valueOf(1))).setScale(2,BigDecimal.ROUND_HALF_UP);
BigDecimal newAvg = multiply.add(score).divide(BigDecimal.valueOf(examCount).add(BigDecimal.valueOf(1)), 2, BigDecimal.ROUND_HALF_UP);
record.setAverageScore(newAvg);
}
}
theoryRecordMapper.updateByPrimaryKey(record);
}
@ -202,7 +198,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
} else {
StuErrorWithBLOBs stuError = stuErrors.get(0);
if (stuError.getSingleIds()!=null) {
List<String> stringList = Arrays.asList(stuError.getSingleIds().substring(1, stuError.getSingleIds().length() - 1).split(","));
List<String> stringList = Arrays.asList(stuError.getSingleIds().substring(1, stuError.getSingleIds().length() - 1).split(", "));
List<String> singleErrorIds = theoryTestDto.getSingleErrorIds();
List<String> combinedList = new ArrayList<>(stringList);
@ -214,7 +210,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
stuError.setSingleIds(String.valueOf(theoryTestDto.getSingleErrorIds()));
}
if (stuError.getMultipleIds()!=null) {
List<String> stringList = Arrays.asList(stuError.getMultipleIds().substring(1, stuError.getMultipleIds().length() - 1).split(","));
List<String> stringList = Arrays.asList(stuError.getMultipleIds().substring(1, stuError.getMultipleIds().length() - 1).split(", "));
List<String> multipleErrorIds = theoryTestDto.getMultipleErrorIds();
List<String> combinedList = new ArrayList<>(stringList);
@ -226,7 +222,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
stuError.setMultipleIds(String.valueOf(theoryTestDto.getMultipleErrorIds()));
}
if (stuError.getJudgeIds()!=null) {
List<String> stringList = Arrays.asList(stuError.getJudgeIds().substring(1, stuError.getJudgeIds().length() - 1).split(","));
List<String> stringList = Arrays.asList(stuError.getJudgeIds().substring(1, stuError.getJudgeIds().length() - 1).split(", "));
List<String> judgeErrorIds = theoryTestDto.getJudgeErrorIds();
List<String> combinedList = new ArrayList<>(stringList);
combinedList.addAll(judgeErrorIds);
@ -254,7 +250,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
StuErrorWithBLOBs stuError = stuErrors.get(0);
String singleIds = stuError.getSingleIds();
if (!singleIds.isEmpty()) {
List<String> singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(","));
List<String> singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(", "));
for (int i = 0; i < singleIdList.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(singleIdList.get(i));
objectiveQuestionList.add(objectiveQuestion);
@ -262,7 +258,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
}
String multipleIds = stuError.getMultipleIds();
if (!multipleIds.isEmpty()) {
List<String> stringList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(","));
List<String> stringList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(", "));
for (int i = 0; i < stringList.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(stringList.get(i));
objectiveQuestionList.add(objectiveQuestion);
@ -270,7 +266,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
}
String judgeIds = stuError.getJudgeIds();
if (!judgeIds.isEmpty()) {
List<String> stringList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(","));
List<String> stringList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(", "));
for (int i = 0; i < stringList.size(); i++) {
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(stringList.get(i));
objectiveQuestionList.add(objectiveQuestion);
@ -290,7 +286,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
}
StuErrorWithBLOBs error = stuErrors.get(0);
if (Constant.OBJECTIVE_TYPE_SINGLE.equals(type)) {
List<String> stringList = Arrays.asList(error.getSingleIds().substring(1, stuErrors.get(0).getSingleIds().length() - 1).split(","));
List<String> stringList = Arrays.asList(error.getSingleIds().substring(1, stuErrors.get(0).getSingleIds().length() - 1).split(", "));
Set<String> set = new LinkedHashSet<>(stringList);
set.remove(objectiveQuestionId);
if(set.isEmpty()){
@ -301,7 +297,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
}
}
if (Constant.OBJECTIVE_TYPE_Many.equals(type)) {
Set<String> set = new LinkedHashSet<>(Arrays.asList(error.getMultipleIds().substring(1, error.getMultipleIds().length() - 1).split(",")));
Set<String> set = new LinkedHashSet<>(Arrays.asList(error.getMultipleIds().substring(1, error.getMultipleIds().length() - 1).split(", ")));
set.remove(objectiveQuestionId);
if(set.isEmpty()){
error.setMultipleIds(null);
@ -311,7 +307,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
}
}
if(Constant.OBJECTIVE_TYPE_JUDGE.equals(type)){
Set<String> set = new LinkedHashSet<>(Arrays.asList(error.getJudgeIds().substring(1, error.getJudgeIds().length() - 1).split(",")));
Set<String> set = new LinkedHashSet<>(Arrays.asList(error.getJudgeIds().substring(1, error.getJudgeIds().length() - 1).split(", ")));
set.remove(objectiveQuestionId);
if(set.isEmpty()){
error.setJudgeIds(null);
@ -329,6 +325,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
PageHelper.startPage(index, size);
StuTheoryExamExample example = new StuTheoryExamExample();
example.createCriteria().andUserIdEqualTo(userId);
example.setOrderByClause("exam_time desc");
List<StuTheoryExam> stuTheoryExams = theoryExamMapper.selectByExample(example);
PageInfo<StuTheoryExam> pageInfo = new PageInfo<>(stuTheoryExams);
return pageInfo;
@ -339,31 +336,71 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
StuTheoryExamWithBLOBs theoryExam = theoryExamMapper.selectByPrimaryKey(theoryExamId);
String singleIds = theoryExam.getSingleIds();
ArrayList<String> idsList = new ArrayList<>();
List<String> singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(","));
List<String> singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(", "));
String multipleIds = theoryExam.getMultipleIds();
List<String> multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(","));
List<String> multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(", "));
String judgeIds = theoryExam.getJudgeIds();
List<String> judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(","));
List<String> judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(", "));
idsList.addAll(singleIdList);
idsList.addAll(multipleIdList);
idsList.addAll(judgeIdList);
ArrayList<String> answerList = new ArrayList<>();
List<String> singleStuAnswer =Arrays.asList(theoryExam.getSingleStuAnswer().substring(1, theoryExam.getSingleStuAnswer().length() - 1).split(","));
List<String> multipleStuAnswer = Arrays.asList(theoryExam.getMultipleStuAnswer().substring(1, theoryExam.getMultipleStuAnswer().length() - 1).split(","));
List<String> judgeStuAnswer = Arrays.asList(theoryExam.getJudgeStuAnswer().substring(1, theoryExam.getJudgeStuAnswer().length() - 1).split(","));
answerList.addAll(singleStuAnswer);
answerList.addAll(multipleStuAnswer);
answerList.addAll(judgeStuAnswer);
if(theoryExam.getSingleStuAnswer()!=null){
String[] singleSplit = theoryExam.getSingleStuAnswer().substring(1, theoryExam.getSingleStuAnswer().length() - 1).split(",");
for (String str : singleSplit) {
if (str.equals("") || str.equals(" ")) {
answerList.add(null);
} else {
answerList.add(str);
}
}
}
if(theoryExam.getMultipleStuAnswer()!=null){
String[] multipleSplit = theoryExam.getMultipleStuAnswer().substring(1, theoryExam.getMultipleStuAnswer().length() - 1).split(",");
for (String str : multipleSplit) {
if (str.equals("") || str.equals(" ")) {
answerList.add(null);
} else {
String strSort = sortString(str);
answerList.add(strSort);
}
}
}
if(theoryExam.getJudgeStuAnswer()!=null){
String[] judgeSplit = theoryExam.getJudgeStuAnswer().substring(1, theoryExam.getJudgeStuAnswer().length() - 1).split(",");
for (String str : judgeSplit) {
if (str.equals("") || str.equals(" ")) {
answerList.add(null);
} else {
answerList.add(str);
}
}
}
List<StuTheoryExamDetailDto> detailDtos=new ArrayList<>();
if(answerList.size()==0){
return null;
}
for (int i = 0; i < answerList.size(); i++) {
if(answerList.get(i)==null){
answerList.set(i,"空");
}
}
for (Integer i = (index-1)*size; i < (index-1)*size+size; i++) {
StuTheoryExamDetailDto detailDto = new StuTheoryExamDetailDto();
String objectiveQuestionId = idsList.get(i);
String stuAnswer = answerList.get(i);
String stuAnswer = answerList.get(i).trim();
SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(objectiveQuestionId);
BigDecimal score = objectiveQuestion.getScore();
String content = objectiveQuestion.getContent();
String answer = objectiveQuestion.getAnswer();
if(answer.equals(stuAnswer)){
if(stuAnswer.equals("true")){
stuAnswer="对";
}
if(stuAnswer.equals("false")){
stuAnswer="错";
}
if(answer.replaceAll(",","").equals(stuAnswer)){
detailDto.setScore(String.valueOf(score));
detailDto.setStatus("正确");
}else {
@ -372,11 +409,9 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
}
detailDto.setContent(content);
detailDto.setMychoice(stuAnswer);
detailDto.setAnswer(answer);
detailDto.setAnswer(answer.replaceAll(",",""));
detailDtos.add(detailDto);
}
return detailDtos;
}
@ -403,5 +438,12 @@ public class TheoryTestServiceImpl implements ITheoryTestService {
}
}
//字母排序
private static String sortString(String str) {
char[] charArray = str.toCharArray();
Arrays.sort(charArray);
return new String(charArray);
}
}

@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -44,10 +45,14 @@ public class TeaResourceCenterServiceImpl implements ITeaResourceCenterService {
public List<TeaResourceCenter> selectResource(String schoolId, String courseId) {
TeaResourceCenterExample example=new TeaResourceCenterExample();
TeaResourceCenterExample.Criteria criteria = example.createCriteria();
TeaResourceCenterExample.Criteria criteria2 = example.createCriteria();
criteria.andCourseIdEqualTo(courseId).andSchoolIdEqualTo(schoolId);
criteria2.andCourseIdEqualTo(courseId).andSchoolIdIsNull();
example.or(criteria2);
if(Constant.BUILT_IN_SCHOOL_ID.equals(schoolId)){
criteria.andCourseIdEqualTo(courseId).andSchoolIdEqualTo(schoolId);
}else {
List<String> schoolIds=new ArrayList<>();
schoolIds.add(Constant.BUILT_IN_SCHOOL_ID);
schoolIds.add(schoolId);
criteria.andCourseIdEqualTo(courseId).andSchoolIdIn(schoolIds);
}
List<TeaResourceCenter> teaResourceCenterList = resourceCenterMapper.selectByExample(example);
return teaResourceCenterList;
}

@ -492,4 +492,13 @@
AND type = #{type}
</select>
<select id="selectBatchByIdList" parameterType="java.util.List" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM sys_objective_question WHERE objective_id IN
<foreach item="item" index="index" collection="idList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
Loading…
Cancel
Save