diff --git a/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java b/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java index 5621ec34d..d9942628a 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PagerQuestionService.java @@ -43,18 +43,15 @@ public class PagerQuestionService { /** * 创建对应的查询example * @param queryVO 查询对象 - * @param isPaging 是否分页 * @param orgIdCanNull orgId是否可以为空 * @param queryLabelIsNull 当查询对象labels属性为空时 是否查询 tags is null * @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)){ BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(queryVO.getOrgId()),"用户组织信息不能为空"); } - if(isPaging){ - PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); - } + PaperQuestionExample example = new PaperQuestionExample(); PaperQuestionExample.Criteria criteria = example.createCriteria(); if (StringUtils.hasText(queryVO.getTopic())) { @@ -114,7 +111,7 @@ public class PagerQuestionService { queryVO.setOrgId(orgId); queryVO.setType(type.name()); queryVO.setLabels(labels); - PaperQuestionExample example = this.createQueryExample(queryVO,false,false,true); + PaperQuestionExample example = this.createQueryExample(queryVO,false,true); return this.questionDAO.countByExample(example); } @@ -125,7 +122,8 @@ public class PagerQuestionService { * @return */ public PageVO 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 page = (Page)this.questionDAO.selectByExampleWithBLOBs(example); List questionVOS = PaperQuestionVO.convert2VOList(page.getResult()); return PageVO.convert(page, questionVOS); @@ -139,7 +137,7 @@ public class PagerQuestionService { * @return */ public List queryQuestions(QuestionQueryVO queryVO,boolean companyIdCanNull) { - PaperQuestionExample example = this.createQueryExample(queryVO,false,companyIdCanNull,false); + PaperQuestionExample example = this.createQueryExample(queryVO,companyIdCanNull,false); List list = this.questionDAO.selectByExampleWithBLOBs(example); List questionVOS = PaperQuestionVO.convert2VOList(list); return questionVOS; diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java b/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java index 4ab94d628..9425ea099 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperCompositionService.java @@ -19,11 +19,13 @@ import club.joylink.rtss.vo.paper.convertor.PaperCompositionConvertor; import club.joylink.rtss.vo.paper.convertor.PaperRuleConvertor; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import com.google.common.base.Joiner; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.util.*; @@ -83,14 +85,28 @@ public class PaperCompositionService { 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 reqList) { + Map> tmpList = reqList.stream().collect(Collectors.groupingBy(k->ruleMapKey(k))); + + reqList.forEach(req -> { req.setPcId(pcId); // PaperQType.assertPaperSubTypeMatchGroupType(req.getSubtype(), req.getType()); + String key = this.ruleMapKey(req); + List 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())){ 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()));