| | |
| | | package com.ots.project.exam.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ots.common.enums.QuestionTypeEnum; |
| | |
| | | import org.springframework.context.i18n.LocaleContextHolder; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ots.common.enums.ExamPaperQuestion.permanentIdDuplicate; |
| | | |
| | | /** |
| | | * 题目列表Service业务层处理 |
| | | * |
| | | * @author Shawn |
| | | * @date 2019-11-20 |
| | | */ |
| | | @Service("examQuestion") |
| | | public class TQuestionServiceImpl implements ITQuestionService { |
| | | @Autowired |
| | | private TQuestionMapper tQuestionMapper; |
| | | |
| | | @Autowired |
| | | private TTextContentMapper tTextContentMapper; |
| | | |
| | | @Autowired |
| | | private ITTextContentService textContentService; |
| | | |
| | | @Autowired |
| | | private IDictDataService dictDataService; |
| | | |
| | | @Autowired |
| | | private DictService dictService; |
| | | |
| | | protected final static ModelMapper modelMapper = ModelMapperSingle.Instance(); |
| | | |
| | | |
| | | /** |
| | | * 查询题目列表 |
| | | * |
| | | * @param id 题目列表ID |
| | | * @return 题目列表 |
| | | */ |
| | | @Override |
| | | public TQuestion selectTQuestionById(Long id) { |
| | | return tQuestionMapper.selectTQuestionById(id); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询题目列表 |
| | | * |
| | | * @param id 题目列表ID |
| | | * @return 题目列表 |
| | | */ |
| | | @Override |
| | | public List<TQuestion> selectTQuestionByIds(List<Long> ids) { |
| | | return tQuestionMapper.selectTQuestionByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<TQuestion> selectTQuestionByPermanentIds(List<String> permanentIds) { |
| | | return tQuestionMapper.selectTQuestionByPermanentIds(permanentIds); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询题目列表列表 |
| | | * |
| | | * @param tQuestion 题目列表 |
| | | * @return 题目列表 |
| | | */ |
| | | @Override |
| | | public List<TQuestion> selectTQuestionList(TQuestion tQuestion) { |
| | | List<TQuestion> tQuestionList = tQuestionMapper.selectTQuestionList(tQuestion); |
| | | List<TQuestion> tQuestionResultList = new ArrayList<>(); |
| | | |
| | | // 国际化的选择的多语言类型 |
| | | String localLangType = dictService.getLangType(LocaleContextHolder.getLocale().toString()); |
| | | for (TQuestion question : tQuestionList) { |
| | | String content = question.getContent(); |
| | | QuestionObject questionObject = JSONObject.parseObject(content, QuestionObject.class); |
| | | |
| | | setChioceAndSelectInput(question, questionObject); |
| | | |
| | | question.setTitle(questionObject.getTitleContent()); |
| | | |
| | | |
| | | // 遍历出各种语言 |
| | | Map<String, String> titleMap = JsonUtil.toJsonObject(question.getTitle(), HashMap.class); |
| | | if (Objects.isNull(titleMap)) { |
| | | TQuestion questionResult = new TQuestion(); |
| | |
| | | questionResult.setLangType("Chinese"); |
| | | tQuestionResultList.add(questionResult); |
| | | } else { |
| | | |
| | | // 外层 |
| | | if (Objects.isNull(tQuestion.getUuid())) { |
| | | |
| | | // 如果是安条件查询 |
| | | if (StringUtils.isNotEmpty(tQuestion.getLangType())) { |
| | | |
| | | // 有这种语言 |
| | | if (StringUtils.isNotEmpty(titleMap.get(tQuestion.getLangType()))) { |
| | | |
| | | // 有先展示国际化 |
| | | if (StringUtils.isNotEmpty(titleMap.get(localLangType))) { |
| | | addQuestionResult(tQuestionResultList, question, localLangType, titleMap.get(localLangType)); |
| | | } else { |
| | | addQuestionResult(tQuestionResultList, question, tQuestion.getLangType(), titleMap.get(tQuestion.getLangType())); |
| | | } |
| | | } |
| | | } else if (StringUtils.isNotEmpty(titleMap.get(localLangType))) { |
| | | } else if (StringUtils.isNotEmpty(titleMap.get(localLangType))) { // 不是安条件查询 |
| | | addQuestionResult(tQuestionResultList, question, localLangType, titleMap.get(localLangType)); |
| | | } else { |
| | | } else { // 无论如何都要随便展示一种语言 |
| | | addQuestionResult(tQuestionResultList, question, titleMap.keySet().stream().findFirst().get(), titleMap.values().stream().findFirst().get()); |
| | | } |
| | | } else { |
| | | |
| | | // 多语言的那层 |
| | | if (StringUtils.isNotEmpty(tQuestion.getLangType())) { |
| | | addQuestionResult(tQuestionResultList, question, tQuestion.getLangType(), titleMap.get(tQuestion.getLangType())); |
| | | } else { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | tQuestionList.clear(); |
| | | tQuestionList.addAll(tQuestionResultList); |
| | | return tQuestionList; |
| | | } |
| | | |
| | | private void setChioceAndSelectInput(TQuestion question, QuestionObject questionObject) { |
| | | if (ExamUtil.isListEmpty(questionObject.getQuestionItemObjects())) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | //选项A、B、C、D |
| | | List<String> choiceInputList = questionObject.getQuestionItemObjects().stream().map(i -> { |
| | | return i.getPrefix(); |
| | | }).collect(Collectors.toList()); |
| | | question.setChoiceInput(choiceInputList); |
| | | |
| | | |
| | | //选项内容 |
| | | List<String> stemList = questionObject.getQuestionItemObjects().stream().map(i -> { |
| | | return ExamUtil.getLangString(question.getLangType(), i.getContent()); |
| | | }).collect(Collectors.toList()); |
| | | question.setSelectInput(stemList); |
| | | } |
| | | |
| | | private void addQuestionResult(List<TQuestion> tQuestionResultList, TQuestion question, String key, String value) { |
| | | TQuestion questionResult = new TQuestion(); |
| | | BeanUtils.copyProperties(question, questionResult); |
| | | |
| | | |
| | | // 语言类型 |
| | | questionResult.setLangType(key); |
| | | |
| | | |
| | | // 语言类型对应的题目 |
| | | questionResult.setTitle(value); |
| | | |
| | | |
| | | // 通过问卷的大题没有选项 |
| | | if (ExamUtil.isListNotEmpty(question.getChoiceInput())) { |
| | | setLanSelectInput(question, key); |
| | | } |
| | | |
| | | tQuestionResultList.add(questionResult); |
| | | } |
| | | |
| | | private void setLanSelectInput(TQuestion question, String key) { |
| | | |
| | | // 语言对应的选项 |
| | | List<String> selectInputList = question.getSelectInput(); |
| | | |
| | | |
| | | // 更新 |
| | | for (String selectInput : selectInputList) { |
| | | selectInput = ExamUtil.getStringByLang(key, selectInput);; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 当在product 的add_question.html的时候调用 |
| | | * |
| | | * @param tQuestion 题目列表 |
| | | * @return 题目列表 |
| | | */ |
| | | @Override |
| | | public List<TQuestion> selectTQuestionsForProductAddQuestion(TQuestion tQuestion) { |
| | | List<TQuestion> tQuestionList = tQuestionMapper.selectTQuestionsForProductAddQuestion(tQuestion); |
| | |
| | | QuestionObject questionObject = JSONObject.parseObject(content, QuestionObject.class); |
| | | question.setLangType(tQuestion.getLangType()); |
| | | setChioceAndSelectInput(question, questionObject); |
| | | |
| | | // 多语言 |
| | | Map<String, String> titleMap = JsonUtil.toJsonObject(questionObject.getTitleContent(), HashMap.class); |
| | | |
| | | if (Objects.isNull(titleMap)) { |
| | | question.setTitle(questionObject.getTitleContent()); |
| | | } else { |
| | | question.setTitle(ExamUtil.getLangString(tQuestion.getLangType(), questionObject.getTitleContent())); |
| | | } |
| | | } |
| | | |
| | | return tQuestionList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 新增题目列表 |
| | | * |
| | | * @param tQuestion 题目列表 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public int insertTQuestion(TQuestion tQuestion) { |
| | |
| | | return permanentIdDuplicate.ordinal(); |
| | | } |
| | | } |
| | | |
| | | //拼装t_text_content,tQuestion参数的属性也是会在此方法内部修改 |
| | | TTextContent textContent = getQuestionTextContent(tQuestion); |
| | | |
| | | |
| | | //入库t_text_content |
| | | tTextContentMapper.insertTTextContent(textContent); |
| | | |
| | | |
| | | //把t_text_content的id赋值给t_question的info_text_content_id |
| | | tQuestion.setInfoTextContentId(textContent.getId()); |
| | | return tQuestionMapper.insertTQuestion(tQuestion); |
| | | } |
| | | |
| | | private TTextContent getQuestionTextContent(TQuestion tQuestion) { |
| | | |
| | | //bgin 答案选项封装,原因是方便后面转换成json |
| | | List<QuestionEditItem> questionEditItems = new ArrayList<QuestionEditItem>(); |
| | | List<QuestionEditItem> itemObjects = null; |
| | | |
| | | |
| | | // 大题目不需要选项 |
| | | if (ExamUtil.isListNotEmpty(tQuestion.getChoiceInput())) { |
| | | itemObjects = getQuestionEditItems(tQuestion, questionEditItems); |
| | | } |
| | | |
| | | QuestionObject questionObject = new QuestionObject(); |
| | | questionObject.setQuestionItemObjects(itemObjects); |
| | | questionObject.setAnalyze(tQuestion.getAnalyze()); |
| | | |
| | | // 多语言 |
| | | if (StringUtils.isNotEmpty(tQuestion.getMultilingual())) { |
| | | questionObject.setTitleContent(tQuestion.getTitle()); |
| | | } else { |
| | |
| | | TTextContent textContent = new TTextContent(); |
| | | textContent.setCreateTime(DateUtils.getNowDate()); |
| | | textContent.setContent(JSON.toJSONString(questionObject)); |
| | | |
| | | //end 答案选项封装,原因是方便后面转换成json |
| | | return textContent; |
| | | } |
| | | |
| | | private List<QuestionEditItem> getQuestionEditItems(TQuestion tQuestion, List<QuestionEditItem> questionEditItems) { |
| | | for (int i = 0; i < tQuestion.getChoiceInput().size(); i++) { |
| | | QuestionEditItem questionEditItem = new QuestionEditItem(); |
| | | questionEditItem.setPrefix(tQuestion.getChoiceInput().get(i)); |
| | | |
| | | if (StringUtils.isNotEmpty(tQuestion.getMultilingual())) { |
| | | // 多语言 |
| | | if (StringUtils.isNotEmpty(tQuestion.getMultilingual())) { // 批量导入的时候已经拼好各种语言 |
| | | questionEditItem.setContent(tQuestion.getSelectInput().get(i)); |
| | | } else { |
| | | questionEditItem.setContent(ExamUtil.getStringMapJson(tQuestion.getLangType(), tQuestion.getSelectInput().get(i), new HashMap<>())); |
| | | } |
| | | |
| | | questionEditItem.setScore(Objects.isNull(tQuestion.getScore()) ? 0 : tQuestion.getScore().intValue()); |
| | | // 题目的分数 |
| | | questionEditItem.setScore(Objects.isNull(tQuestion.getScore()) ? 0 : tQuestion.getScore().intValue());//目前用不上这个分数,先设为0 |
| | | questionEditItems.add(questionEditItem); |
| | | } |
| | | |
| | | |
| | | //遍历每一个选项 |
| | | return questionEditItems.stream().map(i -> |
| | | { |
| | | QuestionEditItem item = modelMapper.map(i, QuestionEditItem.class); |
| | |
| | | } |
| | | ).collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改题目列表 |
| | | * |
| | | * @param tQuestion 题目列表 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateTQuestion(TQuestion tQuestion) { |
| | | |
| | | |
| | | // 多语言的更新 |
| | | if (tQuestion.getUuid() != null) { |
| | | TQuestion questionOld = tQuestionMapper.selectTQuestionById(tQuestion.getId()); |
| | | |
| | | // 合并第二个输入框选项的内容 |
| | | updateQuestionLangContent(tQuestion, questionOld); |
| | | return tQuestionMapper.updateTQuestion(tQuestion); |
| | | } |
| | | |
| | | |
| | | |
| | | // 按照permanateid 更新语言 |
| | | List<TQuestion> questionOldlist = tQuestionMapper.selectTQuestionByPermanentId(tQuestion.getPermanentId()); |
| | | if (ExamUtil.isListNotEmpty(questionOldlist)) { |
| | | |
| | | // 合并第二个输入框选项的内容 |
| | | for (TQuestion tQuestionUpdate : questionOldlist) { |
| | | |
| | | // 兼容旧版本, 旧版本没有templateid,新版本有 |
| | | if (StringUtils.isNotEmpty(tQuestion.getTemplate()) && StringUtils.isEmpty(tQuestionUpdate.getTemplate())) { |
| | | tQuestionUpdate.setTemplate(tQuestion.getTemplate()); |
| | | } |
| | | updateQuestionLangContent(tQuestion, tQuestionUpdate); |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | TQuestion questionOld = null; |
| | | |
| | | |
| | | //修改掉旧的产品包 |
| | | if (!Objects.isNull(tQuestion.getId())) { |
| | | |
| | | // 在题目列表修改的时候会进入此逻辑,其他逻辑是批量导入 |
| | | questionOld = tQuestionMapper.selectTQuestionById(tQuestion.getId()); |
| | | questionOld.setDeleted(2L); |
| | | questionOld.setUpdateTime(DateUtils.getNowDate()); |
| | | tQuestionMapper.updateTQuestion(questionOld); |
| | | } |
| | | |
| | | |
| | | // 更改题目的内容数据 |
| | | setInsertQuestion(tQuestion); |
| | | |
| | | |
| | | //插入新的t_question |
| | | return tQuestionMapper.insertTQuestion(tQuestion); |
| | | } |
| | | |
| | | private void setInsertQuestion(TQuestion tQuestion) { |
| | | |
| | | //新的question用插入新记录的方式 |
| | | tQuestion.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | |
| | | //拼装t_text_content,tQuestion参数的属性也是会在此方法内部修改 |
| | | TTextContent textContent = getQuestionTextContent(tQuestion); |
| | | textContent.setId(null); |
| | | |
| | | |
| | | //入库t_text_content |
| | | tTextContentMapper.insertTTextContent(textContent); |
| | | |
| | | |
| | | //把t_text_content的id赋值给t_question的info_text_content_id |
| | | tQuestion.setInfoTextContentId(textContent.getId()); |
| | | |
| | | tQuestion.setDeleted(1L); |
| | | |
| | | |
| | | // 记录从那个题目修改过来的id |
| | | tQuestion.setLastId(tQuestion.getId()); |
| | | } |
| | | |
| | | |
| | | // 多语言更新题目的内容,修改单个的时候使用 |
| | | private int updateQuestionContent(TQuestion tQuestion, TQuestion questionOld) { |
| | | if (Objects.isNull(tQuestion.getId()) || tQuestion.getId() == 0) { |
| | | tQuestion.setId(questionOld.getId()); |
| | | } |
| | | |
| | | // 题目的从content |
| | | QuestionObject questionObject = JSONObject.parseObject(questionOld.getContent(), QuestionObject.class); |
| | | |
| | | |
| | | //新的question用插入新记录的方式 |
| | | tQuestion.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | |
| | | |
| | | // 最复杂,合并各语言版本 |
| | | // 题目合并 |
| | | Map<String, String> titleMap = JsonUtil.toJsonObject(questionObject.getTitleContent(), HashMap.class); |
| | | titleMap.put(tQuestion.getLangType(), tQuestion.getTitle()); |
| | | questionObject.setTitleContent(JsonUtil.toJsonStr(titleMap)); |
| | | |
| | | |
| | | // 选项的内容合并 |
| | | List<String> selectInput = tQuestion.getSelectInput(); |
| | | int selectInputNum = 0; |
| | | List<QuestionEditItem> questionItemObjects = questionObject.getQuestionItemObjects(); |
| | |
| | | contentMap.put(tQuestion.getLangType(), selectInput.get(selectInputNum++)); |
| | | questionItemObject.setContent(JsonUtil.toJsonStr(contentMap)); |
| | | } |
| | | |
| | | TTextContent questionTextContent = tTextContentMapper.selectTTextContentById(questionOld.getInfoTextContentId()); |
| | | questionTextContent.setUpdateTime(DateUtils.getNowDate()); |
| | | questionTextContent.setContent(JsonUtil.toJsonStr(questionObject)); |
| | | |
| | | |
| | | //入库t_text_content |
| | | return tTextContentMapper.updateTTextContent(questionTextContent); |
| | | } |
| | | |
| | | |
| | | // 导入的时候使用 |
| | | private int updateQuestionLangContent(TQuestion tQuestion, TQuestion questionOld) { |
| | | if (Objects.isNull(tQuestion.getId()) || tQuestion.getId() == 0) { |
| | | tQuestion.setId(questionOld.getId()); |
| | | } |
| | | |
| | | // 题目的从content |
| | | QuestionObject questionObject = JSONObject.parseObject(questionOld.getContent(), QuestionObject.class); |
| | | |
| | | |
| | | //新的question用插入新记录的方式 |
| | | tQuestion.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | |
| | | |
| | | // 最复杂,合并各语言版本 |
| | | // 题目合并,如果是批量导入的话没有uuid |
| | | String langType = tQuestion.getLangType(); |
| | | if (Objects.isNull(tQuestion.getUuid())) { |
| | | langType = "ALL"; |
| | | } |
| | | questionObject.setTitleContent(ExamUtil.getStringMapJson(langType, tQuestion.getTitle(), questionObject.getTitleContent())); |
| | | |
| | | |
| | | // 选项的内容合并 |
| | | updateQuestionEditItem(tQuestion, questionObject); |
| | | |
| | | TTextContent questionTextContent = tTextContentMapper.selectTTextContentById(questionOld.getInfoTextContentId()); |
| | | questionTextContent.setUpdateTime(DateUtils.getNowDate()); |
| | | questionTextContent.setContent(JsonUtil.toJsonStr(questionObject)); |
| | | |
| | | |
| | | |
| | | // 更新一下产品包的内容 |
| | | |
| | | //入库t_text_content |
| | | tQuestionMapper.updateTQuestion(questionOld); |
| | | return tTextContentMapper.updateTTextContent(questionTextContent); |
| | | } |
| | | |
| | | private void updateQuestionEditItem(TQuestion tQuestion, QuestionObject questionObject) { |
| | | |
| | | // 如果有大题,就不需要 |
| | | if (ExamUtil.isListEmpty(tQuestion.getChoiceInput())) { |
| | | return; |
| | | } |
| | | List<String> selectInput = tQuestion.getSelectInput(); |
| | | int selectInputNum = 0; |
| | | List<QuestionEditItem> questionItemObjects = questionObject.getQuestionItemObjects(); |
| | | |
| | | |
| | | // 题目合并,如果是批量导入的话没有uuid |
| | | String langType = tQuestion.getLangType(); |
| | | if (Objects.isNull(tQuestion.getUuid())) { |
| | | langType = "ALL"; |
| | | } |
| | | |
| | | for (QuestionEditItem questionItemObject : questionItemObjects) { |
| | | if (selectInputNum < selectInput.size()) { |
| | | questionItemObject.setContent(ExamUtil.getStringMapJson(langType, selectInput.get(selectInputNum++), questionItemObject.getContent())); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 添加新的选项 |
| | | if (selectInput.size() > questionItemObjects.size()) { |
| | | QuestionEditItem questionItemObject = new QuestionEditItem(); |
| | | String prefix = tQuestion.getChoiceInput().get(tQuestion.getChoiceInput().size() - 1); |
| | |
| | | questionItemObject.setScore(0); |
| | | questionItemObjects.add(questionItemObject); |
| | | } |
| | | |
| | | |
| | | // 删除选项的选项 |
| | | if (selectInput.size() < questionItemObjects.size()) { |
| | | for (int i = questionItemObjects.size() - 1; i > selectInput.size() - 1; i--) { |
| | | questionItemObjects.remove(i); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // 多语言更新题目的内容 |
| | | public int deleteQuestionContent(TQuestion tQuestion) { |
| | | TQuestion questionOld = tQuestionMapper.selectTQuestionById(tQuestion.getId()); |
| | | |
| | | // 原来题目的content |
| | | QuestionObject questionObject = JSONObject.parseObject(questionOld.getContent(), QuestionObject.class); |
| | | |
| | | |
| | | // 新的question用插入新记录的方式 |
| | | tQuestion.setUpdateTime(DateUtils.getNowDate()); |
| | | |
| | | |
| | | // 删除某一种语言 |
| | | Map<String, String> titleMap = JsonUtil.toJsonObject(questionObject.getTitleContent(), HashMap.class); |
| | | titleMap.remove(tQuestion.getLangType()); |
| | | questionObject.setTitleContent(JsonUtil.toJsonStr(titleMap)); |
| | | |
| | | |
| | | // 选项的内容合并 |
| | | List<QuestionEditItem> questionItemObjects = questionObject.getQuestionItemObjects(); |
| | | if (ExamUtil.isListNotEmpty(questionItemObjects)) { |
| | | for (QuestionEditItem questionItemObject : questionItemObjects) { |
| | |
| | | questionItemObject.setContent(JsonUtil.toJsonStr(contentMap)); |
| | | } |
| | | } |
| | | |
| | | TTextContent questionTextContent = tTextContentMapper.selectTTextContentById(questionOld.getInfoTextContentId()); |
| | | questionTextContent.setUpdateTime(DateUtils.getNowDate()); |
| | | questionTextContent.setContent(JsonUtil.toJsonStr(questionObject)); |
| | | |
| | | |
| | | //入库t_text_content |
| | | return tTextContentMapper.updateTTextContent(questionTextContent); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除题目列表对象 |
| | | * |
| | | * @param ids 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteTQuestionByIds(String ids) { |
| | | return tQuestionMapper.updateQuetionByDelete(Convert.toStrArray(ids)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除题目列表信息 |
| | | * |
| | | * @param id 题目列表ID |
| | | * @return 结果 |
| | | */ |
| | | public int deleteTQuestionById(Long id) { |
| | | return tQuestionMapper.deleteTQuestionById(id); |
| | | } |
| | | |
| | | @Override |
| | | public QuestionEditRequestVM getQuestionEditRequestVM(TQuestion question) { |
| | | |
| | | //题目映射 |
| | | TTextContent questionInfoTextContent = textContentService.selectTTextContentById(question.getInfoTextContentId().longValue()); |
| | | QuestionObject questionObject = JsonUtil.toJsonObject(questionInfoTextContent.getContent(), QuestionObject.class); |
| | | QuestionEditRequestVM questionEditRequestVM = modelMapper.map(question, QuestionEditRequestVM.class); |
| | | questionEditRequestVM.setTitle(questionObject.getTitleContent()); |
| | | |
| | | |
| | | //答案 |
| | | QuestionTypeEnum questionTypeEnum = QuestionTypeEnum.fromCode(question.getQuestionType().intValue()); |
| | | switch (questionTypeEnum) { |
| | | case SingleChoice: |
| | |
| | | } |
| | | questionEditRequestVM.setScore(ExamUtil.scoreToVM(0)); |
| | | questionEditRequestVM.setAnalyze(questionObject.getAnalyze()); |
| | | |
| | | |
| | | |
| | | //题目项映射 如果选项为空,那么就给一个默认值,否则智力题会报错 |
| | | if (Objects.nonNull(questionObject.getQuestionItemObjects())) { |
| | | List<QuestionEditItemVM> editItems = questionObject.getQuestionItemObjects().stream().map(o -> { |
| | | QuestionEditItemVM questionEditItemVM = modelMapper.map(o, QuestionEditItemVM.class); |
| | |
| | | } |
| | | return questionEditRequestVM; |
| | | } |
| | | |
| | | @Override |
| | | public String insertImportQuestion(List<Map<Integer, String>> excelList) { |
| | | |
| | | |
| | | // 1、JAQ题目永久编号 维度 题目总分 题目 语言类型 正确答案 |
| | | |
| | | // 2、创建bean |
| | | TQuestion tQuestion = new TQuestion(); |
| | | |
| | | |
| | | |
| | | // 3、取出选项 |
| | | Map<Integer, String> headerMap = excelList.get(0); |
| | | List<String> prefixList = new ArrayList<>(); |
| | | for (int i = 6; i < headerMap.size(); i++) { |
| | | prefixList.add(headerMap.get(i)); |
| | | } |
| | | |
| | | |
| | | // 4、导入的消息 |
| | | StringBuilder successMsg = new StringBuilder(); |
| | | StringBuilder failureMsg = new StringBuilder(); |
| | | |
| | | |
| | | // 5、遍历出输入的题目入库 |
| | | for (int i = 1; i < excelList.size(); i++) { |
| | | |
| | | Map<Integer, String> excelDataMap = excelList.get(i); |
| | | try { |
| | | |
| | | // JAQ题目永久编号 |
| | | tQuestion.setPermanentId(excelDataMap.get(0)); |
| | | |
| | | //维度需要转换,代开发 |
| | | tQuestion.setSubjectId(Long.valueOf(excelDataMap.get(1))); |
| | | |
| | | // 题目总分 |
| | | tQuestion.setScore(Long.valueOf(excelDataMap.get(2))); |
| | | |
| | | // 题目 |
| | | tQuestion.setTitle(excelDataMap.get(3)); |
| | | |
| | | // 语言类型 |
| | | tQuestion.setLangType(excelDataMap.get(4)); |
| | | |
| | | // 正确答案 |
| | | tQuestion.setCorrect(excelDataMap.get(5)); |
| | | |
| | | // 选项 |
| | | int prefixNum = 0; |
| | | tQuestion.setChoiceInput(new ArrayList<>()); |
| | | List<String> choiceInput = tQuestion.getChoiceInput(); |
| | | List<String> choiceInput = tQuestion.getChoiceInput(); // A,B,C,D |
| | | tQuestion.setSelectInput(new ArrayList<>()); |
| | | List<String> selectInput = tQuestion.getSelectInput(); |
| | | |
| | | List<String> selectInput = tQuestion.getSelectInput(); // A,B,C,D的内容 |
| | | for (int j = 6; j < excelDataMap.size(); j++) { |
| | | choiceInput.add(prefixList.get(prefixNum++)); |
| | | selectInput.add(excelDataMap.get(j)); |
| | |
| | | StringBuilder meg = failureMsg.append(successMsg); |
| | | return meg.toString(); |
| | | } |
| | | |
| | | public void setQuestionInfoFromVM(TextContent infoTextContent, QuestionEditRequestVM model) { |
| | | List<QuestionEditItem> itemObjects = model.getItems().stream().map(i -> |
| | | { |
| | |
| | | questionObject.setCorrect(model.getCorrect()); |
| | | infoTextContent.setContent(JsonUtil.toJsonStr(questionObject)); |
| | | } |
| | | |
| | | |
| | | // 如果本题目已经有了该种语言,就不要展示,edit-*.html使用 |
| | | public List<DictData> getType(Long id) { |
| | | |
| | | |
| | | // 查询字典先 |
| | | List<DictData> dictDataList = dictDataService.selectDictDataByType("lang_type"); |
| | | |
| | | |
| | | // 查看已经存在的题目 |
| | | if (Objects.nonNull(id)) { |
| | | TQuestion question = selectTQuestionById(id); |
| | | String content = question.getContent(); |
| | |
| | | return dictDataList; |
| | | } |
| | | } |
| | | |
| | | public List<TQuestion> selectTQuestionByPermanentId(String permanentId) { |
| | | return tQuestionMapper.selectTQuestionByPermanentId(permanentId); |
| | | } |
| | | |
| | | } |