试卷规则修改

This commit is contained in:
tiger_zhou 2022-10-28 10:38:11 +08:00
parent 9733dac257
commit 1b71490dd1
2 changed files with 22 additions and 8 deletions

View File

@ -43,18 +43,15 @@ public class PagerQuestionService {
/** /**
* 创建对应的查询example * 创建对应的查询example
* @param queryVO 查询对象 * @param queryVO 查询对象
* @param isPaging 是否分页
* @param orgIdCanNull orgId是否可以为空 * @param orgIdCanNull orgId是否可以为空
* @param queryLabelIsNull 当查询对象labels属性为空时 是否查询 tags is null * @param queryLabelIsNull 当查询对象labels属性为空时 是否查询 tags is null
* @return * @return
*/ */
private PaperQuestionExample createQueryExample(QuestionQueryVO queryVO, boolean isPaging,boolean orgIdCanNull,boolean queryLabelIsNull){ private PaperQuestionExample createQueryExample(QuestionQueryVO queryVO, boolean orgIdCanNull,boolean queryLabelIsNull){
if(Objects.equals(false,orgIdCanNull)){ if(Objects.equals(false,orgIdCanNull)){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(queryVO.getOrgId()),"用户组织信息不能为空"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(queryVO.getOrgId()),"用户组织信息不能为空");
} }
if(isPaging){
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
}
PaperQuestionExample example = new PaperQuestionExample(); PaperQuestionExample example = new PaperQuestionExample();
PaperQuestionExample.Criteria criteria = example.createCriteria(); PaperQuestionExample.Criteria criteria = example.createCriteria();
if (StringUtils.hasText(queryVO.getTopic())) { if (StringUtils.hasText(queryVO.getTopic())) {
@ -114,7 +111,7 @@ public class PagerQuestionService {
queryVO.setOrgId(orgId); queryVO.setOrgId(orgId);
queryVO.setType(type.name()); queryVO.setType(type.name());
queryVO.setLabels(labels); queryVO.setLabels(labels);
PaperQuestionExample example = this.createQueryExample(queryVO,false,false,true); PaperQuestionExample example = this.createQueryExample(queryVO,false,true);
return this.questionDAO.countByExample(example); return this.questionDAO.countByExample(example);
} }
@ -125,7 +122,8 @@ public class PagerQuestionService {
* @return * @return
*/ */
public PageVO<PaperQuestionVO> pagingQueryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) { public PageVO<PaperQuestionVO> pagingQueryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) {
PaperQuestionExample example = this.createQueryExample(queryVO,true,companyIdCanNull,false); PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
PaperQuestionExample example = this.createQueryExample(queryVO,companyIdCanNull,false);
Page<PaperQuestionWithBLOBs> page = (Page<PaperQuestionWithBLOBs>)this.questionDAO.selectByExampleWithBLOBs(example); Page<PaperQuestionWithBLOBs> page = (Page<PaperQuestionWithBLOBs>)this.questionDAO.selectByExampleWithBLOBs(example);
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(page.getResult()); List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(page.getResult());
return PageVO.convert(page, questionVOS); return PageVO.convert(page, questionVOS);
@ -139,7 +137,7 @@ public class PagerQuestionService {
* @return * @return
*/ */
public List<PaperQuestionVO> queryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) { public List<PaperQuestionVO> queryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) {
PaperQuestionExample example = this.createQueryExample(queryVO,false,companyIdCanNull,false); PaperQuestionExample example = this.createQueryExample(queryVO,companyIdCanNull,false);
List<PaperQuestionWithBLOBs> list = this.questionDAO.selectByExampleWithBLOBs(example); List<PaperQuestionWithBLOBs> list = this.questionDAO.selectByExampleWithBLOBs(example);
List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list); List<PaperQuestionVO> questionVOS = PaperQuestionVO.convert2VOList(list);
return questionVOS; return questionVOS;

View File

@ -19,11 +19,13 @@ import club.joylink.rtss.vo.paper.convertor.PaperCompositionConvertor;
import club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor; import club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.google.common.base.Joiner;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@ -83,14 +85,28 @@ public class PaperCompositionService {
return rsp; return rsp;
} }
private String ruleMapKey(PaperCompositionWithRuleVo.PaperRuleVo vo){
String key = String.format("%s-%s-%s",vo.getType(),vo.getSubtype(), CollectionUtils.isEmpty(vo.getTags())? "" : Joiner.on(",").join(vo.getTags()));
return key;
}
/** /**
* 试卷蓝图添加规则 * 试卷蓝图添加规则
*/ */
private void createPaperCompositionRule(Long pcId, List<PaperCompositionWithRuleVo.PaperRuleVo> reqList) { private void createPaperCompositionRule(Long pcId, List<PaperCompositionWithRuleVo.PaperRuleVo> reqList) {
Map<String,List<PaperCompositionWithRuleVo.PaperRuleVo>> tmpList = reqList.stream().collect(Collectors.groupingBy(k->ruleMapKey(k)));
reqList.forEach(req -> { reqList.forEach(req -> {
req.setPcId(pcId); req.setPcId(pcId);
// //
PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType()); PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType());
String key = this.ruleMapKey(req);
List<PaperCompositionWithRuleVo.PaperRuleVo> voList = tmpList.get(key);
if(!CollectionUtils.isEmpty(voList)){
//检测一个规则只能有一个
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(voList.size() <= 1 ,String.format("试题规则类型[%s],规则类型[%s],分类%s 规则只能有一个", PaperQType.GroupType.getTypeName(req.getType()), PaperQType.SubType.getItemName(req.getSubtype()),req.getTags()));
}
// //
if(!CollectionUtils.isEmpty(req.getTags())){ if(!CollectionUtils.isEmpty(req.getTags())){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(req.getTags().size() <= 1 ,String.format("试题规则类型[%s],规则类型[%s],分类%s最多只能有一个", PaperQType.GroupType.getTypeName(req.getType()), PaperQType.SubType.getItemName(req.getSubtype()),req.getTags())); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(req.getTags().size() <= 1 ,String.format("试题规则类型[%s],规则类型[%s],分类%s最多只能有一个", PaperQType.GroupType.getTypeName(req.getType()), PaperQType.SubType.getItemName(req.getSubtype()),req.getTags()));