新增理论考试新功能 修复考试部分bug 新增python运行接口
parent
e56506444f
commit
a5ccb5b057
@ -1,13 +1,74 @@
|
|||||||
package com.sztzjy.financial_bigdata.controller.stu;
|
package com.sztzjy.financial_bigdata.controller.stu;
|
||||||
|
|
||||||
|
import com.sztzjy.financial_bigdata.annotation.AnonymousAccess;
|
||||||
|
import com.sztzjy.financial_bigdata.entity.SysCaseQuestion;
|
||||||
|
import com.sztzjy.financial_bigdata.entity.SysCaseQuestionExample;
|
||||||
|
import com.sztzjy.financial_bigdata.entity.SysCaseQuestionStep;
|
||||||
|
import com.sztzjy.financial_bigdata.entity.SysCaseQuestionStepExample;
|
||||||
|
import com.sztzjy.financial_bigdata.mapper.SysCaseQuestionMapper;
|
||||||
|
import com.sztzjy.financial_bigdata.mapper.SysCaseQuestionStepMapper;
|
||||||
|
import com.sztzjy.financial_bigdata.service.tea.ITeaCaseStepService;
|
||||||
|
import com.sztzjy.financial_bigdata.util.ResultEntity;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
//实训演练-实训案例-实验实训
|
//实训演练-实训案例-实验实训
|
||||||
@RestController
|
@RestController
|
||||||
@Api(tags = "实训演练-实训案例-实验实训")
|
@Api(tags = "实训演练-实训案例-实验实训")
|
||||||
@RequestMapping("api/stu/exercise/experimentalTrainingController")
|
@RequestMapping("api/stu/exercise/experimentalTrainingController")
|
||||||
public class ExerciseExperimentalTraining {
|
public class ExerciseExperimentalTraining {
|
||||||
|
@Autowired
|
||||||
|
SysCaseQuestionMapper caseQuestionMapper;
|
||||||
|
@Autowired
|
||||||
|
SysCaseQuestionStepMapper caseQuestionStepMapper;
|
||||||
|
@Autowired
|
||||||
|
ITeaCaseStepService stepService;
|
||||||
|
|
||||||
|
//获取案例题基础信息
|
||||||
|
@GetMapping("getCaseInfo")
|
||||||
|
@ApiOperation("获取案例题基础信息")
|
||||||
|
@AnonymousAccess
|
||||||
|
public ResultEntity<SysCaseQuestion> getCaseInfo(@RequestParam String chapterId) {
|
||||||
|
SysCaseQuestionExample example = new SysCaseQuestionExample();
|
||||||
|
example.createCriteria().andChapterIdEqualTo(chapterId);
|
||||||
|
List<SysCaseQuestion> sysCaseQuestions = caseQuestionMapper.selectByExample(example);
|
||||||
|
return new ResultEntity<>(HttpStatus.OK, "获取案例题基础信息查询成功", sysCaseQuestions.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取案例题步骤基础信息
|
||||||
|
//判断是否需要回显、如果学生实训表中 实验实训步骤sort存在、则返回学生答案
|
||||||
|
@GetMapping("getCaseStepInfo")
|
||||||
|
@ApiOperation("获取案例题步骤基础信息")
|
||||||
|
@AnonymousAccess
|
||||||
|
public ResultEntity<List<SysCaseQuestionStep>> getCaseStepInfo(@RequestParam String caseId) {
|
||||||
|
SysCaseQuestionStepExample example = new SysCaseQuestionStepExample();
|
||||||
|
example.createCriteria().andCaseIdEqualTo(caseId);
|
||||||
|
List<SysCaseQuestionStep> stepList = caseQuestionStepMapper.selectByExample(example);
|
||||||
|
for (int i = 0; i < stepList.size(); i++) {
|
||||||
|
stepList.get(0).setAnswer("");
|
||||||
|
stepList.get(0).setAnswerOriginal("");
|
||||||
|
}
|
||||||
|
return new ResultEntity<>(HttpStatus.OK, "获取案例题基础信息查询成功", stepList);
|
||||||
|
}
|
||||||
|
|
||||||
|
//提交案例题
|
||||||
|
@PostMapping("commitCase")
|
||||||
|
@ApiOperation("提交案例题")
|
||||||
|
@AnonymousAccess
|
||||||
|
public ResultEntity getCaseStepInfo(@ApiParam("将学生答案传递到answer中") @RequestParam SysCaseQuestionStep caseQuestionStep) {
|
||||||
|
|
||||||
|
//执行记录操作
|
||||||
|
Boolean flag = stepService.commitCase(caseQuestionStep);
|
||||||
|
return new ResultEntity<>(HttpStatus.OK, "回答正确、该步骤提交成功");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//python在线运行
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.sztzjy.financial_bigdata.controller.stu;// 后端代码
|
||||||
|
|
||||||
|
import com.sztzjy.financial_bigdata.util.ResultEntity;
|
||||||
|
import org.python.core.CompileMode;
|
||||||
|
import org.python.core.Py;
|
||||||
|
import org.python.core.PyCode;
|
||||||
|
import org.python.util.PythonInterpreter;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/python")
|
||||||
|
public class PythonController {
|
||||||
|
|
||||||
|
@PostMapping("/validate")
|
||||||
|
public ResultEntity validatePythonCode(@RequestBody String code) {
|
||||||
|
// 对 Python 代码进行检验
|
||||||
|
PythonInterpreter interpreter = new PythonInterpreter();
|
||||||
|
try {
|
||||||
|
InputStream stream = new ByteArrayInputStream(code.getBytes());
|
||||||
|
PyCode pyCode = Py.compile(stream, "<string>", CompileMode.exec);
|
||||||
|
interpreter.exec(pyCode);
|
||||||
|
return new ResultEntity<>(HttpStatus.OK, "语法正确");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "语法有误",e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String code="if True:\n" +
|
||||||
|
" print (\"True\")\n" +
|
||||||
|
"else:\n" +
|
||||||
|
" print (\"False\")\n";
|
||||||
|
PythonInterpreter interpreter = new PythonInterpreter();
|
||||||
|
try {
|
||||||
|
InputStream stream = new ByteArrayInputStream(code.getBytes());
|
||||||
|
PyCode pyCode = Py.compile(stream, "<string>", CompileMode.exec);
|
||||||
|
interpreter.exec(pyCode);
|
||||||
|
|
||||||
|
System.out.println("2");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage()); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue