理论试题管理代码调整

This commit is contained in:
tiger_zhou 2022-09-23 13:02:06 +08:00
parent f8efdbc965
commit 0b8a0ca0d6
3 changed files with 42 additions and 22 deletions

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.controller.competition.question; package club.joylink.rtss.controller.competition.question;
import club.joylink.rtss.services.completition.question.PagerQuestionService; import club.joylink.rtss.services.papger.PagerQuestionService;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
@ -50,7 +50,7 @@ public class PagerQuestionBankController {
*/ */
@GetMapping(path = "/{questionId}") @GetMapping(path = "/{questionId}")
public PaperQuestionVO getQuestion(@PathVariable Long questionId) { public PaperQuestionVO getQuestion(@PathVariable Long questionId) {
return questionBankService.getQuestion(questionId); return questionBankService.getQuestion(questionId,false);
} }
/** /**

View File

@ -1,4 +1,4 @@
package club.joylink.rtss.services.completition.question; package club.joylink.rtss.services.papger;
import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.constants.Project; import club.joylink.rtss.constants.Project;
@ -22,7 +22,10 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@ -75,7 +78,7 @@ public class PagerQuestionService {
* @return * @return
*/ */
public List<PaperQuestionVO> queryQuestions(QuestionQueryVO queryVO) { public List<PaperQuestionVO> queryQuestions(QuestionQueryVO queryVO) {
List<PaperQuestion> list = (List<PaperQuestion>) this.queryQuestions(queryVO,true); List<PaperQuestion> list = (List<PaperQuestion>) this.queryQuestions(queryVO,false);
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list); List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list);
return questionVOS; return questionVOS;
} }
@ -84,16 +87,31 @@ public class PagerQuestionService {
/** /**
* 获取题型所有数据 * 获取题型所有数据
* @param questionId * @param questionId
* @param doNotCheckDel 是否检测数据状态是否删除 true = 不检测false=检测
* @return * @return
*/ */
public PaperQuestionVO getQuestion(Long questionId) { public PaperQuestionVO getQuestion(Long questionId,boolean doNotCheckDel) {
PaperQuestion question = questionDAO.selectByPrimaryKey(questionId); PaperQuestion question = questionDAO.selectByPrimaryKey(questionId);
boolean isDel = Objects.nonNull(question) || question.getIsDel() == BusinessConsts.DBLogicDelete.NORMAL.ordinal();
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(question) || question.getIsDel() == BusinessConsts.DBLogicDelete.NORMAL.ordinal()); if(doNotCheckDel){
isDel = Objects.nonNull(question);
}
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(isDel);
PaperQuestionVO questionVO = new PaperQuestionVO(question); PaperQuestionVO questionVO = new PaperQuestionVO(question);
return questionVO; return questionVO;
} }
/**
* 检测题目是否正确
* @param questionId 题目id
* @param answer 检测的答案
* @return
*/
public boolean checkAnswer(Long questionId,String answer){
PaperQuestionVO vo = this.getQuestion(questionId,true);
return vo.getOptionList().stream().anyMatch(d->Objects.equals(d,answer.trim()) && Objects.equals(true,d.getCorrect()));
}
/** /**
* 获取所有公司组织下的标签 * 获取所有公司组织下的标签
* *
@ -155,7 +173,7 @@ public class PagerQuestionService {
PaperQuestion question = questionVO.convert2DB(); PaperQuestion question = questionVO.convert2DB();
question.setCreateUserId(accountVO.getId()); question.setCreateUserId(accountVO.getId());
question.setCreateTime(LocalDateTime.now()); question.setCreateTime(LocalDateTime.now());
question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); // question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
if(Objects.nonNull(questionVO.getId())){ if(Objects.nonNull(questionVO.getId())){
PaperQuestionExample example = new PaperQuestionExample(); PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria(); PaperQuestionExample.Criteria criteria = example.createCriteria();
@ -169,7 +187,6 @@ public class PagerQuestionService {
questionDAO.updateByPrimaryKey(question); questionDAO.updateByPrimaryKey(question);
}else{ }else{
questionDAO.insert(question); questionDAO.insert(question);
} }
} }
@ -195,9 +212,9 @@ public class PagerQuestionService {
boolean isDefault = Project.isDefault(Project.valueOf(projectCode)); boolean isDefault = Project.isDefault(Project.valueOf(projectCode));
//默认项目导入题考虑是否有单位关联 //默认项目导入题考虑是否有单位关联
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
if (isDefault) { if (isDefault) {
PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria();
criteria.andProjectCodeIsNull(); criteria.andProjectCodeIsNull();
if (Objects.nonNull(companyId)) { if (Objects.nonNull(companyId)) {
criteria.andCompanyIdEqualTo(companyId); criteria.andCompanyIdEqualTo(companyId);
@ -212,14 +229,13 @@ public class PagerQuestionService {
question.setCreateUserId(accountVO.getId()); question.setCreateUserId(accountVO.getId());
question.setCreateTime(LocalDateTime.now()); question.setCreateTime(LocalDateTime.now());
question.setCompanyId(companyId); question.setCompanyId(companyId);
question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); // question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
questionDAO.insert(question); questionDAO.insert(question);
}); });
} else { } else {
//非默认项目导入题 //非默认项目导入题
PaperQuestionExample example = new PaperQuestionExample(); criteria.andProjectCodeEqualTo(projectCode);
example.createCriteria().andProjectCodeEqualTo(projectCode);
questionDAO.deleteByExample(example); questionDAO.deleteByExample(example);
questions.forEach(questionVO -> { questions.forEach(questionVO -> {
questionVO.setProjectCode(projectCode); questionVO.setProjectCode(projectCode);
@ -227,15 +243,16 @@ public class PagerQuestionService {
question.setProjectCode(projectCode); question.setProjectCode(projectCode);
question.setCreateUserId(accountVO.getId()); question.setCreateUserId(accountVO.getId());
question.setCreateTime(LocalDateTime.now()); question.setCreateTime(LocalDateTime.now());
question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal()); // question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
questionDAO.insert(question); questionDAO.insert(question);
}); });
} }
} }
/**
* 删除 逻辑删除
* @param questionId
*/
public void deleteQuestion(List<Long> questionId) { public void deleteQuestion(List<Long> questionId) {
PaperQuestionExample example = new PaperQuestionExample(); PaperQuestionExample example = new PaperQuestionExample();
example.createCriteria().andIdIn(questionId); example.createCriteria().andIdIn(questionId);

View File

@ -4,6 +4,7 @@ import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.constants.Project; import club.joylink.rtss.constants.Project;
import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestion;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -53,6 +54,7 @@ public class PaperQuestionVO implements Cloneable {
/** /**
*分值 *分值
*/ */
@JsonIgnore
private Float score = 1f; private Float score = 1f;
public PaperQuestionVO(PaperQuestion question) { public PaperQuestionVO(PaperQuestion question) {
@ -74,7 +76,7 @@ public class PaperQuestionVO implements Cloneable {
question.setCompanyId(companyId); question.setCompanyId(companyId);
question.setQuestions(JsonUtils.writeValueAsString(this.optionList)); question.setQuestions(JsonUtils.writeValueAsString(this.optionList));
question.setRaceLable(this.raceLable); question.setRaceLable(this.raceLable);
question.setIsDel(BusinessConsts.DBLogicDelete.NORMAL.ordinal());
return question; return question;
} }
@ -106,14 +108,15 @@ public class PaperQuestionVO implements Cloneable {
clone.setOptionList(cloneList); clone.setOptionList(cloneList);
return clone; return clone;
} }
@JsonIgnore
public boolean isSelect() { public boolean isSelect() {
return BusinessConsts.TheoryType.select.name().equals(type); return BusinessConsts.TheoryType.select.name().equals(type);
} }
@JsonIgnore
public boolean isJudge() { public boolean isJudge() {
return BusinessConsts.TheoryType.judge.name().equals(type); return BusinessConsts.TheoryType.judge.name().equals(type);
} }
@JsonIgnore
public boolean isMulti(){ public boolean isMulti(){
return BusinessConsts.TheoryType.multi.name().equals(type); return BusinessConsts.TheoryType.multi.name().equals(type);
} }