单点登陆

dev
caolin 2023-09-12 13:26:07 +08:00
parent 8926ac4236
commit e3158205b0
3 changed files with 79 additions and 50 deletions

View File

@ -6,6 +6,7 @@ import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author
@ -18,10 +19,20 @@ public class TestQuestionTypeDto {
//科目
private String subject;
private List<TestOfChapter> chapterList;
@Data
@Accessors(chain = true)
public static class TestOfChapter {
//章节
private String chapter;
//判断题
private Integer judgeNum;
//单选题
private Integer radioNum;
//多选题
private Integer multipleChoiceNum;
}
}

View File

@ -110,26 +110,38 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
Optional<TestQuestionTypeDto> optional = testQuestionTypeDtos.stream().filter(s -> StrUtil.equals(s.getSubject(), queryDto.getSubject())).findFirst();
if (optional.isPresent()) {
TestQuestionTypeDto testQuestionTypeDto = optional.get();
List<TestQuestionTypeDto.TestOfChapter> chapterList = testQuestionTypeDto.getChapterList();
if (CollectionUtil.isEmpty(chapterList)){
return resultList;
}
for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) {
//判断题
if (Objects.nonNull(testQuestionTypeDto.getJudgeNum()) && testQuestionTypeDto.getJudgeNum() > 0) {
if (Objects.nonNull(testOfChapter.getJudgeNum()) && testOfChapter.getJudgeNum() > 0) {
queryDto.setType(Constants.QUESTION_TYPE_ONE)
.setNum(testQuestionTypeDto.getJudgeNum());
.setChapter(testOfChapter.getChapter())
.setNum(testOfChapter.getJudgeNum());
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
}
}
for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) {
//单选
if (Objects.nonNull(testQuestionTypeDto.getRadioNum()) && testQuestionTypeDto.getRadioNum() > 0) {
if (Objects.nonNull(testOfChapter.getRadioNum()) && testOfChapter.getRadioNum() > 0) {
queryDto.setType(Constants.QUESTION_TYPE_TWO)
.setNum(testQuestionTypeDto.getRadioNum());
.setChapter(testOfChapter.getChapter())
.setNum(testOfChapter.getRadioNum());
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
}
}
for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) {
//多选
if (Objects.nonNull(testQuestionTypeDto.getMultipleChoiceNum()) && testQuestionTypeDto.getMultipleChoiceNum() > 0) {
if (Objects.nonNull(testOfChapter.getMultipleChoiceNum()) && testOfChapter.getMultipleChoiceNum() > 0) {
queryDto.setType(Constants.QUESTION_TYPE_THREE)
.setNum(testQuestionTypeDto.getMultipleChoiceNum());
.setChapter(testOfChapter.getChapter())
.setNum(testOfChapter.getMultipleChoiceNum());
resultList.addAll(this.getBaseMapper().queryQuestionByRandom(queryDto));
}
}
}
questionOptionHandler(resultList);
return resultList;
}
@ -151,26 +163,38 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
Optional<TestQuestionTypeDto> optional = testQuestionTypeDtos.stream().filter(s -> StrUtil.equals(s.getSubject(), queryDto.getSubject())).findFirst();
if (optional.isPresent()) {
TestQuestionTypeDto testQuestionTypeDto = optional.get();
List<TestQuestionTypeDto.TestOfChapter> chapterList = testQuestionTypeDto.getChapterList();
if (CollectionUtil.isEmpty(chapterList)){
return resultList;
}
for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) {
//判断题
if (Objects.nonNull(testQuestionTypeDto.getJudgeNum()) && testQuestionTypeDto.getJudgeNum() > 0) {
if (Objects.nonNull(testOfChapter.getJudgeNum()) && testOfChapter.getJudgeNum() > 0) {
queryDto.setType(Constants.QUESTION_TYPE_ONE)
.setNum(testQuestionTypeDto.getJudgeNum());
.setChapter(testOfChapter.getChapter())
.setNum(testOfChapter.getJudgeNum());
resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto));
}
}
for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) {
//单选
if (Objects.nonNull(testQuestionTypeDto.getRadioNum()) && testQuestionTypeDto.getRadioNum() > 0) {
if (Objects.nonNull(testOfChapter.getRadioNum()) && testOfChapter.getRadioNum() > 0) {
queryDto.setType(Constants.QUESTION_TYPE_TWO)
.setNum(testQuestionTypeDto.getRadioNum());
.setChapter(testOfChapter.getChapter())
.setNum(testOfChapter.getRadioNum());
resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto));
}
}
for (TestQuestionTypeDto.TestOfChapter testOfChapter : chapterList) {
//多选
if (Objects.nonNull(testQuestionTypeDto.getMultipleChoiceNum()) && testQuestionTypeDto.getMultipleChoiceNum() > 0) {
if (Objects.nonNull(testOfChapter.getMultipleChoiceNum()) && testOfChapter.getMultipleChoiceNum() > 0) {
queryDto.setType(Constants.QUESTION_TYPE_THREE)
.setNum(testQuestionTypeDto.getMultipleChoiceNum());
.setChapter(testOfChapter.getChapter())
.setNum(testOfChapter.getMultipleChoiceNum());
resultList.addAll(this.getBaseMapper().queryQuestionIdByRandom(queryDto));
}
}
}
return resultList;
}
@ -312,18 +336,6 @@ public class TdQuestionServiceImpl extends ServiceImpl<TdQuestionMapper, TdQuest
public static void main(String[] args) {
List<TestQuestionTypeDto> testQuestionTypeDtos = new ArrayList<>();
TestQuestionTypeDto dto1 = new TestQuestionTypeDto()
.setSubject("1")
.setJudgeNum(40)
.setRadioNum(60)
.setMultipleChoiceNum(0);
TestQuestionTypeDto dto2 = new TestQuestionTypeDto()
.setSubject("4")
.setJudgeNum(20)
.setRadioNum(20)
.setMultipleChoiceNum(10);
testQuestionTypeDtos.add(dto1);
testQuestionTypeDtos.add(dto2);
String jsonString = JSONArray.toJSONString(testQuestionTypeDtos);
System.out.println(jsonString);

View File

@ -143,6 +143,9 @@
<if test="queryDto.type !=null">
and tq.TYPE = #{queryDto.type}
</if>
<if test="queryDto.chapter !=null and queryDto.chapter !=''">
and tq.CHAPTER = #{queryDto.chapter}
</if>
</where>
order by rand() limit ${queryDto.num};
</select>
@ -273,6 +276,9 @@
<if test="queryDto.type !=null">
and tq.TYPE = #{queryDto.type}
</if>
<if test="queryDto.chapter !=null and queryDto.chapter !=''">
and tq.CHAPTER = #{queryDto.chapter}
</if>
</where>
order by rand() limit ${queryDto.num};
</select>