diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/ExamController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/ExamController.java index 870b667..60ff3a8 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/ExamController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/ExamController.java @@ -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> 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 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)); diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/PythonController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/PythonController.java index db4ea01..74a7c58 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/PythonController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/PythonController.java @@ -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, "", 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(); } } + + + } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java index be8fde9..7ec734a 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/stu/TheoryTestController.java @@ -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 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 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 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 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 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 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); + } + } diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java index 57c658c..d92888e 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java @@ -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; //上传资源文件 diff --git a/src/main/java/com/sztzjy/financial_bigdata/entity/stu_dto/ObjQuestionCountDto.java b/src/main/java/com/sztzjy/financial_bigdata/entity/stu_dto/ObjQuestionCountDto.java new file mode 100644 index 0000000..64b1cbc --- /dev/null +++ b/src/main/java/com/sztzjy/financial_bigdata/entity/stu_dto/ObjQuestionCountDto.java @@ -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; + +} diff --git a/src/main/java/com/sztzjy/financial_bigdata/mapper/SysObjectiveQuestionMapper.java b/src/main/java/com/sztzjy/financial_bigdata/mapper/SysObjectiveQuestionMapper.java index 0a26997..329478c 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/mapper/SysObjectiveQuestionMapper.java +++ b/src/main/java/com/sztzjy/financial_bigdata/mapper/SysObjectiveQuestionMapper.java @@ -57,4 +57,6 @@ public interface SysObjectiveQuestionMapper { Map selectByList(@Param("list") List list); List selectObjectivityByType(@Param("type")String type, @Param("schoolId")String schoolId); + + List selectBatchByIdList(@Param("idList") List idList); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExamServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExamServiceImpl.java index 23dc16a..bbf75a0 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExamServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExamServiceImpl.java @@ -33,12 +33,6 @@ public class ExamServiceImpl implements IExamService { // 如果结束考试状态为true,则直接回显题目和考生的答题记录 @Override public List 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 singleIdList = Arrays.asList(singleIds.substring(0, singleIds.length() ).split(",")); - List manyIdList = Arrays.asList(manyIds.substring(0, manyIds.length()).split(",")); - List judgeIdList = Arrays.asList(judgeIds.substring(0, judgeIds.length()).split(",")); + List singleIdList = Arrays.asList(singleIds.split(",")); + List manyIdList = Arrays.asList(manyIds.split(",")); + List judgeIdList = Arrays.asList(judgeIds.split(",")); List 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 singleObjectiveQuestionList = objectiveQuestionMapper.selectBatchByIdList(singleIdList);; + objectiveQuestionList.addAll(singleObjectiveQuestionList); + List manyObjectiveQuestionList = objectiveQuestionMapper.selectBatchByIdList(manyIdList);; + objectiveQuestionList.addAll(manyObjectiveQuestionList); + List judgeObjectiveQuestionList = objectiveQuestionMapper.selectBatchByIdList(judgeIdList);; + objectiveQuestionList.addAll(judgeObjectiveQuestionList); return objectiveQuestionList; } diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java index c2c9efd..322442a 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/ExerciseServiceImpl.java @@ -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 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 learningEvalIdlist = Arrays.asList(bloBs.getLearningEvalIdlist().substring(1, bloBs.getLearningEvalIdlist().length() - 1).split(",")); + if(StringUtils.isBlank(bloBs.getLearningEvalAnswer())){ //判断是否提交过 未提交 + List 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 learningEvalAnswerList = Arrays.asList(bloBs.getLearningEvalAnswer().substring(1, bloBs.getLearningEvalAnswer().length() - 1).split(",")); - List learningEvalIdlist = Arrays.asList(bloBs.getLearningEvalIdlist().substring(1, bloBs.getLearningEvalIdlist().length() - 1).split(",")); + List learningEvalAnswerList = Arrays.asList(bloBs.getLearningEvalAnswer().substring(1, bloBs.getLearningEvalAnswer().length() - 1).split(", ")); + List 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); diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java index e79cbd7..c3d645c 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/stu/impl/TheoryTestServiceImpl.java @@ -58,20 +58,14 @@ public class TheoryTestServiceImpl implements ITheoryTestService { String singleIds = stuTheoryExam.getSingleIds(); String multipleIds = stuTheoryExam.getMultipleIds(); String judgeIds = stuTheoryExam.getJudgeIds(); - List singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(",")); - List multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(",")); - List judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(",")); + List singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(", ")); + List multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(", ")); + List judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(", ")); List idlist=new ArrayList<>(); idlist.addAll(singleIdList); idlist.addAll(multipleIdList); idlist.addAll(judgeIdList); - List returnQuestionList = new ArrayList(); - for (int i = 0; i < idlist.size(); i++) { - SysObjectiveQuestion objectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(idlist.get(i)); - returnQuestionList.add(objectiveQuestion); - } -// List returnQuestionList = objectiveQuestionMapper.selectBatchByIdList(idlist); - + List 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 stringList = Arrays.asList(stuError.getSingleIds().substring(1, stuError.getSingleIds().length() - 1).split(",")); + List stringList = Arrays.asList(stuError.getSingleIds().substring(1, stuError.getSingleIds().length() - 1).split(", ")); List singleErrorIds = theoryTestDto.getSingleErrorIds(); List combinedList = new ArrayList<>(stringList); @@ -214,7 +210,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService { stuError.setSingleIds(String.valueOf(theoryTestDto.getSingleErrorIds())); } if (stuError.getMultipleIds()!=null) { - List stringList = Arrays.asList(stuError.getMultipleIds().substring(1, stuError.getMultipleIds().length() - 1).split(",")); + List stringList = Arrays.asList(stuError.getMultipleIds().substring(1, stuError.getMultipleIds().length() - 1).split(", ")); List multipleErrorIds = theoryTestDto.getMultipleErrorIds(); List combinedList = new ArrayList<>(stringList); @@ -226,7 +222,7 @@ public class TheoryTestServiceImpl implements ITheoryTestService { stuError.setMultipleIds(String.valueOf(theoryTestDto.getMultipleErrorIds())); } if (stuError.getJudgeIds()!=null) { - List stringList = Arrays.asList(stuError.getJudgeIds().substring(1, stuError.getJudgeIds().length() - 1).split(",")); + List stringList = Arrays.asList(stuError.getJudgeIds().substring(1, stuError.getJudgeIds().length() - 1).split(", ")); List judgeErrorIds = theoryTestDto.getJudgeErrorIds(); List 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 singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(",")); + List 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 stringList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(",")); + List 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 stringList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(",")); + List 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 stringList = Arrays.asList(error.getSingleIds().substring(1, stuErrors.get(0).getSingleIds().length() - 1).split(",")); + List stringList = Arrays.asList(error.getSingleIds().substring(1, stuErrors.get(0).getSingleIds().length() - 1).split(", ")); Set 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 set = new LinkedHashSet<>(Arrays.asList(error.getMultipleIds().substring(1, error.getMultipleIds().length() - 1).split(","))); + Set 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 set = new LinkedHashSet<>(Arrays.asList(error.getJudgeIds().substring(1, error.getJudgeIds().length() - 1).split(","))); + Set 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 stuTheoryExams = theoryExamMapper.selectByExample(example); PageInfo 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 idsList = new ArrayList<>(); - List singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(",")); + List singleIdList = Arrays.asList(singleIds.substring(1, singleIds.length() - 1).split(", ")); String multipleIds = theoryExam.getMultipleIds(); - List multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(",")); + List multipleIdList = Arrays.asList(multipleIds.substring(1, multipleIds.length() - 1).split(", ")); String judgeIds = theoryExam.getJudgeIds(); - List judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(",")); + List judgeIdList = Arrays.asList(judgeIds.substring(1, judgeIds.length() - 1).split(", ")); idsList.addAll(singleIdList); idsList.addAll(multipleIdList); idsList.addAll(judgeIdList); ArrayList answerList = new ArrayList<>(); - List singleStuAnswer =Arrays.asList(theoryExam.getSingleStuAnswer().substring(1, theoryExam.getSingleStuAnswer().length() - 1).split(",")); - List multipleStuAnswer = Arrays.asList(theoryExam.getMultipleStuAnswer().substring(1, theoryExam.getMultipleStuAnswer().length() - 1).split(",")); - List 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 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); + } + } diff --git a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaResourceCenterServiceImpl.java b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaResourceCenterServiceImpl.java index 0945458..60088ac 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaResourceCenterServiceImpl.java +++ b/src/main/java/com/sztzjy/financial_bigdata/service/tea/impl/TeaResourceCenterServiceImpl.java @@ -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 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 schoolIds=new ArrayList<>(); + schoolIds.add(Constant.BUILT_IN_SCHOOL_ID); + schoolIds.add(schoolId); + criteria.andCourseIdEqualTo(courseId).andSchoolIdIn(schoolIds); + } List teaResourceCenterList = resourceCenterMapper.selectByExample(example); return teaResourceCenterList; } diff --git a/src/main/resources/mapper/SysObjectiveQuestionMapper.xml b/src/main/resources/mapper/SysObjectiveQuestionMapper.xml index cb1a657..da6d18a 100644 --- a/src/main/resources/mapper/SysObjectiveQuestionMapper.xml +++ b/src/main/resources/mapper/SysObjectiveQuestionMapper.xml @@ -492,4 +492,13 @@ AND type = #{type} + + \ No newline at end of file