|
@@ -3,16 +3,19 @@ package com.fs.course.service.impl;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.course.cache.FsUserCourseCategoryCacheService;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.*;
|
|
|
import com.fs.course.dto.FsCourseQuestionBankImportDTO;
|
|
|
import com.fs.course.mapper.*;
|
|
|
import com.fs.course.param.FsCourseQuestionAnswerUParam;
|
|
|
import com.fs.course.service.IFsCourseQuestionBankService;
|
|
|
+import com.fs.course.service.cache.IFsCourseQuestionBankCacheService;
|
|
|
import com.fs.store.domain.FsUser;
|
|
|
import com.fs.store.mapper.FsUserMapper;
|
|
|
import com.fs.store.service.IFsStorePaymentService;
|
|
@@ -20,6 +23,7 @@ import com.fs.system.service.ISysConfigService;
|
|
|
import com.google.gson.JsonParser;
|
|
|
import com.hc.openapi.tool.fastjson.JSON;
|
|
|
import jodd.util.StringUtil;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -58,6 +62,12 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
@Autowired
|
|
|
private FsUserCourseCategoryMapper courseCategoryMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IFsCourseQuestionBankCacheService fsCourseQuestionBankCacheService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCourseCategoryCacheService fsUserCourseCategoryCacheService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询题库
|
|
|
*
|
|
@@ -80,31 +90,6 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
public List<FsCourseQuestionBank> selectFsCourseQuestionBankList(FsCourseQuestionBank fsCourseQuestionBank)
|
|
|
{
|
|
|
List<FsCourseQuestionBank> fsCourseQuestionBanks = fsCourseQuestionBankMapper.selectFsCourseQuestionBankList(fsCourseQuestionBank);
|
|
|
- for (FsCourseQuestionBank courseQuestionBank : fsCourseQuestionBanks) {
|
|
|
-
|
|
|
- if(StringUtil.isNotBlank(courseQuestionBank.getQuestion())) {
|
|
|
- // 问题列表多个 以分隔符 | 结尾
|
|
|
- JSONArray questionArr = com.alibaba.fastjson.JSON.parseArray(courseQuestionBank.getQuestion());
|
|
|
- List<String> questionOpt = new ArrayList<>();
|
|
|
- for(int i=0;i<questionArr.size();i++){
|
|
|
- JSONObject jsonObject = questionArr.getJSONObject(i);
|
|
|
- String name = jsonObject.getString("name");
|
|
|
- questionOpt.add(name);
|
|
|
- }
|
|
|
- courseQuestionBank.setQuestionOption(String.join("|",questionOpt));
|
|
|
- }
|
|
|
-
|
|
|
- if(StringUtil.isNotBlank(courseQuestionBank.getAnswer())) {
|
|
|
- // 如果是json数组
|
|
|
- if(JsonParser.parseString(courseQuestionBank.getAnswer()).isJsonArray()) {
|
|
|
- String answerOpt = String.join("|", JSONUtil.parseArray(courseQuestionBank.getAnswer()).toList(String.class));
|
|
|
- courseQuestionBank.setAnswerOption(answerOpt);
|
|
|
- } else {
|
|
|
- courseQuestionBank.setAnswerOption(courseQuestionBank.getAnswer());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return fsCourseQuestionBanks;
|
|
|
}
|
|
|
|
|
@@ -386,11 +371,17 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
StringBuilder importErrorMsg = new StringBuilder();
|
|
|
StringBuilder importMsg = new StringBuilder();
|
|
|
|
|
|
+ List<FsCourseQuestionBank> importData = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<String,FsUserCourseCategory> categoryData = courseCategoryMapper.queryAllCategoryData();
|
|
|
+
|
|
|
for (FsCourseQuestionBankImportDTO importDTO : list) {
|
|
|
try {
|
|
|
String title = importDTO.getTitle();
|
|
|
String type = importDTO.getType();
|
|
|
String questionType = importDTO.getQuestionType();
|
|
|
+ String questionSubTyp = importDTO.getQuestionSubTyp();
|
|
|
+
|
|
|
String question = importDTO.getQuestion();
|
|
|
String answer = importDTO.getAnswer();
|
|
|
|
|
@@ -449,10 +440,17 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
}
|
|
|
|
|
|
// 分类
|
|
|
+ FsUserCourseCategory fsUserCourseCategory = categoryData.get(questionType);
|
|
|
Long questionTypeId = null;
|
|
|
- FsUserCourseCategory category = courseCategoryMapper.selectFsUserCourseCategoryByName(questionType);
|
|
|
- if (Objects.nonNull(category)) {
|
|
|
- questionTypeId = category.getCateId();
|
|
|
+ if(fsUserCourseCategory != null) {
|
|
|
+ questionTypeId = fsUserCourseCategory.getCateId();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 题目子分类
|
|
|
+ fsUserCourseCategory = categoryData.get(questionSubTyp);
|
|
|
+ Long questionSubTypeId = null;
|
|
|
+ if(fsUserCourseCategory != null) {
|
|
|
+ questionSubTypeId = fsUserCourseCategory.getCateId();
|
|
|
}
|
|
|
|
|
|
FsCourseQuestionBank questionBank = new FsCourseQuestionBank();
|
|
@@ -465,7 +463,10 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
questionBank.setAnswer(answers.length > 1 ? JSON.toJSONString(answers) : answer);
|
|
|
questionBank.setCreateTime(new Date());
|
|
|
questionBank.setCreateBy(nickName);
|
|
|
- fsCourseQuestionBankMapper.insertFsCourseQuestionBank(questionBank);
|
|
|
+ questionBank.setQuestionSubType(questionSubTypeId);
|
|
|
+
|
|
|
+ importData.add(questionBank);
|
|
|
+
|
|
|
|
|
|
importSuccessMsg.append("<br/>").append(successNum).append("、题目 ").append(title).append(" 导入成功");
|
|
|
successNum++;
|
|
@@ -476,6 +477,10 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(CollectionUtils.isNotEmpty(importData)) {
|
|
|
+ fsCourseQuestionBankMapper.insertFsCourseQuestionBankBatch(importData);
|
|
|
+ }
|
|
|
+
|
|
|
// 在所有导入处理完成后,构建最终的导入结果消息
|
|
|
importMsg.insert(0, "导入完成!成功" + successNum + " 条,失败" + failureNum + "条。");
|
|
|
importMsg.append(importErrorMsg);
|
|
@@ -493,6 +498,62 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
return fsCourseQuestionBankMapper.selectFsCourseQuestionBankByIds(ids);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<FsCourseQuestionBank> selectFsCourseQuestionBankListExport(FsCourseQuestionBank fsCourseQuestionBank) {
|
|
|
+ List<FsCourseQuestionBank> fsCourseQuestionBanks = this.selectFsCourseQuestionBankList(fsCourseQuestionBank);
|
|
|
+
|
|
|
+ for (FsCourseQuestionBank courseQuestionBank : fsCourseQuestionBanks) {
|
|
|
+
|
|
|
+ if(StringUtil.isNotBlank(courseQuestionBank.getQuestion())) {
|
|
|
+ // 问题列表多个 以分隔符 | 结尾
|
|
|
+ JSONArray questionArr = com.alibaba.fastjson.JSON.parseArray(courseQuestionBank.getQuestion());
|
|
|
+ List<String> questionOpt = new ArrayList<>();
|
|
|
+ for(int i=0;i<questionArr.size();i++){
|
|
|
+ JSONObject jsonObject = questionArr.getJSONObject(i);
|
|
|
+ String name = jsonObject.getString("name");
|
|
|
+ questionOpt.add(name);
|
|
|
+ }
|
|
|
+ courseQuestionBank.setQuestionOption(String.join("|",questionOpt));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtil.isNotBlank(courseQuestionBank.getAnswer())) {
|
|
|
+ // 如果是json数组
|
|
|
+ if(JsonParser.parseString(courseQuestionBank.getAnswer()).isJsonArray()) {
|
|
|
+ String answerOpt = String.join("|", JSONUtil.parseArray(courseQuestionBank.getAnswer()).toList(String.class));
|
|
|
+ courseQuestionBank.setAnswerOption(answerOpt);
|
|
|
+ } else {
|
|
|
+ courseQuestionBank.setAnswerOption(courseQuestionBank.getAnswer());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 问题类别
|
|
|
+ if(ObjectUtils.isNotNull(courseQuestionBank.getQuestionType())) {
|
|
|
+ String questionType = fsCourseQuestionBankCacheService.selectFsUserCourseCategoryByCateId(courseQuestionBank.getQuestionType());
|
|
|
+
|
|
|
+ courseQuestionBank.setQuestionTypeStr(questionType);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 题目类型
|
|
|
+ if(ObjectUtils.isNotNull(courseQuestionBank.getType())) {
|
|
|
+ String type = courseQuestionBank.getType() == 1 ? "单选" : "多选";
|
|
|
+ courseQuestionBank.setTypeStr(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 题目子类别
|
|
|
+ if(ObjectUtils.isNotNull(courseQuestionBank.getQuestionSubType())) {
|
|
|
+ String questionType = fsCourseQuestionBankCacheService.selectFsUserCourseCategoryByCateId(courseQuestionBank.getQuestionSubType());
|
|
|
+ courseQuestionBank.setQuestionSubTypeStr(questionType);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return fsCourseQuestionBanks;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String selectNameByCateId(Long cateId) {
|
|
|
+ return fsCourseQuestionBankMapper.selectNameByCateId(cateId);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static String[] convertStringToArray(String inputString) {
|
|
|
String cleanString = inputString.replaceAll("[\\[\\]\"\\s]", "");
|