用户测评

hehai
shijie 4 years ago
parent 227fb1ce0c
commit a068d0a086
  1. 76
      src/main/java/com/msdw/tms/api/EvaluationRecordControllerApi.java
  2. 12
      src/main/java/com/msdw/tms/api/QuestionsControllerApi.java
  3. 89
      src/main/java/com/msdw/tms/common/utils/Constant.java
  4. 108
      src/main/java/com/msdw/tms/controller/EvaluationRecordController.java
  5. 14
      src/main/java/com/msdw/tms/controller/QuestionsController.java
  6. 31
      src/main/java/com/msdw/tms/dao/EvaluationQuestionDao.java
  7. 22
      src/main/java/com/msdw/tms/dao/EvaluationRecordDao.java
  8. 4
      src/main/java/com/msdw/tms/dao/QuestionsDao.java
  9. 59
      src/main/java/com/msdw/tms/entity/EvaluationQuestionEntity.java
  10. 52
      src/main/java/com/msdw/tms/entity/EvaluationRecordEntity.java
  11. 1
      src/main/java/com/msdw/tms/entity/response/CommonCode.java
  12. 40
      src/main/java/com/msdw/tms/entity/vo/EvaluationDetailVO.java
  13. 38
      src/main/java/com/msdw/tms/entity/vo/EvaluationQuestionVO.java
  14. 25
      src/main/java/com/msdw/tms/entity/vo/EvaluationRecordDetailVO.java
  15. 44
      src/main/java/com/msdw/tms/entity/vo/EvaluationRecordSubmitVO.java
  16. 72
      src/main/java/com/msdw/tms/entity/vo/EvaluationRecordVO.java
  17. 2
      src/main/java/com/msdw/tms/entity/vo/EvaluationVO.java
  18. 18
      src/main/java/com/msdw/tms/service/EvaluationQuestionService.java
  19. 40
      src/main/java/com/msdw/tms/service/EvaluationRecordService.java
  20. 2
      src/main/java/com/msdw/tms/service/QuestionsService.java
  21. 18
      src/main/java/com/msdw/tms/service/impl/EvaluationQuestionServiceImpl.java
  22. 338
      src/main/java/com/msdw/tms/service/impl/EvaluationRecordServiceImpl.java
  23. 8
      src/main/java/com/msdw/tms/service/impl/EvaluationRulesServiceImpl.java
  24. 84
      src/main/java/com/msdw/tms/service/impl/QuestionsServiceImpl.java
  25. BIN
      src/main/resources/excel-template/试题导入失败数据导出模板.xlsx
  26. 108
      src/main/resources/mapper/tms/EvaluationQuestionDao.xml
  27. 47
      src/main/resources/mapper/tms/EvaluationRecordDao.xml
  28. 14
      src/main/resources/mapper/tms/QuestionsDao.xml
  29. 36
      src/main/resources/sql/data.sql
  30. 30
      src/test/java/com/msdw/tms/TmsApplicationTests.java
  31. 31
      src/test/java/com/msdw/tms/service/EvaluationRecordServiceTest.java
  32. 12
      src/test/java/com/msdw/tms/service/QuestionsServiceTest.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);
}

@ -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批量导出
*/

@ -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;

@ -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);
}
}

@ -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 {

@ -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<EvaluationQuestionEntity> {
int updateById(EvaluationQuestionEntity evaluationQuestion);
EvaluationQuestionVO selectByInfo(@Param("evaluationRecordId") Integer evaluationRecordId,
@Param("questionSortNo") Integer questionSortNo);
List<EvaluationDetailVO> selectDetailByInfo(@Param("evaluationRecordId") Integer evaluationRecordId);
int sumScore(@Param("evaluationRecordId") Integer evaluationRecordId);
List<Integer> sumScoreListByUserId(@Param("userId") Integer userId);
}

@ -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<EvaluationRecordEntity> {
EvaluationRecordVO selectVOByInfo(@Param("evaluationRecordId") Integer evaluationRecordId,
@Param("questionSortNo") Integer questionSortNo);
}

@ -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<QuestionsEntity> {
List<Integer> selectIds(@Param("questionType") Integer questionType);
}

@ -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;
}

@ -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;
}

@ -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, "抱歉,系统繁忙,请稍后重试!");
//操作是否成功

@ -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;
}

@ -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;
}

@ -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<EvaluationDetailVO> evaluationDetailVOS;
}

@ -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;
}

@ -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;
}

@ -58,5 +58,5 @@ public class EvaluationVO implements Serializable {
/**
*试题列表
*/
private Set<QuestionsVO> Questions;
private Set<Integer> Questions;
}

@ -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<EvaluationQuestionEntity> {
}

@ -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<EvaluationRecordEntity> {
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);
}

@ -43,7 +43,7 @@ public interface QuestionsService extends IService<QuestionsEntity> {
void downloadFiles(HttpServletResponse response) throws IOException;
EvaluationVO evaluation();
EvaluationVO randomQuestions();
void exportQuestion(HttpServletResponse response) throws Exception;

@ -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<EvaluationQuestionDao, EvaluationQuestionEntity> implements EvaluationQuestionService {
}

@ -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<EvaluationRecordDao, EvaluationRecordEntity> 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<EvaluationRecordEntity>().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<EvaluationQuestionEntity> 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<Integer> 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<Integer> averageValue(Integer number) {
if (number == null || number == 0) {
ExceptionCast.cast(CommonCode.EVALUATION_QUESTION_NUM_INVALID);
}
Integer score = 100 / number;
List<Integer> 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<EvaluationQuestionEntity> 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<EvaluationDetailVO> evaluationDetailVOS = evaluationQuestionDao.selectDetailByInfo(evaluationRecordId);
EvaluationRecordDetailVO evaluationRecordDetailVO = new EvaluationRecordDetailVO();
evaluationRecordDetailVO.setTotalScore(sumScore);
evaluationRecordDetailVO.setEvaluationDetailVOS(evaluationDetailVOS);
return evaluationRecordDetailVO;
}
@Override
public String selectNotMade(Integer evaluationRecordId) {
QueryWrapper<EvaluationQuestionEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("evaluation_record_id", evaluationRecordId)
.eq("question_status", Constant.QuestionStatus.NOT_MADE.getType());
List<EvaluationQuestionEntity> list = evaluationQuestionService.list(queryWrapper);
List<Integer> 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<Integer> 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<String, String> 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;
}
}

