From daf7acb4f107a427e4a83ba1eb26e5e6012cbdaf Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: Wed, 26 Jun 2024 17:04:52 +0800
Subject: [PATCH] update
---
exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExExamPaperServiceImpl.java | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExExamPaperServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExExamPaperServiceImpl.java
index a24760b..5bd7e0d 100644
--- a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExExamPaperServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExExamPaperServiceImpl.java
@@ -88,6 +88,8 @@
examPaper.setCreateBy(SecurityUtils.getUsername());
if(examPaper.getLimitTime()>0){
examPaper.setLimit(1);
+ }else{
+ examPaper.setLimit(0);
}
int row=baseMapper.insert(examPaper);
if(row<1){
@@ -135,19 +137,19 @@
}
private List<ExPaperQuestion> getPaperQuestions(Long paperId,Long bankId,Integer questionMethod,Integer questionCount,Integer questionScore, QuestionTypeEnum questionTypeEnum) {
- SysUser user=SecurityUtils.getLoginUser().getUser();
- Integer totalQuestionCount=questionMapper.selectCountByBankId(user.getCompanyId(), bankId, questionTypeEnum.getCode());
+ SysUser currentUser=SecurityUtils.getLoginUser().getUser();
+ Integer totalQuestionCount=questionMapper.selectCountByBankId(currentUser.getCompanyId(), bankId, questionTypeEnum.getCode());
if(totalQuestionCount< questionCount){
throw new ApiException(String.format("所选题库<%s>数量不足,无法分配",questionTypeEnum.getInfo()));
}
List<ExQuestion> questions=new ArrayList<>();
if(Objects.equals(questionMethod, QuestionAssignEnum.RANDOM.getCode())){//随机分配
- questions=questionMapper.selectRandomQuestion(user.getCompanyId(), bankId,questionTypeEnum.getCode(), questionCount);
+ questions=questionMapper.selectRandomQuestion(currentUser.getCompanyId(), bankId,questionTypeEnum.getCode(), questionCount);
}else{//顺序分配
- int totalPage=questionCount/ questionMethod;//不能整除,忽略最后一页
+ int totalPage=questionCount/questionMethod;//不能整除,忽略最后一页
Random random=new Random();
int startIndex=random.nextInt(totalPage)+1;
- questions=questionMapper.selectQuestionWithLimit(user.getCompanyId(), bankId,questionTypeEnum.getCode(),startIndex, questionCount);
+ questions=questionMapper.selectQuestionWithLimit(currentUser.getCompanyId(), bankId,questionTypeEnum.getCode(),startIndex, questionCount);
}
List<ExPaperQuestion> paperQuestionList=questions.stream().map(item -> {
ExPaperQuestion exPaperQuestion=new ExPaperQuestion();
@@ -162,6 +164,7 @@
@Override
public int updateExamPaper(ExExamPaper examPaper) {
+ checkUserAllowed(examPaper);
if(!checkNameUnique(examPaper)){
throw new ApiException("试卷名称已存在");
}
@@ -170,7 +173,9 @@
throw new ApiException("该试卷下已分配学员,不能编辑");
}
examPaper.setCode(null);//编号不能修改
- if(examPaper.getLimitTime()==0){
+ if(examPaper.getLimitTime()>0){
+ examPaper.setLimit(1);
+ }else{
examPaper.setLimit(0);
}
int row=baseMapper.updateById(examPaper);
@@ -199,16 +204,17 @@
@Override
public int deleteExamPaperById(Long paperId) {
+ checkUserAllowed(baseMapper.selectById(paperId));
//查询该试卷分配的学员人数
if(checkPaperHasStudent(paperId)){
throw new ApiException("该试卷下已分配学员,不能删除");
}
- int row=baseMapper.deleteById(paperId);
+ int row=baseMapper.deletePaperById(paperId);
if(row<1){
throw new ApiException("删除试卷失败");
}
//删除考卷试题
- paperQuestionMapper.deletebyPapaerId(paperId);
+ // paperQuestionMapper.deletebyPapaerId(paperId);
return row;
}
@@ -233,9 +239,7 @@
@Override
public int changeExamPaperStatus(Long paperId, Integer status) {
+ checkUserAllowed(baseMapper.selectById(paperId));
return baseMapper.updateById(new ExExamPaper().setId(paperId).setStatus(status).setUpdateBy(SecurityUtils.getUsername()));
}
-
-
-
}
--
Gitblit v1.9.2