|
|
@ -25,6 +25,9 @@ import java.text.NumberFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -43,6 +46,9 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
StringRedisTemplate redisTemplate; |
|
|
|
StringRedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
ThreadPoolExecutor executor; |
|
|
|
|
|
|
|
|
|
|
|
private String REMAINING_TINE_KEY = "REMAINING_TINE"; |
|
|
|
private String REMAINING_TINE_KEY = "REMAINING_TINE"; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -51,7 +57,7 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
//TODO 接口幂等性处理
|
|
|
|
//TODO 接口幂等性处理
|
|
|
|
//根据用户id和是否提交,查询测评记录信息
|
|
|
|
//根据用户id和是否提交,查询测评记录信息
|
|
|
|
EvaluationRecordEntity one = this.getOne(new QueryWrapper<EvaluationRecordEntity>().eq("user_id", userId) |
|
|
|
EvaluationRecordEntity one = this.getOne(new QueryWrapper<EvaluationRecordEntity>().eq("user_id", userId) |
|
|
|
.eq("evaluation_status", Constant.Submit.SUBMIT.getType())); |
|
|
|
.eq("evaluation_status", Constant.Submit.NOT_SUBMIT.getType())); |
|
|
|
|
|
|
|
|
|
|
|
if (one == null) { |
|
|
|
if (one == null) { |
|
|
|
//随机抽取试题数据
|
|
|
|
//随机抽取试题数据
|
|
|
@ -70,8 +76,6 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
EvaluationQuestionEntity evaluationQuestionEntity = new EvaluationQuestionEntity(); |
|
|
|
EvaluationQuestionEntity evaluationQuestionEntity = new EvaluationQuestionEntity(); |
|
|
|
evaluationQuestionEntity.setEvaluationRecordId(evaluationRecord.getId()); |
|
|
|
evaluationQuestionEntity.setEvaluationRecordId(evaluationRecord.getId()); |
|
|
|
evaluationQuestionEntity.setQuestionId(question); |
|
|
|
evaluationQuestionEntity.setQuestionId(question); |
|
|
|
// evaluationQuestionEntity.setIsTure(Constant.QuestionIsTure.FALSE.getType());
|
|
|
|
|
|
|
|
// evaluationQuestionEntity.setQuestionStatus(Constant.QuestionStatus.NOT_MADE.getType());
|
|
|
|
|
|
|
|
return evaluationQuestionEntity; |
|
|
|
return evaluationQuestionEntity; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
@ -139,29 +143,33 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
|
|
|
|
@Transactional |
|
|
|
public EvaluationRecordVO convertQuestion(Integer evaluationRecordId, |
|
|
|
public EvaluationRecordVO convertQuestion(Integer evaluationRecordId, |
|
|
|
Integer currentQuestionSortNo, |
|
|
|
Integer currentQuestionSortNo, |
|
|
|
String userAnswer, |
|
|
|
String userAnswer, |
|
|
|
Integer changeSortNo) { |
|
|
|
Integer changeSortNo) throws ExecutionException, InterruptedException { |
|
|
|
if (currentQuestionSortNo < 1 |
|
|
|
if (currentQuestionSortNo < 1 |
|
|
|
|| currentQuestionSortNo > this.getById(evaluationRecordId).getTotalQuestionNum() |
|
|
|
|| currentQuestionSortNo > this.getById(evaluationRecordId).getTotalQuestionNum() |
|
|
|
|| changeSortNo < 1 |
|
|
|
|| changeSortNo < 1 |
|
|
|
|| changeSortNo > this.getById(evaluationRecordId).getTotalQuestionNum()) { |
|
|
|
|| changeSortNo > this.getById(evaluationRecordId).getTotalQuestionNum()) { |
|
|
|
ExceptionCast.cast(CommonCode.INVALID_PARAM); |
|
|
|
ExceptionCast.cast(CommonCode.INVALID_PARAM); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO 异步调用。。。
|
|
|
|
|
|
|
|
//提交当前试题信息
|
|
|
|
//提交当前试题信息
|
|
|
|
boolean result = submitCurrentQuestion(evaluationRecordId, |
|
|
|
CompletableFuture<Void> submitCurrentQuestionFuture = CompletableFuture.runAsync(() |
|
|
|
currentQuestionSortNo, |
|
|
|
-> submitCurrentQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer), executor); |
|
|
|
userAnswer, |
|
|
|
|
|
|
|
changeSortNo); |
|
|
|
//修改测评记录表当前题目顺序号
|
|
|
|
if (!result) { |
|
|
|
CompletableFuture<Void> updateCurrentSortNoFuture = CompletableFuture.runAsync(() |
|
|
|
ExceptionCast.cast(CommonCode.FAIL); |
|
|
|
-> updateCurrentSortNo(changeSortNo, evaluationRecordId), executor); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<EvaluationRecordVO> future = CompletableFuture.supplyAsync(() |
|
|
|
|
|
|
|
-> this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo), executor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture.allOf(submitCurrentQuestionFuture, updateCurrentSortNoFuture, future).get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EvaluationRecordVO evaluationRecordVO = future.get(); |
|
|
|
//查询下一题信息
|
|
|
|
//查询下一题信息
|
|
|
|
EvaluationRecordVO evaluationRecordVO = this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo); |
|
|
|
|
|
|
|
evaluationRecordVO.setQuestionTypeName(getQuestionTypeName(evaluationRecordVO.getQuestionType())); |
|
|
|
evaluationRecordVO.setQuestionTypeName(getQuestionTypeName(evaluationRecordVO.getQuestionType())); |
|
|
|
return evaluationRecordVO; |
|
|
|
return evaluationRecordVO; |
|
|
|
} |
|
|
|
} |
|
|
@ -170,67 +178,81 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
public EvaluationRecordSubmitVO submitEvaluation(Integer evaluationRecordId, |
|
|
|
public EvaluationRecordSubmitVO submitEvaluation(Integer evaluationRecordId, |
|
|
|
Integer currentQuestionSortNo, |
|
|
|
Integer currentQuestionSortNo, |
|
|
|
String userAnswer, |
|
|
|
String userAnswer, |
|
|
|
Integer userId) { |
|
|
|
Integer userId) throws ExecutionException, InterruptedException { |
|
|
|
//清除redis中的倒计时
|
|
|
|
//清除redis中的倒计时
|
|
|
|
|
|
|
|
CompletableFuture<Void> deleteKeyFuture = CompletableFuture.runAsync(() -> { |
|
|
|
String key = REMAINING_TINE_KEY + userId; |
|
|
|
String key = REMAINING_TINE_KEY + userId; |
|
|
|
redisTemplate.delete(key); |
|
|
|
redisTemplate.delete(key); |
|
|
|
|
|
|
|
}, executor); |
|
|
|
|
|
|
|
|
|
|
|
boolean result = submitCurrentQuestion(evaluationRecordId, |
|
|
|
CompletableFuture<Void> submitCurrentQuestionFuture = CompletableFuture.runAsync(() |
|
|
|
currentQuestionSortNo, |
|
|
|
-> submitCurrentQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer), executor); |
|
|
|
userAnswer, |
|
|
|
|
|
|
|
null); |
|
|
|
|
|
|
|
if (!result) { |
|
|
|
|
|
|
|
ExceptionCast.cast(CommonCode.FAIL); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO 优化,使用多线程异步调用
|
|
|
|
//修改提交时间和测评记录状态
|
|
|
|
//修改提交时间
|
|
|
|
CompletableFuture<Void> updateEvaluationFuture = CompletableFuture.runAsync(() -> { |
|
|
|
EvaluationRecordEntity entity = new EvaluationRecordEntity(); |
|
|
|
EvaluationRecordEntity entity = new EvaluationRecordEntity(); |
|
|
|
entity.setId(evaluationRecordId); |
|
|
|
entity.setId(evaluationRecordId); |
|
|
|
entity.setEvaluationStatus(Constant.Submit.SUBMIT.getType()); |
|
|
|
entity.setEvaluationStatus(Constant.Submit.SUBMIT.getType()); |
|
|
|
entity.setSubmitTime(new Date()); |
|
|
|
entity.setSubmitTime(new Date()); |
|
|
|
this.updateById(entity); |
|
|
|
this.updateById(entity); |
|
|
|
|
|
|
|
}, executor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EvaluationRecordSubmitVO submitVO = new EvaluationRecordSubmitVO(); |
|
|
|
|
|
|
|
|
|
|
|
//查询总成绩
|
|
|
|
//查询总成绩
|
|
|
|
|
|
|
|
CompletableFuture<Void> sumScoreFuture = CompletableFuture.runAsync(() -> { |
|
|
|
int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); |
|
|
|
int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); |
|
|
|
|
|
|
|
//得分
|
|
|
|
|
|
|
|
submitVO.setTotalScore(sumScore); |
|
|
|
|
|
|
|
//是否通过
|
|
|
|
|
|
|
|
submitVO.setIsPassed(sumScore > Constant.PASSING_SCORE ? Constant.EVALUATIONN_PASSED : Constant.EVALUATIONN_NOT_PASSED); |
|
|
|
|
|
|
|
}, executor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<EvaluationRecordEntity> getByIdFuture = CompletableFuture.supplyAsync(() -> { |
|
|
|
|
|
|
|
EvaluationRecordEntity evaluationRecord = this.getById(evaluationRecordId); |
|
|
|
|
|
|
|
BeanUtils.copyProperties(evaluationRecord, submitVO); |
|
|
|
|
|
|
|
return evaluationRecord; |
|
|
|
|
|
|
|
}, executor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<Void> countFuture = getByIdFuture.thenAcceptAsync((res) -> { |
|
|
|
QueryWrapper<EvaluationQuestionEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
QueryWrapper<EvaluationQuestionEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("evaluation_record_id", evaluationRecordId) |
|
|
|
queryWrapper.eq("evaluation_record_id", evaluationRecordId) |
|
|
|
.eq("is_ture", Constant.QuestionIsTure.TRUE.getType()); |
|
|
|
.eq("is_ture", Constant.QuestionIsTure.TRUE.getType()); |
|
|
|
|
|
|
|
|
|
|
|
//查询答对几题
|
|
|
|
//查询答对几题
|
|
|
|
int count = evaluationQuestionService.count(queryWrapper); |
|
|
|
int count = evaluationQuestionService.count(queryWrapper); |
|
|
|
|
|
|
|
//答对几道
|
|
|
|
EvaluationRecordEntity evaluationRecord = this.getById(evaluationRecordId); |
|
|
|
submitVO.setCorrectQuestionNum(count); |
|
|
|
|
|
|
|
|
|
|
|
EvaluationRecordSubmitVO submitVO = new EvaluationRecordSubmitVO(); |
|
|
|
|
|
|
|
BeanUtils.copyProperties(evaluationRecord, submitVO); |
|
|
|
|
|
|
|
//正确率
|
|
|
|
//正确率
|
|
|
|
// 创建一个数值格式化对象
|
|
|
|
// 创建一个数值格式化对象
|
|
|
|
NumberFormat numberFormat = NumberFormat.getInstance(); |
|
|
|
NumberFormat numberFormat = NumberFormat.getInstance(); |
|
|
|
// 设置精确到小数点后2位
|
|
|
|
// 设置精确到小数点后2位
|
|
|
|
numberFormat.setMaximumFractionDigits(2); |
|
|
|
numberFormat.setMaximumFractionDigits(2); |
|
|
|
submitVO.setCorrectRate(numberFormat.format((float) count / (float) evaluationRecord.getTotalQuestionNum() * 100) + "%"); |
|
|
|
submitVO.setCorrectRate(numberFormat.format((float) count / (float) res.getTotalQuestionNum() * 100) + "%"); |
|
|
|
//是否通过
|
|
|
|
|
|
|
|
submitVO.setIsPassed(sumScore > Constant.PASSING_SCORE ? Constant.EVALUATIONN_PASSED : Constant.EVALUATIONN_NOT_PASSED); |
|
|
|
}, executor); |
|
|
|
//得分
|
|
|
|
|
|
|
|
submitVO.setTotalScore(sumScore); |
|
|
|
CompletableFuture.allOf(deleteKeyFuture, submitCurrentQuestionFuture, updateEvaluationFuture, |
|
|
|
//答对几道
|
|
|
|
sumScoreFuture, getByIdFuture, countFuture).get(); |
|
|
|
submitVO.setCorrectQuestionNum(count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return submitVO; |
|
|
|
return submitVO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public EvaluationRecordDetailVO evaluationDetail(Integer evaluationRecordId) { |
|
|
|
public EvaluationRecordDetailVO evaluationDetail(Integer evaluationRecordId) throws ExecutionException, InterruptedException { |
|
|
|
//TODO 异步查询
|
|
|
|
EvaluationRecordDetailVO evaluationRecordDetailVO = new EvaluationRecordDetailVO(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<Void> sumScoreFuture = CompletableFuture.runAsync(() -> { |
|
|
|
//查询总成绩
|
|
|
|
//查询总成绩
|
|
|
|
int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); |
|
|
|
int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); |
|
|
|
List<EvaluationDetailVO> evaluationDetailVOS = evaluationQuestionDao.selectDetailByInfo(evaluationRecordId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EvaluationRecordDetailVO evaluationRecordDetailVO = new EvaluationRecordDetailVO(); |
|
|
|
|
|
|
|
evaluationRecordDetailVO.setTotalScore(sumScore); |
|
|
|
evaluationRecordDetailVO.setTotalScore(sumScore); |
|
|
|
|
|
|
|
}, executor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture<Void> evaluationDetailVOSFuture = CompletableFuture.runAsync(() -> { |
|
|
|
|
|
|
|
List<EvaluationDetailVO> evaluationDetailVOS = evaluationQuestionDao.selectDetailByInfo(evaluationRecordId); |
|
|
|
evaluationRecordDetailVO.setEvaluationDetailVOS(evaluationDetailVOS); |
|
|
|
evaluationRecordDetailVO.setEvaluationDetailVOS(evaluationDetailVOS); |
|
|
|
|
|
|
|
}, executor); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CompletableFuture.allOf(sumScoreFuture, evaluationDetailVOSFuture).get(); |
|
|
|
return evaluationRecordDetailVO; |
|
|
|
return evaluationRecordDetailVO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -242,7 +264,7 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
.eq("question_status", Constant.QuestionStatus.NOT_MADE.getType()); |
|
|
|
.eq("question_status", Constant.QuestionStatus.NOT_MADE.getType()); |
|
|
|
|
|
|
|
|
|
|
|
List<EvaluationQuestionEntity> list = evaluationQuestionService.list(queryWrapper); |
|
|
|
List<EvaluationQuestionEntity> list = evaluationQuestionService.list(queryWrapper); |
|
|
|
List<Integer> collect = list.stream().map(item -> item.getQuestionSortNo()).collect(Collectors.toList()); |
|
|
|
List<Integer> collect = list.stream().map(EvaluationQuestionEntity::getQuestionSortNo).collect(Collectors.toList()); |
|
|
|
if (collect.size() == 0) { |
|
|
|
if (collect.size() == 0) { |
|
|
|
return "已完成全部题目"; |
|
|
|
return "已完成全部题目"; |
|
|
|
} |
|
|
|
} |
|
|
@ -284,11 +306,9 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//提交当前试题,并修改当前测评记录表
|
|
|
|
//提交当前试题,并修改当前测评记录表
|
|
|
|
@Transactional |
|
|
|
private void submitCurrentQuestion(Integer evaluationRecordId, |
|
|
|
public boolean submitCurrentQuestion(Integer evaluationRecordId, |
|
|
|
|
|
|
|
Integer currentQuestionSortNo, |
|
|
|
Integer currentQuestionSortNo, |
|
|
|
String userAnswer, |
|
|
|
String userAnswer) { |
|
|
|
Integer changeSortNo) { |
|
|
|
|
|
|
|
//1、根据当前传递的evaluationRecordId和currentQuestionSortNo查询当前试题
|
|
|
|
//1、根据当前传递的evaluationRecordId和currentQuestionSortNo查询当前试题
|
|
|
|
EvaluationQuestionVO evaluationQuestionVO = evaluationQuestionDao.selectByInfo(evaluationRecordId, currentQuestionSortNo); |
|
|
|
EvaluationQuestionVO evaluationQuestionVO = evaluationQuestionDao.selectByInfo(evaluationRecordId, currentQuestionSortNo); |
|
|
|
if (evaluationQuestionVO == null) { |
|
|
|
if (evaluationQuestionVO == null) { |
|
|
@ -320,19 +340,15 @@ public class EvaluationRecordServiceImpl extends ServiceImpl<EvaluationRecordDao |
|
|
|
evaluationQuestion.setQuestionScore(questionPoints); |
|
|
|
evaluationQuestion.setQuestionScore(questionPoints); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
int updateQuestion = evaluationQuestionDao.updateById(evaluationQuestion); |
|
|
|
evaluationQuestionDao.updateById(evaluationQuestion); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateCurrentSortNo(Integer changeSortNo, Integer evaluationRecordId) { |
|
|
|
//修改测评记录表
|
|
|
|
//修改测评记录表
|
|
|
|
if (changeSortNo != null) { |
|
|
|
|
|
|
|
EvaluationRecordEntity evaluationRecordEntity = new EvaluationRecordEntity(); |
|
|
|
EvaluationRecordEntity evaluationRecordEntity = new EvaluationRecordEntity(); |
|
|
|
evaluationRecordEntity.setCurrentQuestionSortNo(changeSortNo); |
|
|
|
evaluationRecordEntity.setCurrentQuestionSortNo(changeSortNo); |
|
|
|
evaluationRecordEntity.setId(evaluationRecordId); |
|
|
|
evaluationRecordEntity.setId(evaluationRecordId); |
|
|
|
boolean updateRecord = this.updateById(evaluationRecordEntity); |
|
|
|
this.updateById(evaluationRecordEntity); |
|
|
|
return updateQuestion > 0 && updateRecord; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updateQuestion > 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |