parent
227fb1ce0c
commit
a068d0a086
32 changed files with 1391 additions and 84 deletions
@ -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); |
||||
} |
@ -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); |
||||
} |
||||
|
||||
} |
@ -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); |
||||
} |
@ -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; |
||||
|
||||
} |
@ -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; |
||||
} |
@ -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);
|
||||
} |
||||
|
@ -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; |
||||
} |
||||
|
||||
|
||||
} |
Binary file not shown.
@ -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> |
@ -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); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue