|
|
@ -1,15 +1,18 @@ |
|
|
package com.project.interaction.domain.service.impl; |
|
|
package com.project.interaction.domain.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
import com.project.interaction.domain.service.PostToGenerateQuestionDomainService; |
|
|
import com.project.interaction.domain.service.PostToGenerateQuestionDomainService; |
|
|
|
|
|
import com.project.question.domain.dto.QuestionDTO; |
|
|
import com.project.question.domain.dto.TaskKnowledgePointDTO; |
|
|
import com.project.question.domain.dto.TaskKnowledgePointDTO; |
|
|
import com.project.question.domain.enums.QuestionSourceTypeEnum; |
|
|
|
|
|
import com.project.question.domain.service.QuestionBaseService; |
|
|
import com.project.question.domain.service.QuestionBaseService; |
|
|
import com.project.question.domain.service.QuestionKpRelBaseService; |
|
|
import com.project.question.domain.service.QuestionKpRelBaseService; |
|
|
|
|
|
import com.project.question.domain.service.SaveQuestionDomainService; |
|
|
import com.project.task.domain.enums.QuestionTypeEnum; |
|
|
import com.project.task.domain.enums.QuestionTypeEnum; |
|
|
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 java.util.List; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQuestionDomainService { |
|
|
public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQuestionDomainService { |
|
|
@ -22,16 +25,73 @@ public class PostToGenerateQuestionDomainServiceImpl implements PostToGenerateQu |
|
|
@Autowired |
|
|
@Autowired |
|
|
private QuestionKpRelBaseService questionKpRelBaseService; |
|
|
private QuestionKpRelBaseService questionKpRelBaseService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private SaveQuestionDomainService saveQuestionDomainService; |
|
|
|
|
|
|
|
|
|
|
|
private final String[] optionListStr = {"A" , "B" , "C" , "D"}; |
|
|
|
|
|
|
|
|
|
|
|
private final String[] trueFalseListStr = {"A" , "B"}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<Integer> list = Arrays.asList(0,1,2,3); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void postToGenerateQuestion(List<TaskKnowledgePointDTO> dtoList, QuestionTypeEnum questionType, int num) throws Exception { |
|
|
public void postToGenerateQuestion(List<TaskKnowledgePointDTO> dtoList, QuestionTypeEnum questionType, int num) throws Exception { |
|
|
System.out.println(String.format("<=======生成了%d道%s, 结合了知识点【%s】属于%s=======>" , |
|
|
// System.out.println(String.format("<=======生成了%d道%s, 结合了知识点【%s】属于%s=======>" ,
|
|
|
num , |
|
|
// num ,
|
|
|
questionType.getDescription() , |
|
|
// questionType.getDescription() ,
|
|
|
String.join("," , dtoList.stream().map(dto -> dto.getId().toString()).toList()) , |
|
|
// String.join("," , dtoList.stream().map(dto -> dto.getId().toString()).toList()) ,
|
|
|
dtoList.size() > 1 ? QuestionSourceTypeEnum.Multi_Concept.getDesc() : QuestionSourceTypeEnum.Single_Concept.getDesc())); |
|
|
// dtoList.size() > 1 ? QuestionSourceTypeEnum.Multi_Concept.getDesc() : QuestionSourceTypeEnum.Single_Concept.getDesc()));
|
|
|
|
|
|
|
|
|
// todo 算法交互,请求生成问题
|
|
|
// todo 算法交互,请求生成问题
|
|
|
|
|
|
// todo 先写死,写死问题和选项
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < num; i++) { |
|
|
|
|
|
QuestionDTO questionDTO = new QuestionDTO(); |
|
|
|
|
|
questionDTO.setKpIdList(dtoList.stream().map(TaskKnowledgePointDTO::getId).collect(Collectors.toList())); |
|
|
|
|
|
questionDTO.setQuestionType(questionType.getValue()); |
|
|
|
|
|
QuestionDTO.QuestionDetailDTO detailDTO = new QuestionDTO.QuestionDetailDTO(); |
|
|
|
|
|
|
|
|
|
|
|
detailDTO.setQuestionContent(String.format("这是一道%s" , questionType.getDescription())); |
|
|
|
|
|
detailDTO.setType(questionType.getValue()); |
|
|
|
|
|
if (QuestionTypeEnum.SINGLE_CHOICE.equals(questionType)) { |
|
|
|
|
|
int rightAnswerNo = RandomUtil.randomInt(0, 4); |
|
|
|
|
|
TreeMap<String , String> optionList = new TreeMap<>(); |
|
|
|
|
|
for (int j = 0; j < optionListStr.length; j++) { |
|
|
|
|
|
optionList.put(optionListStr[j] , String.format("这是%s选项" , optionListStr[j])); |
|
|
|
|
|
if (j == rightAnswerNo) { |
|
|
|
|
|
detailDTO.setRightAnswer(optionListStr[j]); |
|
|
|
|
|
detailDTO.setAnalysis(String.format("这道题选%s" , optionListStr[j])); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
detailDTO.setOptions(optionList); |
|
|
|
|
|
} else if (QuestionTypeEnum.MULTIPLE_CHOICE.equals(questionType)) { |
|
|
|
|
|
Collections.shuffle(list); // 随机打乱
|
|
|
|
|
|
Set<Integer> result = list.subList(0, 2).stream().collect(Collectors.toSet()); |
|
|
|
|
|
TreeMap<String , String> optionList = new TreeMap<>(); |
|
|
|
|
|
List<String> rightAnswerList = new ArrayList<>(); |
|
|
|
|
|
for (int j = 0; j < optionListStr.length; j++) { |
|
|
|
|
|
optionList.put(optionListStr[j] , String.format("这是%s选项" , optionListStr[j])); |
|
|
|
|
|
if (result.contains(j)) { |
|
|
|
|
|
rightAnswerList.add(optionListStr[j]); |
|
|
|
|
|
} |
|
|
|
|
|
detailDTO.setRightAnswer(String.join("," , rightAnswerList)); |
|
|
|
|
|
detailDTO.setAnalysis(String.format("这道题选%s" , detailDTO.getRightAnswer())); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
int rightAnswerNo = RandomUtil.randomInt(0, 2); |
|
|
|
|
|
TreeMap<String , String> optionList = new TreeMap<>(); |
|
|
|
|
|
for (int j = 0; j < trueFalseListStr.length; j++) { |
|
|
|
|
|
optionList.put(trueFalseListStr[j] , j == 0 ? "对" : "错"); |
|
|
|
|
|
if (j == rightAnswerNo) { |
|
|
|
|
|
detailDTO.setRightAnswer(trueFalseListStr[j]); |
|
|
|
|
|
detailDTO.setAnalysis(String.format("这道题选%s" , trueFalseListStr[j])); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
saveQuestionDomainService.save(questionDTO); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|