@ -71,6 +71,14 @@ public class EvaluationRulesServiceImpl extends ServiceImpl<EvaluationRulesDao,
@Override
public boolean updateEvaluationRulesById(EvaluationRulesEntity evaluationRules) {
//控制测评题数不能超过100道
if (evaluationRules == null
|| evaluationRules.getQuestionNum() == null
|| evaluationRules.getQuestionNum() > 100
|| evaluationRules.getQuestionNum() < 0) {
ExceptionCast.cast(CommonCode.QUESTION_NUM_INVALID);
}
QueryWrapper<QuestionsEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("is_del", Constant.IsDel.NOT_DEL.getType()) //未删除
.eq("is_enable", Constant.IsEnable.ENABLE.getType()); //启用

@ -449,6 +449,10 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
/**
* 上传模板文件修改模板信息表数据
*
* @param file 上传的文件
* @return 文件处理的结果集
* @throws IOException io异常
*/
@Override
@Transactional
@ -476,31 +480,23 @@ public class QuestionsServiceImpl extends ServiceImpl<QuestionsDao, QuestionsEnt
}
@Override
public EvaluationVO evaluation() {
QueryWrapper<QuestionsEntity> 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<QuestionsVO> set = new HashSet<>();
Set<Integer> 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<QuestionsEntity> questions = this.list(queryWrapper);
set = getRandomList(questionNum, questions);
List<Integer> 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<QuestionsDao, QuestionsEnt
//判断各条目的题型是否启用
if (evaluationRules.getIsSingleEnable().equals(Constant.IsEnable.ENABLE.getType())) {
singleNum = evaluationRules.getSingleNum();
List<QuestionsEntity> 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<Integer> 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<QuestionsEntity> 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<Integer> 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<QuestionsEntity> 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<Integer> 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<QuestionsDao, QuestionsEnt
return evaluation;
}
private <T> Set<T> getRandomList(int len, List<T> list) {
Set<T> 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<QuestionsDao, QuestionsEnt
new ExcelExportUtil(QuestionsImportFailureVO.class, Constant.ROW_INDEX, Constant.STYLE_INDEX).
export(response, fis, parse, "导入失败数据表.xlsx");
}
private Set<QuestionsVO> getRandomList(int len, List<QuestionsEntity> list) {
Set<QuestionsVO> 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;
}
}

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.dao.EvaluationQuestionDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.msdw.tms.entity.EvaluationQuestionEntity" id="evaluationQuestionMap">
<result property="id" column="id"/>
<result property="evaluationRecordId" column="evaluation_record_id"/>
<result property="questionId" column="question_id"/>
<result property="questionSortNo" column="question_sort_no"/>
<result property="questionStatus" column="question_status"/>
<result property="userAnswer" column="user_answer"/>
<result property="isTure" column="is_ture"/>
<result property="questionPoints" column="question_points"/>
<result property="questionScore" column="question_score"/>
</resultMap>
<update id="updateById" parameterType="com.msdw.tms.entity.EvaluationQuestionEntity">
UPDATE
tms_evaluation_question
<set>
<if test="questionStatus != null">
question_status=#{questionStatus, jdbcType=INTEGER},
</if>
<if test="userAnswer != null">
user_answer=#{userAnswer, jdbcType=VARCHAR},
</if>
<if test="isTure != null">
is_ture=#{isTure, jdbcType=INTEGER},
</if>
<if test="questionScore != null">
question_score=#{questionScore, jdbcType=INTEGER},
</if>
</set>
WHERE
id = #{id, jdbcType=INTEGER}
</update>
<select id="sumScore" resultType="java.lang.Integer">
SELECT
SUM(question_score)
FROM
tms_evaluation_question
WHERE
evaluation_record_id = #{evaluationRecordId,jdbcType=INTEGER}
</select>
<select id="sumScoreListByUserId" resultType="java.lang.Integer">
SELECT
SUM(question_score)
FROM
tms_evaluation_question
GROUP BY
evaluation_record_id
HAVING
evaluation_record_id IN (
SELECT
id
FROM
tms_evaluation_record
WHERE
user_id = #{userId}
AND evaluation_status = 1
)
</select>
<select id="selectByInfo" resultType="com.msdw.tms.entity.vo.EvaluationQuestionVO">
SELECT
eq.id,
eq.question_id,
eq.question_points,
eq.user_answer,
q.answer
FROM
tms_evaluation_question eq
INNER JOIN
tms_questions q
ON
eq.question_id = q.id
WHERE
evaluation_record_id = #{evaluationRecordId,jdbcType=INTEGER}
AND
question_sort_no = #{questionSortNo,jdbcType=INTEGER}
</select>
<select id="selectDetailByInfo" resultType="com.msdw.tms.entity.vo.EvaluationDetailVO">
SELECT
eq.question_sort_no,
eq.is_ture,
eq.question_score,
eq.user_answer,
q.answer,
q.answer_analysis
FROM
tms_evaluation_question eq
INNER JOIN
tms_questions q
ON
eq.question_id = q.id
WHERE
eq.evaluation_record_id = #{evaluationRecordId,jdbcType=INTEGER}
ORDER BY
eq.question_sort_no
ASC
</select>
</mapper>

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.msdw.tms.dao.EvaluationRecordDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.msdw.tms.entity.EvaluationRecordEntity" id="evaluationRecordMap">
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="currentQuestionSortNo" column="current_question_sort_no"/>
<result property="totalQuestionNum" column="total_question_num"/>
<result property="evaluationStatus" column="evaluation_status"/>
<result property="startTime" column="start_time"/>
<result property="submitTime" column="submit_time"/>
</resultMap>
<select id="selectVOByInfo" resultType="com.msdw.tms.entity.vo.EvaluationRecordVO">
SELECT
er.id,
er.user_id,
er.current_question_sort_no,
er.total_question_num,
q.question_type,
q.question_stem,
q.option_a,
q.option_b,
q.option_c,
q.option_d,
q.option_e,
q.option_f,
eq.user_answer
FROM
tms_evaluation_record er
INNER JOIN
tms_evaluation_question eq
ON
er.id = eq.evaluation_record_id
INNER JOIN
tms_questions q
ON
eq.question_id = q.id
WHERE
eq.evaluation_record_id = #{evaluationRecordId}
AND
eq.question_sort_no = #{questionSortNo}
</select>
</mapper>

@ -23,4 +23,18 @@
<result property="modifyUser" column="modify_user"/>
<result property="modifyTime" column="modify_time"/>
</resultMap>
<select id="selectIds" parameterType="int" resultType="int">
SELECT
id
FROM
tms_questions
WHERE
is_del = 0
AND
is_enable = 1
<if test="questionType != null and questionType != ''">
and question_type = #{questionType}
</if>
</select>
</mapper>

@ -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);
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='记录用户测评信息';

@ -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;
}
}

@ -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);
}
}

@ -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());
// }
}

Loading…
Cancel
Save