|
@@ -20,7 +20,6 @@ import com.github.pagehelper.PageInfo;
|
|
|
import com.zhongzheng.common.core.page.TableDataInfo;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
-import com.zhongzheng.common.type.EncryptHandler;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
import com.zhongzheng.common.utils.ServletUtils;
|
|
@@ -40,7 +39,6 @@ import com.zhongzheng.modules.exam.bo.ExamKnowledgeAddBo;
|
|
|
import com.zhongzheng.modules.exam.bo.ExamKnowledgeBusinessAddBo;
|
|
|
import com.zhongzheng.modules.exam.domain.ExamKnowledge;
|
|
|
import com.zhongzheng.modules.exam.domain.ExamPaper;
|
|
|
-import com.zhongzheng.modules.exam.service.IExamApplyService;
|
|
|
import com.zhongzheng.modules.exam.service.IExamKnowledgeService;
|
|
|
import com.zhongzheng.modules.exam.service.IExamPaperService;
|
|
|
import com.zhongzheng.modules.goods.bo.*;
|
|
@@ -77,6 +75,8 @@ import org.w3c.dom.NodeList;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
import java.text.NumberFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -4241,6 +4241,292 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
return HttpUtils.sendGet(QUESTION_DETAIL, topParam);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> importXlsxQuestionList( List<QuestionImportV4> questionList2,String param) {
|
|
|
+ if (CollectionUtils.isEmpty(questionList2)){
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < questionList2.size(); i++) {
|
|
|
+ QuestionImportV4 questionImportV4 = questionList2.get(i);
|
|
|
+ Integer a = 0;
|
|
|
+ Question question = new Question();
|
|
|
+ question.setStatus(1);
|
|
|
+ question.setPublishStatus(1);
|
|
|
+ question.setCode(ServletUtils.getEncoded("TM"));
|
|
|
+ question.setFromPlat(1);
|
|
|
+ if (questionImportV4.getAnalysisContent().equals("单选题") && questionImportV4.getType().equals("否")){
|
|
|
+ //单选向下取4格
|
|
|
+ a = 4;
|
|
|
+ List<QuestionImportV4> questionImportV = questionList2.subList(i, i + a);
|
|
|
+ //第一个是内容
|
|
|
+ QuestionImportV4 v4 = questionImportV.get(0);
|
|
|
+ question.setContent(v4.getQuestionName());
|
|
|
+ question.setType(1);
|
|
|
+ question.setAnswerQuestion(v4.getDescribe());
|
|
|
+ question.setCode(ServletUtils.getEncoded("TM"));
|
|
|
+ //正确选项
|
|
|
+ Integer index = 0;
|
|
|
+ //转换单选选项
|
|
|
+ List<QuestionOptionVo> vos = new ArrayList<>();
|
|
|
+ for (int i1 = 0; i1 < questionImportV.size(); i1++) {
|
|
|
+ QuestionImportV4 questionImportV41 = questionImportV.get(i1);
|
|
|
+ QuestionOptionVo vo = new QuestionOptionVo();
|
|
|
+ vo.setContent(questionImportV41.getOption());
|
|
|
+ vo.setOptionsId(i1+1);
|
|
|
+ if (questionImportV41.getCorrect().equals("是")){
|
|
|
+ index = i1 +1;
|
|
|
+ }
|
|
|
+ vos.add(vo);
|
|
|
+ }
|
|
|
+ question.setAnswerQuestion(index.toString());
|
|
|
+ question.setJsonStr(JSONArray.toJSONString(vos));
|
|
|
+ }else if (questionImportV4.getAnalysisContent().equals("多选题") && questionImportV4.getType().equals("否")){
|
|
|
+ a = 5;
|
|
|
+ List<QuestionImportV4> questionImportV1 = questionList2.subList(i, i + a);
|
|
|
+ //第一个是内容
|
|
|
+ QuestionImportV4 v41 = questionImportV1.get(0);
|
|
|
+ question.setContent(v41.getQuestionName());
|
|
|
+ question.setType(2);
|
|
|
+ question.setAnswerQuestion(v41.getDescribe());
|
|
|
+ //正确选项
|
|
|
+ List<Integer> index1 = new ArrayList<>();
|
|
|
+ //转换单选选项
|
|
|
+ List<QuestionOptionVo> vos1 = new ArrayList<>();
|
|
|
+ for (int i1 = 0; i1 < questionImportV1.size(); i1++) {
|
|
|
+ QuestionImportV4 questionImportV41 = questionImportV1.get(i1);
|
|
|
+ QuestionOptionVo vo = new QuestionOptionVo();
|
|
|
+ vo.setContent(questionImportV41.getOption());
|
|
|
+ vo.setOptionsId(i1+1);
|
|
|
+ if (questionImportV41.getCorrect().equals("是")){
|
|
|
+ index1.add(i1+1);
|
|
|
+ }
|
|
|
+ vos1.add(vo);
|
|
|
+ }
|
|
|
+ question.setAnswerQuestion(index1.stream().map(x -> x.toString()).collect(Collectors.joining(",")));
|
|
|
+ question.setJsonStr(JSONArray.toJSONString(vos1));
|
|
|
+ }else if (questionImportV4.getAnalysisContent().equals("判断题") && questionImportV4.getType().equals("否")){
|
|
|
+ a = 2;
|
|
|
+ List<QuestionImportV4> questionImportV2 = questionList2.subList(i, i + a);
|
|
|
+ //第一个是内容
|
|
|
+ QuestionImportV4 v42 = questionImportV2.get(0);
|
|
|
+ question.setContent(v42.getQuestionName());
|
|
|
+ question.setType(3);
|
|
|
+ question.setAnswerQuestion(v42.getDescribe());
|
|
|
+ //正确选项
|
|
|
+ Integer index2 = 0;
|
|
|
+ //转换单选选项
|
|
|
+ for (QuestionImportV4 importV4 : questionImportV2) {
|
|
|
+ if (importV4.getCorrect().equals("是")){
|
|
|
+ index2 = importV4.getOption().equals("正确")?1:0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ question.setAnswerQuestion(index2.toString());
|
|
|
+
|
|
|
+ }else if (questionImportV4.getAnalysisContent().equals("案例题")){
|
|
|
+ a = 1;
|
|
|
+ List<QuestionImportV4> questionImportV3 = questionList2.subList(i, i + a);
|
|
|
+ //第一个是内容
|
|
|
+ QuestionImportV4 v42 = questionImportV3.get(0);
|
|
|
+ question.setContent(v42.getQuestionName());
|
|
|
+ question.setType(4);
|
|
|
+ question.setAnswerQuestion(v42.getDescribe());
|
|
|
+ //截取案例题小题
|
|
|
+ List<QuestionImportV4> vv = new ArrayList<>();
|
|
|
+ for (int i1 = i+1; i1 < questionList2.size(); i1++) {
|
|
|
+ QuestionImportV4 questionImportV41 = questionList2.get(i1);
|
|
|
+ if (StringUtils.isNotBlank(questionImportV41.getAnalysisContent()) && questionImportV41.getAnalysisContent().equals("案例题")){
|
|
|
+ //碰到下一个案例题停止循环
|
|
|
+ break ;
|
|
|
+ }
|
|
|
+ vv.add(questionImportV41);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(vv)){
|
|
|
+ List<QuestionInfoVo> vv1 = new ArrayList<>();
|
|
|
+ for (int i1 = 0; i1 < vv.size(); i1++) {
|
|
|
+ QuestionImportV4 questionImportV41 = vv.get(i1);
|
|
|
+ Integer y = 0;
|
|
|
+ if (questionImportV41.getAnalysisContent().equals("单选题")){
|
|
|
+ //单选向下取4格
|
|
|
+ y = 4;
|
|
|
+ List<QuestionImportV4> questionImportV5 = vv.subList(i1, i1 + y);
|
|
|
+ QuestionImportV4 questionImportV42 = questionImportV5.get(0);
|
|
|
+ QuestionInfoVo questionInfoVo = new QuestionInfoVo();
|
|
|
+ questionInfoVo.setContent(questionImportV42.getQuestionName());
|
|
|
+ questionInfoVo.setType(1);
|
|
|
+ //正确选项
|
|
|
+ Integer index = 0;
|
|
|
+ //转换单选选项
|
|
|
+ List<QuestionDetailVo> vos = new ArrayList<>();
|
|
|
+ for (int i2 = 0; i2 < questionImportV5.size(); i2++) {
|
|
|
+ QuestionImportV4 questionImportV43 = questionImportV5.get(i2);
|
|
|
+ QuestionDetailVo vo = new QuestionDetailVo();
|
|
|
+ vo.setContent(questionImportV43.getOption());
|
|
|
+ vo.setOptionsId(i2+1);
|
|
|
+ if (questionImportV43.getCorrect().equals("是")){
|
|
|
+ index = i2 +1;
|
|
|
+ }
|
|
|
+ vos.add(vo);
|
|
|
+ }
|
|
|
+ questionInfoVo.setAnswerQuestion(index.toString());
|
|
|
+ questionInfoVo.setOptionsList(vos);
|
|
|
+ vv1.add(questionInfoVo);
|
|
|
+ a = a+y;
|
|
|
+ }else if (questionImportV41.getAnalysisContent().equals("多选题")){
|
|
|
+ //单选向下取5格
|
|
|
+ y = 5;
|
|
|
+ List<QuestionImportV4> questionImportV6 = vv.subList(i1, i1 + y);
|
|
|
+ QuestionImportV4 questionImportV42 = questionImportV6.get(0);
|
|
|
+ QuestionInfoVo questionInfoVo = new QuestionInfoVo();
|
|
|
+ questionInfoVo.setContent(questionImportV42.getQuestionName());
|
|
|
+ questionInfoVo.setType(2);
|
|
|
+ //正确选项
|
|
|
+ List<Integer> index = new ArrayList<>();
|
|
|
+ //转换单选选项
|
|
|
+ List<QuestionDetailVo> vos = new ArrayList<>();
|
|
|
+ for (int i2 = 0; i2 < questionImportV6.size(); i2++) {
|
|
|
+ QuestionImportV4 questionImportV43 = questionImportV6.get(i2);
|
|
|
+ QuestionDetailVo vo = new QuestionDetailVo();
|
|
|
+ vo.setContent(questionImportV43.getOption());
|
|
|
+ vo.setOptionsId(i2+1);
|
|
|
+ if (questionImportV43.getCorrect().equals("是")){
|
|
|
+ index.add(i2 +1);
|
|
|
+ }
|
|
|
+ vos.add(vo);
|
|
|
+ }
|
|
|
+ questionInfoVo.setAnswerQuestion(index.stream().map(x -> x.toString()).collect(Collectors.joining(",")));
|
|
|
+ questionInfoVo.setOptionsList(vos);
|
|
|
+ vv1.add(questionInfoVo);
|
|
|
+ a = a+y;
|
|
|
+ }else if (questionImportV41.getAnalysisContent().equals("判断题")){
|
|
|
+ //单选向下取2格
|
|
|
+ y = 2;
|
|
|
+ List<QuestionImportV4> questionImportV7 = vv.subList(i1, i1 + y);
|
|
|
+ QuestionImportV4 questionImportV42 = questionImportV7.get(0);
|
|
|
+ QuestionInfoVo questionInfoVo = new QuestionInfoVo();
|
|
|
+ questionInfoVo.setContent(questionImportV42.getQuestionName());
|
|
|
+ questionInfoVo.setType(3);
|
|
|
+ //正确选项
|
|
|
+ Integer index2 = 0;
|
|
|
+ //转换单选选项
|
|
|
+ for (QuestionImportV4 importV4 : questionImportV7) {
|
|
|
+ if (importV4.getCorrect().equals("是")){
|
|
|
+ index2 = importV4.getOption().equals("正确")?1:0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ questionInfoVo.setAnswerQuestion(index2.toString());
|
|
|
+ vv1.add(questionInfoVo);
|
|
|
+ a = a+y;
|
|
|
+ }
|
|
|
+ i1 = i1+y-1;
|
|
|
+ }
|
|
|
+ question.setJsonStr(JSONArray.toJSONString(vv1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ question.setCreateTime(DateUtils.getNowTime());
|
|
|
+ question.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ save(question);
|
|
|
+ //题目业务层次
|
|
|
+ QuestionBusinessImportVo importVo = JSON.parseObject(param, QuestionBusinessImportVo.class);
|
|
|
+ CourseEducationType educationType = iCourseEducationTypeService
|
|
|
+ .getOne(new LambdaQueryWrapper<CourseEducationType>()
|
|
|
+ .eq(CourseEducationType::getEducationName, importVo.getEducationName())
|
|
|
+ .eq(CourseEducationType::getStatus, 1)
|
|
|
+ .last("limit 1"));
|
|
|
+ CourseProjectType projectType = iCourseProjectTypeService.getOne(new LambdaUpdateWrapper<CourseProjectType>()
|
|
|
+ .eq(CourseProjectType::getEducationId, educationType.getId())
|
|
|
+ .eq(CourseProjectType::getProjectName, importVo.getProjectName())
|
|
|
+ .eq(CourseProjectType::getStatus, 1)
|
|
|
+ .last("limit 1"));
|
|
|
+ CourseBusiness business = iCourseBusinessService.getOne(new LambdaUpdateWrapper<CourseBusiness>()
|
|
|
+ .eq(CourseBusiness::getProjectId, projectType.getId())
|
|
|
+ .eq(CourseBusiness::getBusinessName, importVo.getBusinessName())
|
|
|
+ .eq(CourseBusiness::getStatus, 1)
|
|
|
+ .last("limit 1"));
|
|
|
+ CourseSubject courseSubject = iCourseSubjectService.getOneByName(importVo.getSubjectName(),projectType.getId());
|
|
|
+ QuestionBusiness business1 = new QuestionBusiness();
|
|
|
+ business1.setEducationTypeId(educationType.getId());
|
|
|
+ business1.setProjectId(projectType.getId());
|
|
|
+ business1.setBusinessId(business.getId());
|
|
|
+ business1.setSubjectId(courseSubject.getId());
|
|
|
+ business1.setMajorId(question.getQuestionId());
|
|
|
+ business1.setType(1);
|
|
|
+ iQuestionBusinessService.save(business1);
|
|
|
+
|
|
|
+ //重置索引
|
|
|
+ i = i+a-1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> importImage(List<QuestionImageVo> questionList2) {
|
|
|
+ if (CollectionUtils.isEmpty(questionList2)){
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ String path = "https://www.xyyxt.net";
|
|
|
+ for (QuestionImageVo imageVo : questionList2) {
|
|
|
+ String imageUrl = imageVo.getImageUrl();
|
|
|
+ // 使用正则表达式匹配图片路径
|
|
|
+ Pattern pattern = Pattern.compile("src=\"([^\"]+)\"");
|
|
|
+ Matcher matcher = pattern.matcher(imageUrl);
|
|
|
+ String imagePath = "";
|
|
|
+ if (matcher.find()) {
|
|
|
+ imagePath = path + matcher.group(1);
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取单引号内的中文内容
|
|
|
+ // 匹配单引号内的中文字符(包括中文标点)
|
|
|
+ Pattern pattern1 = Pattern.compile("Title='([^']+[\\u4e00-\\u9fa5]+[^']*)'");
|
|
|
+ Matcher matcher1 = pattern1.matcher(imageUrl);
|
|
|
+ String chineseText = "";
|
|
|
+ if (matcher1.find()) {
|
|
|
+ chineseText = matcher1.group(1);
|
|
|
+ }else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Question question = getOne(new LambdaQueryWrapper<Question>().eq(Question::getStatus, 1).eq(Question::getContent, chineseText).last("limit 1"));
|
|
|
+ if (ObjectUtils.isNull(question)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String ossPath = "";
|
|
|
+ //上传oss图片
|
|
|
+ try {
|
|
|
+ URL url = new URL(imagePath);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+ connection.setConnectTimeout(5000);
|
|
|
+ connection.setReadTimeout(5000);
|
|
|
+
|
|
|
+ // 检查响应码
|
|
|
+ int responseCode = connection.getResponseCode();
|
|
|
+ if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
+ try (InputStream inputStream = connection.getInputStream()) {
|
|
|
+ String s = ossService.uploadInputStream(inputStream, 6);
|
|
|
+ ossPath = ossHost + "/" + s;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ connection.disconnect();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("oss图片上传失败");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(ossPath)){
|
|
|
+ String format = String.format("<p>%s<img src=\"%s\"></p>", question.getContent(), ossPath);
|
|
|
+ question.setContent(format);
|
|
|
+ updateById(question);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private void handlePhoto(List<ExternalQuestionDetailVo> questionDetailVos) {
|
|
|
String prefix = "\\Uploads\\qdytopic\\";
|
|
|
String upStr = OSS_PREFIX + "/web/Uploads/qdytopic/";
|
|
@@ -4531,4 +4817,6 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
}
|
|
|
return String.join(",", list);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|