From 9cc6d9fa9581707a5b7059b3acb5386156f86c9a Mon Sep 17 00:00:00 2001 From: mzh820631607 Date: Mon, 28 Sep 2020 19:37:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B5=8B=E8=AF=84=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=EF=BC=88=E5=BC=80=E5=90=AF=E8=99=9A=E6=8B=9F=E4=BB=BF?= =?UTF-8?q?=E7=9C=9F=E5=AE=9E=E9=AA=8C=E3=80=82=E6=95=99=E5=AD=A6=E5=AE=9E?= =?UTF-8?q?=E9=AA=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/EvaluationRecordControllerApi.java | 15 +- .../EvaluationRecordController.java | 197 +++++++++-- .../com/msdw/tms/dao/EvaluationRecordDao.java | 9 +- .../com/msdw/tms/dao/FractionEntityDao.java | 14 + .../com/msdw/tms/entity/FractionEntity.java | 25 ++ .../tms/entity/vo/TMSEvaluationRecordVO.java | 70 ++++ .../tms/service/EvaluationRecordService.java | 27 +- .../tms/service/FractionEntityService.java | 12 + .../impl/EvaluationRecordServiceImpl.java | 313 +++++++++++++++++- .../impl/FractionEntityServiceImpl.java | 34 ++ .../mapper/tms/EvaluationRecordDao.xml | 2 +- .../mapper/tms/FractionEntityDao.xml | 16 + 12 files changed, 684 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/msdw/tms/dao/FractionEntityDao.java create mode 100644 src/main/java/com/msdw/tms/entity/FractionEntity.java create mode 100644 src/main/java/com/msdw/tms/entity/vo/TMSEvaluationRecordVO.java create mode 100644 src/main/java/com/msdw/tms/service/FractionEntityService.java create mode 100644 src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java create mode 100644 src/main/resources/mapper/tms/FractionEntityDao.xml diff --git a/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java b/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java index a6ca51d..d2a1bc1 100644 --- a/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java +++ b/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java @@ -2,6 +2,7 @@ package com.msdw.tms.api; import com.msdw.tms.common.utils.R; import com.msdw.tms.entity.vo.EvaluationRecordVO; +import com.msdw.tms.entity.vo.TMSEvaluationRecordVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -39,19 +40,19 @@ public interface EvaluationRecordControllerApi { * 开始测评,返回第一题的数据 */ @ApiOperation(value = "开始测评", notes = "开始测评") - R startEvaluation(Integer userId); + R startEvaluation(Integer userId,Integer type); /** * 上一题 */ @ApiOperation(value = "上一题", notes = "上一题") - R previousQuestion(EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException; + R previousQuestion(TMSEvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException; /** * 下一题 */ @ApiOperation(value = "下一题", notes = "下一题") - R nextQuestion(EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException; + R nextQuestion(TMSEvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException; /** * 提交之前查询是否还有未做完的试题 @@ -63,7 +64,7 @@ public interface EvaluationRecordControllerApi { * 提交测评 */ @ApiOperation(value = "提交测评", notes = "提交测评") - R submitEvaluation(EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException; + R submitEvaluation(TMSEvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException; /** * 成绩详情 @@ -76,4 +77,10 @@ public interface EvaluationRecordControllerApi { */ @ApiOperation(value = "查询是否能够开启实验", notes = "查询是否能够开启实验") R isOpenExperiment(Integer userId); + + @ApiOperation(value = "查询是否能开启虚拟仿真实验",notes = "查询是否能开启虚拟仿真实验") + R isOpenExercise(Integer userId); + + @ApiOperation(value = "查询是否能开启教学实验",notes = "查询是否能开启教学实验") + R isOpenTeaching(Integer userId); } diff --git a/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java index f9aef3e..6cf9c29 100644 --- a/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java +++ b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java @@ -2,11 +2,15 @@ package com.msdw.tms.controller; import com.msdw.tms.api.EvaluationRecordControllerApi; import com.msdw.tms.common.utils.R; +import com.msdw.tms.entity.FractionEntity; import com.msdw.tms.entity.vo.EvaluationRecordDetailVO; import com.msdw.tms.entity.vo.EvaluationRecordSubmitVO; import com.msdw.tms.entity.vo.EvaluationRecordVO; +import com.msdw.tms.entity.vo.TMSEvaluationRecordVO; import com.msdw.tms.service.EvaluationRecordService; +import com.msdw.tms.service.FractionEntityService; import com.msdw.tms.service.QuestionsService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -28,8 +32,9 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi @Resource private QuestionsService questionsService; - -// @Override + @Autowired + private FractionEntityService fractionEntityService; + // @Override // @GetMapping("/has_notmade") // public R hasNotMadeEvaluation(Integer userId) { // boolean b = evaluationRecordService.hasNotMadeEvaluation(userId); @@ -52,53 +57,28 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi @Override @GetMapping("/start") - public R startEvaluation(@RequestParam(value = "userId") Integer userId) { - EvaluationRecordVO evaluationRecordVO = evaluationRecordService.startEvaluation(userId); + public R startEvaluation(@RequestParam(value = "userId") Integer userId,Integer type) { + TMSEvaluationRecordVO evaluationRecordVO = evaluationRecordService.startEvaluation(userId); + evaluationRecordVO.setTypes(type); return R.ok().put("data", evaluationRecordVO); } @Override @PostMapping("/previous") - public R previousQuestion(@RequestBody EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { + public R previousQuestion(@RequestBody TMSEvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { Integer evaluationRecordId = evaluationRecordVO.getId(); String userAnswer = evaluationRecordVO.getUserAnswer(); Integer currentQuestionSortNo = evaluationRecordVO.getCurrentQuestionSortNo(); - EvaluationRecordVO recordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo - 1); + TMSEvaluationRecordVO recordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo - 1); return R.ok().put("data", recordVO); } -// 备份:上一题/下一题/提交 -// @Override -// @GetMapping("/previous") -// public R previousQuestion(@RequestParam("evaluationRecordId") Integer evaluationRecordId, -// @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, -// @RequestParam(value = "userAnswer", required = false) String userAnswer) throws ExecutionException, InterruptedException { -// EvaluationRecordVO evaluationRecordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo - 1); -// return R.ok().put("data", evaluationRecordVO); -// } -// @Override -// @GetMapping("/next") -// public R nextQuestion(@RequestParam("evaluationRecordId") Integer evaluationRecordId, -// @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, -// @RequestParam(value = "userAnswer", required = false) String userAnswer) throws ExecutionException, InterruptedException { -// EvaluationRecordVO evaluationRecordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo + 1); -// return R.ok().put("data", evaluationRecordVO); -// } -// @Override -// @GetMapping("/submit") -// public R submitEvaluation(@RequestParam("evaluationRecordId") Integer evaluationRecordId, -// @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, -// @RequestParam(value = "userAnswer", required = false) String userAnswer, -// @RequestParam("userId") Integer userId) throws ExecutionException, InterruptedException { -// EvaluationRecordSubmitVO recordSubmitVO = evaluationRecordService.submitEvaluation(evaluationRecordId, currentQuestionSortNo, userAnswer, userId); -// return R.ok().put("data", recordSubmitVO); -// } @Override @PostMapping("/next") - public R nextQuestion(@RequestBody EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { + public R nextQuestion(@RequestBody TMSEvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { Integer evaluationRecordId = evaluationRecordVO.getId(); String userAnswer = evaluationRecordVO.getUserAnswer(); Integer currentQuestionSortNo = evaluationRecordVO.getCurrentQuestionSortNo(); - EvaluationRecordVO recordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo + 1); + TMSEvaluationRecordVO recordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo + 1); return R.ok().put("data", recordVO); } @@ -111,12 +91,19 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi @Override @PostMapping("/submit") - public R submitEvaluation(@RequestBody EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { + public R submitEvaluation(@RequestBody TMSEvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { Integer evaluationRecordId = evaluationRecordVO.getId(); String userAnswer = evaluationRecordVO.getUserAnswer(); Integer currentQuestionSortNo = evaluationRecordVO.getCurrentQuestionSortNo(); Integer userId = evaluationRecordVO.getUserId(); + + Integer types = evaluationRecordVO.getTypes(); EvaluationRecordSubmitVO recordSubmitVO = evaluationRecordService.submitEvaluation(evaluationRecordId, currentQuestionSortNo, userAnswer, userId); + Integer totalScore = recordSubmitVO.getTotalScore(); + FractionEntity fractionEntity = new FractionEntity(); + FractionEntity fraction = fractionEntity.setUserId(userId).setFraction(totalScore).setTypes(types); + fractionEntityService.insertRecord(fraction); + return R.ok().put("data", recordSubmitVO); } @@ -139,6 +126,146 @@ public class EvaluationRecordController implements EvaluationRecordControllerApi return R.ok().put("data", openExperiment); } + @Override + @GetMapping("/openExercise") + public R isOpenExercise(Integer userId){ + Integer score = fractionEntityService.queryExerciseRecord(userId); + return R.ok(); + } + + @Override + @GetMapping("/openTeaching") + public R isOpenTeaching(Integer userId){ + Integer score = fractionEntityService.queryTeachingRecord(userId); + return R.ok(); + } + +//// @Override +//// @GetMapping("/has_notmade") +//// public R hasNotMadeEvaluation(Integer userId) { +//// boolean b = evaluationRecordService.hasNotMadeEvaluation(userId); +//// return R.ok().put("data", b); +//// } +// +//// @Override +//// @GetMapping("/clean_time") +//// public R cleanRemainingTime(Integer userId) { +//// evaluationRecordService.cleanRemainingTime(userId); +//// return R.ok(); +//// } +// +// @Override +// @GetMapping("/remaining") +// public R getEvaluationRemainingTime(Integer userId) { +// String remainingTime = questionsService.getEvaluationRemainingTime(userId); +// return R.ok().put("data", remainingTime); +// } +// +// @Override +// @GetMapping("/start") +// public R startEvaluation(@RequestParam(value = "userId") Integer userId,Integer type) { +// TMSEvaluationRecordVO evaluationRecordVO = evaluationRecordService.startEvaluation(userId); +// evaluationRecordVO.setType(type); +// return R.ok().put("data", evaluationRecordVO); +// } +//// @Override +//// @GetMapping("/start") +//// public R startEvaluation(@RequestParam(value = "userId") Integer userId) { +//// EvaluationRecordVO evaluationRecordVO = evaluationRecordService.startEvaluation(userId); +//// return R.ok().put("data", evaluationRecordVO); +//// } +// +// @Override +// @PostMapping("/previous") +// public R previousQuestion(@RequestBody EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { +// Integer evaluationRecordId = evaluationRecordVO.getId(); +// String userAnswer = evaluationRecordVO.getUserAnswer(); +// Integer currentQuestionSortNo = evaluationRecordVO.getCurrentQuestionSortNo(); +// EvaluationRecordVO recordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo - 1); +// return R.ok().put("data", recordVO); +// } +//// @Override +//// @PostMapping("/previous") +//// public R previousQuestion(@RequestBody EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { +//// Integer evaluationRecordId = evaluationRecordVO.getId(); +//// String userAnswer = evaluationRecordVO.getUserAnswer(); +//// Integer currentQuestionSortNo = evaluationRecordVO.getCurrentQuestionSortNo(); +//// EvaluationRecordVO recordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo - 1); +//// return R.ok().put("data", recordVO); +//// } +//// 备份:上一题/下一题/提交 +//// @Override +//// @GetMapping("/previous") +//// public R previousQuestion(@RequestParam("evaluationRecordId") Integer evaluationRecordId, +//// @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, +//// @RequestParam(value = "userAnswer", required = false) String userAnswer) throws ExecutionException, InterruptedException { +//// EvaluationRecordVO evaluationRecordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo - 1); +//// return R.ok().put("data", evaluationRecordVO); +//// } +//// @Override +//// @GetMapping("/next") +//// public R nextQuestion(@RequestParam("evaluationRecordId") Integer evaluationRecordId, +//// @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, +//// @RequestParam(value = "userAnswer", required = false) String userAnswer) throws ExecutionException, InterruptedException { +//// EvaluationRecordVO evaluationRecordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo + 1); +//// return R.ok().put("data", evaluationRecordVO); +//// } +//// @Override +//// @GetMapping("/submit") +//// public R submitEvaluation(@RequestParam("evaluationRecordId") Integer evaluationRecordId, +//// @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, +//// @RequestParam(value = "userAnswer", required = false) String userAnswer, +//// @RequestParam("userId") Integer userId) throws ExecutionException, InterruptedException { +//// EvaluationRecordSubmitVO recordSubmitVO = evaluationRecordService.submitEvaluation(evaluationRecordId, currentQuestionSortNo, userAnswer, userId); +//// return R.ok().put("data", recordSubmitVO); +//// } +// @Override +// @PostMapping("/next") +// public R nextQuestion(@RequestBody EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { +// Integer evaluationRecordId = evaluationRecordVO.getId(); +// String userAnswer = evaluationRecordVO.getUserAnswer(); +// Integer currentQuestionSortNo = evaluationRecordVO.getCurrentQuestionSortNo(); +// EvaluationRecordVO recordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo + 1); +// return R.ok().put("data", recordVO); +// } +// +// @Override +// @GetMapping("/not_made") +// public R selectNotMade(@RequestParam("evaluationRecordId") Integer evaluationRecordId) { +// String result = evaluationRecordService.selectNotMade(evaluationRecordId); +// return R.ok().put("data", result); +// } +// +// @Override +// @PostMapping("/submit") +// public R submitEvaluation(@RequestBody EvaluationRecordVO evaluationRecordVO) throws ExecutionException, InterruptedException { +// Integer evaluationRecordId = evaluationRecordVO.getId(); +// String userAnswer = evaluationRecordVO.getUserAnswer(); +// Integer currentQuestionSortNo = evaluationRecordVO.getCurrentQuestionSortNo(); +// Integer userId = evaluationRecordVO.getUserId(); +// EvaluationRecordSubmitVO recordSubmitVO = evaluationRecordService.submitEvaluation(evaluationRecordId, currentQuestionSortNo, userAnswer, userId); +// return R.ok().put("data", recordSubmitVO); +// } +// +// @Override +// @GetMapping("/detail") +// public R evaluationScoreDetail(Integer evaluationRecordId) throws ExecutionException, InterruptedException { +// EvaluationRecordDetailVO detailVO = evaluationRecordService.evaluationDetail(evaluationRecordId); +// return R.ok().put("data", detailVO); +// } +// +// /** +// * 查询是否能够开启实验 +// * @param userId +// * @return +// */ +// @Override +// @GetMapping("/can_experiment") +// public R isOpenExperiment(Integer userId) { +// boolean openExperiment = evaluationRecordService.isOpenExperiment(userId); +// return R.ok().put("data", openExperiment); +// } + diff --git a/src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java b/src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java index 42acc4a..a9af9dc 100644 --- a/src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java +++ b/src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java @@ -3,6 +3,7 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.msdw.tms.entity.EvaluationRecordEntity; import com.msdw.tms.entity.vo.EvaluationRecordVO; +import com.msdw.tms.entity.vo.TMSEvaluationRecordVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -17,6 +18,10 @@ import java.util.List; */ @Mapper public interface EvaluationRecordDao extends BaseMapper { - EvaluationRecordVO selectVOByInfo(@Param("evaluationRecordId") Integer evaluationRecordId, - @Param("questionSortNo") Integer questionSortNo); + TMSEvaluationRecordVO selectVOByInfo(@Param("evaluationRecordId") Integer evaluationRecordId, + @Param("questionSortNo") Integer questionSortNo); + + +// EvaluationRecordVO selectVOByInfo(@Param("evaluationRecordId") Integer evaluationRecordId, +// @Param("questionSortNo") Integer questionSortNo); } diff --git a/src/main/java/com/msdw/tms/dao/FractionEntityDao.java b/src/main/java/com/msdw/tms/dao/FractionEntityDao.java new file mode 100644 index 0000000..639ac5d --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/FractionEntityDao.java @@ -0,0 +1,14 @@ +package com.msdw.tms.dao; + +import com.msdw.tms.entity.FractionEntity; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface FractionEntityDao { + + void insertRecord(FractionEntity fraction); + + Integer queryExerciseRecord(Integer userId); + + Integer queryTeachingRecord(Integer userId); +} diff --git a/src/main/java/com/msdw/tms/entity/FractionEntity.java b/src/main/java/com/msdw/tms/entity/FractionEntity.java new file mode 100644 index 0000000..3b90481 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/FractionEntity.java @@ -0,0 +1,25 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@Data +@Accessors(chain = true) +@TableName("tms_evaluation_fraction") +public class FractionEntity implements Serializable { + + //主键自增 + @TableId(type = IdType.AUTO) + private Integer id; + //绑定用户id + private Integer userId; + //记录总分数 + private Integer fraction; + //测评类型(1练习 2虚拟仿真 3教学) + private Integer types; +} diff --git a/src/main/java/com/msdw/tms/entity/vo/TMSEvaluationRecordVO.java b/src/main/java/com/msdw/tms/entity/vo/TMSEvaluationRecordVO.java new file mode 100644 index 0000000..9ea7de1 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/TMSEvaluationRecordVO.java @@ -0,0 +1,70 @@ +package com.msdw.tms.entity.vo; + +import lombok.Data; + +/** + * 用户测评信息 + */ +@Data +public class TMSEvaluationRecordVO { + /** + * 主键 + */ + private Integer id; + /** + * 当前测评的用户的id + */ + private Integer userId; + /** + * 记录当前做到第几题,用于刷新页面以后保持在当前题目,默认开始时是第一题 + */ + private Integer currentQuestionSortNo; + /** + * 总题目数量 + */ + private Integer totalQuestionNum; + /** + * 题型 + */ + private Integer questionType; + /** + * 题型名称 + */ + private String questionTypeName; + /** + * 题干信息 + */ + private String questionStem; + /** + * A选项内容 + */ + private String optionA; + /** + * B选项内容 + */ + private String optionB; + /** + * C选项内容 + */ + private String optionC; + /** + * D选项内容 + */ + private String optionD; + /** + * E选项内容 + */ + private String optionE; + /** + * F选项内容 + */ + private String optionF; + /** + * 用户答案 + */ + private String userAnswer; + /** + * 测试类型 + */ + private Integer types; +} diff --git a/src/main/java/com/msdw/tms/service/EvaluationRecordService.java b/src/main/java/com/msdw/tms/service/EvaluationRecordService.java index 6db5ab8..6a342f8 100644 --- a/src/main/java/com/msdw/tms/service/EvaluationRecordService.java +++ b/src/main/java/com/msdw/tms/service/EvaluationRecordService.java @@ -2,9 +2,11 @@ package com.msdw.tms.service; import com.baomidou.mybatisplus.extension.service.IService; import com.msdw.tms.entity.EvaluationRecordEntity; +import com.msdw.tms.entity.FractionEntity; import com.msdw.tms.entity.vo.EvaluationRecordDetailVO; import com.msdw.tms.entity.vo.EvaluationRecordSubmitVO; import com.msdw.tms.entity.vo.EvaluationRecordVO; +import com.msdw.tms.entity.vo.TMSEvaluationRecordVO; import java.util.concurrent.ExecutionException; @@ -16,10 +18,9 @@ import java.util.concurrent.ExecutionException; * @date 2020-08-28 10:15:48 */ public interface EvaluationRecordService extends IService { + TMSEvaluationRecordVO startEvaluation(Integer userId); - EvaluationRecordVO startEvaluation(Integer userId); - - EvaluationRecordVO convertQuestion(Integer evaluationRecordId, + TMSEvaluationRecordVO convertQuestion(Integer evaluationRecordId, Integer currentQuestionSortNo, String userAnswer, Integer changeSortNo) throws ExecutionException, InterruptedException; @@ -37,6 +38,26 @@ public interface EvaluationRecordService extends IService().eq("user_id", userId) @@ -89,7 +88,7 @@ public class EvaluationRecordServiceImpl extends ServiceImpl future = CompletableFuture.supplyAsync(() // -> this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo), executor); - EvaluationRecordVO evaluationRecordVO = this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo); + TMSEvaluationRecordVO evaluationRecordVO = this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo); // CompletableFuture.allOf(submitCurrentQuestionFuture, updateCurrentSortNoFuture, future).get(); @@ -354,4 +353,308 @@ public class EvaluationRecordServiceImpl extends ServiceImpl().eq("user_id", userId) +// .eq("evaluation_status", Constant.Submit.NOT_SUBMIT.getType())); +// +// if (one == null) { +// //随机抽取试题数据 +// EvaluationVO evaluation = questionsService.randomQuestions(); +// +// //保存测评记录 +// EvaluationRecordEntity evaluationRecord = new EvaluationRecordEntity(); +// evaluationRecord.setUserId(userId); +// evaluationRecord.setEvaluationStatus(Constant.Submit.NOT_SUBMIT.getType()); +// evaluationRecord.setTotalQuestionNum(evaluation.getQuestionNum()); +// evaluationRecord.setCurrentQuestionSortNo(1); +// evaluationRecord.setStartTime(new Date()); +// this.save(evaluationRecord); +// +// List evaluationQuestionList = evaluation.getQuestions().stream().map(question -> { +// EvaluationQuestionEntity evaluationQuestionEntity = new EvaluationQuestionEntity(); +// evaluationQuestionEntity.setEvaluationRecordId(evaluationRecord.getId()); +// evaluationQuestionEntity.setQuestionId(question); +// return evaluationQuestionEntity; +// }).collect(Collectors.toList()); +// +// List list = averageValue(evaluation.getQuestionNum()); +// for (int i = 0; i < list.size(); i++) { +// evaluationQuestionList.get(i).setQuestionSortNo(i + 1); +// evaluationQuestionList.get(i).setQuestionPoints(list.get(i)); +// } +// evaluationQuestionService.saveBatch(evaluationQuestionList); +// +// one = evaluationRecord; +// } +// +// EvaluationRecordVO evaluationRecordVO = this.getBaseMapper() +// .selectVOByInfo(one.getId(), one.getCurrentQuestionSortNo()); +// evaluationRecordVO.setQuestionTypeName(getQuestionTypeName(evaluationRecordVO.getQuestionType())); +// return evaluationRecordVO; +// } +// +// private String getQuestionTypeName(Integer questionType) { +// String questionTypeName = ""; +// //处理试题类型 +// if (questionType.equals(Constant.QuestionType.SINGLE_CHOICE.getType())) { +// //单选题 +// questionTypeName = Constant.QuestionType.SINGLE_CHOICE.getDesc(); +// } else if (questionType.equals(Constant.QuestionType.MULTIPLE_CHOICE.getType())) { +// //多选题 +// questionTypeName = Constant.QuestionType.MULTIPLE_CHOICE.getDesc(); +// } else if (questionType.equals(Constant.QuestionType.TRUE_OR_FALSE.getType())) { +// //判断题 +// questionTypeName = Constant.QuestionType.TRUE_OR_FALSE.getDesc(); +// } else { +// ExceptionCast.cast(CommonCode.QUESTIONTYPE_INVALID); +// } +// return questionTypeName; +// } +// +// /** +// * 平均分配分值 +// * +// * @param number 判分点数量 +// * @return +// */ +// private List averageValue(Integer number) { +// if (number == null || number == 0) { +// ExceptionCast.cast(CommonCode.EVALUATION_QUESTION_NUM_INVALID); +// } +// Integer score = 100 / number; +// List list = new ArrayList<>(); +// if (100 % number == 0) { +// for (int i = 0; i < number; i++) { +// list.add(score); +// } +// } else { +// int n; +// for (int i = 0; i < number; i++) { +// list.add(score); +// } +// for (int i = 100 % number; i > 0; i--) { +// n = score + 1; +// list.set(i, n); +// } +// } +// return list; +// } +// +// @Override +// @Transactional +// public EvaluationRecordVO convertQuestion(Integer evaluationRecordId, +// Integer currentQuestionSortNo, +// String userAnswer, +// Integer changeSortNo) throws ExecutionException, InterruptedException { +// if (currentQuestionSortNo < 1 +// || currentQuestionSortNo > this.getById(evaluationRecordId).getTotalQuestionNum() +// || changeSortNo < 1 +// || changeSortNo > this.getById(evaluationRecordId).getTotalQuestionNum()) { +// ExceptionCast.cast(CommonCode.INVALID_PARAM); +// } +// //提交当前试题信息 +// submitCurrentQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer); +//// CompletableFuture submitCurrentQuestionFuture = CompletableFuture.runAsync(() +//// -> submitCurrentQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer), executor); +// +// //修改测评记录表当前题目顺序号 +// updateCurrentSortNo(changeSortNo, evaluationRecordId); +//// CompletableFuture updateCurrentSortNoFuture = CompletableFuture.runAsync(() +//// -> updateCurrentSortNo(changeSortNo, evaluationRecordId), executor); +// +//// CompletableFuture future = CompletableFuture.supplyAsync(() +//// -> this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo), executor); +// +// EvaluationRecordVO evaluationRecordVO = this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo); +// +//// CompletableFuture.allOf(submitCurrentQuestionFuture, updateCurrentSortNoFuture, future).get(); +// +//// EvaluationRecordVO evaluationRecordVO = future.get(); +// //查询下一题信息 +// evaluationRecordVO.setQuestionTypeName(getQuestionTypeName(evaluationRecordVO.getQuestionType())); +// return evaluationRecordVO; +// } +// +// @Override +// public EvaluationRecordSubmitVO submitEvaluation(Integer evaluationRecordId, +// Integer currentQuestionSortNo, +// String userAnswer, +// Integer userId) throws ExecutionException, InterruptedException { +// //清除redis中的倒计时 +// CompletableFuture deleteKeyFuture = CompletableFuture.runAsync(() -> { +// String key = REMAINING_TINE_KEY + userId; +// redisTemplate.delete(key); +// }, executor); +// +// CompletableFuture submitCurrentQuestionFuture = CompletableFuture.runAsync(() +// -> submitCurrentQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer), executor); +// +// //修改提交时间和测评记录状态 +// CompletableFuture updateEvaluationFuture = CompletableFuture.runAsync(() -> { +// EvaluationRecordEntity entity = new EvaluationRecordEntity(); +// entity.setId(evaluationRecordId); +// entity.setEvaluationStatus(Constant.Submit.SUBMIT.getType()); +// entity.setSubmitTime(new Date()); +// this.updateById(entity); +// }, executor); +// +// EvaluationRecordSubmitVO submitVO = new EvaluationRecordSubmitVO(); +// +// //查询总成绩 +// CompletableFuture sumScoreFuture = CompletableFuture.runAsync(() -> { +// int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); +// //得分 +// submitVO.setTotalScore(sumScore); +// //是否通过 +// submitVO.setIsPassed(sumScore > Constant.PASSING_SCORE ? Constant.EVALUATIONN_PASSED : Constant.EVALUATIONN_NOT_PASSED); +// }, executor); +// +// CompletableFuture getByIdFuture = CompletableFuture.supplyAsync(() -> { +// EvaluationRecordEntity evaluationRecord = this.getById(evaluationRecordId); +// BeanUtils.copyProperties(evaluationRecord, submitVO); +// return evaluationRecord; +// }, executor); +// +// CompletableFuture countFuture = getByIdFuture.thenAcceptAsync((res) -> { +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.eq("evaluation_record_id", evaluationRecordId) +// .eq("is_ture", Constant.QuestionIsTure.TRUE.getType()); +// //查询答对几题 +// int count = evaluationQuestionService.count(queryWrapper); +// //答对几道 +// submitVO.setCorrectQuestionNum(count); +// //正确率 +// // 创建一个数值格式化对象 +// NumberFormat numberFormat = NumberFormat.getInstance(); +// // 设置精确到小数点后2位 +// numberFormat.setMaximumFractionDigits(2); +// submitVO.setCorrectRate(numberFormat.format((float) count / (float) res.getTotalQuestionNum() * 100) + "%"); +// +// }, executor); +// +// CompletableFuture.allOf(deleteKeyFuture, submitCurrentQuestionFuture, updateEvaluationFuture, +// sumScoreFuture, getByIdFuture, countFuture).get(); +// +// return submitVO; +// } +// +// @Override +// public EvaluationRecordDetailVO evaluationDetail(Integer evaluationRecordId) throws ExecutionException, InterruptedException { +// EvaluationRecordDetailVO evaluationRecordDetailVO = new EvaluationRecordDetailVO(); +// +// CompletableFuture sumScoreFuture = CompletableFuture.runAsync(() -> { +// //查询总成绩 +// int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); +// evaluationRecordDetailVO.setTotalScore(sumScore); +// }, executor); +// +// CompletableFuture evaluationDetailVOSFuture = CompletableFuture.runAsync(() -> { +// List evaluationDetailVOS = evaluationQuestionDao.selectDetailByInfo(evaluationRecordId); +// evaluationRecordDetailVO.setEvaluationDetailVOS(evaluationDetailVOS); +// }, executor); +// +// CompletableFuture.allOf(sumScoreFuture, evaluationDetailVOSFuture).get(); +// return evaluationRecordDetailVO; +// } +// +// @Override +// public String selectNotMade(Integer evaluationRecordId) { +// +// QueryWrapper queryWrapper = new QueryWrapper<>(); +// queryWrapper.eq("evaluation_record_id", evaluationRecordId) +// .eq("question_status", Constant.QuestionStatus.NOT_MADE.getType()); +// +// List list = evaluationQuestionService.list(queryWrapper); +// List collect = list.stream().map(EvaluationQuestionEntity::getQuestionSortNo).collect(Collectors.toList()); +// if (collect.size() == 0) { +// return "已完成全部题目"; +// } +// return "还有以下题目未完成" + collect.toString(); +// } +// +// @Override +// public void cleanRemainingTime(Integer userId) { +// //清除redis中的倒计时 +// String key = REMAINING_TINE_KEY + userId; +// redisTemplate.delete(key); +// } +// +// @Override +// public boolean isOpenExperiment(Integer userId) { +// List list = evaluationQuestionDao.sumScoreListByUserId(userId); +// if (list != null && list.size() > 0) { +// for (Integer integer : list) { +// if (integer > Constant.PASSING_SCORE) { +// return true; +// } +// } +// } +// return false; +// } +// +//// @Override +//// public boolean hasNotMadeEvaluation(Integer userId) { +//// //先判断数据库是否已经有了此次测评 +//// //如果有,继续,如果没有,重新开始 +//// ValueOperations ops = redisTemplate.opsForValue(); +//// String key = REMAINING_TINE_KEY + userId; +//// if (StringUtils.isNotEmpty(ops.get(key))) { +//// //继续上次 +//// +//// } +//// +//// return false; +//// } +// +// //提交当前试题,并修改当前测评记录表 +// private void submitCurrentQuestion(Integer evaluationRecordId, +// Integer currentQuestionSortNo, +// String userAnswer) { +// //1、根据当前传递的evaluationRecordId和currentQuestionSortNo查询当前试题 +// EvaluationQuestionVO evaluationQuestionVO = evaluationQuestionDao.selectByInfo(evaluationRecordId, currentQuestionSortNo); +// if (evaluationQuestionVO == null) { +// ExceptionCast.cast(CommonCode.INVALID_PARAM); +// } +// // 题目分值 +// Integer questionPoints = evaluationQuestionVO.getQuestionPoints(); +// //正确答案 +// String answer = evaluationQuestionVO.getAnswer(); +// //修改当前试题状态 +// //记录用户的答案 +// //判断当前试题正误 +// //记录试题得分 +// EvaluationQuestionEntity evaluationQuestion = new EvaluationQuestionEntity(); +// evaluationQuestion.setId(evaluationQuestionVO.getId()); +// evaluationQuestion.setUserAnswer(userAnswer); +// //如果用户答案为空,则设置状态为未作,设为错,得分设为0 +// if (StringUtils.isEmpty(userAnswer)) { +// evaluationQuestion.setQuestionStatus(Constant.QuestionStatus.NOT_MADE.getType()); +// evaluationQuestion.setIsTure(Constant.QuestionIsTure.FALSE.getType()); +// evaluationQuestion.setQuestionScore(0); +// } else { +// evaluationQuestion.setQuestionStatus(Constant.QuestionStatus.MADE.getType()); +// if (!answer.equals(userAnswer)) { +// evaluationQuestion.setIsTure(Constant.QuestionIsTure.FALSE.getType()); +// evaluationQuestion.setQuestionScore(0); +// } else { +// evaluationQuestion.setIsTure(Constant.QuestionIsTure.TRUE.getType()); +// evaluationQuestion.setQuestionScore(questionPoints); +// } +// } +// evaluationQuestionDao.updateById(evaluationQuestion); +// +// } +// +// private void updateCurrentSortNo(Integer changeSortNo, Integer evaluationRecordId) { +// //修改测评记录表 +// EvaluationRecordEntity evaluationRecordEntity = new EvaluationRecordEntity(); +// evaluationRecordEntity.setCurrentQuestionSortNo(changeSortNo); +// evaluationRecordEntity.setId(evaluationRecordId); +// this.updateById(evaluationRecordEntity); +// } } \ No newline at end of file diff --git a/src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java new file mode 100644 index 0000000..077d0e1 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/FractionEntityServiceImpl.java @@ -0,0 +1,34 @@ +package com.msdw.tms.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.msdw.tms.dao.FractionEntityDao; +import com.msdw.tms.entity.FractionEntity; +import com.msdw.tms.service.FractionEntityService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class FractionEntityServiceImpl implements FractionEntityService { + + @Autowired + private FractionEntityDao fractionMapper; + + @Override + public void insertRecord(FractionEntity fraction) { + fractionMapper.insertRecord(fraction); + + } + + @Override + public Integer queryExerciseRecord(Integer userId) { + Integer score = fractionMapper.queryExerciseRecord(userId); + return score; + } + + @Override + public Integer queryTeachingRecord(Integer userId) { + Integer score = fractionMapper.queryTeachingRecord(userId); + return score; + + } +} diff --git a/src/main/resources/mapper/tms/EvaluationRecordDao.xml b/src/main/resources/mapper/tms/EvaluationRecordDao.xml index be180d8..c0f72e8 100644 --- a/src/main/resources/mapper/tms/EvaluationRecordDao.xml +++ b/src/main/resources/mapper/tms/EvaluationRecordDao.xml @@ -14,7 +14,7 @@ - SELECT er.id, er.user_id, diff --git a/src/main/resources/mapper/tms/FractionEntityDao.xml b/src/main/resources/mapper/tms/FractionEntityDao.xml new file mode 100644 index 0000000..7149a44 --- /dev/null +++ b/src/main/resources/mapper/tms/FractionEntityDao.xml @@ -0,0 +1,16 @@ + + + + + + INSERT INTO tms_evaluation_fraction(types,fraction,userId) VALUES (#{types},#{fraction},#{userId}) + + + + + + \ No newline at end of file