diff --git a/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java b/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java new file mode 100644 index 0000000..9e97f95 --- /dev/null +++ b/src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java @@ -0,0 +1,76 @@ +package com.msdw.tms.api; + +import com.msdw.tms.common.utils.R; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@Api(value = "用户测评信息记录与操作", tags = "提供用户测评信息增删改查等相关方法") +public interface EvaluationRecordControllerApi { +// /** +// * 查询是否有为作完的测评 +// */ +// @ApiOperation(value = "查询是否有为作完的测评", notes = "查询是否有为作完的测评") +// R hasNotMadeEvaluation(Integer userId); + +// /** +// * 清空倒计时 +// */ +// @ApiOperation(value = "清空倒计时", notes = "清空倒计时") +// R cleanRemainingTime(Integer userId); + + /** + * 获取测评剩余时间 + */ + @ApiOperation(value = "获取测评剩余时间", notes = "获取测评剩余时间") + R getEvaluationRemainingTime(Integer userId); + + /** + * 开始测评,返回第一题的数据 + */ + @ApiOperation(value = "开始测评", notes = "开始测评") + R startEvaluation(Integer userId); + + /** + * 上一题 + */ + @ApiOperation(value = "上一题", notes = "上一题") + R previousQuestion(Integer evaluationRecordId, Integer currentQuestionSortNo, String userAnswer); + + /** + * 下一题 + */ + @ApiOperation(value = "下一题", notes = "下一题") + R nextQuestion(Integer evaluationRecordId, Integer currentQuestionSortNo, String userAnswer); + + /** + * 提交之前查询是否还有未做完的试题 + */ + @ApiOperation(value = "提交之前查询是否还有未做完的试题", notes = "提交之前查询是否还有未做完的试题") + R selectNotMade(Integer evaluationRecordId); + + /** + * 提交测评 + */ + @ApiOperation(value = "提交测评", notes = "提交测评") + R submitEvaluation(Integer evaluationRecordId, Integer currentQuestionSortNo, String userAnswer, Integer userId); + + /** + * 成绩详情 + */ + @ApiOperation(value = "成绩详情", notes = "成绩详情") + R evaluationScoreDetail(Integer evaluationRecordId); + + /** + * 查询是否能够开启实验 + */ + @ApiOperation(value = "查询是否能够开启实验", notes = "查询是否能够开启实验") + R isOpenExperiment(Integer userId); +} diff --git a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java index 7ebee11..bc234ab 100644 --- a/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java +++ b/src/main/java/com/msdw/tms/api/QuestionsControllerApi.java @@ -77,18 +77,6 @@ public interface QuestionsControllerApi { @ApiOperation(value = "excel模板文件下载", notes = "excel模板文件下载") R downloadFiles(HttpServletResponse response) throws IOException; - /** - * 抽题测评 - */ - @ApiOperation(value = "抽题测评", notes = "抽题测评") - R evaluation (); - - /** - * 抽题测评 - */ - @ApiOperation(value = "获取测评剩余时间", notes = "获取测评剩余时间") - R getEvaluationRemainingTime (Integer userId); - /** * 通过excel批量导出 */ diff --git a/src/main/java/com/msdw/tms/common/utils/Constant.java b/src/main/java/com/msdw/tms/common/utils/Constant.java index bd399bf..96214b0 100644 --- a/src/main/java/com/msdw/tms/common/utils/Constant.java +++ b/src/main/java/com/msdw/tms/common/utils/Constant.java @@ -98,6 +98,19 @@ public class Constant { * excel后缀 */ public static final String EXCEL_SUFFIX = ".xlsx"; + /** + * 测评总分 + */ + public static final int EVALUATION_SCORE = 100; + /** + * 及格分数 + */ + public static final int PASSING_SCORE = 60; + /** + * 测评是否通过 1、通过/0、未通过 + */ + public static final String EVALUATIONN_PASSED = "通过"; + public static final String EVALUATIONN_NOT_PASSED = "未通过"; /** * 菜单类型 * @@ -270,11 +283,11 @@ public class Constant { /** * 随机 */ - RANDOM(0, "随机"), + RANDOM(1, "随机"), /** * 自定义 */ - CUSTOMIZE(1, "自定义"); + CUSTOMIZE(0, "自定义"); private Integer type; //类型 private String desc; //描述 @@ -345,7 +358,7 @@ public class Constant { } /** - * 项目是否提交 + * 项目是否提交1:已提交/0:未提交 */ public enum Submit { @@ -361,8 +374,6 @@ public class Constant { this.desc = desc; } - ; - public Integer getType() { return type; } @@ -391,7 +402,73 @@ public class Constant { Ascription(Integer type, String desc) { this.type = type; this.desc = desc; - }; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + } + + /** + * 当前题目答案是否正确 1、正确/0、错误 + */ + public enum QuestionIsTure { + + TRUE(1, "正确"), + FALSE(0, "错误"); + + private Integer type; + private String desc; + + QuestionIsTure(Integer type, String desc) { + this.type = type; + this.desc = desc; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + } + + /** + * 当前题目状态 1、已作/0、未作 + */ + public enum QuestionStatus { + + MADE(1, "已作"), + NOT_MADE(0, "未作"); + + private Integer type; + private String desc; + + QuestionStatus(Integer type, String desc) { + this.type = type; + this.desc = desc; + } public Integer getType() { return type; diff --git a/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java new file mode 100644 index 0000000..282010a --- /dev/null +++ b/src/main/java/com/msdw/tms/controller/EvaluationRecordController.java @@ -0,0 +1,108 @@ +package com.msdw.tms.controller; + +import com.msdw.tms.api.EvaluationRecordControllerApi; +import com.msdw.tms.common.utils.R; +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.service.EvaluationRecordService; +import com.msdw.tms.service.QuestionsService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@RestController +@RequestMapping("tms/evaluationrecord") +public class EvaluationRecordController implements EvaluationRecordControllerApi { + @Resource + private EvaluationRecordService evaluationRecordService; + + @Resource + private QuestionsService questionsService; + +// @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) { + EvaluationRecordVO evaluationRecordVO = evaluationRecordService.startEvaluation(userId); + return R.ok().put("data", evaluationRecordVO); + } + + @Override + @PostMapping("/previous") + public R previousQuestion(@RequestParam("evaluationRecordId") Integer evaluationRecordId, + @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, + @RequestParam(value = "userAnswer", required = false) String userAnswer) { + EvaluationRecordVO evaluationRecordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo - 1); + return R.ok().put("data", evaluationRecordVO); + } + + @Override + @PostMapping("/next") + public R nextQuestion(@RequestParam("evaluationRecordId") Integer evaluationRecordId, + @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, + @RequestParam(value = "userAnswer", required = false) String userAnswer) { + EvaluationRecordVO evaluationRecordVO = evaluationRecordService.convertQuestion(evaluationRecordId, currentQuestionSortNo, userAnswer, currentQuestionSortNo + 1); + return R.ok().put("data", evaluationRecordVO); + } + + @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(@RequestParam("evaluationRecordId") Integer evaluationRecordId, + @RequestParam("currentQuestionSortNo") Integer currentQuestionSortNo, + @RequestParam(value = "userAnswer", required = false) String userAnswer, + @RequestParam("userId") Integer userId) { + EvaluationRecordSubmitVO recordSubmitVO = evaluationRecordService.submitEvaluation(evaluationRecordId, currentQuestionSortNo, userAnswer, userId); + return R.ok().put("data", recordSubmitVO); + } + + @Override + @GetMapping("/detail") + public R evaluationScoreDetail(Integer evaluationRecordId) { + EvaluationRecordDetailVO detailVO = evaluationRecordService.evaluationDetail(evaluationRecordId); + return R.ok().put("data", detailVO); + } + + @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/controller/QuestionsController.java b/src/main/java/com/msdw/tms/controller/QuestionsController.java index 73f515d..f4c0cef 100644 --- a/src/main/java/com/msdw/tms/controller/QuestionsController.java +++ b/src/main/java/com/msdw/tms/controller/QuestionsController.java @@ -144,20 +144,6 @@ public class QuestionsController implements QuestionsControllerApi { return R.ok(); } - @Override - @GetMapping("/evaluation") - public R evaluation() { - EvaluationVO evaluation = questionsService.evaluation(); - return R.ok().put("data", evaluation); - } - - @Override - @GetMapping("/remaining") - public R getEvaluationRemainingTime(Integer userId) { - String remainingTime = questionsService.getEvaluationRemainingTime(userId); - return R.ok().put("data", remainingTime); - } - @Override @GetMapping("/export") public void exportQuestion(HttpServletResponse response) throws Exception { diff --git a/src/main/java/com/msdw/tms/dao/EvaluationQuestionDao.java b/src/main/java/com/msdw/tms/dao/EvaluationQuestionDao.java new file mode 100644 index 0000000..8387ff1 --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/EvaluationQuestionDao.java @@ -0,0 +1,31 @@ +package com.msdw.tms.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.msdw.tms.entity.EvaluationQuestionEntity; +import com.msdw.tms.entity.vo.EvaluationDetailVO; +import com.msdw.tms.entity.vo.EvaluationQuestionVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 测评试题表,记录每次测评的试题,与测评记录表相关联 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:49 + */ +@Mapper +public interface EvaluationQuestionDao extends BaseMapper { + int updateById(EvaluationQuestionEntity evaluationQuestion); + + EvaluationQuestionVO selectByInfo(@Param("evaluationRecordId") Integer evaluationRecordId, + @Param("questionSortNo") Integer questionSortNo); + + List selectDetailByInfo(@Param("evaluationRecordId") Integer evaluationRecordId); + + int sumScore(@Param("evaluationRecordId") Integer evaluationRecordId); + + List sumScoreListByUserId(@Param("userId") Integer userId); +} diff --git a/src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java b/src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java new file mode 100644 index 0000000..42acc4a --- /dev/null +++ b/src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java @@ -0,0 +1,22 @@ +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 org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@Mapper +public interface EvaluationRecordDao extends BaseMapper { + EvaluationRecordVO selectVOByInfo(@Param("evaluationRecordId") Integer evaluationRecordId, + @Param("questionSortNo") Integer questionSortNo); +} diff --git a/src/main/java/com/msdw/tms/dao/QuestionsDao.java b/src/main/java/com/msdw/tms/dao/QuestionsDao.java index 036c9e6..7f8c369 100644 --- a/src/main/java/com/msdw/tms/dao/QuestionsDao.java +++ b/src/main/java/com/msdw/tms/dao/QuestionsDao.java @@ -3,6 +3,9 @@ package com.msdw.tms.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.msdw.tms.entity.QuestionsEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 记录试题信息 @@ -13,4 +16,5 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface QuestionsDao extends BaseMapper { + List selectIds(@Param("questionType") Integer questionType); } diff --git a/src/main/java/com/msdw/tms/entity/EvaluationQuestionEntity.java b/src/main/java/com/msdw/tms/entity/EvaluationQuestionEntity.java new file mode 100644 index 0000000..e69c1ee --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/EvaluationQuestionEntity.java @@ -0,0 +1,59 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; + +/** + * 测评试题表,记录每次测评的试题,与测评记录表相关联 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:49 + */ +@Data +@TableName("tms_evaluation_question") +public class EvaluationQuestionEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 自增主键 + */ + @TableId + private Integer id; + /** + * 测评记录表id + */ + private Integer evaluationRecordId; + /** + * 试题id + */ + private Integer questionId; + /** + * 试题顺序号 + */ + private Integer questionSortNo; + /** + * 试题状态:是否已被作过:1、已作/0、未作 + */ + private Integer questionStatus; + /** + * 用户填写的答案 + */ + private String userAnswer; + /** + * 是否正确:1、正确/0、错误 + */ + private Integer isTure; + /** + * 试题分值 + */ + private Integer questionPoints; + /** + * 试题得分 + */ + private Integer questionScore; + +} diff --git a/src/main/java/com/msdw/tms/entity/EvaluationRecordEntity.java b/src/main/java/com/msdw/tms/entity/EvaluationRecordEntity.java new file mode 100644 index 0000000..d234793 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/EvaluationRecordEntity.java @@ -0,0 +1,52 @@ +package com.msdw.tms.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@Data +@TableName("tms_evaluation_record") +public class EvaluationRecordEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 自增主键 + */ + @TableId + private Integer id; + /** + * 当前测评的用户的id + */ + private Integer userId; + /** + * 记录当前做到第几题,用于刷新页面以后保持在当前题目,默认开始时是第一题 + */ + private Integer currentQuestionSortNo; + /** + * 总题目数量 + */ + private Integer totalQuestionNum; + /** + * 当前测评状态:1:已提交/0:未提交 + */ + private Integer evaluationStatus; + /** + * 开始时间 + */ + private Date startTime; + /** + * 提交时间 + */ + private Date submitTime; + +} diff --git a/src/main/java/com/msdw/tms/entity/response/CommonCode.java b/src/main/java/com/msdw/tms/entity/response/CommonCode.java index 6003682..d3374b6 100644 --- a/src/main/java/com/msdw/tms/entity/response/CommonCode.java +++ b/src/main/java/com/msdw/tms/entity/response/CommonCode.java @@ -16,6 +16,7 @@ public enum CommonCode implements ResultCode { EVALUATION_TIME_INVALID(false, 10008, "测评时间错误!"), EXCEL_FILE_INVALID(false, 10009, "上传excel文件错误!"), REPEAT_INEXCEL(false, 10010, "试题在excel表中重复!"), + EVALUATION_QUESTION_NUM_INVALID(false, 10011, "当前测评题数设置为0,请先设置测评题数!"), FAIL(false, 11111, "操作失败!"), SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); //操作是否成功 diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationDetailVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationDetailVO.java new file mode 100644 index 0000000..cd7c916 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationDetailVO.java @@ -0,0 +1,40 @@ +package com.msdw.tms.entity.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 测评试题表,记录每次测评的试题,与测评记录表相关联 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:49 + */ +@Data +public class EvaluationDetailVO implements Serializable { + /** + * 序号 + */ + private Integer questionSortNo; + /** + * 是否正确 + */ + private Integer isTrue; + /** + * 试题得分 + */ + private Integer questionScore; + /** + * 用户填写的答案 + */ + private String userAnswer; + /** + * 正确答案 + */ + private String answer; + /** + * 解析 + */ + private String answerAnalysis; +} diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationQuestionVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationQuestionVO.java new file mode 100644 index 0000000..692c6b7 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationQuestionVO.java @@ -0,0 +1,38 @@ +package com.msdw.tms.entity.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 测评试题表,记录每次测评的试题,与测评记录表相关联 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:49 + */ +@Data +public class EvaluationQuestionVO implements Serializable { + + /** + * 主键 + */ + private Integer id; + /** + * 试题id + */ + private Integer questionId; + /** + * 试题分值 + */ + private Integer questionPoints; + /** + * 用户填写的答案 + */ + private String userAnswer; + /** + * 正确答案 + */ + private String answer; + +} diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordDetailVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordDetailVO.java new file mode 100644 index 0000000..ebb9afa --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordDetailVO.java @@ -0,0 +1,25 @@ +package com.msdw.tms.entity.vo; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@Data +public class EvaluationRecordDetailVO implements Serializable { + /** + * 总得分 + */ + private Integer totalScore; + /** + * 详情列表 + */ + private List evaluationDetailVOS; +} diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordSubmitVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordSubmitVO.java new file mode 100644 index 0000000..7fc0d5f --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordSubmitVO.java @@ -0,0 +1,44 @@ +package com.msdw.tms.entity.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@Data +public class EvaluationRecordSubmitVO implements Serializable { + /** + * 主键 + */ + private Integer id; + /** + * 当前测评的用户的id + */ + private Integer userId; + /** + * 总题目数量 + */ + private Integer totalQuestionNum; + /** + * 是否通过 + */ + private String isPassed; + /** + * 总得分 + */ + private Integer totalScore; + /** + * 答对几题 + */ + private Integer correctQuestionNum; + /** + * 正确率 + */ + private String correctRate; +} diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordVO.java new file mode 100644 index 0000000..37a2a45 --- /dev/null +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationRecordVO.java @@ -0,0 +1,72 @@ +package com.msdw.tms.entity.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@Data +public class EvaluationRecordVO implements Serializable { + /** + * 主键 + */ + 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; +} diff --git a/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java b/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java index 68a8172..c770330 100644 --- a/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java +++ b/src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java @@ -58,5 +58,5 @@ public class EvaluationVO implements Serializable { /** *试题列表 */ - private Set Questions; + private Set Questions; } diff --git a/src/main/java/com/msdw/tms/service/EvaluationQuestionService.java b/src/main/java/com/msdw/tms/service/EvaluationQuestionService.java new file mode 100644 index 0000000..8ebc1ce --- /dev/null +++ b/src/main/java/com/msdw/tms/service/EvaluationQuestionService.java @@ -0,0 +1,18 @@ +package com.msdw.tms.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.msdw.tms.common.utils.PageUtils; +import com.msdw.tms.entity.EvaluationQuestionEntity; + +import java.util.Map; + +/** + * 测评试题表,记录每次测评的试题,与测评记录表相关联 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:49 + */ +public interface EvaluationQuestionService extends IService { +} + diff --git a/src/main/java/com/msdw/tms/service/EvaluationRecordService.java b/src/main/java/com/msdw/tms/service/EvaluationRecordService.java new file mode 100644 index 0000000..e660664 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/EvaluationRecordService.java @@ -0,0 +1,40 @@ +package com.msdw.tms.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.msdw.tms.entity.EvaluationRecordEntity; +import com.msdw.tms.entity.vo.EvaluationRecordDetailVO; +import com.msdw.tms.entity.vo.EvaluationRecordSubmitVO; +import com.msdw.tms.entity.vo.EvaluationRecordVO; + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +public interface EvaluationRecordService extends IService { + + EvaluationRecordVO startEvaluation(Integer userId); + + EvaluationRecordVO convertQuestion(Integer evaluationRecordId, + Integer currentQuestionSortNo, + String userAnswer, + Integer changeSortNo); + + EvaluationRecordSubmitVO submitEvaluation(Integer evaluationRecordId, + Integer currentQuestionSortNo, + String userAnswer, + Integer userId); + + EvaluationRecordDetailVO evaluationDetail(Integer evaluationRecordId); + + String selectNotMade(Integer evaluationRecordId); + + void cleanRemainingTime(Integer userId); + + boolean isOpenExperiment(Integer userId); + + // boolean hasNotMadeEvaluation(Integer userId); +} + diff --git a/src/main/java/com/msdw/tms/service/QuestionsService.java b/src/main/java/com/msdw/tms/service/QuestionsService.java index f791ba5..d8bf9b3 100644 --- a/src/main/java/com/msdw/tms/service/QuestionsService.java +++ b/src/main/java/com/msdw/tms/service/QuestionsService.java @@ -43,7 +43,7 @@ public interface QuestionsService extends IService { void downloadFiles(HttpServletResponse response) throws IOException; - EvaluationVO evaluation(); + EvaluationVO randomQuestions(); void exportQuestion(HttpServletResponse response) throws Exception; diff --git a/src/main/java/com/msdw/tms/service/impl/EvaluationQuestionServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/EvaluationQuestionServiceImpl.java new file mode 100644 index 0000000..15afd92 --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/EvaluationQuestionServiceImpl.java @@ -0,0 +1,18 @@ +package com.msdw.tms.service.impl; + +import org.springframework.stereotype.Service; +import java.util.Map; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.msdw.tms.common.utils.PageUtils; +import com.msdw.tms.common.utils.Query; + +import com.msdw.tms.dao.EvaluationQuestionDao; +import com.msdw.tms.entity.EvaluationQuestionEntity; +import com.msdw.tms.service.EvaluationQuestionService; + + +@Service("evaluationQuestionService") +public class EvaluationQuestionServiceImpl extends ServiceImpl implements EvaluationQuestionService { +} \ No newline at end of file diff --git a/src/main/java/com/msdw/tms/service/impl/EvaluationRecordServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/EvaluationRecordServiceImpl.java new file mode 100644 index 0000000..e7869ba --- /dev/null +++ b/src/main/java/com/msdw/tms/service/impl/EvaluationRecordServiceImpl.java @@ -0,0 +1,338 @@ +package com.msdw.tms.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.msdw.tms.common.exception.ExceptionCast; +import com.msdw.tms.common.utils.Constant; +import com.msdw.tms.dao.EvaluationQuestionDao; +import com.msdw.tms.dao.EvaluationRecordDao; +import com.msdw.tms.entity.EvaluationQuestionEntity; +import com.msdw.tms.entity.EvaluationRecordEntity; +import com.msdw.tms.entity.response.CommonCode; +import com.msdw.tms.entity.vo.*; +import com.msdw.tms.service.EvaluationQuestionService; +import com.msdw.tms.service.EvaluationRecordService; +import com.msdw.tms.service.QuestionsService; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + + +@Service("evaluationRecordService") +public class EvaluationRecordServiceImpl extends ServiceImpl implements EvaluationRecordService { + + @Resource + QuestionsService questionsService; + + @Resource + EvaluationQuestionService evaluationQuestionService; + + @Resource + EvaluationQuestionDao evaluationQuestionDao; + + @Autowired + StringRedisTemplate redisTemplate; + + private String REMAINING_TINE_KEY = "REMAINING_TINE"; + + @Override + @Transactional + public EvaluationRecordVO startEvaluation(Integer userId) { + //TODO 接口幂等性处理 + //根据用户id和是否提交,查询测评记录信息 + EvaluationRecordEntity one = this.getOne(new QueryWrapper().eq("user_id", userId) + .eq("evaluation_status", Constant.Submit.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); + // evaluationQuestionEntity.setIsTure(Constant.QuestionIsTure.FALSE.getType()); + // evaluationQuestionEntity.setQuestionStatus(Constant.QuestionStatus.NOT_MADE.getType()); + 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 + public EvaluationRecordVO convertQuestion(Integer evaluationRecordId, + Integer currentQuestionSortNo, + String userAnswer, + Integer changeSortNo) { + if (currentQuestionSortNo < 1 + || currentQuestionSortNo > this.getById(evaluationRecordId).getTotalQuestionNum() + || changeSortNo < 1 + || changeSortNo > this.getById(evaluationRecordId).getTotalQuestionNum()) { + ExceptionCast.cast(CommonCode.INVALID_PARAM); + } + + //TODO 异步调用。。。 + //提交当前试题信息 + boolean result = submitCurrentQuestion(evaluationRecordId, + currentQuestionSortNo, + userAnswer, + changeSortNo); + if (!result) { + ExceptionCast.cast(CommonCode.FAIL); + } + + //查询下一题信息 + EvaluationRecordVO evaluationRecordVO = this.getBaseMapper().selectVOByInfo(evaluationRecordId, changeSortNo); + evaluationRecordVO.setQuestionTypeName(getQuestionTypeName(evaluationRecordVO.getQuestionType())); + return evaluationRecordVO; + } + + @Override + public EvaluationRecordSubmitVO submitEvaluation(Integer evaluationRecordId, + Integer currentQuestionSortNo, + String userAnswer, + Integer userId) { + //清除redis中的倒计时 + String key = REMAINING_TINE_KEY + userId; + redisTemplate.delete(key); + + boolean result = submitCurrentQuestion(evaluationRecordId, + currentQuestionSortNo, + userAnswer, + null); + if (!result) { + ExceptionCast.cast(CommonCode.FAIL); + } + + //TODO 优化,使用多线程异步调用 + //修改提交时间 + EvaluationRecordEntity entity = new EvaluationRecordEntity(); + entity.setId(evaluationRecordId); + entity.setEvaluationStatus(Constant.Submit.SUBMIT.getType()); + entity.setSubmitTime(new Date()); + this.updateById(entity); + + //查询总成绩 + int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("evaluation_record_id", evaluationRecordId) + .eq("is_ture", Constant.QuestionIsTure.TRUE.getType()); + + //查询答对几题 + int count = evaluationQuestionService.count(queryWrapper); + + EvaluationRecordEntity evaluationRecord = this.getById(evaluationRecordId); + + EvaluationRecordSubmitVO submitVO = new EvaluationRecordSubmitVO(); + BeanUtils.copyProperties(evaluationRecord, submitVO); + //正确率 + // 创建一个数值格式化对象 + NumberFormat numberFormat = NumberFormat.getInstance(); + // 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + submitVO.setCorrectRate(numberFormat.format((float) count / (float) evaluationRecord.getTotalQuestionNum() * 100) + "%"); + //是否通过 + submitVO.setIsPassed(sumScore > Constant.PASSING_SCORE ? Constant.EVALUATIONN_PASSED : Constant.EVALUATIONN_NOT_PASSED); + //得分 + submitVO.setTotalScore(sumScore); + //答对几道 + submitVO.setCorrectQuestionNum(count); + + return submitVO; + } + + @Override + public EvaluationRecordDetailVO evaluationDetail(Integer evaluationRecordId) { + //TODO 异步查询 + //查询总成绩 + int sumScore = evaluationQuestionDao.sumScore(evaluationRecordId); + List evaluationDetailVOS = evaluationQuestionDao.selectDetailByInfo(evaluationRecordId); + + EvaluationRecordDetailVO evaluationRecordDetailVO = new EvaluationRecordDetailVO(); + evaluationRecordDetailVO.setTotalScore(sumScore); + evaluationRecordDetailVO.setEvaluationDetailVOS(evaluationDetailVOS); + 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(item -> item.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; +// } + + //提交当前试题,并修改当前测评记录表 + @Transactional + public boolean submitCurrentQuestion(Integer evaluationRecordId, + Integer currentQuestionSortNo, + String userAnswer, + Integer changeSortNo) { + //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); + } + } + int updateQuestion = evaluationQuestionDao.updateById(evaluationQuestion); + + //修改测评记录表 + if (changeSortNo != null) { + EvaluationRecordEntity evaluationRecordEntity = new EvaluationRecordEntity(); + evaluationRecordEntity.setCurrentQuestionSortNo(changeSortNo); + evaluationRecordEntity.setId(evaluationRecordId); + boolean updateRecord = this.updateById(evaluationRecordEntity); + return updateQuestion > 0 && updateRecord; + } + + return updateQuestion > 0; + } + + +} \ No newline at end of file diff --git a/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java index dd10e50..e2e8f80 100644 --- a/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java @@ -71,6 +71,14 @@ public class EvaluationRulesServiceImpl extends ServiceImpl 100 + || evaluationRules.getQuestionNum() < 0) { + ExceptionCast.cast(CommonCode.QUESTION_NUM_INVALID); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType()) //未删除 .eq("is_enable", Constant.IsEnable.ENABLE.getType()); //启用 diff --git a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java index 78e9dad..025a648 100644 --- a/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java @@ -449,6 +449,10 @@ public class QuestionsServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType()) //未删除 - .eq("is_enable", Constant.IsEnable.ENABLE.getType()); //启用 - + public EvaluationVO randomQuestions() { // 查询测评规则类型 EvaluationRulesVO evaluationRules = evaluationRulesService.getEvaluationRules(); - EvaluationVO evaluation = new EvaluationVO(); - BeanUtils.copyProperties(evaluationRules, evaluation); - - //TODO 提交测评时删除redis中的该条数据 - - //搜集随机抽取的试题 - Set set = new HashSet<>(); + Set set = new HashSet<>(); //根据测评规则的类型不同 Integer evaluationType = evaluationRules.getEvaluationType(); if (evaluationType.equals(Constant.RulesType.RANDOM.getType())) {//随机 // 类型为随机,直接用题目数量 Integer questionNum = evaluationRules.getQuestionNum(); + if (questionNum == null || questionNum == 0) { + ExceptionCast.cast(CommonCode.EVALUATION_QUESTION_NUM_INVALID); + } // 查询题库所有未删除,未禁用的题目id - List questions = this.list(queryWrapper); - set = getRandomList(questionNum, questions); + List ids = this.getBaseMapper().selectIds(null); + set = getRandomList(questionNum, ids); } else if (evaluationType.equals(Constant.RulesType.CUSTOMIZE.getType())) {//自定义 // 单选题数量 int singleNum = 0; @@ -511,24 +507,27 @@ public class QuestionsServiceImpl extends ServiceImpl singleChoice = this.list(queryWrapper.eq("question_type", - Constant.QuestionType.SINGLE_CHOICE.getType())); - set.addAll(getRandomList(singleNum, singleChoice)); + if (singleNum == 0) { + ExceptionCast.cast(CommonCode.EVALUATION_QUESTION_NUM_INVALID); + } + List ids = this.getBaseMapper().selectIds(Constant.QuestionType.SINGLE_CHOICE.getType()); + set.addAll(getRandomList(singleNum, ids)); } if (evaluationRules.getIsMultipleEnable().equals(Constant.IsEnable.ENABLE.getType())) { multipleNum = evaluationRules.getMultipleNum(); - - List multipleChoice = this.list(queryWrapper.eq("question_type", - Constant.QuestionType.MULTIPLE_CHOICE.getType())); - set.addAll(getRandomList(multipleNum, multipleChoice)); + if (multipleNum == 0) { + ExceptionCast.cast(CommonCode.EVALUATION_QUESTION_NUM_INVALID); + } + List ids = this.getBaseMapper().selectIds(Constant.QuestionType.MULTIPLE_CHOICE.getType()); + set.addAll(getRandomList(multipleNum, ids)); } if (evaluationRules.getIsJudgmentEnable().equals(Constant.IsEnable.ENABLE.getType())) { judgmentNum = evaluationRules.getJudgmentNum(); - - List judgments = this.list(queryWrapper.eq("question_type", - Constant.QuestionType.TRUE_OR_FALSE.getType())); - set.addAll(getRandomList(judgmentNum, judgments)); + if (judgmentNum == 0) { + ExceptionCast.cast(CommonCode.EVALUATION_QUESTION_NUM_INVALID); + } + List ids = this.getBaseMapper().selectIds(Constant.QuestionType.TRUE_OR_FALSE.getType()); + set.addAll(getRandomList(judgmentNum, ids)); } // 总题数等于各类题目数量之和 evaluation.setQuestionNum(singleNum + multipleNum + judgmentNum); @@ -538,6 +537,20 @@ public class QuestionsServiceImpl extends ServiceImpl Set getRandomList(int len, List list) { + Set set = new HashSet<>(); + Random random = new Random(); + int i; + while (true) { + i = random.nextInt(list.size()); + set.add(list.get(i)); + if (set.size() >= len) { + break; + } + } + return set; + } + @Override public void exportQuestion(HttpServletResponse response) throws Exception { // 请求包装类 @@ -616,21 +629,4 @@ public class QuestionsServiceImpl extends ServiceImpl getRandomList(int len, List list) { - Set set = new HashSet<>(); - Random random = new Random(); - int i; - while (true) { - i = random.nextInt(list.size()); - QuestionsVO questionsVO = new QuestionsVO(); - BeanUtils.copyProperties(list.get(i), questionsVO); - questionsVO.setQuestionTypeName(getQuestionTypeName(list.get(i).getQuestionType())); - set.add(questionsVO); - if (set.size() >= len) { - break; - } - } - return set; - } } \ No newline at end of file diff --git a/src/main/resources/excel-template/试题导入失败数据导出模板.xlsx b/src/main/resources/excel-template/试题导入失败数据导出模板.xlsx index 9bea0c3..042244a 100644 Binary files a/src/main/resources/excel-template/试题导入失败数据导出模板.xlsx and b/src/main/resources/excel-template/试题导入失败数据导出模板.xlsx differ diff --git a/src/main/resources/mapper/tms/EvaluationQuestionDao.xml b/src/main/resources/mapper/tms/EvaluationQuestionDao.xml new file mode 100644 index 0000000..eab21eb --- /dev/null +++ b/src/main/resources/mapper/tms/EvaluationQuestionDao.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + UPDATE + tms_evaluation_question + + + question_status=#{questionStatus, jdbcType=INTEGER}, + + + user_answer=#{userAnswer, jdbcType=VARCHAR}, + + + is_ture=#{isTure, jdbcType=INTEGER}, + + + question_score=#{questionScore, jdbcType=INTEGER}, + + + WHERE + id = #{id, jdbcType=INTEGER} + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/tms/EvaluationRecordDao.xml b/src/main/resources/mapper/tms/EvaluationRecordDao.xml new file mode 100644 index 0000000..be180d8 --- /dev/null +++ b/src/main/resources/mapper/tms/EvaluationRecordDao.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/tms/QuestionsDao.xml b/src/main/resources/mapper/tms/QuestionsDao.xml index aa23977..31b9656 100644 --- a/src/main/resources/mapper/tms/QuestionsDao.xml +++ b/src/main/resources/mapper/tms/QuestionsDao.xml @@ -23,4 +23,18 @@ + + \ No newline at end of file diff --git a/src/main/resources/sql/data.sql b/src/main/resources/sql/data.sql index f40c053..410d162 100644 --- a/src/main/resources/sql/data.sql +++ b/src/main/resources/sql/data.sql @@ -78,4 +78,38 @@ CREATE TABLE `tms_xlsx_template` ( -- ---------------------------- -- Records of tms_xlsx_template -- ---------------------------- -INSERT INTO `tms_xlsx_template` VALUES ('1', 'xlsx/20200826/1598430904075.xlsx', 'http://liuwanr.oss-cn-shenzhen.aliyuncs.com/xlsx/20200826/1598430904075.xlsx', null); \ No newline at end of file +INSERT INTO `tms_xlsx_template` VALUES ('1', 'xlsx/20200826/1598430904075.xlsx', 'http://liuwanr.oss-cn-shenzhen.aliyuncs.com/xlsx/20200826/1598430904075.xlsx', null); + +-- ---------------------------- +-- Table structure for tms_evaluation_question +-- ---------------------------- +DROP TABLE IF EXISTS `tms_evaluation_question`; +CREATE TABLE `tms_evaluation_question` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `evaluation_record_id` int(11) DEFAULT NULL COMMENT '测评记录表id', + `question_id` int(11) DEFAULT NULL COMMENT '试题id', + `question_sort_no` int(11) DEFAULT NULL COMMENT '试题顺序号', + `question_status` int(11) DEFAULT '0' COMMENT '试题状态:是否已被作过:1、已作/0、未作', + `user_answer` varchar(32) DEFAULT NULL COMMENT '用户填写的答案', + `is_ture` int(11) DEFAULT '0' COMMENT '是否正确:1、正确/0、错误', + `question_points` int(11) DEFAULT NULL COMMENT '试题分值', + `question_score` int(11) DEFAULT NULL COMMENT '试题得分', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COMMENT='测评试题表,记录每次测评的试题,与测评记录表相关联'; + +-- ---------------------------- +-- Table structure for tms_evaluation_record +-- ---------------------------- +DROP TABLE IF EXISTS `tms_evaluation_record`; +CREATE TABLE `tms_evaluation_record` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增主键', + `user_id` int(11) DEFAULT NULL COMMENT '当前测评的用户的id', + `current_question_sort_no` int(11) DEFAULT '1' COMMENT '记录当前做到第几题,用于刷新页面以后保持在当前题目,默认开始时是第一题', + `total_question_num` int(11) DEFAULT NULL COMMENT '总题目数量', + `evaluation_status` int(11) DEFAULT '0' COMMENT '当前测评状态:1:已提交/0:未提交', + `start_time` datetime DEFAULT NULL COMMENT '开始时间', + `submit_time` datetime DEFAULT NULL COMMENT '提交时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='记录用户测评信息'; + + diff --git a/src/test/java/com/msdw/tms/TmsApplicationTests.java b/src/test/java/com/msdw/tms/TmsApplicationTests.java index 7ec0c78..cc8570c 100644 --- a/src/test/java/com/msdw/tms/TmsApplicationTests.java +++ b/src/test/java/com/msdw/tms/TmsApplicationTests.java @@ -10,6 +10,8 @@ import org.springframework.data.redis.core.ValueOperations; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; @@ -415,4 +417,32 @@ class TmsApplicationTests { stringRedisTemplate.opsForList().leftPush("sss", list.toString()); } + @Test + void t12() { +// System.out.println(((float) 3 / (float) 10) * 100 + "%"); + + int diliverNum = 3;//举例子的变量 + int queryMailNum = 10;//举例子的变量 +// 创建一个数值格式化对象 + NumberFormat numberFormat = NumberFormat.getInstance(); +// 设置精确到小数点后2位 + numberFormat.setMaximumFractionDigits(2); + String result = numberFormat.format((float) diliverNum / (float) queryMailNum * 100); + System.out.println("diliverNum和queryMailNum的百分比为:" + result + "%"); + } + + + public String getPercent(int x, int total) { + String result = "";//接受百分比的值 + double x_double = x * 1.0; + double tempresult = x / total; + //NumberFormat nf = NumberFormat.getPercentInstance(); 注释掉的也是一种方法 + //nf.setMinimumFractionDigits( 2 ); 保留到小数点后几位 + DecimalFormat df1 = new DecimalFormat("0.00%"); //##.00% 百分比格式,后面不足2位的用0补齐 + //result=nf.format(tempresult); + result = df1.format(tempresult); + return result; + } + + } diff --git a/src/test/java/com/msdw/tms/service/EvaluationRecordServiceTest.java b/src/test/java/com/msdw/tms/service/EvaluationRecordServiceTest.java new file mode 100644 index 0000000..a801d17 --- /dev/null +++ b/src/test/java/com/msdw/tms/service/EvaluationRecordServiceTest.java @@ -0,0 +1,31 @@ +package com.msdw.tms.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.msdw.tms.common.utils.PageUtils; +import com.msdw.tms.entity.EvaluationRecordEntity; +import com.msdw.tms.entity.vo.EvaluationRulesVO; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.Map; + +/** + * 记录用户测评信息 + * + * @author gongsj + * @email gongsj@gmail.com + * @date 2020-08-28 10:15:48 + */ +@SpringBootTest +public class EvaluationRecordServiceTest { + + @Resource + EvaluationRecordService evaluationRecordService; + + @Test + void getEvaluationRules() { + evaluationRecordService.startEvaluation(1); + } +} + diff --git a/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java index 31729c3..e8aa298 100644 --- a/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java +++ b/src/test/java/com/msdw/tms/service/QuestionsServiceTest.java @@ -120,10 +120,12 @@ class QuestionsServiceTest { questionsService.downloadFiles(response); } - @Test - void evaluation() { - EvaluationVO evaluation = questionsService.evaluation(); - System.out.println(evaluation.toString()); - } +// @Test +// void evaluation() { +// EvaluationVO evaluation = questionsService.evaluation(); +// System.out.println(evaluation.toString()); +// } + + }