考试练习优化
This commit is contained in:
parent
9c84a5657d
commit
bc52cd32f0
|
|
@ -62,112 +62,10 @@ public class CmsExaminationController {
|
|||
@RequestMapping("/examination/start/{id}")
|
||||
@GetMapping()
|
||||
public String start(@PathVariable String id, ModelMap mmap) {
|
||||
ExamExamination examExamination = examExaminationService.selectById( id );
|
||||
// SysUser sysUser = sysUserService.selectUserByLoginName( JwtUtil.getLoginName() );
|
||||
// Integer userId = Integer.parseInt( sysUser.getUserId().toString() );
|
||||
//考试类型
|
||||
String type = examExamination.getType();
|
||||
//试卷ID
|
||||
Integer examPaperId = examExamination.getExamPaperId();
|
||||
//考试次数
|
||||
Integer examNumber = examExamination.getExamNumber();
|
||||
//考试时长
|
||||
Integer timeLength = examExamination.getTimeLength();
|
||||
//考试记录ID
|
||||
ExamExamination examExamination = examExaminationService.selectById(id);
|
||||
Integer examUserExaminationId = -1;
|
||||
// if(1==1){
|
||||
// mmap.put("error","已超过" + examNumber + "次考试");
|
||||
// return prefix + "list";
|
||||
// }
|
||||
ExamUserExamination insert = new ExamUserExamination();
|
||||
//正式考试
|
||||
if (type.equals( "2" )) {
|
||||
ExamUserExamination examUserExamination = new ExamUserExamination();
|
||||
examUserExamination.setVipUserId( 1 );
|
||||
examUserExamination.setExamPaperId( examPaperId );
|
||||
examUserExamination.setExamExaminationId( Integer.parseInt( id ) );
|
||||
//考试记录集合
|
||||
List<ExamUserExamination> userExamination = examUserExaminationService.selectLastOne( examUserExamination );
|
||||
// 最后一次考试
|
||||
ExamUserExamination last;
|
||||
|
||||
//超过考试次数
|
||||
if (userExamination.size() >= examNumber) {
|
||||
|
||||
last = userExamination.get( 0 );
|
||||
//最后一次考试已交卷,直接返回
|
||||
if (last.getUpdateDate() != null && !last.getUpdateDate().equals( "" )) {
|
||||
throw new BaseException("已超过" + examNumber + "次考试,");
|
||||
// return error( 500, "已超过" + examNumber + "次考试," );
|
||||
} else {
|
||||
// 最后一次考试未交卷,但超过考试时长,直接返回
|
||||
if (last.getCreateDate().getTime() + timeLength * 60 * 1000 < new Date().getTime()) {
|
||||
throw new BaseException( "已超过" + examNumber + "次考试," );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (userExamination.size() <= 0 //考试次数小于0
|
||||
|| userExamination.get( 0 ).getUpdateDate() != null //最后一次考试已交卷
|
||||
|| userExamination.get( 0 ).getCreateDate().getTime() + timeLength * 60 * 1000 < new Date().getTime()//最后一次考试,已超过考过时长
|
||||
) {
|
||||
insert.setExamExaminationId( Integer.parseInt( id ) );
|
||||
insert.setVipUserId( 1 );
|
||||
insert.setCreateDate( new Date() );
|
||||
insert.setExamPaperId( examPaperId );
|
||||
insert.setDelFlag( "0" );
|
||||
insert.setScore( 0 );
|
||||
examUserExaminationService.insertOne( insert );
|
||||
examUserExaminationId = insert.getId();
|
||||
} else {
|
||||
examUserExaminationId = userExamination.get( 0 ).getId();
|
||||
}
|
||||
|
||||
}
|
||||
ExamPaper examPaper = examPaperService.selectById(examPaperId);
|
||||
List<ExamQuestionVO> data = new ArrayList<>();
|
||||
List<ExamQuestionVO> list = examPaperService.selectQuestionAndItemByPaperId( examPaperId );
|
||||
//随机试卷
|
||||
if(examPaper.getType().equals("2")){
|
||||
Collections.shuffle( list );
|
||||
ExamPaperTypeNumber examPaperTypeNumber = new ExamPaperTypeNumber();
|
||||
examPaperTypeNumber.setExamPaperId(examPaperId);
|
||||
List<ExamPaperTypeNumber> examPaperTypeNumbers = examPaperTypeNumberService.selectList(examPaperTypeNumber);
|
||||
//三种题型的数量
|
||||
int one=0,two=0,three=0;
|
||||
for (ExamPaperTypeNumber item : examPaperTypeNumbers) {
|
||||
if(item.getExamQuestionType()==1){
|
||||
one = item.getNumber();
|
||||
}
|
||||
if(item.getExamQuestionType()==2){
|
||||
two = item.getNumber();
|
||||
}
|
||||
if(item.getExamQuestionType()==3){
|
||||
three = item.getNumber();
|
||||
}
|
||||
}
|
||||
for (ExamQuestionVO item : list) {
|
||||
if(item.getType().equals("1")&&one>0){
|
||||
data.add(item);
|
||||
one--;
|
||||
}
|
||||
if(item.getType().equals("2")&&two>0){
|
||||
data.add(item);
|
||||
two--;
|
||||
}
|
||||
if(item.getType().equals("3")&&three>0){
|
||||
data.add(item);
|
||||
three--;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
data = list;
|
||||
}
|
||||
//是否乱序
|
||||
if (examExamination.getQuestionDisorder().equals( "2" )) {
|
||||
Collections.shuffle( list );
|
||||
}
|
||||
List<ExamQuestionVO> data = examExaminationService.queryExaminationQuestion(examExamination,examUserExaminationId);
|
||||
Integer examPaperId = examExamination.getExamPaperId();
|
||||
|
||||
mmap.put( "data", data );
|
||||
mmap.put( "examUserExaminationId", examUserExaminationId );
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public class CmsPracticeController {
|
|||
Collections.shuffle(result);
|
||||
}
|
||||
mmap.put("data", result);
|
||||
mmap.put("practice",examPracticeService.selectById(id));
|
||||
return prefix + "detail";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@
|
|||
|
||||
<div class="layui-col-md9">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-card" th:each="question:${data}">
|
||||
<div class="layui-card" style="text-align: center;">
|
||||
<span style="font-size: 30px;line-height: 60px">[[${examExamination.name}]]</span>
|
||||
</div>
|
||||
<div class="layui-card question" th:each="question:${data}">
|
||||
<div class="layui-card-header">[[${questionStat.index+1}]]:<span
|
||||
th:text="${question.title}"></span>
|
||||
<span th:if="${question.type=='1'}">(单选)</span>
|
||||
|
|
@ -34,18 +37,18 @@
|
|||
|
||||
|
||||
<!--<div class="layui-card-body">-->
|
||||
<!--<button class="layui-btn layui-btn-warm"-->
|
||||
<!--th:onclick="'analysis('+${question.id}+',\''+${question.answer}+'\')'">解析-->
|
||||
<!--</button>-->
|
||||
<!--<button class="layui-btn layui-btn-warm"-->
|
||||
<!--th:onclick="'analysis('+${question.id}+',\''+${question.answer}+'\')'">解析-->
|
||||
<!--</button>-->
|
||||
<!--</div>-->
|
||||
<!--<div class="layui-card-body" hidden th:id="${question.id}+'answer'">-->
|
||||
<!--解析:正确答案[[${question.answer}]]<br>-->
|
||||
<!--[[${question.label}]]-->
|
||||
<!--解析:正确答案[[${question.answer}]]<br>-->
|
||||
<!--[[${question.label}]]-->
|
||||
<!--</div>-->
|
||||
</div>
|
||||
|
||||
<div class="layui-card">
|
||||
<button class="layui-btn layui-btn-warm" onclick="endPaper()">交卷</button>
|
||||
<button class="layui-btn layui-btn-warm" onclick="endPaper()" >交卷</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -53,7 +56,6 @@
|
|||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -78,26 +80,23 @@ document.write(unescape("%3Cspan id='cnzz_stat_icon_30088308'%3E%3C/span%3E%3Csc
|
|||
})
|
||||
|
||||
|
||||
|
||||
function endPaper() {
|
||||
var userAnswer = $("." + id + "useranswer:checked").val();
|
||||
if (userAnswer != answer) {
|
||||
layer.msg('回答错误', {icon: 2});
|
||||
var data = [];
|
||||
$(".question").each(function(){
|
||||
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: "/api/v1/practice/answer",
|
||||
contentType: "application/json",
|
||||
data: "[" + id + "]",
|
||||
success: function (result) {
|
||||
if (result.code != web_status.SUCCESS) {
|
||||
$.modal.msgError(result.msg);
|
||||
}
|
||||
})
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: "/api/v1/examination/finish/"+[[${examUserExaminationId}]]+"/"+[[${examExamination.id}]]+"/"+[[${paperId}]],
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
success: function (result) {
|
||||
if (result.code != web_status.SUCCESS) {
|
||||
$.modal.msgError(result.msg);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
$("#" + id + "answer").show()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@
|
|||
,limitName: 'pageSize' //每页数据量的参数名,默认:limit
|
||||
}
|
||||
,response: {
|
||||
statusCode: 200 //规定成功的状态码,默认:0
|
||||
statusCode: 200,
|
||||
countName: 'total'//规定成功的状态码,默认:0
|
||||
}
|
||||
,page: true
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@
|
|||
<div class="fly-panel">
|
||||
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-card" style="text-align: center;">
|
||||
<span style="font-size: 30px;line-height: 60px">[[${practice.name}]]</span>
|
||||
</div>
|
||||
|
||||
<div class="layui-card" th:each="question:${data}">
|
||||
<div class="layui-card-header">[[${questionStat.index+1}]]:<span th:text="${question.title}"></span>
|
||||
<span th:if="${question.type=='1'}">(单选)</span>
|
||||
|
|
|
|||
|
|
@ -43,11 +43,12 @@
|
|||
,{title: '操作',toolbar: '#barDemo'}
|
||||
] ]
|
||||
,request: {
|
||||
pageName: 'pageNumber' //页码的参数名称,默认:page
|
||||
pageName: 'pageNum' //页码的参数名称,默认:page
|
||||
,limitName: 'pageSize' //每页数据量的参数名,默认:limit
|
||||
}
|
||||
,response: {
|
||||
statusCode: 200 //规定成功的状态码,默认:0
|
||||
statusCode: 200
|
||||
,countName: 'total'
|
||||
}
|
||||
,page: true
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue