Files
DoLuEdu-WordFileParse/java-src/service/impl/FileServiceImpl.java
Quentin 3271fee5cc init: WordFileParse docx→HTML 解析服务(含 Word EQ 域公式修复)
服务:Spring Boot 3.2 + docx4j 8.3.9,POST /api/v3/server_office_file/file/parse
      接受 .docx,返回 HTML(公式 → LaTeX,图片 → RustFS 外链)

公式支持三类来源:
- OMML(Word 2007+ 公式)      → Python omml_mathml2latex
- MathType OLE 对象            → Ruby mathtype2mathml → MathML → LaTeX
- Word EQ 域(老教辅主力)      → EqToLatexUtil(本次新增)

本次改动:
1. 新增 java-svc/.../core/EqToLatexUtil.java:
   移植自 jby backend-services office-core,EQ 语法 → LaTeX
   (\f→\dfrac、\r→\sqrt、\i→\int/\sum/\prod、\s→^{}/_{}、\b→\left\right、
     \a→array、\x→\boxed/\overline、\o\al 堆叠、圈码、化学符号、极限、连等式)
   品牌标记 JBYU* → WPU*,与采集端一致
2. CtoMathFinder:接上 EQ 分支(原为 not-ported 桩),域代码经
   EqToLatexUtil.convert 转 LaTeX 写入 eqLatexMap(WPEQNUM 占位符)
3. WordParseUtil.dealPlaceholder:EQ 的 LaTeX 同样加 \( \) 包裹
   (原先因 WPEQNUM 例外不加包裹,前端/MathJax 不渲染)

修前症状:教辅 Word 里分式/方程组/上下标整段丢失(如 {−1/3, 1} 变成 {-,1})
修后实测:46 份教辅 2908 处 EQ 域全部还原,公式总数 2954 处、零未包裹残留

安全:application.yml(含 RustFS 密钥)不入库,提供 application.yml.example;
      OssService 的 @Value 默认密钥已清空
2026-09-29 09:43:13 +08:00

2256 lines
153 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* cn.hutool.core.io.FileUtil
* com.alibaba.fastjson.JSON
* com.alibaba.fastjson.JSONObject
* com.baomidou.mybatisplus.core.conditions.Wrapper
* com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
* com.baomidou.mybatisplus.core.toolkit.Wrappers
* com.jby.common.base.entity.CommonBean
* com.jby.common.bo.SessionUser
* com.jby.common.exceptions.BizAssert
* com.jby.common.exceptions.BusinessException
* com.jby.common.feign.FeignUtils
* com.jby.common.result.Result
* com.jby.common.util.FileUtil
* com.jby.common.util.RequestUtil
* com.jby.common.util.SpringContextHolder
* com.jby.common.util.UniqueUtil
* com.jby.office.constant.ConfigConstants$FileConfig
* com.jby.office.constant.Constants
* com.jby.office.domain.dto.QuestionSourceFeatureMetadataDTO
* com.jby.office.domain.param.DownloadFileParam
* com.jby.office.domain.param.FileParam
* com.jby.office.domain.param.GenerateFileParam
* com.jby.office.domain.param.GlobalConfigParam
* com.jby.office.domain.param.OfficeFileParseParam
* com.jby.office.domain.param.OfficeFileParseRecordParam
* com.jby.office.domain.param.QueryFileParam
* com.jby.office.domain.param.UpdateFileParam
* com.jby.office.domain.vo.ExportQuestionVO
* com.jby.office.domain.vo.OfficeConfigVO
* com.jby.office.domain.vo.OfficeFileConfigVO
* com.jby.office.domain.vo.OfficeFileDownloadScheduleVO
* com.jby.office.domain.vo.OfficeFileElementVO
* com.jby.office.domain.vo.OfficeFileInfoVO
* com.jby.office.domain.vo.OfficeFileParseRecordVO
* com.jby.office.domain.vo.OfficeFileParseVO
* com.jby.office.domain.vo.OfficeFileStyleVO
* com.jby.office.domain.vo.OfficeGlobalConfigVO
* com.jby.office.domain.vo.OfficeMarginVO
* com.jby.office.domain.vo.OfficeQuestionBlockVO
* com.jby.office.domain.vo.QuestionDetailVO
* com.jby.office.domain.vo.TagVO
* com.jby.office.enums.BooleanEnum
* com.jby.office.enums.DownScheduleTypeEnum
* com.jby.office.enums.EditionEnum
* com.jby.office.enums.ElementTypeEnum
* com.jby.office.enums.FileTypeEnum
* com.jby.office.enums.ListenEnum
* com.jby.officecore.config.OfficeCoreConfig
* com.jby.officecore.domain.bo.CreateDocumentBO
* com.jby.officecore.domain.bo.CreateFileBO
* com.jby.officecore.domain.bo.ElementNumBO
* com.jby.officecore.domain.bo.QuestionBO
* com.jby.officecore.domain.bo.TitleBO
* com.jby.officecore.domain.param.CreatePdfParam
* com.jby.officecore.domain.param.ParseParam
* com.jby.officecore.enums.AttrEnum
* com.jby.officecore.enums.CollectQuestionEnum
* com.jby.officecore.enums.LogicTypeEnum
* com.jby.officecore.enums.MarginTypeEnum
* com.jby.officecore.enums.PageEnum
* com.jby.officecore.enums.QuestionEnum
* com.jby.officecore.enums.TagEnum
* com.jby.officecore.enums.TitleShowEnum
* com.jby.officecore.utils.AttachmentUtil
* com.jby.officecore.utils.CodeUtil
* com.jby.officecore.utils.ElementNumberUtil
* com.jby.officecore.utils.OfficeParseUtil
* com.jby.officecore.utils.WordExportUtil
* com.jby.officecore.utils.WordParseUtil
* com.jby.system.domain.param.NodeParam
* com.jby.system.enums.AttachmentModuleEnum
* javax.annotation.Resource
* org.apache.commons.collections4.CollectionUtils
* org.apache.commons.compress.utils.Lists
* org.apache.commons.lang3.StringUtils
* org.apache.poi.xwpf.usermodel.XWPFDocument
* org.jsoup.Jsoup
* org.jsoup.nodes.Document
* org.jsoup.nodes.Element
* org.jsoup.nodes.Node
* org.jsoup.select.Elements
* org.map.utils.BeanMapping
* org.slf4j.Logger
* org.slf4j.LoggerFactory
* org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
* org.springframework.stereotype.Service
* org.springframework.web.multipart.MultipartFile
*/
package com.jby.officefile.service.impl;
import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jby.common.base.entity.CommonBean;
import com.jby.common.bo.SessionUser;
import com.jby.common.exceptions.BizAssert;
import com.jby.common.exceptions.BusinessException;
import com.jby.common.feign.FeignUtils;
import com.jby.common.result.Result;
import com.jby.common.util.RequestUtil;
import com.jby.common.util.SpringContextHolder;
import com.jby.common.util.UniqueUtil;
import com.jby.office.constant.ConfigConstants;
import com.jby.office.constant.Constants;
import com.jby.office.domain.dto.QuestionSourceFeatureMetadataDTO;
import com.jby.office.domain.param.DownloadFileParam;
import com.jby.office.domain.param.FileParam;
import com.jby.office.domain.param.GenerateFileParam;
import com.jby.office.domain.param.GlobalConfigParam;
import com.jby.office.domain.param.OfficeFileParseParam;
import com.jby.office.domain.param.OfficeFileParseRecordParam;
import com.jby.office.domain.param.QueryFileParam;
import com.jby.office.domain.param.UpdateFileParam;
import com.jby.office.domain.vo.ExportQuestionVO;
import com.jby.office.domain.vo.OfficeConfigVO;
import com.jby.office.domain.vo.OfficeFileConfigVO;
import com.jby.office.domain.vo.OfficeFileDownloadScheduleVO;
import com.jby.office.domain.vo.OfficeFileElementVO;
import com.jby.office.domain.vo.OfficeFileInfoVO;
import com.jby.office.domain.vo.OfficeFileParseRecordVO;
import com.jby.office.domain.vo.OfficeFileParseVO;
import com.jby.office.domain.vo.OfficeFileStyleVO;
import com.jby.office.domain.vo.OfficeGlobalConfigVO;
import com.jby.office.domain.vo.OfficeMarginVO;
import com.jby.office.domain.vo.OfficeQuestionBlockVO;
import com.jby.office.domain.vo.QuestionDetailVO;
import com.jby.office.domain.vo.TagVO;
import com.jby.office.enums.BooleanEnum;
import com.jby.office.enums.DownScheduleTypeEnum;
import com.jby.office.enums.EditionEnum;
import com.jby.office.enums.ElementTypeEnum;
import com.jby.office.enums.FileTypeEnum;
import com.jby.office.enums.ListenEnum;
import com.jby.officecore.config.OfficeCoreConfig;
import com.jby.officecore.domain.bo.CreateDocumentBO;
import com.jby.officecore.domain.bo.CreateFileBO;
import com.jby.officecore.domain.bo.ElementNumBO;
import com.jby.officecore.domain.bo.QuestionBO;
import com.jby.officecore.domain.bo.TitleBO;
import com.jby.officecore.domain.param.CreatePdfParam;
import com.jby.officecore.domain.param.ParseParam;
import com.jby.officecore.enums.AttrEnum;
import com.jby.officecore.enums.CollectQuestionEnum;
import com.jby.officecore.enums.LogicTypeEnum;
import com.jby.officecore.enums.MarginTypeEnum;
import com.jby.officecore.enums.PageEnum;
import com.jby.officecore.enums.QuestionEnum;
import com.jby.officecore.enums.TagEnum;
import com.jby.officecore.enums.TitleShowEnum;
import com.jby.officecore.utils.AttachmentUtil;
import com.jby.officecore.utils.CodeUtil;
import com.jby.officecore.utils.ElementNumberUtil;
import com.jby.officecore.utils.OfficeParseUtil;
import com.jby.officecore.utils.WordExportUtil;
import com.jby.officecore.utils.WordParseUtil;
import com.jby.officefile.config.OfficeFileConfig;
import com.jby.officefile.domain.entity.OfficeFileDownloadSchedule;
import com.jby.officefile.domain.entity.OfficeFileParseRecord;
import com.jby.officefile.feign.OfficeFileServiceFeign;
import com.jby.officefile.feign.OfficeGlobalConfigServiceFeign;
import com.jby.officefile.mapper.OfficeFileDownloadScheduleMapper;
import com.jby.officefile.service.FileService;
import com.jby.officefile.service.OfficeFileDownloadScheduleService;
import com.jby.officefile.service.OfficeFileParseRecordService;
import com.jby.system.domain.param.NodeParam;
import com.jby.system.enums.AttachmentModuleEnum;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;
import org.map.utils.BeanMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@Service
public class FileServiceImpl
implements FileService {
private static final Logger log = LoggerFactory.getLogger(FileServiceImpl.class);
private static final Pattern QUESTION_NUM_PATTERN = Pattern.compile("<u>(?:(?:</?u>|[\u300a\u300b\\s]|&nbsp;)*\\d(?:</?u>|[\u300a\u300b\\s]|&nbsp;)*)+</u>");
public static final Set<Long> ANSWER_MERGE_QUESTION_TYPE_SET_OLD = Stream.of(1L, 2L, 3L, 4L, 5L, 7L, 8L, 9L, 10L, 11L).collect(Collectors.toSet());
private static final Set<Long> ANSWER_MERGE_QUESTION_TYPE_SET_NEW = Stream.of(1048L, 1049L, 1050L, 1051L, 1054L, 1055L, 1525L).collect(Collectors.toSet());
@Resource
private OfficeCoreConfig officeCoreConfig;
@Resource
private OfficeFileConfig officeFileConfig;
@Resource
private OfficeFileDownloadScheduleService downloadScheduleService;
@Resource
private OfficeFileDownloadScheduleMapper officeFileDownloadScheduleMapper;
@Resource
private OfficeFileServiceFeign officeFileServiceFeign;
@Resource
private OfficeGlobalConfigServiceFeign officeGlobalConfigServiceFeign;
@Resource(name="batchDownloadMainExecutor")
private ThreadPoolTaskExecutor batchDownloadMainExecutor;
@Resource(name="batchDownloadTaskExecutor")
private ThreadPoolTaskExecutor batchDownloadTaskExecutor;
@Resource
private OfficeFileParseRecordService officeFileParseRecordService;
@Override
public OfficeFileInfoVO generateFileByUrl(GenerateFileParam param) {
BizAssert.isNotBlank((String)param.getSourceUrl(), (String)"\u6e90\u6587\u4ef6\u5730\u5740\u4e3a\u7a7a");
BizAssert.notNull((Object)param.getPhaseId(), (String)"\u5b66\u6bb5id\u4e3a\u7a7a");
BizAssert.notNull((Object)param.getCourseId(), (String)"\u5b66\u79d1id\u4e3a\u7a7a");
FileServiceImpl.compatibleEncode(param);
if (StringUtils.isBlank((CharSequence)param.getFileName())) {
param.setFileName(com.jby.common.util.FileUtil.getFileName((String)param.getSourceUrl()));
}
ParseParam parseParam = new ParseParam().setSourceUrl(param.getSourceUrl());
this.addLatexReplaceList(parseParam);
String html = WordParseUtil.parseByUrl((ParseParam)parseParam);
List elementList = OfficeParseUtil.buildElements((String)html);
param.setElementList(elementList);
return (OfficeFileInfoVO)FeignUtils.parse((Result)this.officeFileServiceFeign.generateFile(param));
}
private static void compatibleEncode(GenerateFileParam param) {
if (!param.getFileName().contains("+")) {
param.setFileName(com.jby.common.util.FileUtil.decodeUrl((String)param.getFileName()));
}
if (!param.getSourceUrl().contains("+")) {
param.setSourceUrl(com.jby.common.util.FileUtil.decodeUrl((String)param.getSourceUrl()));
}
}
@Override
public OfficeFileInfoVO generateFileByFile(FileParam fileParam) {
BizAssert.notNull((Object)fileParam.getSourceFile(), (String)"\u6e90\u6587\u4ef6\u4e3a\u7a7a");
BizAssert.isTrue((fileParam.getSourceFile().getSize() != 0L ? 1 : 0) != 0, (String)"\u6587\u6863\u5185\u5bb9\u4e3a\u7a7a\uff01");
BizAssert.isNotBlank((String)fileParam.getGenerateFileJson(), (String)"json\u53c2\u6570\u4e3a\u7a7a");
GenerateFileParam param = (GenerateFileParam)JSONObject.parseObject((String)fileParam.getGenerateFileJson(), GenerateFileParam.class);
BizAssert.notNull((Object)param.getPhaseId(), (String)"\u5b66\u6bb5id\u4e3a\u7a7a");
BizAssert.notNull((Object)param.getCourseId(), (String)"\u5b66\u79d1id\u4e3a\u7a7a");
if (StringUtils.isBlank((CharSequence)param.getFileName())) {
param.setFileName(com.jby.common.util.FileUtil.getFileName((String)fileParam.getSourceFile().getOriginalFilename()));
}
ParseParam parseParam = new ParseParam().setSourceFile(fileParam.getSourceFile());
this.addLatexReplaceList(parseParam);
String html = WordParseUtil.parseByFile((ParseParam)parseParam);
List elementList = OfficeParseUtil.buildElements((String)html);
param.setElementList(elementList);
return (OfficeFileInfoVO)FeignUtils.parse((Result)this.officeFileServiceFeign.generateFile(param));
}
@Override
public OfficeFileParseVO parseOfficeFile(OfficeFileParseParam param) {
BizAssert.notNull((Object)param.getFile(), (String)"\u6587\u6863\u4e3a\u7a7a");
BizAssert.isTrue((param.getFile().getSize() != 0L ? 1 : 0) != 0, (String)"\u6587\u6863\u5185\u5bb9\u4e3a\u7a7a\uff01");
WordParseUtil.validSize((double)param.getFile().getSize(), null);
ParseParam parseParam = new ParseParam().setSourceFile(param.getFile()).setNewParseVersion(param.getNewParseVersion()).setFileId(param.getFileId());
this.addLatexReplaceList(parseParam);
String html = WordParseUtil.parseByFile((ParseParam)parseParam);
return new OfficeFileParseVO().setFileId(param.getFileId()).setContent(html);
}
private void addLatexReplaceList(ParseParam parseParam) {
try {
OfficeGlobalConfigVO configVO = (OfficeGlobalConfigVO)FeignUtils.parse((Result)this.officeGlobalConfigServiceFeign.getGlobalConfigInfo(new GlobalConfigParam().setConfigKey("LATEX_REPLACE")));
if (Objects.nonNull(configVO) && CollectionUtils.isNotEmpty((Collection)configVO.getConfigList())) {
List latexReplaceList = JSONObject.parseArray((String)JSON.toJSONString((Object)configVO.getConfigList()), JSONObject.class);
parseParam.setLatexReplaceList(latexReplaceList);
}
}
catch (Exception e) {
log.error("\u6dfb\u52a0latex\u516c\u5f0f\u89c4\u8303\u914d\u7f6e\u4fe1\u606f\u5f02\u5e38", (Throwable)e);
}
}
@Override
public String downloadOfficeFile(DownloadFileParam param) {
String fileUrl;
if (FileTypeEnum.PDF.getType().equals(param.getFileType())) {
fileUrl = Objects.isNull(param.getPdfFile()) ? this.downloadPdf(param) : this.downloadListenAudio(param);
} else {
CreateFileBO createFileBO;
OfficeFileInfoVO fileInfo = (OfficeFileInfoVO)FeignUtils.parse((Result)this.officeFileServiceFeign.getFileDetail(new QueryFileParam().setFileId(param.getFileId())));
if (EditionEnum.STUDENT_ANSWER_END.getEdition().equals(param.getEdition())) {
createFileBO = this.createDocument(param.setEdition(EditionEnum.STUDENT.getEdition()), fileInfo, null);
this.createDocument(param.setEdition(EditionEnum.ANSWER.getEdition()), fileInfo, createFileBO.getDocument());
} else {
createFileBO = this.createDocument(param, fileInfo, null);
}
fileUrl = WordExportUtil.createOfficeFile((CreateFileBO)createFileBO);
}
log.info("\u4e0b\u8f7d\u5728\u7ebf\u7f16\u8f91\u6587\u4ef6\u6210\u529f, fileUrl={}, param={}", (Object)fileUrl, (Object)JSON.toJSONString((Object)param));
if (BooleanEnum.TRUE.getValue().equals(param.getIsEncodeUrl())) {
fileUrl = com.jby.common.util.FileUtil.encodeUrl((String)fileUrl);
}
return fileUrl;
}
private CreateFileBO createDocument(DownloadFileParam param, OfficeFileInfoVO fileInfoVO, XWPFDocument xwpfDocument) {
OfficeFileInfoVO fileInfo = (OfficeFileInfoVO)JSON.parseObject((String)JSON.toJSONString((Object)fileInfoVO), OfficeFileInfoVO.class);
this.filterElementList(fileInfo, param.getEdition());
ArrayList<String> contentList = new ArrayList<String>();
ArrayList<ExportQuestionVO> questionList = new ArrayList<ExportQuestionVO>();
this.collectContent(contentList, questionList, fileInfo, fileInfo.getOfficeConfigVO(), param.getEdition());
PageEnum pageEnum = PageEnum.getPageEnum((String)param.getPage());
String templateName = this.getTemplateName(StringUtils.isBlank((CharSequence)param.getTemplateName()) ? pageEnum.name() : param.getTemplateName(), param.getEdition(), fileInfo.getFileConfigList());
XWPFDocument document = WordExportUtil.createDocument((CreateDocumentBO)new CreateDocumentBO().setTemplateName(templateName).setPageEnum(pageEnum).setOfficeConfig(fileInfo.getOfficeConfigVO()).setContentList(contentList).setFileMarginVO(fileInfo.getFileMarginVO()).setEdition(param.getEdition()).setNewDownloadVersion(param.getNewDownloadVersion()).setXwpfDocument(xwpfDocument));
BizAssert.notNull((Object)document, (String)"\u751f\u6210\u6587\u6863\u5f02\u5e38");
return new CreateFileBO().setDocument(document).setFileName(fileInfo.getFileName()).setQuestionList(questionList).setDownloadListenType(param.getDownloadListenType());
}
private String getTemplateName(String templateName, Integer edition, List<OfficeFileConfigVO> fileConfigList) {
Optional<OfficeFileConfigVO> bindingLine;
if (EditionEnum.STUDENT.getEdition().equals(edition) && (bindingLine = fileConfigList.stream().filter(e -> "bindingLine".equals(e.getFieldKey()) && BooleanEnum.TRUE.getValue().equals(e.getEnableField())).findAny()).isPresent()) {
templateName = templateName + "_" + bindingLine.get().getFieldKey();
}
return templateName + "." + "docx";
}
private void collectContent(List<String> contentList, List<ExportQuestionVO> questionList, OfficeFileInfoVO fileInfo, OfficeConfigVO officeConfig, Integer edition) {
Map configMap = fileInfo.getFileConfigList().stream().collect(Collectors.toMap(OfficeFileConfigVO::getFieldKey, Function.identity(), (l, r) -> l));
for (String head : ConfigConstants.FileConfig.FILE_HEAD_LIST) {
String content;
OfficeFileConfigVO headConfig = (OfficeFileConfigVO)configMap.get(head);
String string = content = "title".equals(headConfig.getFieldKey()) ? fileInfo.getFileLabelName() : headConfig.getFieldValue();
if (!BooleanEnum.TRUE.getValue().equals(headConfig.getEnableField()) || !StringUtils.isNotBlank((CharSequence)content)) continue;
String fieldValue = this.addDefaultTemplateStyle(officeConfig.getTemplateStyleMap(), headConfig.getFieldKey(), content);
contentList.add(fieldValue);
}
this.collectElementInfo(fileInfo, contentList, questionList, officeConfig, edition);
}
private String addDefaultTemplateStyle(Map<String, String> templateStyleMap, String templateKey, String template) {
String templateStyle = templateStyleMap.get(templateKey);
if (StringUtils.isNotBlank((CharSequence)templateStyle) && templateStyle.contains("replaceKey")) {
return templateStyle.replace("replaceKey", template);
}
return template;
}
private void filterElementList(OfficeFileInfoVO fileInfo, Integer edition) {
if (EditionEnum.STUDENT.getEdition().equals(edition)) {
fileInfo.setElementList(fileInfo.getElementList().stream().filter(e -> Boolean.TRUE.equals(e.getStudentShow())).collect(Collectors.toList()));
}
if (EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition)) {
fileInfo.setElementList(fileInfo.getElementList().stream().filter(e -> ElementTypeEnum.ANSWER_FILTER_SET.contains(e.getElementType())).peek(m -> {
if (ElementTypeEnum.TEXT.getType().equals(m.getElementType()) && StringUtils.isNotBlank((CharSequence)m.getContent())) {
Document doc = Jsoup.parse((String)m.getContent());
Element body = doc.body();
Elements targetSpans = body.select("span." + AttrEnum.TINYMCE_HOLLOWOUT.getAttr() + ", span." + AttrEnum.TINYMCE_HIDDENANDANSWER.getAttr());
if (CollectionUtils.isEmpty((Collection)targetSpans)) {
m.setDeleted(Boolean.TRUE);
return;
}
Element container = body.child(0);
container.empty();
for (int i = 0; i < targetSpans.size(); ++i) {
((Element)targetSpans.get(i)).removeClass(AttrEnum.TINYMCE_HOLLOWOUT.getAttr());
((Element)targetSpans.get(i)).removeClass(AttrEnum.TINYMCE_HIDDENANDANSWER.getAttr());
container.appendChild((Node)((Element)targetSpans.get(i)).clone());
if (i >= targetSpans.size() - 1) continue;
container.appendChild((Node)new Element("span").text("\uff1b"));
}
m.setContent(body.html());
}
}).filter(e -> !Boolean.TRUE.equals(e.getDeleted())).collect(Collectors.toList()));
}
}
private void collectElementInfo(OfficeFileInfoVO fileInfo, List<String> contentList, List<ExportQuestionVO> questionList, OfficeConfigVO officeConfig, Integer edition) {
ElementNumberUtil elementNumberUtil = new ElementNumberUtil();
ArrayList<TitleBO> titleList = new ArrayList<TitleBO>();
titleList.add(new TitleBO().setQuestionList(new ArrayList()));
for (OfficeFileElementVO element : fileInfo.getElementList()) {
if (ElementTypeEnum.TITLE_1.getType().equals(element.getElementType())) {
titleList.add(new TitleBO().setIndex(Integer.valueOf(contentList.size())).setElementNumberStyle(element.getElementNumberStyle()).setQuestionList(new ArrayList()));
}
if (ElementTypeEnum.QUESTION.getType().equals(element.getElementType()) && element.getQuestionShowType() != 1) {
this.collectQuestionBankInfo(contentList, edition, officeConfig, element, titleList, questionList, fileInfo.getFileStyle());
} else if (ElementTypeEnum.RELATION_SET.contains(element.getElementType()) && (EditionEnum.STUDENT.getEdition().equals(edition) || EditionEnum.TEACHER.getEdition().equals(edition))) {
this.collectAttachmentInfo(contentList, officeConfig.getAttachmentCard(), officeConfig.getCommonIconMap(), element, fileInfo.getFileMarginVO());
} else if (ElementTypeEnum.CONTENT_SET.contains(element.getElementType())) {
ElementNumBO elementNumBO = elementNumberUtil.getElementNum(element, fileInfo.getFileStyle(), officeConfig.getElementNumStyleMap(), officeConfig.getElementIconMap());
String elementContent = elementNumBO.getStyleElementNum() + officeConfig.getTagVO().getDivStart() + this.notNullContent(element.getContent()) + officeConfig.getTagVO().getDivEnd();
contentList.add(elementContent);
} else if (ElementTypeEnum.QUESTION_BLOCK.getType().equals(element.getElementType())) {
String[] split;
OfficeQuestionBlockVO officeQuestionBlockVO = element.getOfficeQuestionBlockVO();
if (officeQuestionBlockVO == null) continue;
ElementNumBO elementNumBO = elementNumberUtil.getElementNum(element, fileInfo.getFileStyle(), officeConfig.getElementNumStyleMap(), officeConfig.getElementIconMap());
TagVO tagVO = officeConfig.getTagVO();
String questionBlockType = tagVO.getQuestionBlockType();
String questionBlockTypeTag = "";
if (StringUtils.isNotBlank((CharSequence)questionBlockType) && (split = questionBlockType.split("#")).length == 3) {
int blockType = element.getOfficeQuestionBlockVO().getBlockType();
questionBlockTypeTag = split[blockType - 1];
}
if (StringUtils.isNotBlank((CharSequence)questionBlockTypeTag)) {
questionBlockTypeTag = questionBlockTypeTag.replaceAll("number", elementNumBO.getStyleElementNum());
String scoreStr = FileServiceImpl.getScoreStr(officeQuestionBlockVO);
questionBlockTypeTag = questionBlockTypeTag.replaceAll("score", scoreStr);
}
String blockContent = this.notNullContent(officeQuestionBlockVO.getBlockContent());
if (StringUtils.isNotBlank((CharSequence)questionBlockTypeTag) && StringUtils.isNotBlank((CharSequence)blockContent)) {
blockContent = this.insertTagIntoFirstElement(blockContent, questionBlockTypeTag);
}
String elementContent = officeConfig.getTagVO().getDivStart() + blockContent + officeConfig.getTagVO().getDivEnd();
contentList.add(elementContent);
}
this.addElementAfterInfo(contentList, edition, element, officeConfig.getTagVO());
}
this.dealTitle(fileInfo, contentList, titleList, officeConfig.getElementNumStyleMap());
if (EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition)) {
this.dealAnswerMergeNew2(contentList, titleList);
}
}
private static String getScoreStr(OfficeQuestionBlockVO officeQuestionBlockVO) {
BigDecimal score = officeQuestionBlockVO.getScore();
String scoreStr = "";
if (score != null && score.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal stripped = score.stripTrailingZeros();
scoreStr = stripped.scale() <= 0 ? stripped.toPlainString() : stripped.setScale(1, RoundingMode.HALF_UP).toPlainString();
scoreStr = "(" + scoreStr + "\u5206" + ")";
}
return scoreStr;
}
private String insertTagIntoFirstElement(String blockContent, String insertTag) {
try {
Element firstChild;
Document doc = Jsoup.parse((String)blockContent);
doc.outputSettings().prettyPrint(false).indentAmount(0);
Element body = doc.body();
Element firstElement = body.children().first();
if (firstElement == null) {
return insertTag + blockContent;
}
Elements children = firstElement.children();
if (!children.isEmpty() && "br".equalsIgnoreCase((firstChild = children.first()).tagName())) {
firstChild.remove();
}
firstElement.prepend(insertTag);
return body.html();
}
catch (Exception e) {
log.error("\u63d2\u5165\u9898\u5757\u6807\u7b7e\u5230\u5185\u5bb9\u5931\u8d25, blockContent:{}, insertTag:{}", new Object[]{blockContent, insertTag, e});
return insertTag + blockContent;
}
}
private void dealAnswerMerge(List<String> contentList, List<TitleBO> titleList) {
List<ArrayList<List<Integer>>> groups;
if (CollectionUtils.isEmpty(contentList)) {
return;
}
HashMap<Integer, TitleBO> indexToTitleMap = new HashMap<Integer, TitleBO>();
for (TitleBO titleBO : titleList) {
if (CollectionUtils.isEmpty((Collection)titleBO.getQuestionList())) continue;
for (QuestionBO q2 : titleBO.getQuestionList()) {
if (!Objects.nonNull(q2.getIndex())) continue;
indexToTitleMap.put(q2.getIndex(), titleBO);
}
}
IdentityHashMap<TitleBO, List<ArrayList<List<Integer>>>> titleGroups = new IdentityHashMap<TitleBO, List<ArrayList<List<Integer>>>>();
for (TitleBO title : titleList) {
if (CollectionUtils.isEmpty((Collection)title.getQuestionList())) continue;
List sortedQuestions = title.getQuestionList().stream().filter(q -> Objects.nonNull(q.getIndex())).sorted(Comparator.comparing(QuestionBO::getIndex)).collect(Collectors.toList());
groups = new ArrayList();
ArrayList<Integer> currentGroup = new ArrayList<Integer>();
for (QuestionBO questionBO : sortedQuestions) {
if (Boolean.TRUE.equals(questionBO.getIsMergeAnswer())) {
currentGroup.add(questionBO.getIndex());
continue;
}
if (!currentGroup.isEmpty()) {
groups.add(new ArrayList(currentGroup));
currentGroup.clear();
}
groups.add((ArrayList<List<Integer>>)Collections.singletonList(questionBO.getIndex()));
}
if (!currentGroup.isEmpty()) {
groups.add(currentGroup);
}
titleGroups.put(title, groups);
}
ArrayList<String> arrayList = new ArrayList<String>();
int i = 0;
while (i < contentList.size()) {
if (indexToTitleMap.containsKey(i)) {
TitleBO title = (TitleBO)indexToTitleMap.get(i);
groups = (List)titleGroups.get(title);
boolean found = false;
for (List list : groups) {
if (!list.contains(i) || !((Integer)list.get(0)).equals(i)) continue;
StringBuilder merged = new StringBuilder();
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
int idx = (Integer)iterator.next();
if (merged.length() > 0) {
merged.append(" ");
}
merged.append(contentList.get(idx));
}
arrayList.add(merged.toString());
i = (Integer)Collections.max(list) + 1;
found = true;
break;
}
if (found) continue;
arrayList.add(contentList.get(i));
++i;
continue;
}
arrayList.add(contentList.get(i));
++i;
}
contentList.clear();
contentList.addAll(arrayList);
}
private void dealTitle(OfficeFileInfoVO fileInfo, List<String> contentList, List<TitleBO> titleList, Map<String, Map<String, String>> styleMap) {
titleList.forEach(titleBO -> {
if (Objects.isNull(titleBO.getIndex()) || CollectionUtils.isEmpty((Collection)titleBO.getQuestionList())) {
return;
}
Integer showType = fileInfo.getFileStyle().getShowQuestionNumberScore();
ArrayList<String> showList = new ArrayList<String>();
if (TitleShowEnum.SHOW_QUESTION_NUM_SET.contains(showType)) {
showList.add("\u5171" + titleBO.getQuestionList().size() + "\u5c0f\u9898");
}
if (TitleShowEnum.SHOW_QUESTION_SCORE_SET.contains(showType)) {
BigDecimal total = titleBO.getQuestionList().stream().map(QuestionBO::getScore).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
if ((total = total.stripTrailingZeros()).scale() <= 0) {
total = total.setScale(0);
}
showList.add("\u5171" + total + "\u5206");
}
if (CollectionUtils.isNotEmpty(showList)) {
String questionTip = "(" + String.join((CharSequence)",", showList) + ")";
if (StringUtils.isBlank((CharSequence)titleBO.getElementNumberStyle())) {
String elementNumberStyle = (String)((Map)styleMap.get("elementType" + ElementTypeEnum.TITLE_1.getType())).get("numStyle");
questionTip = elementNumberStyle.replace("elementNumber\u3001", questionTip);
}
String title = (String)contentList.get(titleBO.getIndex());
contentList.set(titleBO.getIndex(), title + questionTip);
}
fileInfo.getFileConfigList().stream().filter(e -> "bigScoreLine".equals(e.getFieldKey()) && BooleanEnum.TRUE.getValue().equals(e.getEnableField()) && StringUtils.isNotBlank((CharSequence)e.getFieldValue())).map(OfficeFileConfigVO::getFieldValue).findFirst().ifPresent(bigScoreLine -> {
String title = (String)contentList.get(titleBO.getIndex());
contentList.set(titleBO.getIndex(), bigScoreLine + title);
});
});
}
private void collectAttachmentInfo(List<String> contentList, String attachmentCard, Map<String, String> commonIconMap, OfficeFileElementVO element, OfficeMarginVO officeMarginVO) {
String qrCodeUrl = null;
if (ElementTypeEnum.AUDIO.getType().equals(element.getElementType()) && Objects.nonNull(element.getAudioDetail())) {
qrCodeUrl = element.getAudioDetail().getQrCodeUrl();
}
if (ElementTypeEnum.VIDEO.getType().equals(element.getElementType()) && Objects.nonNull(element.getVideoDetail())) {
qrCodeUrl = element.getVideoDetail().getQrCodeUrl();
}
if (ElementTypeEnum.GGB.getType().equals(element.getElementType()) && Objects.nonNull(element.getGgbDetail())) {
qrCodeUrl = element.getGgbDetail().getQrCodeUrl();
}
if (ElementTypeEnum.CHEMISTRY.getType().equals(element.getElementType()) && Objects.nonNull(element.getChemistryDetail())) {
qrCodeUrl = element.getChemistryDetail().getQrCodeUrl();
}
if (ElementTypeEnum.MINDMAP.getType().equals(element.getElementType()) && Objects.nonNull(element.getMindmapDetailVo())) {
qrCodeUrl = element.getMindmapDetailVo().getQrCodeUrl();
}
String attachmentContent = this.getAttachmentCard(attachmentCard, commonIconMap, element.getElementType(), element.getAttachmentName(), qrCodeUrl);
if (officeMarginVO != null && !StringUtils.isEmpty((CharSequence)officeMarginVO.getLeftMargin())) {
Document doc;
Element tabNode;
String currLeftMarginStr = officeMarginVO.getLeftMargin();
double currLeftMargin = Double.parseDouble(currLeftMarginStr = currLeftMarginStr.replaceAll("[^\\d.]", ""));
if (currLeftMargin > MarginTypeEnum.NORMAL.getLeftMargin() && (tabNode = (doc = Jsoup.parse((String)attachmentContent)).select(TagEnum.TAB.getName()).first()) != null) {
String widthStr = tabNode.attr(AttrEnum.WIDTH.getAttr());
double width = Double.parseDouble(widthStr);
tabNode.attr(AttrEnum.WIDTH.getAttr(), (int)(width *= MarginTypeEnum.NORMAL.getLeftMargin() / currLeftMargin) + "");
attachmentContent = doc.body().html();
}
}
contentList.add(attachmentContent);
}
private void collectQuestionInfo(List<String> contentList, List<ExportQuestionVO> questionList, OfficeFileStyleVO fileStyle, Integer edition, OfficeConfigVO officeConfig, ElementNumberUtil elementNumberUtil, List<TitleBO> titleList, OfficeFileElementVO element) {
QuestionDetailVO question = element.getQuestionDetail();
if (Objects.isNull(question)) {
ElementNumBO elementNumBO = elementNumberUtil.getElementNum(element, fileStyle, officeConfig.getElementNumStyleMap(), officeConfig.getElementIconMap());
String questionContent = officeConfig.getTagVO().getDivStart() + "\u9898\u76ee\u4fe1\u606f\u4e3a\u7a7a" + officeConfig.getTagVO().getDivEnd();
this.addRestoreInfo(titleList, contentList.size(), questionContent, null, false);
contentList.add(elementNumBO.getStyleElementNum() + questionContent);
return;
}
if (CollectionUtils.isEmpty((Collection)question.getChildList())) {
ElementNumBO elementNumBO = question.isSystemQuestionNumber() != false ? elementNumberUtil.getElementNum(element, fileStyle, officeConfig.getElementNumStyleMap(), officeConfig.getElementIconMap()) : new ElementNumBO().setStyleElementNum(question.getShowCustomQuestionNumber());
Set collectTypes = CollectQuestionEnum.getCollectTypes((QuestionEnum)QuestionEnum.SINGLE_QUESTION, (Integer)edition, (String)question.getTypeName());
this.addQuestionInfo(contentList, titleList, elementNumBO.getStyleElementNum(), question, collectTypes, officeConfig.getTagVO(), QuestionEnum.SINGLE_QUESTION, fileStyle, edition);
questionList.add(new ExportQuestionVO().setQuestion(question));
return;
}
String elementNum = question.isSystemQuestionNumber() != false ? "" : question.getShowCustomQuestionNumber();
Set collectTypes = CollectQuestionEnum.getCollectTypes((QuestionEnum)QuestionEnum.PARENT_QUESTION, (Integer)edition, (String)question.getTypeName());
Integer contentIndex = this.addQuestionInfo(contentList, titleList, elementNum, question, collectTypes, officeConfig.getTagVO(), QuestionEnum.PARENT_QUESTION, fileStyle, edition);
collectTypes = CollectQuestionEnum.getCollectTypes((QuestionEnum)QuestionEnum.CHILD_QUESTION, (Integer)edition, (String)question.getTypeName());
ArrayList<Integer> elementNumList = new ArrayList<Integer>();
for (int i = 0; i < question.getChildList().size(); ++i) {
ElementNumBO elementNumBO;
QuestionDetailVO child = (QuestionDetailVO)question.getChildList().get(i);
if (question.isSystemQuestionNumber().booleanValue()) {
elementNumBO = elementNumberUtil.getElementNum(element, fileStyle, officeConfig.getElementNumStyleMap(), officeConfig.getElementIconMap());
} else {
elementNumBO = new ElementNumBO().setElementNum(Integer.valueOf(i + 1));
String customNumber = elementNumBO.getElementNum() + ".";
if ((EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition)) && StringUtils.isNotBlank((CharSequence)question.getShowCustomQuestionNumber())) {
customNumber = question.getShowCustomQuestionNumber().trim() + "-" + customNumber;
}
elementNumBO.setStyleElementNum(customNumber);
}
this.addQuestionInfo(contentList, titleList, elementNumBO.getStyleElementNum(), child, collectTypes, officeConfig.getTagVO(), QuestionEnum.CHILD_QUESTION, null, edition);
elementNumList.add(elementNumBO.getElementNum());
}
this.dealQuestionNum(contentList, question, contentIndex, elementNumList);
questionList.add(new ExportQuestionVO().setQuestion(question));
}
private void dealQuestionNum(List<String> contentList, QuestionDetailVO question, Integer contentIndex, List<Integer> elementNumList) {
if ((Constants.QUESTION_TYPE_SET.contains(question.getTypeName()) || "\u5b8c\u5f62\u586b\u7a7a".equals(question.getTypeName())) && Objects.nonNull(contentIndex)) {
String content = contentList.get(contentIndex);
Matcher matcher = QUESTION_NUM_PATTERN.matcher(content);
StringBuffer sb = new StringBuffer();
int count = 0;
while (matcher.find() && count <= elementNumList.size() - 1) {
String newNum = "<u> " + elementNumList.get(count++).toString() + " " + "</u>";
matcher.appendReplacement(sb, newNum);
}
matcher.appendTail(sb);
contentList.set(contentIndex, sb.toString());
}
}
private void markQuestionImg(QuestionDetailVO question) {
if (Objects.nonNull(question)) {
this.replaceQuestionImg(question);
if (CollectionUtils.isNotEmpty((Collection)question.getChildList())) {
question.getChildList().forEach(this::replaceQuestionImg);
}
}
}
private void replaceQuestionImg(QuestionDetailVO question) {
question.setContent(this.replaceImg(question.getContent()));
question.setOptionA(this.replaceImg(question.getOptionA()));
question.setOptionB(this.replaceImg(question.getOptionB()));
question.setOptionC(this.replaceImg(question.getOptionC()));
question.setOptionD(this.replaceImg(question.getOptionD()));
question.setOptionE(this.replaceImg(question.getOptionE()));
question.setOptionF(this.replaceImg(question.getOptionF()));
question.setOptionG(this.replaceImg(question.getOptionG()));
question.setAnswer(this.replaceImg(question.getAnswer()));
question.setAnswerExplanation(Optional.ofNullable(question.getAnswerExplanation()).orElse(Collections.emptyList()).stream().map(this::replaceImg).collect(Collectors.toList()));
}
private String replaceImg(String content) {
if (StringUtils.isBlank((CharSequence)content)) {
return content;
}
return content.replace("<img", "<imq");
}
private void addElementAfterInfo(List<String> contentList, Integer edition, OfficeFileElementVO element, TagVO tagVO) {
if (!EditionEnum.ANSWER.getEdition().equals(edition) && !EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition)) {
this.addEmptyArea(contentList, element.getEmptyLineNum(), element.getHasLine());
}
this.addTeachingRemark(contentList, edition, element, tagVO);
this.addPageBreak(contentList, edition, element.getHasPageBreak());
}
private void addEmptyArea(List<String> contentList, Integer emptyLineNum, Boolean hasLine) {
if (Objects.nonNull(emptyLineNum) && emptyLineNum > 0) {
String tag = Boolean.TRUE.equals(hasLine) ? "<hr>" : "<br>";
for (int i = 0; i < emptyLineNum; ++i) {
contentList.add(tag);
}
}
}
private void addTeachingRemark(List<String> contentList, Integer edition, OfficeFileElementVO element, TagVO tagVO) {
if (EditionEnum.TEACHER.getEdition().equals(edition) && Boolean.TRUE.equals(element.getIsShowRemark()) && StringUtils.isNotBlank((CharSequence)element.getTeachingRemark())) {
contentList.add(tagVO.getTeachingRemark() + tagVO.getDivStart() + element.getTeachingRemark() + tagVO.getDivEnd());
}
}
private void addPageBreak(List<String> contentList, Integer edition, Boolean hasPageBreak) {
if (!EditionEnum.STUDENT.getEdition().equals(edition) || !Boolean.TRUE.equals(hasPageBreak)) {
return;
}
contentList.add("<pbr></pbr>");
}
private Integer addQuestionInfo(List<String> contentList, List<TitleBO> titleList, String elementNum, QuestionDetailVO question, Set<CollectQuestionEnum> collectTypes, TagVO tagVO, QuestionEnum questionEnum, OfficeFileStyleVO fileStyle, Integer edition) {
ArrayList<String> questionContentList = new ArrayList<String>();
Integer contentIndex = null;
if (collectTypes.contains(CollectQuestionEnum.CONTENT) && StringUtils.isNotBlank((CharSequence)question.getContent())) {
questionContentList.add(tagVO.getDivStart() + question.getContent() + tagVO.getDivEnd());
contentIndex = contentList.size();
}
if (collectTypes.contains(CollectQuestionEnum.ORIGINAL_TEXT) && StringUtils.isNotBlank((CharSequence)question.getOriginalText())) {
questionContentList.add(tagVO.getListeningText() + tagVO.getDivStart() + question.getOriginalText() + tagVO.getDivEnd());
}
if (collectTypes.contains(CollectQuestionEnum.DECIPHERMENT) && StringUtils.isNotBlank((CharSequence)question.getDecipherment())) {
questionContentList.add(tagVO.getDecipherment() + tagVO.getDivStart() + question.getDecipherment() + tagVO.getDivEnd());
}
if (collectTypes.contains(CollectQuestionEnum.OPTION)) {
this.addOption(questionContentList, question, tagVO);
}
if (collectTypes.contains(CollectQuestionEnum.EMPTY_AREA)) {
this.addEmptyArea(questionContentList, question.getEmptyLineNum(), question.getHasLine());
}
String answer = collectTypes.contains(CollectQuestionEnum.ANSWER) ? question.getAnswer() : "";
ArrayList answerExplanationList = new ArrayList();
if (collectTypes.contains(CollectQuestionEnum.EXPLANATION) && CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation())) {
question.getAnswerExplanation().stream().filter(StringUtils::isNotBlank).forEach(answerExplanationList::add);
}
String answerTag = tagVO.getAnswer();
if (EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition)) {
answerTag = " ";
}
if ((EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition)) && (ANSWER_MERGE_QUESTION_TYPE_SET_OLD.contains(question.getTypeDetailId()) || ANSWER_MERGE_QUESTION_TYPE_SET_NEW.contains(question.getLogicTypeId()) || StringUtils.isNotBlank((CharSequence)question.getDecipherment()))) {
String answerExplanation2 = "";
if (StringUtils.isNotBlank((CharSequence)answer)) {
answerExplanation2 = answerTag + tagVO.getDivStart() + answer + tagVO.getDivEnd();
}
if (CollectionUtils.isNotEmpty(answerExplanationList)) {
answerExplanation2 = answerExplanation2 + tagVO.getExplanation() + tagVO.getDivStart() + String.join((CharSequence)",", answerExplanationList) + tagVO.getDivEnd();
}
if (StringUtils.isNotBlank((CharSequence)answerExplanation2)) {
questionContentList.add(answerExplanation2);
}
} else {
if (StringUtils.isNotBlank((CharSequence)answer)) {
questionContentList.add(answerTag + tagVO.getDivStart() + answer + tagVO.getDivEnd());
}
if (CollectionUtils.isNotEmpty(answerExplanationList)) {
answerExplanationList.forEach(answerExplanation -> questionContentList.add(tagVO.getExplanation() + tagVO.getDivStart() + answerExplanation + tagVO.getDivEnd()));
}
}
Boolean isMergeAnswer = !(!EditionEnum.ANSWER.getEdition().equals(edition) && !EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition) || !ANSWER_MERGE_QUESTION_TYPE_SET_OLD.contains(question.getTypeDetailId()) && !ANSWER_MERGE_QUESTION_TYPE_SET_NEW.contains(question.getLogicTypeId()) || !CollectionUtils.isEmpty(answerExplanationList));
if (CollectionUtils.isEmpty(questionContentList)) {
return null;
}
if (Boolean.TRUE.equals(question.getIsShowScore()) && Objects.nonNull(question.getScore()) && question.getScore().compareTo(BigDecimal.ZERO) > 0) {
elementNum = elementNum + "\uff08" + question.getScore().stripTrailingZeros().toPlainString() + "\u5206\uff09";
}
String firstContent = (String)questionContentList.get(0);
if (StringUtils.isNotEmpty((CharSequence)question.getSource()) && fileStyle != null && fileStyle.getQuestionSourceShowFlag() == 1) {
questionContentList.set(0, elementNum + "\uff08" + question.getSource() + "\uff09" + firstContent);
} else {
questionContentList.set(0, elementNum + firstContent);
}
if (QuestionEnum.PARENT_QUESTION.equals((Object)questionEnum)) {
contentList.addAll(questionContentList);
return contentIndex;
}
this.addRestoreInfo(titleList, contentList.size(), firstContent, question.getScore(), isMergeAnswer);
contentList.addAll(questionContentList);
return null;
}
private void addRestoreInfo(List<TitleBO> titleList, int index, String restore, BigDecimal score, Boolean isMergeAnswer) {
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setIndex(Integer.valueOf(index)).setQuestionContent(restore).setScore(score).setIsMergeAnswer(isMergeAnswer));
}
private void addOption(List<String> contentList, QuestionDetailVO question, TagVO tagVO) {
if (Boolean.TRUE.equals(question.getIsSubjective())) {
return;
}
List<String> optionList = this.getOptionList(question, tagVO);
if (Objects.nonNull(question.getOptionColumn()) && question.getOptionColumn() > 1) {
this.addMultiColumnOptionByTab(contentList, optionList, question.getOptionColumn());
} else {
contentList.addAll(optionList);
}
}
private void addMultiColumnOptionByTab(List<String> contentList, List<String> optionList, Integer columnNum) {
if (CollectionUtils.isEmpty(optionList)) {
return;
}
StringBuilder optionBuilder = new StringBuilder();
for (int i = 0; i < optionList.size(); ++i) {
if (i > 0) {
optionBuilder.append(i % columnNum == 0 ? "<br>" : "<tab></tab>");
}
optionBuilder.append(optionList.get(i));
}
contentList.add(optionBuilder.toString());
}
private String addMultiColumnOptionByTab(List<String> optionList, Integer columnNum) {
StringBuilder optionBuilder = new StringBuilder();
for (int i = 0; i < optionList.size(); ++i) {
if (i > 0) {
optionBuilder.append(i % columnNum == 0 ? "<br>" : "<tab></tab>");
}
String option = FileServiceImpl.removeSpaceStrOfEnd(optionList.get(i));
optionBuilder.append(option);
}
return optionBuilder.toString();
}
private List<String> getOptionList(QuestionDetailVO question, TagVO tagVO) {
ArrayList<String> optionList = new ArrayList<String>();
if ("\u5224\u65ad\u9898".equals(question.getTypeDetailName())) {
optionList.add(tagVO.getDivStart() + "T. \u6b63\u786e" + tagVO.getDivEnd());
optionList.add(tagVO.getDivStart() + "F. \u9519\u8bef" + tagVO.getDivEnd());
return optionList;
}
if (StringUtils.isNotBlank((CharSequence)question.getOptionA())) {
String optionA = FileServiceImpl.removeSpaceStrOfEnd(question.getOptionA());
optionList.add("A. " + tagVO.getDivStart() + optionA + tagVO.getDivEnd());
}
if (StringUtils.isNotBlank((CharSequence)question.getOptionB())) {
String optionB = FileServiceImpl.removeSpaceStrOfEnd(question.getOptionB());
optionList.add("B. " + tagVO.getDivStart() + optionB + tagVO.getDivEnd());
}
if (StringUtils.isNotBlank((CharSequence)question.getOptionC())) {
String optionC = FileServiceImpl.removeSpaceStrOfEnd(question.getOptionC());
optionList.add("C. " + tagVO.getDivStart() + optionC + tagVO.getDivEnd());
}
if (StringUtils.isNotBlank((CharSequence)question.getOptionD())) {
String optionD = FileServiceImpl.removeSpaceStrOfEnd(question.getOptionD());
optionList.add("D. " + tagVO.getDivStart() + optionD + tagVO.getDivEnd());
}
if (StringUtils.isNotBlank((CharSequence)question.getOptionE())) {
String optionE = FileServiceImpl.removeSpaceStrOfEnd(question.getOptionE());
optionList.add("E. " + tagVO.getDivStart() + optionE + tagVO.getDivEnd());
}
if (StringUtils.isNotBlank((CharSequence)question.getOptionF())) {
String optionF = FileServiceImpl.removeSpaceStrOfEnd(question.getOptionF());
optionList.add("F. " + tagVO.getDivStart() + optionF + tagVO.getDivEnd());
}
if (StringUtils.isNotBlank((CharSequence)question.getOptionG())) {
String optionG = FileServiceImpl.removeSpaceStrOfEnd(question.getOptionG());
optionList.add("G. " + tagVO.getDivStart() + optionG + tagVO.getDivEnd());
}
return optionList;
}
private static String removeSpaceStrOfEnd(String input) {
if (input == null) {
return null;
}
String step1 = input.replaceAll("(?<=>)([^<]*?)\\s+(?=<)", "$1");
String step2 = step1.replaceAll("\\s+$", "");
return step2;
}
private String notNullContent(String content) {
return StringUtils.isBlank((CharSequence)content) ? "" : content;
}
private String getAttachmentCard(String attachmentCard, Map<String, String> iconMap, Integer elementType, String attachmentName, String qrCodeUrl) {
BizAssert.isNotBlank((String)attachmentCard, (String)"\u9644\u4ef6\u5361\u7247\u6837\u5f0f\u4e3a\u7a7a");
BizAssert.notNull(iconMap, (String)"\u56fe\u6807\u914d\u7f6e\u4fe1\u606f\u4e3a\u7a7a");
ElementTypeEnum elementTypeEnum = ElementTypeEnum.get((Integer)elementType);
BizAssert.notNull((Object)elementTypeEnum, (String)"\u975e\u6cd5\u5143\u7d20\u7c7b\u578b");
qrCodeUrl = StringUtils.isBlank((CharSequence)qrCodeUrl) ? "" : qrCodeUrl;
attachmentName = StringUtils.isBlank((CharSequence)attachmentName) ? "\u672a\u547d\u540d" : attachmentName;
try {
String attachmentIcon = null;
if (ElementTypeEnum.AUDIO.getType().equals(elementType)) {
attachmentIcon = iconMap.get("audioIcon");
} else if (ElementTypeEnum.VIDEO.getType().equals(elementType)) {
attachmentIcon = iconMap.get("videoIcon");
} else if (ElementTypeEnum.GGB.getType().equals(elementType)) {
attachmentIcon = iconMap.get("ggbIcon");
} else if (ElementTypeEnum.CHEMISTRY.getType().equals(elementType)) {
attachmentIcon = iconMap.get("chemistryIcon");
} else if (ElementTypeEnum.MINDMAP.getType().equals(elementType)) {
attachmentIcon = iconMap.get("mindmapIcon");
}
BizAssert.isNotBlank((String)attachmentIcon, (String)("\u672a\u627e\u5230\u5143\u7d20\u3010" + elementTypeEnum.getName() + "\u3011\u56fe\u6807\uff0c\u8bf7\u8054\u7cfb\u7ba1\u7406\u5458"));
assert (attachmentIcon != null);
return attachmentCard.replace("attachmentIcon", attachmentIcon).replace("attachmentName", attachmentName).replace("qrCodeUrl", qrCodeUrl);
}
catch (BusinessException e) {
log.error("\u83b7\u53d6\u9644\u4ef6\u5361\u7247\u6837\u5f0f\u5f02\u5e38, attachmentCard:{}, iconMap:{}, elementType:{},attachmentName:{},qrCodeUrl:{}", new Object[]{attachmentCard, JSON.toJSONString(iconMap), elementType, attachmentName, qrCodeUrl, e});
throw e;
}
catch (Exception e) {
log.error("\u83b7\u53d6\u9644\u4ef6\u5361\u7247\u6837\u5f0f\u5f02\u5e38, attachmentCard:{}, iconMap:{}, elementType:{},attachmentName:{},qrCodeUrl:{}", new Object[]{attachmentCard, JSON.toJSONString(iconMap), elementType, attachmentName, qrCodeUrl, e});
throw new BusinessException("\u83b7\u53d6\u9644\u4ef6\u5361\u7247\u6837\u5f0f\u5f02\u5e38, \u8bf7\u8054\u7cfb\u7ba1\u7406\u5458");
}
}
private String downloadListenAudio(DownloadFileParam param) {
BizAssert.notNull((Object)param.getPdfFile(), (String)"pdf\u6587\u4ef6\u4e3a\u7a7a");
OfficeFileInfoVO fileInfo = (OfficeFileInfoVO)FeignUtils.parse((Result)this.officeFileServiceFeign.getFileInfo(new QueryFileParam().setFileId(param.getFileId())));
this.filterElementList(fileInfo, param.getEdition());
List<ExportQuestionVO> questionList = this.getQuestionList(fileInfo);
return WordExportUtil.createOfficeFile((CreateFileBO)new CreateFileBO().setPdf(param.getPdfFile()).setFileName(fileInfo.getFileName()).setQuestionList(questionList).setDownloadListenType(param.getDownloadListenType()));
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private String downloadPdf(DownloadFileParam param) {
BizAssert.notNull((Object)param.getFileId(), (String)"\u6587\u6863id\u4e3a\u7a7a");
BizAssert.notNull((Object)param.getEdition(), (String)"\u4e0b\u8f7d\u7248\u672c\u4e3a\u7a7a");
String path = WordExportUtil.createPdf((CreatePdfParam)new CreatePdfParam().setShareCode(CodeUtil.convertToCode((long)param.getFileId())).setTemplate(String.format(this.officeFileConfig.getOfficeTemplate(), System.currentTimeMillis(), param.getFileId(), param.getEdition())));
assert (path != null);
File localFile = com.jby.common.util.FileUtil.getFile((String)path);
try {
MultipartFile file = com.jby.common.util.FileUtil.getMultipartFile((String)localFile.getName(), (File)localFile);
OfficeFileInfoVO fileInfo = (OfficeFileInfoVO)FeignUtils.parse((Result)this.officeFileServiceFeign.getFileInfo(new QueryFileParam().setFileId(param.getFileId())));
this.filterElementList(fileInfo, param.getEdition());
List<ExportQuestionVO> questionList = this.getQuestionList(fileInfo);
String string = WordExportUtil.createOfficeFile((CreateFileBO)new CreateFileBO().setPdf(file).setFileName(fileInfo.getFileName()).setQuestionList(questionList).setDownloadListenType(param.getDownloadListenType()));
return string;
}
finally {
FileUtil.del((File)localFile);
}
}
private List<ExportQuestionVO> getQuestionList(OfficeFileInfoVO fileInfo) {
return fileInfo.getElementList().stream().filter(e -> ElementTypeEnum.QUESTION.getType().equals(e.getElementType()) && Objects.nonNull(e.getQuestionDetail())).map(e -> new ExportQuestionVO().setQuestion(e.getQuestionDetail())).collect(Collectors.toList());
}
@Override
public OfficeFileDownloadScheduleVO batchDownloadOfficeFile(NodeParam rootNode) {
OfficeFileDownloadScheduleVO schedule = (OfficeFileDownloadScheduleVO)BeanMapping.toBean((Object)((Object)this.initDownloadSchedule(rootNode)), OfficeFileDownloadScheduleVO.class);
CompletableFuture.runAsync(() -> {
try {
this.asyncExecuteDownloadTask(rootNode, schedule.getId());
log.info("\u6279\u91cf\u4e0b\u8f7d\u5728\u7ebf\u6587\u4ef6\u5f02\u6b65\u4e3b\u7ebf\u7a0b====>\u7ed3\u675f, \u8fdb\u5ea6\u4e3b\u952eid:{}", (Object)schedule.getId());
}
catch (Exception e) {
log.error("\u5f02\u6b65\u4e0b\u8f7d\u4efb\u52a1\u6267\u884c\u5931\u8d25: {}", (Object)e.getMessage(), (Object)e);
}
}, (Executor)this.batchDownloadMainExecutor).exceptionally(e -> {
log.error("\u6279\u91cf\u4e0b\u8f7d\u5728\u7ebf\u6587\u4ef6\u5f02\u6b65\u4e3b\u4efb\u52a1\u63d0\u4ea4\u5931\u8d25: {}", (Object)e.getMessage(), e);
throw new BusinessException("\u6279\u91cf\u4e0b\u8f7d\u5728\u7ebf\u6587\u4ef6\u5f02\u6b65\u4e3b\u4efb\u52a1\u63d0\u4ea4\u5931\u8d25");
});
return schedule;
}
private OfficeFileDownloadSchedule initDownloadSchedule(NodeParam rootNode) {
SessionUser sessionUser = RequestUtil.getSessionUser((boolean)true);
OfficeFileDownloadSchedule progress = new OfficeFileDownloadSchedule();
progress.setCreateBy(sessionUser.getId());
progress.setCreateTime(LocalDateTime.now());
progress.setUpdateBy(sessionUser.getId());
progress.setUpdateTime(LocalDateTime.now());
progress.setFileName(rootNode.getNodeName());
AtomicInteger totalCount = new AtomicInteger(0);
this.countTotalFiles(rootNode, progress, totalCount);
if (this.officeFileConfig.getMaxDownloadNum() < totalCount.get()) {
throw new BusinessException("\u6587\u4ef6\u6570\u91cf\u8d85\u8fc7 " + this.officeFileConfig.getMaxDownloadNum() + "\u4e2a\uff0c\u65e0\u6cd5\u4e0b\u8f7d\uff0c\u8bf7\u91cd\u65b0\u9009\u62e9");
}
this.downloadScheduleService.saveOrUpdate((Object)progress);
return progress;
}
private void countTotalFiles(NodeParam rootNode, OfficeFileDownloadSchedule progress, AtomicInteger totalCount) {
if (rootNode.getIsFile().booleanValue()) {
progress.setTotalCount(totalCount.incrementAndGet());
} else if (CollectionUtils.isNotEmpty((Collection)rootNode.getNodeList())) {
for (NodeParam child : rootNode.getNodeList()) {
this.countTotalFiles(child, progress, totalCount);
}
}
}
private void asyncExecuteDownloadTask(NodeParam rootNode, Long id) {
OfficeFileDownloadSchedule downloadProgress = (OfficeFileDownloadSchedule)((Object)this.downloadScheduleService.getById(id));
ArrayList<CompletableFuture<Void>> downloadFutures = new ArrayList<CompletableFuture<Void>>();
try {
this.submitDownloadTasks(rootNode, "", downloadFutures);
}
catch (Exception e) {
log.error("\u4e0b\u8f7d\u4efb\u52a1\u5f02\u5e38{}", (Object)e.getMessage());
downloadProgress.setStatus(Integer.valueOf(DownScheduleTypeEnum.FAIL_TYPE.getType()));
this.officeFileDownloadScheduleMapper.updateById((Object)downloadProgress);
throw new BusinessException("\u4e0b\u8f7d\u4efb\u52a1\u5f02\u5e38");
}
CompletableFuture.allOf(downloadFutures.toArray(new CompletableFuture[0])).join();
String saveKey = AttachmentUtil.organize((NodeParam)rootNode);
AtomicInteger successCount = new AtomicInteger(0);
AtomicInteger failureCount = new AtomicInteger(0);
try {
for (CompletableFuture completableFuture : downloadFutures) {
try {
completableFuture.join();
downloadProgress.setSuccessCount(successCount.incrementAndGet());
}
catch (CompletionException e) {
log.error("Download task failed\uff1a{}", (Object)e.getMessage());
downloadProgress.setFailCount(failureCount.incrementAndGet());
}
}
String sourceKey = saveKey + "/" + rootNode.getNodeName();
String string = AttachmentUtil.compressToZip((String)sourceKey, (String)saveKey, (String)rootNode.getNodeName());
log.info("Compression completed: {}", (Object)string);
downloadProgress.setFileUrl(string);
downloadProgress.setStatus(Integer.valueOf(DownScheduleTypeEnum.SUCCESS_TYPE.getType()));
this.officeFileDownloadScheduleMapper.updateById((Object)downloadProgress);
}
catch (Exception e) {
log.error("\u538b\u7f29\u5931\u8d25\uff1a{}", (Object)e.getMessage());
downloadProgress.setStatus(Integer.valueOf(DownScheduleTypeEnum.FAIL_TYPE.getType()));
this.officeFileDownloadScheduleMapper.updateById((Object)downloadProgress);
throw new BusinessException("\u538b\u7f29\u5931\u8d25");
}
}
private void submitDownloadTasks(NodeParam node, String currentPath, List<CompletableFuture<Void>> downloadFutures) {
if (node.getIsFile().booleanValue()) {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
if (node.getOfficeFileId() != null && StringUtils.isBlank((CharSequence)node.getFileUrl())) {
DownloadFileParam param = new DownloadFileParam();
param.setFileId(node.getOfficeFileId());
param.setFileType(FileTypeEnum.WORD.getType());
param.setEdition(EditionEnum.TEACHER.getEdition());
param.setDownloadListenType(ListenEnum.COMBINE_FILE.getType());
try {
String filePath = this.downloadOfficeFile(param);
node.setFileUrl(filePath);
}
catch (Exception e) {
log.error("Download task failed for file {}: {}", new Object[]{node.getOfficeFileId(), e.getMessage(), e});
}
}
}, (Executor)this.batchDownloadTaskExecutor);
downloadFutures.add(future);
} else {
String newPath = currentPath + node.getNodeName() + "/";
if (CollectionUtils.isNotEmpty((Collection)node.getNodeList())) {
node.getNodeList().forEach(child -> this.submitDownloadTasks((NodeParam)child, newPath, downloadFutures));
}
}
}
public OfficeFileDownloadScheduleVO batchDownloadOfficeFile2(NodeParam rootNode) {
OfficeFileDownloadSchedule downloadProgress = this.initDownloadSchedule(rootNode);
String parentPath = this.initDownloadPath();
ArrayList<CompletableFuture<Void>> downloadFutures = new ArrayList<CompletableFuture<Void>>();
this.submitDownloadTasks(rootNode, "", downloadFutures);
CompletableFuture.allOf(downloadFutures.toArray(new CompletableFuture[0])).join();
String saveKey = AttachmentUtil.organize((NodeParam)rootNode);
CompletableFuture<Void> allDownloadsFuture = CompletableFuture.allOf(downloadFutures.toArray(new CompletableFuture[0]));
CompletionStage future = allDownloadsFuture.thenApplyAsync(v -> {
AtomicInteger successCount = new AtomicInteger(0);
AtomicInteger failureCount = new AtomicInteger(0);
try {
for (CompletableFuture downloadFuture : downloadFutures) {
try {
downloadFuture.join();
downloadProgress.setSuccessCount(successCount.incrementAndGet());
}
catch (CompletionException e) {
log.error("Download task failed", e.getCause());
downloadProgress.setFailCount(failureCount.incrementAndGet());
}
}
String sourceKey = saveKey + "/" + rootNode.getNodeName();
String zipPath = AttachmentUtil.compressToZip((String)sourceKey, (String)saveKey, (String)rootNode.getNodeName());
log.info("Compression completed: {}", (Object)zipPath);
downloadProgress.setFileUrl(zipPath);
downloadProgress.setStatus(Integer.valueOf(DownScheduleTypeEnum.SUCCESS_TYPE.getType()));
this.officeFileDownloadScheduleMapper.updateById((Object)downloadProgress);
return downloadProgress;
}
catch (Exception e) {
log.error("Compression failed", (Throwable)e);
downloadProgress.setStatus(Integer.valueOf(DownScheduleTypeEnum.FAIL_TYPE.getType()));
this.officeFileDownloadScheduleMapper.updateById((Object)downloadProgress);
return null;
}
}, (Executor)this.batchDownloadTaskExecutor);
OfficeFileDownloadSchedule join = (OfficeFileDownloadSchedule)((Object)((CompletableFuture)future).join());
return (OfficeFileDownloadScheduleVO)BeanMapping.toBean((Object)((Object)join), OfficeFileDownloadScheduleVO.class, (s, t) -> t.setId(s.getId()));
}
private String initDownloadPath() {
return SpringContextHolder.getActiveProfile() + "/" + AttachmentModuleEnum.OFFICE_FILE.getModule() + "/" + "organize" + "/" + LocalDateTime.now().format(DateTimeFormatter.BASIC_ISO_DATE) + "/" + UniqueUtil.getUuid();
}
@Override
public OfficeFileParseRecordVO getOfficeFileParseRecordByMd5(String md5) {
List officeFileParseRecordList = this.officeFileParseRecordService.list((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery().eq(OfficeFileParseRecord::getFileMd5, (Object)md5)).orderByDesc(CommonBean::getCreateTime));
if (CollectionUtils.isNotEmpty((Collection)officeFileParseRecordList)) {
return (OfficeFileParseRecordVO)BeanMapping.toBean(officeFileParseRecordList.get(0), OfficeFileParseRecordVO.class);
}
return null;
}
@Override
public void saveOfficeFileParseRecord(OfficeFileParseRecordParam param) {
OfficeFileParseRecord bean = (OfficeFileParseRecord)((Object)BeanMapping.toBean((Object)param, OfficeFileParseRecord.class));
this.officeFileParseRecordService.save((Object)bean);
if (Objects.nonNull(bean.getFileId()) && bean.getFileId() > 0L && StringUtils.isNotBlank((CharSequence)bean.getFileUrl())) {
UpdateFileParam updateFileParam = new UpdateFileParam();
updateFileParam.setFileUrl(bean.getFileUrl());
updateFileParam.setFileId(bean.getFileId());
this.officeFileServiceFeign.updateFileUrl(updateFileParam);
}
}
@Override
public List<OfficeFileParseRecordVO> queryFileUrlByFileIds(OfficeFileParseRecordParam param) {
List officeFileParseRecordList = this.officeFileParseRecordService.list((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery().in(OfficeFileParseRecord::getFileId, (Collection)param.getFileIds())).orderByDesc(CommonBean::getCreateTime));
if (CollectionUtils.isEmpty((Collection)officeFileParseRecordList)) {
return Collections.emptyList();
}
return officeFileParseRecordList.stream().map(record -> (OfficeFileParseRecordVO)BeanMapping.toBean((Object)record, OfficeFileParseRecordVO.class)).collect(Collectors.toList());
}
private void addOption(QuestionDetailVO question, List<String> contentList, String questionNumber) {
if (Boolean.FALSE.equals(question.getIsSubjective()) && CollectionUtils.isNotEmpty((Collection)question.getOptionsList())) {
AtomicInteger counter = new AtomicInteger(0);
List<String> optionList = question.getOptionsList().stream().filter(StringUtils::isNotBlank).map(m -> (char)(65 + counter.getAndIncrement()) + "." + m.replace("<p>", "<span>").replace("</p>", "</span>")).collect(Collectors.toList());
if (Objects.nonNull(question.getOptionColumn()) && question.getOptionColumn() > 1) {
contentList.add(questionNumber + this.addMultiColumnOptionByTab(optionList, question.getOptionColumn()));
} else {
for (int i = 0; i < optionList.size(); ++i) {
if (i == 0 && Objects.nonNull(question.getQuestionNumber())) {
contentList.add(questionNumber + optionList.get(i));
continue;
}
contentList.add((String)optionList.get(i));
}
}
}
}
private void dealCombination(QuestionDetailVO question, Integer edition, TagVO tagVO, List<String> contentList, OfficeFileStyleVO fileStyle) {
String allExplation;
boolean isAnswerEdition = EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition);
String string = allExplation = CollectionUtils.isEmpty((Collection)question.getAnswerExplanation()) ? "" : (String)question.getAnswerExplanation().get(0);
if (!isAnswerEdition) {
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
}
String contentPrefix1 = this.getContentPrefix(question, fileStyle);
contentList.add(contentPrefix1 + tagVO.getDivStart() + question.getContent() + tagVO.getDivEnd());
if (CollectionUtils.isNotEmpty((Collection)question.getChildList())) {
question.getChildList().forEach(two -> {
String contentPrefix2 = this.getContentPrefix((QuestionDetailVO)two, fileStyle);
contentList.add(contentPrefix2 + tagVO.getDivStart() + two.getContent() + tagVO.getDivEnd());
this.addOption((QuestionDetailVO)two, contentList, "");
if (CollectionUtils.isNotEmpty((Collection)two.getChildList())) {
two.getChildList().forEach(three -> {
if (LogicTypeEnum.MULTIPLE_CHOOSE_MULTIPLE.getLogicTypeId().equals(three.getLogicTypeId())) {
return;
}
String contentPrefix3 = this.getContentPrefix((QuestionDetailVO)three, fileStyle);
contentList.add(contentPrefix3 + tagVO.getDivStart() + three.getContent() + tagVO.getDivEnd());
this.addOption((QuestionDetailVO)three, contentList, "");
});
}
});
}
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
HashMap questionMap = new HashMap();
AtomicBoolean lastMerger = new AtomicBoolean(false);
if (CollectionUtils.isNotEmpty((Collection)question.getChildList())) {
ArrayList twoAnswerList = new ArrayList();
question.getChildList().forEach(two -> {
questionMap.put(two.getQuestionId(), two);
String twoAnswer = two.getAnswer();
if (StringUtils.isNotBlank((CharSequence)twoAnswer) && !LogicTypeEnum.MULTIPLE_CHOOSE_MULTIPLE.getLogicTypeId().equals(two.getLogicTypeId())) {
if (CollectionUtils.isEmpty((Collection)twoAnswerList)) {
twoAnswerList.add(tagVO.getAnswer() + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(two.getShowQuestionNumber(), twoAnswer) + tagVO.getDivEnd());
} else if (lastMerger.get() || LogicTypeEnum.RESPONSE.getLogicTypeId().equals(two.getLogicTypeId()) || LogicTypeEnum.COMBINATION.getLogicTypeId().equals(two.getLogicTypeId())) {
twoAnswerList.add(tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(two.getShowQuestionNumber(), twoAnswer) + tagVO.getDivEnd());
} else {
twoAnswerList.set(twoAnswerList.size() - 1, (String)twoAnswerList.get(twoAnswerList.size() - 1) + " " + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(two.getShowQuestionNumber(), twoAnswer) + tagVO.getDivEnd());
}
lastMerger.set(LogicTypeEnum.RESPONSE.getLogicTypeId().equals(two.getLogicTypeId()) || LogicTypeEnum.COMBINATION.getLogicTypeId().equals(two.getLogicTypeId()));
}
if (CollectionUtils.isNotEmpty((Collection)two.getChildList())) {
ArrayList threeAnswerList = Lists.newArrayList();
two.getChildList().forEach(three -> {
String threeAnswer = three.getAnswer();
if (StringUtils.isNotBlank((CharSequence)threeAnswer)) {
if (CollectionUtils.isEmpty((Collection)threeAnswerList)) {
threeAnswerList.add(((QuestionDetailVO)questionMap.get(three.getParentId())).getShowQuestionNumber() + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(three.getShowQuestionNumber(), threeAnswer) + tagVO.getDivEnd());
if (CollectionUtils.isEmpty((Collection)twoAnswerList)) {
threeAnswerList.set(0, tagVO.getAnswer() + (String)threeAnswerList.get(0));
}
} else if (lastMerger.get() || LogicTypeEnum.RESPONSE.getLogicTypeId().equals(three.getLogicTypeId())) {
threeAnswerList.add(tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(three.getShowQuestionNumber(), threeAnswer) + tagVO.getDivEnd());
} else {
threeAnswerList.set(threeAnswerList.size() - 1, (String)threeAnswerList.get(threeAnswerList.size() - 1) + " " + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(three.getShowQuestionNumber(), threeAnswer) + tagVO.getDivEnd());
}
lastMerger.set(LogicTypeEnum.RESPONSE.getLogicTypeId().equals(two.getLogicTypeId()));
}
});
if (CollectionUtils.isNotEmpty((Collection)threeAnswerList)) {
twoAnswerList.addAll(threeAnswerList);
}
}
});
if (CollectionUtils.isNotEmpty(twoAnswerList)) {
contentList.addAll(twoAnswerList.stream().map(m -> FileServiceImpl.checkContentStyle(m) ? m.replace("<p>", "<span>").replace("</p>", "</span>") : m).collect(Collectors.toList()));
}
}
if (CollectionUtils.isNotEmpty((Collection)question.getChildList())) {
ArrayList twoExplanationList = new ArrayList();
question.getChildList().forEach(two -> {
if (CollectionUtils.isNotEmpty((Collection)two.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)two.getAnswerExplanation().get(0)))) {
if (CollectionUtils.isEmpty((Collection)twoExplanationList)) {
twoExplanationList.add(tagVO.getExplanation() + tagVO.getDivStart() + allExplation + FileServiceImpl.joinQuestionNum(two.getShowQuestionNumber(), (String)two.getAnswerExplanation().get(0)) + tagVO.getDivEnd());
} else {
twoExplanationList.add(tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(two.getShowQuestionNumber(), (String)two.getAnswerExplanation().get(0)) + tagVO.getDivEnd());
}
}
if (CollectionUtils.isNotEmpty((Collection)two.getChildList())) {
ArrayList threeExplanationList = new ArrayList();
two.getChildList().forEach(three -> {
if (CollectionUtils.isNotEmpty((Collection)three.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)three.getAnswerExplanation().get(0)))) {
if (CollectionUtils.isEmpty((Collection)threeExplanationList)) {
threeExplanationList.add(((QuestionDetailVO)questionMap.get(three.getParentId())).getShowQuestionNumber() + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(three.getShowQuestionNumber(), (String)three.getAnswerExplanation().get(0)) + tagVO.getDivEnd());
if (CollectionUtils.isEmpty((Collection)twoExplanationList)) {
threeExplanationList.set(0, tagVO.getExplanation() + allExplation + (String)threeExplanationList.get(0));
}
} else {
threeExplanationList.add(tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(three.getShowQuestionNumber(), (String)three.getAnswerExplanation().get(0)) + tagVO.getDivEnd());
}
}
});
if (CollectionUtils.isNotEmpty(threeExplanationList)) {
twoExplanationList.addAll(threeExplanationList);
}
}
});
if (CollectionUtils.isNotEmpty(twoExplanationList)) {
contentList.addAll(twoExplanationList.stream().map(m -> FileServiceImpl.checkContentStyle(m) ? m.replace("<p>", "<span>").replace("</p>", "</span>") : m).collect(Collectors.toList()));
}
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
}
} else {
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
if (StringUtils.isNotBlank((CharSequence)allExplation)) {
contentList.add(tagVO.getDivStart() + allExplation + tagVO.getDivEnd());
}
}
HashMap<Long, QuestionDetailVO> questionMap = new HashMap<Long, QuestionDetailVO>();
questionMap.put(question.getQuestionId(), question);
if (CollectionUtils.isNotEmpty((Collection)question.getChildList())) {
ArrayList twoAnswerExplanationList = new ArrayList();
AtomicInteger index = new AtomicInteger(0);
question.getChildList().forEach(two -> {
FileServiceImpl.dealQuestionAnswerExplationStyle(two);
questionMap.put(two.getQuestionId(), (QuestionDetailVO)two);
String twoAnswer = two.getAnswer();
String twoTmp = "";
if (StringUtils.isNotBlank((CharSequence)twoAnswer) && !LogicTypeEnum.MULTIPLE_CHOOSE_MULTIPLE.getLogicTypeId().equals(two.getLogicTypeId())) {
twoTmp = twoTmp + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(two.getShowQuestionNumber(), twoAnswer) + tagVO.getDivEnd();
}
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)two.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)two.getAnswerExplanation().get(0)))) {
twoTmp = LogicTypeEnum.MULTIPLE_CHOOSE_MULTIPLE.getLogicTypeId().equals(two.getLogicTypeId()) ? twoTmp + tagVO.getDivStart() + (String)two.getAnswerExplanation().get(0) + tagVO.getDivEnd() : (LogicTypeEnum.RESPONSE.getLogicTypeId().equals(two.getLogicTypeId()) ? twoTmp + "<br/>" + tagVO.getExplanation() + tagVO.getDivStart() + (String)two.getAnswerExplanation().get(0) + tagVO.getDivEnd() : twoTmp + tagVO.getExplanation() + tagVO.getDivStart() + (String)two.getAnswerExplanation().get(0) + tagVO.getDivEnd());
twoTmp = twoTmp + "###\u3010\u4e0d\u5408\u5e76\u3011###";
}
if (StringUtils.isNotBlank((CharSequence)twoTmp)) {
if (!twoTmp.contains(tagVO.getExplanation()) && (LogicTypeEnum.RESPONSE.getLogicTypeId().equals(two.getLogicTypeId()) || LogicTypeEnum.COMBINATION.getLogicTypeId().equals(two.getLogicTypeId()))) {
twoAnswerExplanationList.add(twoTmp + "###\u3010\u4e0d\u5408\u5e76\u3011###");
} else {
twoAnswerExplanationList.add(twoTmp);
}
}
if (CollectionUtils.isNotEmpty((Collection)two.getChildList())) {
ArrayList threeAnswerExplanationList = new ArrayList();
two.getChildList().forEach(three -> {
FileServiceImpl.dealQuestionAnswerExplationStyle(three);
String threeAnswer = three.getAnswer();
String threeTmp = "";
if (StringUtils.isNotBlank((CharSequence)threeAnswer)) {
threeTmp = threeTmp + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(three.getShowQuestionNumber(), threeAnswer) + tagVO.getDivEnd();
}
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)three.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)three.getAnswerExplanation().get(0)))) {
threeTmp = threeTmp + tagVO.getExplanation() + tagVO.getDivStart() + (String)three.getAnswerExplanation().get(0) + tagVO.getDivEnd() + "###\u3010\u4e0d\u5408\u5e76\u3011###";
}
if (StringUtils.isNotBlank((CharSequence)threeTmp)) {
if (CollectionUtils.isEmpty((Collection)threeAnswerExplanationList)) {
threeTmp = ((QuestionDetailVO)questionMap.get(three.getParentId())).getShowQuestionNumber() + threeTmp;
}
if (!threeTmp.contains(tagVO.getExplanation()) && LogicTypeEnum.RESPONSE.getLogicTypeId().equals(three.getLogicTypeId())) {
threeAnswerExplanationList.add(threeTmp + "###\u3010\u4e0d\u5408\u5e76\u3011###");
} else {
threeAnswerExplanationList.add(threeTmp);
}
}
});
if (CollectionUtils.isNotEmpty(threeAnswerExplanationList)) {
twoAnswerExplanationList.addAll(threeAnswerExplanationList);
}
}
if (index.getAndIncrement() == 0 && CollectionUtils.isNotEmpty((Collection)twoAnswerExplanationList)) {
String content = (String)twoAnswerExplanationList.get(0);
String newContent = question.getShowQuestionNumber() + content;
twoAnswerExplanationList.set(0, newContent);
}
});
if (CollectionUtils.isNotEmpty(twoAnswerExplanationList)) {
contentList.addAll(twoAnswerExplanationList);
}
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
}
}
private void dealBlank(QuestionDetailVO question, Integer edition, TagVO tagVO, List<String> contentList, OfficeFileStyleVO fileStyle) {
boolean isAnswerEdition;
boolean bl = isAnswerEdition = EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition);
if (!isAnswerEdition) {
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
}
String contentPrefix = this.getContentPrefix(question, fileStyle);
String questionStem = contentPrefix + tagVO.getDivStart() + question.getContent() + tagVO.getDivEnd();
List numList = question.getChildList().stream().map(QuestionDetailVO::getShowQuestionNumber).collect(Collectors.toList());
Document parse = Jsoup.parseBodyFragment((String)questionStem);
parse.outputSettings().prettyPrint(false).indentAmount(0);
Elements numberSpans = parse.select("span.tinymce-horizontal-number, span.tinymce-line-number");
for (int i = 0; i < numberSpans.size(); ++i) {
Element span = (Element)numberSpans.get(i);
span.html(span.html().replaceAll("\\d+\\.?", (String)numList.get(i)).replace("&nbsp;", "&ensp;"));
}
contentList.add(parse.body().html());
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
String answer = question.getChildList().stream().filter(f -> StringUtils.isNotBlank((CharSequence)f.getAnswer())).map(m -> FileServiceImpl.joinQuestionNum2(m.getShowQuestionNumber(), m.getAnswer())).collect(Collectors.joining(" "));
if (StringUtils.isNotBlank((CharSequence)answer)) {
contentList.add(tagVO.getAnswer() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle(answer) ? answer.replace("<p>", "<span>").replace("</p>", "</span>") : answer) + tagVO.getDivEnd());
}
ArrayList<String> answerExplanation = new ArrayList<String>();
if (CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)question.getAnswerExplanation().get(0)))) {
answerExplanation.add(tagVO.getDivStart() + (String)question.getAnswerExplanation().get(0) + tagVO.getDivEnd());
}
answerExplanation.addAll(question.getChildList().stream().filter(f -> CollectionUtils.isNotEmpty((Collection)f.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)f.getAnswerExplanation().get(0)))).map(m -> FileServiceImpl.joinQuestionNum(m.getShowQuestionNumber(), (String)m.getAnswerExplanation().get(0))).collect(Collectors.toList()));
if (CollectionUtils.isNotEmpty(answerExplanation)) {
for (int i = 0; i < answerExplanation.size(); ++i) {
if (i == 0) {
contentList.add(tagVO.getExplanation() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle((String)answerExplanation.get(i)) ? ((String)answerExplanation.get(i)).replace("<p>", "<span>").replace("</p>", "</span>") : (String)answerExplanation.get(i)) + tagVO.getDivEnd());
continue;
}
contentList.add(tagVO.getDivStart() + (FileServiceImpl.checkContentStyle((String)answerExplanation.get(i)) ? ((String)answerExplanation.get(i)).replace("<p>", "<span>").replace("</p>", "</span>") : (String)answerExplanation.get(i)) + tagVO.getDivEnd());
}
}
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
} else {
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
}
ArrayList<String> answerExplanationList = new ArrayList<String>();
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)question.getAnswerExplanation().get(0)))) {
answerExplanationList.add(tagVO.getDivStart() + (String)question.getAnswerExplanation().get(0) + tagVO.getDivEnd());
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
answerExplanationList.addAll(question.getChildList().stream().map(m -> {
String tmp = "";
if (StringUtils.isNotBlank((CharSequence)m.getAnswer())) {
tmp = tmp + FileServiceImpl.joinQuestionNum(m.getShowQuestionNumber(), m.getAnswer());
}
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)m.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)m.getAnswerExplanation().get(0)))) {
tmp = tmp + tagVO.getExplanation() + tagVO.getDivStart() + (String)m.getAnswerExplanation().get(0) + tagVO.getDivEnd() + "###\u3010\u4e0d\u5408\u5e76\u3011###";
}
return tmp;
}).collect(Collectors.toList()));
} else {
String answer = question.getChildList().stream().filter(f -> StringUtils.isNotBlank((CharSequence)f.getAnswer())).map(m -> FileServiceImpl.joinQuestionNum2(m.getShowQuestionNumber(), m.getAnswer())).collect(Collectors.joining(" "));
answerExplanationList.add(answer);
}
if (CollectionUtils.isNotEmpty(answerExplanationList)) {
contentList.addAll(answerExplanationList.stream().map(m -> FileServiceImpl.checkContentStyle(m) ? m.replace("<p>", "<span>").replace("</p>", "</span>") : m).collect(Collectors.toList()));
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
}
}
private void dealCompletion(QuestionDetailVO question, Integer edition, TagVO tagVO, List<String> contentList, OfficeFileStyleVO fileStyle) {
boolean isAnswerEdition;
boolean bl = isAnswerEdition = EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition);
if (!isAnswerEdition) {
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
}
String contentPrefix = this.getContentPrefix(question, fileStyle);
String questionStem = contentPrefix + tagVO.getDivStart() + question.getContent() + tagVO.getDivEnd();
List numList = question.getChildList().stream().map(QuestionDetailVO::getQuestionNumber).collect(Collectors.toList());
Document parse = Jsoup.parseBodyFragment((String)questionStem);
parse.outputSettings().prettyPrint(false).indentAmount(0);
Elements numberSpans = parse.select("span.tinymce-horizontal-number, span.tinymce-line-number");
for (int i = 0; i < numberSpans.size(); ++i) {
Element span = (Element)numberSpans.get(i);
span.html(span.html().replaceAll("\\d+\\.?", (String)numList.get(i)).replace("&nbsp;", "&ensp;"));
}
contentList.add(parse.body().html());
question.getChildList().forEach(f -> this.addOption((QuestionDetailVO)f, contentList, f.getShowQuestionNumber()));
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
String answer = question.getChildList().stream().filter(f -> StringUtils.isNotBlank((CharSequence)f.getAnswer())).map(m -> FileServiceImpl.joinQuestionNum2(m.getShowQuestionNumber(), m.getAnswer())).collect(Collectors.joining(" "));
if (StringUtils.isNotBlank((CharSequence)answer)) {
contentList.add(tagVO.getAnswer() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle(answer) ? answer.replace("<p>", "<span>").replace("</p>", "</span>") : answer) + tagVO.getDivEnd());
}
ArrayList<String> answerExplanation = new ArrayList<String>();
if (CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)question.getAnswerExplanation().get(0)))) {
answerExplanation.add(tagVO.getDivStart() + (String)question.getAnswerExplanation().get(0) + tagVO.getDivEnd());
}
answerExplanation.addAll(question.getChildList().stream().filter(f -> CollectionUtils.isNotEmpty((Collection)f.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)f.getAnswerExplanation().get(0)))).map(m -> FileServiceImpl.joinQuestionNum(m.getShowQuestionNumber(), (String)m.getAnswerExplanation().get(0))).collect(Collectors.toList()));
if (CollectionUtils.isNotEmpty(answerExplanation)) {
for (int i = 0; i < answerExplanation.size(); ++i) {
if (i == 0) {
contentList.add(tagVO.getExplanation() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle((String)answerExplanation.get(i)) ? ((String)answerExplanation.get(i)).replace("<p>", "<span>").replace("</p>", "</span>") : (String)answerExplanation.get(i)) + tagVO.getDivEnd());
continue;
}
contentList.add(tagVO.getDivStart() + (FileServiceImpl.checkContentStyle((String)answerExplanation.get(i)) ? ((String)answerExplanation.get(i)).replace("<p>", "<span>").replace("</p>", "</span>") : (String)answerExplanation.get(i)) + tagVO.getDivEnd());
}
}
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
} else {
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
}
ArrayList<String> answerExplanationList = new ArrayList<String>();
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)question.getAnswerExplanation().get(0)))) {
answerExplanationList.add(tagVO.getDivStart() + (String)question.getAnswerExplanation().get(0) + tagVO.getDivEnd());
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
answerExplanationList.addAll(question.getChildList().stream().map(m -> {
String tmp = "";
if (StringUtils.isNotBlank((CharSequence)m.getAnswer())) {
tmp = tmp + FileServiceImpl.joinQuestionNum(m.getShowQuestionNumber(), m.getAnswer());
}
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)m.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)m.getAnswerExplanation().get(0)))) {
tmp = tmp + tagVO.getExplanation() + tagVO.getDivStart() + (String)m.getAnswerExplanation().get(0) + tagVO.getDivEnd() + "###\u3010\u4e0d\u5408\u5e76\u3011###";
}
return tmp;
}).collect(Collectors.toList()));
} else {
String answer = question.getChildList().stream().filter(f -> StringUtils.isNotBlank((CharSequence)f.getAnswer())).map(m -> FileServiceImpl.joinQuestionNum2(m.getShowQuestionNumber(), m.getAnswer())).collect(Collectors.joining(" "));
answerExplanationList.add(answer);
}
if (CollectionUtils.isNotEmpty(answerExplanationList)) {
contentList.addAll(answerExplanationList.stream().map(m -> FileServiceImpl.checkContentStyle(m) ? m.replace("<p>", "<span>").replace("</p>", "</span>") : m).collect(Collectors.toList()));
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
}
}
private void dealMultipleChooseMultiple(QuestionDetailVO question, Integer edition, TagVO tagVO, List<String> contentList, OfficeFileStyleVO fileStyle) {
boolean isAnswerEdition;
boolean bl = isAnswerEdition = EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition);
if (!isAnswerEdition) {
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
}
String contentPrefix = this.getContentPrefix(question, fileStyle);
String questionStem = contentPrefix + tagVO.getDivStart() + question.getContent() + tagVO.getDivEnd();
List numList = question.getChildList().stream().map(QuestionDetailVO::getQuestionNumber).collect(Collectors.toList());
Document parse = Jsoup.parseBodyFragment((String)questionStem);
parse.outputSettings().prettyPrint(false).indentAmount(0);
Elements numberSpans = parse.select("span.tinymce-horizontal-number, span.tinymce-line-number");
for (int i = 0; i < numberSpans.size(); ++i) {
Element span = (Element)numberSpans.get(i);
span.html(span.html().replaceAll("\\d+\\.?", (String)numList.get(i)).replace("&nbsp;", "&ensp;"));
}
contentList.add(parse.body().html());
this.addOption(question, contentList, "");
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
String answer = question.getChildList().stream().filter(f -> StringUtils.isNotBlank((CharSequence)f.getAnswer())).map(m -> FileServiceImpl.joinQuestionNum2(m.getShowQuestionNumber(), m.getAnswer())).collect(Collectors.joining(" "));
if (StringUtils.isNotBlank((CharSequence)answer)) {
contentList.add(tagVO.getAnswer() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle(answer) ? answer.replace("<p>", "<span>").replace("</p>", "</span>") : answer) + tagVO.getDivEnd());
}
ArrayList<String> answerExplanation = new ArrayList<String>();
if (CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)question.getAnswerExplanation().get(0)))) {
answerExplanation.add(tagVO.getDivStart() + (String)question.getAnswerExplanation().get(0) + tagVO.getDivEnd());
}
answerExplanation.addAll(question.getChildList().stream().filter(f -> CollectionUtils.isNotEmpty((Collection)f.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)f.getAnswerExplanation().get(0)))).map(m -> FileServiceImpl.joinQuestionNum(m.getShowQuestionNumber(), (String)m.getAnswerExplanation().get(0))).collect(Collectors.toList()));
if (CollectionUtils.isNotEmpty(answerExplanation)) {
for (int i = 0; i < answerExplanation.size(); ++i) {
if (i == 0) {
contentList.add(tagVO.getExplanation() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle((String)answerExplanation.get(i)) ? ((String)answerExplanation.get(i)).replace("<p>", "<span>").replace("</p>", "</span>") : (String)answerExplanation.get(i)) + tagVO.getDivEnd());
continue;
}
contentList.add(tagVO.getDivStart() + (FileServiceImpl.checkContentStyle((String)answerExplanation.get(i)) ? ((String)answerExplanation.get(i)).replace("<p>", "<span>").replace("</p>", "</span>") : (String)answerExplanation.get(i)) + tagVO.getDivEnd());
}
}
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
} else {
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 1);
}
ArrayList<String> answerExplanationList = new ArrayList<String>();
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)question.getAnswerExplanation().get(0)))) {
answerExplanationList.add(tagVO.getDivStart() + (String)question.getAnswerExplanation().get(0) + tagVO.getDivEnd());
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
answerExplanationList.addAll(question.getChildList().stream().map(m -> {
String tmp = "";
if (StringUtils.isNotBlank((CharSequence)m.getAnswer())) {
tmp = tmp + FileServiceImpl.joinQuestionNum(m.getShowQuestionNumber(), m.getAnswer());
}
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)m.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)m.getAnswerExplanation().get(0)))) {
tmp = tmp + tagVO.getExplanation() + tagVO.getDivStart() + (String)m.getAnswerExplanation().get(0) + tagVO.getDivEnd() + "###\u3010\u4e0d\u5408\u5e76\u3011###";
}
return tmp;
}).collect(Collectors.toList()));
} else {
String answer = question.getChildList().stream().filter(f -> StringUtils.isNotBlank((CharSequence)f.getAnswer())).map(m -> FileServiceImpl.joinQuestionNum2(m.getShowQuestionNumber(), m.getAnswer())).collect(Collectors.joining(" "));
answerExplanationList.add(answer);
}
if (CollectionUtils.isNotEmpty(answerExplanationList)) {
contentList.addAll(answerExplanationList.stream().map(m -> FileServiceImpl.checkContentStyle(m) ? m.replace("<p>", "<span>").replace("</p>", "</span>") : m).collect(Collectors.toList()));
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, question, tagVO, contentList, 2);
}
}
}
private void collectQuestionBankInfo(List<String> contentList, Integer edition, OfficeConfigVO officeConfig, OfficeFileElementVO element, List<TitleBO> titleList, List<ExportQuestionVO> questionList, OfficeFileStyleVO fileStyle) {
QuestionDetailVO one = element.getQuestionDetail();
int startIndex = contentList.size();
if (Objects.nonNull(one)) {
questionList.add(new ExportQuestionVO().setQuestion(one));
if (EditionEnum.STUDENT.getEdition().equals(edition) || EditionEnum.TEACHER.getEdition().equals(edition)) {
if (LogicTypeEnum.COMBINATION.getLogicTypeId().equals(one.getLogicTypeId()) && Objects.nonNull(one.getMergerType()) && one.getMergerType() == 1) {
BigDecimal score = one.getChildList().stream().map(m -> {
if (CollectionUtils.isNotEmpty((Collection)m.getChildList())) {
return m.getChildList().stream().filter(c2 -> Objects.nonNull(c2.getScore()) && c2.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
}
return Objects.nonNull(m.getScore()) ? m.getScore() : BigDecimal.ZERO;
}).reduce(BigDecimal.ZERO, BigDecimal::add);
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(one.getContent()).setScore(score));
} else if (CollectionUtils.isNotEmpty((Collection)one.getChildList())) {
for (QuestionDetailVO child1 : one.getChildList()) {
if ("\u6bb5\u843d".equals(child1.getLogicTypeName())) continue;
if (CollectionUtils.isNotEmpty((Collection)child1.getChildList())) {
List child1List = child1.getChildList();
if (child1.getLogicTypeName().equals("\u7ec4\u5408")) {
BigDecimal reduce = child1List.stream().filter(m -> Objects.nonNull(m.getScore()) && m.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(child1.getContent()).setScore(reduce));
continue;
}
child1List.forEach(child2 -> ((TitleBO)titleList.get(titleList.size() - 1)).getQuestionList().add(new QuestionBO().setQuestionContent(child2.getContent()).setScore(child2.getScore())));
continue;
}
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(child1.getContent()).setScore(child1.getScore()));
}
} else {
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(one.getContent()).setScore(one.getScore()));
}
}
TagVO tagVO = officeConfig.getTagVO();
if (LogicTypeEnum.COMBINATION.getLogicTypeId().equals(one.getLogicTypeId())) {
this.dealCombination(one, edition, tagVO, contentList, fileStyle);
} else if (LogicTypeEnum.BLANK.getLogicTypeId().equals(one.getLogicTypeId()) && Objects.nonNull(one.getMergerType()) && one.getMergerType() == 1) {
this.dealBlank(one, edition, tagVO, contentList, fileStyle);
} else if (LogicTypeEnum.COMPLETION.getLogicTypeId().equals(one.getLogicTypeId())) {
this.dealCompletion(one, edition, tagVO, contentList, fileStyle);
} else if (LogicTypeEnum.MULTIPLE_CHOOSE_MULTIPLE.getLogicTypeId().equals(one.getLogicTypeId())) {
this.dealMultipleChooseMultiple(one, edition, tagVO, contentList, fileStyle);
} else {
boolean isAnswerEdition;
boolean bl = isAnswerEdition = EditionEnum.ANSWER.getEdition().equals(edition) || EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition);
if (!isAnswerEdition) {
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, one, tagVO, contentList, 1);
}
String contentPrefix = this.getContentPrefix(one, fileStyle);
contentList.add(contentPrefix + tagVO.getDivStart() + one.getContent() + tagVO.getDivEnd());
this.addOption(one, contentList, "");
if (EditionEnum.TEACHER.getEdition().equals(edition)) {
if (StringUtils.isNotBlank((CharSequence)one.getAnswer())) {
contentList.add(tagVO.getAnswer() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle(one.getAnswer()) ? one.getAnswer().replace("<p>", "<span>").replace("</p>", "</span>") : one.getAnswer()) + tagVO.getDivEnd());
}
if (CollectionUtils.isNotEmpty((Collection)one.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)one.getAnswerExplanation().get(0)))) {
contentList.add(tagVO.getExplanation() + tagVO.getDivStart() + (FileServiceImpl.checkContentStyle((String)one.getAnswerExplanation().get(0)) ? ((String)one.getAnswerExplanation().get(0)).replace("<p>", "<span>").replace("</p>", "</span>") : (String)one.getAnswerExplanation().get(0)) + tagVO.getDivEnd());
}
this.addQuestionInfo(edition, one, tagVO, contentList, 2);
}
} else {
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, one, tagVO, contentList, 1);
}
String tmp = "";
if (StringUtils.isNotBlank((CharSequence)one.getAnswer())) {
tmp = FileServiceImpl.checkContentStyle(one.getAnswer()) ? tmp + one.getShowQuestionNumber() + tagVO.getDivStart() + one.getAnswer().replace("<p>", "<span>").replace("</p>", "</span>") + tagVO.getDivEnd() : tmp + tagVO.getDivStart() + FileServiceImpl.joinQuestionNum(one.getShowQuestionNumber(), one.getAnswer()) + tagVO.getDivEnd();
}
if (EditionEnum.ANSWER.getEdition().equals(edition) && CollectionUtils.isNotEmpty((Collection)one.getAnswerExplanation()) && StringUtils.isNotBlank((CharSequence)((CharSequence)one.getAnswerExplanation().get(0)))) {
if (LogicTypeEnum.RESPONSE.getLogicTypeId().equals(one.getLogicTypeId())) {
tmp = tmp + "<br/>";
}
tmp = tmp + tagVO.getExplanation() + tagVO.getDivStart() + (String)one.getAnswerExplanation().get(0) + tagVO.getDivEnd() + "###\u3010\u4e0d\u5408\u5e76\u3011###";
}
if (!tmp.contains(tagVO.getExplanation()) && LogicTypeEnum.RESPONSE.getLogicTypeId().equals(one.getLogicTypeId())) {
contentList.add(tmp + "###\u3010\u4e0d\u5408\u5e76\u3011###");
} else {
contentList.add(tmp);
}
if (EditionEnum.ANSWER.getEdition().equals(edition)) {
this.addQuestionInfo(edition, one, tagVO, contentList, 2);
}
}
}
for (int i = startIndex; i < contentList.size(); ++i) {
if (!EditionEnum.ANSWER.getEdition().equals(edition) && !EditionEnum.ANSWER_ONLY_ANSWER.getEdition().equals(edition)) continue;
contentList.set(i, contentList.get(i) + "###\u3010\u9898\u76ee\u3011###");
}
}
}
private void collectQuestionInfoNew(List<String> contentList, List<ExportQuestionVO> questionList, OfficeFileStyleVO fileStyle, String editionStr, OfficeConfigVO officeConfig, ElementNumberUtil elementNumberUtil, List<TitleBO> titleList, OfficeFileElementVO element) {
QuestionDetailVO question1 = element.getQuestionDetail();
String logicTypeName = question1.getLogicTypeName();
questionList.add(new ExportQuestionVO().setQuestion(question1));
String elementNum1 = "\u586b\u7a7a".equals(logicTypeName) && Objects.nonNull(question1.getMergerType()) && question1.getMergerType() == 1 || "\u5b8c\u5f62".equals(logicTypeName) || "\u591a\u9009\u591a".equals(logicTypeName) || "\u7ec4\u5408".equals(logicTypeName) && question1.getMergerType() == 0 ? "" : this.getQuestionNum(question1, element, fileStyle, officeConfig, elementNumberUtil);
Integer startIndex1 = this.dealQuestionInfo(contentList, elementNum1, question1, logicTypeName, officeConfig.getTagVO(), fileStyle, 1, editionStr);
if (editionStr.equals("\u3010\u5b66\u751f\u7248\u3011") || editionStr.equals("\u3010\u6559\u5e08\u7248\u3011")) {
if (question1.getLogicTypeName().equals("\u7ec4\u5408") && Objects.nonNull(question1.getMergerType()) && question1.getMergerType() == 1) {
BigDecimal score = question1.getChildList().stream().map(m -> {
if (CollectionUtils.isNotEmpty((Collection)m.getChildList())) {
return m.getChildList().stream().filter(c2 -> Objects.nonNull(c2.getScore()) && c2.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
}
return Objects.nonNull(m.getScore()) ? m.getScore() : BigDecimal.ZERO;
}).reduce(BigDecimal.ZERO, BigDecimal::add);
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(question1.getContent()).setScore(score));
} else if (CollectionUtils.isNotEmpty((Collection)question1.getChildList())) {
for (QuestionDetailVO child1 : question1.getChildList()) {
if ("\u6bb5\u843d".equals(child1.getLogicTypeName())) continue;
if (CollectionUtils.isNotEmpty((Collection)child1.getChildList())) {
List child1List = child1.getChildList();
if (child1.getLogicTypeName().equals("\u7ec4\u5408")) {
BigDecimal reduce = child1List.stream().filter(m -> Objects.nonNull(m.getScore()) && m.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(child1.getContent()).setScore(reduce));
continue;
}
child1List.forEach(child2 -> ((TitleBO)titleList.get(titleList.size() - 1)).getQuestionList().add(new QuestionBO().setQuestionContent(child2.getContent()).setScore(child2.getScore())));
continue;
}
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(child1.getContent()).setScore(child1.getScore()));
}
} else {
titleList.get(titleList.size() - 1).getQuestionList().add(new QuestionBO().setQuestionContent(question1.getContent()).setScore(question1.getScore()));
}
}
ArrayList<String> numList1 = new ArrayList<String>();
if (!CollectionUtils.isEmpty((Collection)question1.getChildList())) {
int num1 = 0;
for (int i = 0; i < question1.getChildList().size(); ++i) {
QuestionDetailVO question2 = (QuestionDetailVO)question1.getChildList().get(i);
String elementNum2 = "";
if (!"\u6bb5\u843d".equals(question2.getLogicTypeName()) || question2.getMergerType() != 1) {
if (!"\u7ec4\u5408".equals(logicTypeName)) {
elementNum2 = this.getQuestionNum(question2, element, fileStyle, officeConfig, elementNumberUtil);
} else if (!"\u5b8c\u5f62".equals(question2.getLogicTypeName()) && !"\u591a\u9009\u591a".equals(question2.getLogicTypeName())) {
if (question1.getMergerType() == 0) {
elementNum2 = this.getQuestionNum(question2, element, fileStyle, officeConfig, elementNumberUtil);
} else {
elementNum2 = "(" + (num1 + 1) + ")";
++num1;
}
}
}
numList1.add(elementNum2.replace(".", ""));
Integer startIndex2 = this.dealQuestionInfo(contentList, elementNum2, question2, logicTypeName, officeConfig.getTagVO(), fileStyle, 2, editionStr);
ArrayList<String> numList2 = new ArrayList<String>();
if (!CollectionUtils.isEmpty((Collection)question2.getChildList())) {
int num2 = 0;
for (int j = 0; j < question2.getChildList().size(); ++j) {
QuestionDetailVO question3 = (QuestionDetailVO)question2.getChildList().get(j);
String elementNum3 = "";
if (!"\u6bb5\u843d".equals(question3.getLogicTypeName()) || question3.getMergerType() != 1) {
if ("\u5b8c\u5f62".equals(question3.getLogicTypeName()) || "\u591a\u9009\u591a".equals(question3.getLogicTypeName())) {
elementNum3 = this.getQuestionNum(question3, element, fileStyle, officeConfig, elementNumberUtil);
} else if (question1.getMergerType() == 0) {
elementNum3 = "(" + (num2 + 1) + ")";
++num2;
} else {
elementNum3 = String.valueOf((char)(9311 + num2 + 1));
++num2;
}
}
numList2.add(elementNum3.replace(".", ""));
this.dealQuestionInfo(contentList, elementNum3, question3, logicTypeName, officeConfig.getTagVO(), fileStyle, 3, editionStr);
}
}
if (!editionStr.equals("\u3010\u5b66\u751f\u7248\u3011") && !editionStr.equals("\u3010\u6559\u5e08\u7248\u3011")) continue;
if ("\u5b8c\u5f62".equals(question2.getLogicTypeName()) || "\u591a\u9009\u591a".equals(question2.getLogicTypeName())) {
this.updateContentNum(contentList, startIndex2, numList2);
}
if (!"\u7ec4\u5408".equals(question2.getLogicTypeName())) continue;
ArrayList<String> answerList = new ArrayList<String>();
ArrayList<String> explanationList = new ArrayList<String>();
ArrayList<String> otherList = new ArrayList<String>();
boolean lastIsMerge = false;
for (int j = startIndex2.intValue(); j < contentList.size(); ++j) {
String content = contentList.get(j);
if (content.contains("\u3010\u7b54\u6848\u3011")) {
content = content.replace("\u3010\u7b54\u6848\u3011", "");
if (CollectionUtils.isEmpty(answerList)) {
answerList.add("\u3010\u7b54\u6848\u3011\u3010\u5408\u5e76\u3011" + elementNum2 + content);
} else if (content.contains("\u3010\u5408\u5e76\u3011") || lastIsMerge) {
answerList.add("\u3010\u7b54\u6848\u3011\u3010\u5408\u5e76\u3011" + content);
} else {
answerList.set(answerList.size() - 1, (String)answerList.get(answerList.size() - 1) + " " + content);
}
lastIsMerge = content.contains("\u3010\u5408\u5e76\u3011");
continue;
}
if (content.contains("\u3010\u89e3\u6790\u3011")) {
content = content.replace("\u3010\u89e3\u6790\u3011", "");
explanationList.add("\u3010\u89e3\u6790\u3011" + elementNum2 + content);
continue;
}
otherList.add(content);
}
contentList.subList(startIndex2, contentList.size()).clear();
contentList.addAll(otherList);
contentList.addAll(answerList);
contentList.addAll(explanationList);
}
}
if (editionStr.equals("\u3010\u5b66\u751f\u7248\u3011") || editionStr.equals("\u3010\u6559\u5e08\u7248\u3011")) {
if ("\u586b\u7a7a".equals(logicTypeName) && Objects.nonNull(question1.getMergerType()) && question1.getMergerType() == 1 || "\u5b8c\u5f62".equals(logicTypeName) || "\u591a\u9009\u591a".equals(logicTypeName)) {
this.updateContentNum(contentList, startIndex1, numList1);
}
if ("\u7ec4\u5408".equals(question1.getLogicTypeName())) {
List<Object> answerList = new ArrayList();
ArrayList<String> explanationList = new ArrayList<String>();
ArrayList<String> otherList = new ArrayList<String>();
boolean lastIsMerge = false;
String lastNum = "";
for (int i = startIndex1.intValue(); i < contentList.size(); ++i) {
String content = contentList.get(i);
if (content.contains("\u3010\u7b54\u6848\u3011")) {
if (CollectionUtils.isEmpty(answerList)) {
answerList.add(officeConfig.getTagVO().getAnswer() + officeConfig.getTagVO().getDivStart() + (question1.getMergerType() == 0 ? elementNum1 : "") + content.replace("\u3010\u7b54\u6848\u3011", "") + officeConfig.getTagVO().getDivEnd());
} else if (content.contains("\u3010\u5408\u5e76\u3011") || lastIsMerge) {
answerList.add(officeConfig.getTagVO().getDivStart() + (question1.getMergerType() == 0 ? elementNum1 : "") + content.replace("\u3010\u7b54\u6848\u3011", "") + officeConfig.getTagVO().getDivEnd());
} else {
answerList.set(answerList.size() - 1, (String)answerList.get(answerList.size() - 1) + " " + (question1.getMergerType() == 0 ? elementNum1 : "") + content.replace("\u3010\u7b54\u6848\u3011", ""));
}
lastIsMerge = content.contains("\u3010\u5408\u5e76\u3011");
continue;
}
if (content.contains("\u3010\u89e3\u6790\u3011")) {
String curNum;
String regExp = question1.getMergerType() == 0 ? "^(\\d+\\.)" : "^(\\(\\d+\\))";
Pattern pattern = Pattern.compile(regExp);
Matcher matcher = pattern.matcher(content.replace("\u3010\u89e3\u6790\u3011", ""));
if (CollectionUtils.isEmpty(explanationList)) {
lastNum = matcher.find() ? matcher.group(1) : "";
explanationList.add(officeConfig.getTagVO().getExplanation() + officeConfig.getTagVO().getDivStart() + content.replace("\u3010\u89e3\u6790\u3011", "") + officeConfig.getTagVO().getDivEnd());
continue;
}
String string = curNum = matcher.find() ? matcher.group(1) : "";
if (curNum.equals(lastNum)) {
explanationList.add(officeConfig.getTagVO().getDivStart() + content.replace("\u3010\u89e3\u6790\u3011", "").replaceFirst(Pattern.quote(curNum), "") + officeConfig.getTagVO().getDivEnd());
} else {
explanationList.add(officeConfig.getTagVO().getDivStart() + content.replace("\u3010\u89e3\u6790\u3011", "") + officeConfig.getTagVO().getDivEnd());
}
lastNum = curNum;
continue;
}
otherList.add(content);
}
answerList = answerList.stream().map(m -> m.replace("\u3010\u5408\u5e76\u3011", "")).collect(Collectors.toList());
contentList.subList(startIndex1, contentList.size()).clear();
contentList.addAll(otherList);
contentList.addAll(answerList);
contentList.addAll(explanationList);
}
if ("\u586b\u7a7a".equals(logicTypeName) && question1.getMergerType() == 1 || "\u5b8c\u5f62".equals(logicTypeName) || "\u591a\u9009\u591a".equals(logicTypeName)) {
String lj = "\u5b8c\u5f62".equals(logicTypeName) || "\u591a\u9009\u591a".equals(logicTypeName) ? " " : "\uff1b";
String answer = "";
ArrayList<String> explanationList = new ArrayList<String>();
ArrayList<String> otherList = new ArrayList<String>();
for (int i = startIndex1.intValue(); i < contentList.size(); ++i) {
String content = contentList.get(i);
if (content.contains("\u3010\u7b54\u6848\u3011")) {
content = content.replace("\u3010\u7b54\u6848\u3011", "");
answer = StringUtils.isBlank((CharSequence)answer) ? content : answer + lj + content;
continue;
}
if (content.contains("\u3010\u89e3\u6790\u3011")) {
if (CollectionUtils.isEmpty(explanationList)) {
explanationList.add(officeConfig.getTagVO().getExplanation() + officeConfig.getTagVO().getDivStart() + content.replace("\u3010\u89e3\u6790\u3011", "") + officeConfig.getTagVO().getDivEnd());
continue;
}
explanationList.add(officeConfig.getTagVO().getDivStart() + content.replace("\u3010\u89e3\u6790\u3011", "") + officeConfig.getTagVO().getDivEnd());
continue;
}
otherList.add(content);
}
contentList.subList(startIndex1, contentList.size()).clear();
contentList.addAll(otherList);
contentList.add(officeConfig.getTagVO().getAnswer() + officeConfig.getTagVO().getDivStart() + answer + officeConfig.getTagVO().getDivEnd());
contentList.addAll(explanationList);
}
}
ArrayList<String> cList = new ArrayList<String>();
for (int i = startIndex1.intValue(); i < contentList.size(); ++i) {
String content = contentList.get(i);
if (!content.contains(editionStr)) continue;
content = content.replace("\u3010\u5408\u5e76\u3011", "").replace("\u3010\u5b66\u751f\u7248\u3011", "").replace("\u3010\u6559\u5e08\u7248\u3011", "");
if ("\u3010\u6559\u5e08\u7248\u3011".equals(editionStr) || "\u3010\u5b66\u751f\u7248\u3011".equals(editionStr)) {
content = content.replace("\u3010\u7b54\u6848\u7248\u3011", "").replace("\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011", "");
}
cList.add(content);
}
contentList.subList(startIndex1, contentList.size()).clear();
contentList.addAll(cList);
}
private String getQuestionNum(QuestionDetailVO question, OfficeFileElementVO element, OfficeFileStyleVO fileStyle, OfficeConfigVO officeConfig, ElementNumberUtil elementNumberUtil) {
ElementNumBO elementNumBO = question.isSystemQuestionNumber() != false ? elementNumberUtil.getElementNum(element, fileStyle, officeConfig.getElementNumStyleMap(), officeConfig.getElementIconMap()) : new ElementNumBO().setStyleElementNum(question.getShowCustomQuestionNumber());
return elementNumBO.getStyleElementNum();
}
private Integer dealQuestionInfo(List<String> contentList, String numStr, QuestionDetailVO question, String logicTypeName, TagVO tagVO, OfficeFileStyleVO fileStyle, Integer level, String editionStr) {
boolean isAnswerEdition;
ArrayList<String> tmpContentList = new ArrayList<String>();
boolean bl = isAnswerEdition = "\u3010\u7b54\u6848\u7248\u3011".equals(editionStr) || "\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011".equals(editionStr);
if (StringUtils.isNotBlank((CharSequence)question.getContent())) {
String content = tagVO.getDivStart() + question.getContent() + tagVO.getDivEnd() + "\u3010\u5b66\u751f\u7248\u3011" + "\u3010\u6559\u5e08\u7248\u3011";
if (!isAnswerEdition && level == 1 && CollectionUtils.isNotEmpty((Collection)question.getSourceFeature()) && Objects.nonNull(fileStyle) && fileStyle.getQuestionSourceShowFlag() == 1 && StringUtils.isNotBlank((CharSequence)((QuestionSourceFeatureMetadataDTO)question.getSourceFeature().get(0)).getSourceShortNote())) {
String source = "\uff08" + ((QuestionSourceFeatureMetadataDTO)question.getSourceFeature().get(0)).getSourceShortNote() + "\uff09";
content = source + content;
}
if (Boolean.TRUE.equals(question.getIsShowScore()) && !isAnswerEdition) {
if (level == 1 && question.getLogicTypeName().equals("\u7ec4\u5408") && Objects.nonNull(question.getMergerType()) && question.getMergerType() == 1) {
BigDecimal score = question.getChildList().stream().map(m -> {
if (CollectionUtils.isNotEmpty((Collection)m.getChildList())) {
return m.getChildList().stream().filter(c2 -> Objects.nonNull(c2.getScore()) && c2.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
}
return Objects.nonNull(m.getScore()) ? m.getScore() : BigDecimal.ZERO;
}).reduce(BigDecimal.ZERO, BigDecimal::add);
if (score.compareTo(BigDecimal.ZERO) > 0) {
content = "\uff08" + score.stripTrailingZeros().toPlainString() + "\u5206\uff09" + content;
}
} else if (CollectionUtils.isNotEmpty((Collection)question.getChildList())) {
int questionsNum = 0;
ArrayList<BigDecimal> scoreList = new ArrayList<BigDecimal>();
for (QuestionDetailVO child1 : question.getChildList()) {
if ("\u6bb5\u843d".equals(child1.getLogicTypeName())) continue;
if (CollectionUtils.isNotEmpty((Collection)child1.getChildList())) {
List child1List = child1.getChildList();
questionsNum = child1.getLogicTypeName().equals("\u7ec4\u5408") ? ++questionsNum : (questionsNum += child1List.size());
BigDecimal reduce = child1List.stream().filter(m -> Objects.nonNull(m.getScore()) && m.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
if (reduce.compareTo(BigDecimal.ZERO) <= 0) continue;
scoreList.add(reduce);
continue;
}
++questionsNum;
if (!Objects.nonNull(child1.getScore()) || child1.getScore().compareTo(BigDecimal.ZERO) <= 0) continue;
scoreList.add(child1.getScore());
}
BigDecimal sumScore = scoreList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
if (sumScore.compareTo(BigDecimal.ZERO) > 0) {
HashSet scoreSet = new HashSet(scoreList);
String scoreStr = questionsNum == scoreList.size() && scoreSet.size() == 1 ? "(\u5171" + questionsNum + "\u5c0f\u9898\uff0c\u6bcf\u5c0f\u9898" + ((BigDecimal)scoreList.get(0)).stripTrailingZeros().toPlainString() + "\u5206\uff0c\u6ee1\u5206" + sumScore.stripTrailingZeros().toPlainString() + "\u5206)" : "(\u5171" + questionsNum + "\u5c0f\u9898\uff0c\u6ee1\u5206" + sumScore.stripTrailingZeros().toPlainString() + "\u5206)";
tmpContentList.add(scoreStr + "\u3010\u5b66\u751f\u7248\u3011" + "\u3010\u6559\u5e08\u7248\u3011");
}
} else if (Objects.nonNull(question.getScore()) && question.getScore().compareTo(BigDecimal.ZERO) > 0) {
content = "\uff08" + question.getScore().stripTrailingZeros().toPlainString() + "\u5206\uff09" + content;
}
}
tmpContentList.add(numStr + content);
}
if (StringUtils.isNotBlank((CharSequence)question.getOriginalText())) {
tmpContentList.add(tagVO.getListeningText() + tagVO.getDivStart() + question.getOriginalText() + tagVO.getDivEnd() + "\u3010\u6559\u5e08\u7248\u3011" + "\u3010\u7b54\u6848\u7248\u3011" + "\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011" + (isAnswerEdition ? "###\u3010\u4e0d\u5408\u5e76\u3011###" : ""));
}
if (StringUtils.isNotBlank((CharSequence)question.getDecipherment())) {
tmpContentList.add(tagVO.getDecipherment() + tagVO.getDivStart() + question.getDecipherment() + tagVO.getDivEnd() + "\u3010\u6559\u5e08\u7248\u3011" + "\u3010\u7b54\u6848\u7248\u3011" + "\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011" + (isAnswerEdition ? "###\u3010\u4e0d\u5408\u5e76\u3011###" : ""));
}
if (!"\u591a\u9009\u591a".equals(question.getLogicTypeName()) || !Objects.isNull(question.getMergerType())) {
if ("\u5b8c\u5f62".equals(question.getLogicTypeName())) {
this.addOptionNew(tmpContentList, question, tagVO, numStr);
} else {
this.addOptionNew(tmpContentList, question, tagVO, "");
}
}
this.addEmptyArea(tmpContentList, question.getEmptyLineNum(), question.getHasLine());
String answerStr = "";
String answerPrefix = "\u3010\u7b54\u6848\u3011";
if ("\u89e3\u7b54".equals(question.getLogicTypeName()) || "\u7ec4\u5408".equals(question.getLogicTypeName())) {
answerPrefix = "\u3010\u5408\u5e76\u3011\u3010\u7b54\u6848\u3011";
}
String answer = StringUtils.isBlank((CharSequence)question.getAnswer()) ? "\u6682\u65e0" : question.getAnswer();
answer = tagVO.getDivStart() + answer.replace("</p>;<p>", "</p>\uff1b<p>") + tagVO.getDivEnd() + "\u3010\u6559\u5e08\u7248\u3011" + "\u3010\u7b54\u6848\u7248\u3011" + "\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011";
if (question.getLogicTypeName().equals("\u5224\u65ad")) {
if (question.getTrueFalseType() == 1) {
answer = answer.replace("T", "\u221a").replace("F", "\u00d7");
} else if (question.getTrueFalseType() == 2) {
answer = answer.replace("T", "\u5bf9").replace("F", "\u9519");
}
}
if (!question.getLogicTypeName().equals("\u7ec4\u5408") && !question.getLogicTypeName().equals("\u6bb5\u843d")) {
if (!(level != 1 || question.getLogicTypeName().equals("\u586b\u7a7a") && Objects.nonNull(question.getMergerType()) && question.getMergerType() == 1 || question.getLogicTypeName().equals("\u5b8c\u5f62") || question.getLogicTypeName().equals("\u591a\u9009\u591a"))) {
answerStr = answerPrefix + (isAnswerEdition ? numStr + " " : "") + answer;
} else if (level == 2 && (!"\u591a\u9009\u591a".equals(question.getLogicTypeName()) || "\u591a\u9009\u591a".equals(logicTypeName))) {
answerStr = answerPrefix + numStr + (isAnswerEdition ? " " : "") + answer;
} else if (level == 3) {
answerStr = answerPrefix + numStr + (isAnswerEdition ? " " : "") + answer;
}
}
String answerExplanationStr = "";
if (CollectionUtils.isNotEmpty((Collection)question.getAnswerExplanation())) {
boolean isLevel1AndNoNum = level == 1 && (!"\u586b\u7a7a".equals(logicTypeName) || !Objects.nonNull(question.getMergerType()) || question.getMergerType() != 1) && !"\u5b8c\u5f62".equals(logicTypeName) && !"\u591a\u9009\u591a".equals(logicTypeName);
ArrayList<String> answerExplanationList = new ArrayList<String>();
for (String answerExplanationTmp : question.getAnswerExplanation()) {
if (!StringUtils.isNotBlank((CharSequence)answerExplanationTmp)) continue;
answerExplanationTmp = tagVO.getDivStart() + answerExplanationTmp + tagVO.getDivEnd();
if (CollectionUtils.isEmpty(answerExplanationList)) {
answerExplanationList.add(isLevel1AndNoNum | isAnswerEdition ? answerExplanationTmp : numStr + answerExplanationTmp);
continue;
}
answerExplanationList.add(isAnswerEdition ? "\uff1b" + answerExplanationTmp : "<p>" + answerExplanationTmp + "</p>");
}
if (CollectionUtils.isNotEmpty(answerExplanationList)) {
answerExplanationStr = "\u3010\u89e3\u6790\u3011\u3010\u6559\u5e08\u7248\u3011\u3010\u7b54\u6848\u7248\u3011\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011" + String.join((CharSequence)"", answerExplanationList);
}
}
if (isAnswerEdition) {
String string = answerExplanationStr = "\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011".equals(editionStr) ? "" : answerExplanationStr;
if ("\u7ec4\u5408".equals(question.getLogicTypeName()) && (level != 1 || !Objects.nonNull(question.getMergerType()) || question.getMergerType() != 0)) {
tmpContentList.add("###\u3010\u5408\u5e76\u7ec4\u5408\u3011###\u3010\u7b54\u6848\u7248\u3011\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011" + numStr);
}
if ("\u89e3\u7b54".equals(question.getLogicTypeName()) && StringUtils.isNotBlank((CharSequence)answerStr) || !"\u89e3\u7b54".equals(question.getLogicTypeName()) && StringUtils.isNotBlank((CharSequence)answerExplanationStr) && StringUtils.isNotBlank((CharSequence)answerStr)) {
answerStr = answerStr + "###\u3010\u4e0d\u5408\u5e76\u3011###";
}
if (StringUtils.isNotBlank((CharSequence)answerStr) || StringUtils.isNotBlank((CharSequence)answerExplanationStr)) {
tmpContentList.add(answerStr + ("\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011".equals(editionStr) ? "" : answerExplanationStr));
}
} else {
if (StringUtils.isNotBlank((CharSequence)answerStr)) {
tmpContentList.add(answerStr);
}
if (StringUtils.isNotBlank((CharSequence)answerExplanationStr)) {
tmpContentList.add(answerExplanationStr);
}
}
Integer startIndex = contentList.size();
contentList.addAll(tmpContentList);
return startIndex;
}
private void updateContentNum(List<String> contentList, Integer startIndex, List<String> numList) {
if (contentList.get(startIndex).startsWith("(\u5171")) {
Integer n = startIndex;
Integer n2 = startIndex = Integer.valueOf(startIndex + 1);
}
Document parse = Jsoup.parseBodyFragment((String)contentList.get(startIndex));
parse.outputSettings().prettyPrint(false).indentAmount(0);
Elements numberSpans = parse.select("span.tinymce-horizontal-number, span.tinymce-line-number");
for (int i = 0; i < numberSpans.size(); ++i) {
Element span = (Element)numberSpans.get(i);
span.html(span.html().replaceAll("\\d+\\.?", numList.get(i)).replace("&nbsp;", "&ensp;"));
}
contentList.set(startIndex, parse.body().html());
}
private void addOptionNew(List<String> contentList, QuestionDetailVO question, TagVO tagVO, String numStr) {
if (Boolean.TRUE.equals(question.getIsSubjective())) {
return;
}
ArrayList<String> tContentList = new ArrayList<String>();
List<String> optionList = this.getOptionList(question, tagVO);
if (Objects.nonNull(question.getOptionColumn()) && question.getOptionColumn() > 1) {
this.addMultiColumnOptionByTab(tContentList, optionList, question.getOptionColumn());
} else {
tContentList.addAll(optionList);
}
contentList.addAll(tContentList.stream().map(m -> numStr + m + "\u3010\u5b66\u751f\u7248\u3011" + "\u3010\u6559\u5e08\u7248\u3011").collect(Collectors.toList()));
}
private void dealAnswerMergeNew(List<String> contentList, List<TitleBO> titleList, String editionStr, TagVO tagVO) {
if (CollectionUtils.isNotEmpty(titleList)) {
List<Object> newContentList = new ArrayList<String>();
int lastIndex = 0;
for (int i = 0; i < titleList.size(); ++i) {
Integer endIndex;
Integer startIndex = titleList.get(i).getIndex();
if (Objects.isNull(startIndex)) continue;
for (int k = lastIndex; k < startIndex; ++k) {
newContentList.add(contentList.get(k));
}
if (i < titleList.size() - 1) {
TitleBO nextTitleBO = titleList.get(i + 1);
endIndex = nextTitleBO.getIndex();
} else {
endIndex = contentList.size();
}
boolean lastIsZh = false;
boolean lastNotMerge = true;
for (int j = startIndex.intValue(); j < endIndex; ++j) {
boolean curNotMerge;
String content = contentList.get(j);
if (!content.contains(editionStr)) {
newContentList.add(content);
curNotMerge = true;
} else {
curNotMerge = content.contains("###\u3010\u4e0d\u5408\u5e76\u3011###");
if (lastIsZh) {
newContentList.set(newContentList.size() - 1, (String)newContentList.get(newContentList.size() - 1) + content);
} else if (content.contains("###\u3010\u5408\u5e76\u7ec4\u5408\u3011###")) {
if (lastNotMerge) {
newContentList.add(content);
} else {
newContentList.set(newContentList.size() - 1, (String)newContentList.get(newContentList.size() - 1) + content);
}
} else if (curNotMerge) {
newContentList.add(content);
} else if (lastNotMerge) {
newContentList.add(content);
} else {
newContentList.set(newContentList.size() - 1, (String)newContentList.get(newContentList.size() - 1) + " " + content);
}
}
lastNotMerge = curNotMerge;
lastIsZh = content.contains("###\u3010\u5408\u5e76\u7ec4\u5408\u3011###");
}
lastIndex = endIndex;
}
for (int k = lastIndex; k < contentList.size(); ++k) {
newContentList.add(contentList.get(k));
}
newContentList = newContentList.stream().map(m -> {
if (!m.contains(tagVO.getExplanation()) && m.contains("\u3010\u89e3\u6790\u3011")) {
m = m.replace("\u3010\u89e3\u6790\u3011", tagVO.getExplanation());
}
return m.replace("\u3010\u7b54\u6848\u7248\u3011", "").replace("\u3010\u7b54\u6848\u7248\u4ec5\u7b54\u6848\u3011", "").replace("\u3010\u7b54\u6848\u3011", "").replace("###\u3010\u4e0d\u5408\u5e76\u3011###", "").replace("###\u3010\u5408\u5e76\u7ec4\u5408\u3011###", "");
}).collect(Collectors.toList());
contentList.clear();
contentList.addAll(newContentList);
}
}
private void dealAnswerMergeNew2(List<String> contentList, List<TitleBO> titleList) {
if (CollectionUtils.isNotEmpty(titleList)) {
List<Object> newContentList = new ArrayList<String>();
int lastIndex = 0;
for (int i = 0; i < titleList.size(); ++i) {
Integer endIndex;
Integer startIndex = titleList.get(i).getIndex();
if (Objects.isNull(startIndex)) {
startIndex = 0;
}
for (int k = lastIndex; k < startIndex; ++k) {
newContentList.add(contentList.get(k));
}
if (i < titleList.size() - 1) {
TitleBO nextTitleBO = titleList.get(i + 1);
endIndex = nextTitleBO.getIndex();
} else {
endIndex = contentList.size();
}
boolean lastElementMerge = false;
for (int j = startIndex.intValue(); j < endIndex; ++j) {
String content = contentList.get(j);
if (CollectionUtils.isEmpty(newContentList) || !content.contains("###\u3010\u9898\u76ee\u3011###") || content.contains("###\u3010\u4e0d\u5408\u5e76\u3011###") || content.contains("###\u3010\u5408\u5e76\u7ec4\u5408\u3011###") || lastElementMerge) {
newContentList.add(content);
} else {
newContentList.set(newContentList.size() - 1, FileServiceImpl.joinContent((String)newContentList.get(newContentList.size() - 1), content));
}
lastElementMerge = content.contains("###\u3010\u4e0d\u5408\u5e76\u3011###") || !content.contains("###\u3010\u9898\u76ee\u3011###");
}
lastIndex = endIndex;
}
for (int k = lastIndex; k < contentList.size(); ++k) {
newContentList.add(contentList.get(k));
}
newContentList = newContentList.stream().map(m -> m.replace("###\u3010\u4e0d\u5408\u5e76\u3011###", "").replace("###\u3010\u9898\u76ee\u3011###", "").replace("###\u3010\u5408\u5e76\u7ec4\u5408\u3011###", "")).collect(Collectors.toList());
contentList.clear();
contentList.addAll(newContentList);
}
}
private String getContentPrefix(QuestionDetailVO question, OfficeFileStyleVO fileStyle) {
boolean isPrefix = false;
String questionNumber = question.getShowQuestionNumber();
String extraChoose = Boolean.TRUE.equals(question.getIsExtra()) ? "\uff08\u9644\u52a0\u9898\uff09" : "";
String scoreStr = "";
if (Boolean.TRUE.equals(question.getIsShowScore())) {
if (LogicTypeEnum.COMBINATION.getLogicTypeId().equals(question.getLogicTypeId()) && Objects.nonNull(question.getMergerType()) && question.getMergerType() == 1) {
BigDecimal score = question.getChildList().stream().map(m -> {
if (CollectionUtils.isNotEmpty((Collection)m.getChildList())) {
return m.getChildList().stream().filter(c2 -> Objects.nonNull(c2.getScore()) && c2.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
}
return Objects.nonNull(m.getScore()) ? m.getScore() : BigDecimal.ZERO;
}).reduce(BigDecimal.ZERO, BigDecimal::add);
if (score.compareTo(BigDecimal.ZERO) > 0) {
scoreStr = "\uff08" + score.stripTrailingZeros().toPlainString() + "\u5206\uff09";
}
} else if (CollectionUtils.isNotEmpty((Collection)question.getChildList())) {
isPrefix = true;
int questionsNum = 0;
ArrayList<BigDecimal> scoreList = new ArrayList<BigDecimal>();
for (QuestionDetailVO child1 : question.getChildList()) {
if ("\u6bb5\u843d".equals(child1.getLogicTypeName())) continue;
if (CollectionUtils.isNotEmpty((Collection)child1.getChildList())) {
List child1List = child1.getChildList();
questionsNum = child1.getLogicTypeName().equals("\u7ec4\u5408") ? ++questionsNum : (questionsNum += child1List.size());
BigDecimal reduce = child1List.stream().filter(m -> Objects.nonNull(m.getScore()) && m.getScore().compareTo(BigDecimal.ZERO) > 0).map(QuestionDetailVO::getScore).reduce(BigDecimal.ZERO, BigDecimal::add);
if (reduce.compareTo(BigDecimal.ZERO) <= 0) continue;
scoreList.add(reduce);
continue;
}
++questionsNum;
if (!Objects.nonNull(child1.getScore()) || child1.getScore().compareTo(BigDecimal.ZERO) <= 0) continue;
scoreList.add(child1.getScore());
}
BigDecimal sumScore = scoreList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
if (sumScore.compareTo(BigDecimal.ZERO) > 0) {
HashSet scoreSet = new HashSet(scoreList);
scoreStr = questionsNum == scoreList.size() && scoreSet.size() == 1 ? "(\u5171" + questionsNum + "\u5c0f\u9898\uff0c\u6bcf\u5c0f\u9898" + ((BigDecimal)scoreList.get(0)).stripTrailingZeros().toPlainString() + "\u5206\uff0c\u6ee1\u5206" + sumScore.stripTrailingZeros().toPlainString() + "\u5206)" : "(\u5171" + questionsNum + "\u5c0f\u9898\uff0c\u6ee1\u5206" + sumScore.stripTrailingZeros().toPlainString() + "\u5206)";
}
} else if (Objects.nonNull(question.getScore()) && question.getScore().compareTo(BigDecimal.ZERO) > 0) {
scoreStr = "\uff08" + question.getScore().stripTrailingZeros().toPlainString() + "\u5206\uff09";
}
}
String source = "";
if (Objects.nonNull(fileStyle) && fileStyle.getQuestionSourceShowFlag() == 1 && CollectionUtils.isNotEmpty((Collection)question.getSourceFeature()) && StringUtils.isNotBlank((CharSequence)((QuestionSourceFeatureMetadataDTO)question.getSourceFeature().get(0)).getSourceShortNote())) {
source = "\uff08" + ((QuestionSourceFeatureMetadataDTO)question.getSourceFeature().get(0)).getSourceShortNote() + "\uff09";
}
if (isPrefix) {
return extraChoose + scoreStr + "<br>" + questionNumber + source;
}
return questionNumber + extraChoose + scoreStr + source;
}
private void addQuestionInfo(Integer edition, QuestionDetailVO question, TagVO tagVO, List<String> contentList, Integer group) {
String mergeInfo;
String string = mergeInfo = EditionEnum.ANSWER.getEdition().equals(edition) ? "###\u3010\u4e0d\u5408\u5e76\u3011###" : "";
if (group == 1 && (EditionEnum.TEACHER.getEdition().equals(edition) || EditionEnum.ANSWER.getEdition().equals(edition)) && StringUtils.isNotBlank((CharSequence)question.getDecipherment())) {
contentList.add(tagVO.getDivStart().replace("color: rgba(0, 0, 0, 0.65)", "color: rgba(128, 128, 128)") + tagVO.getDecipherment().replace("font-weight: bold;", "").replace("color: rgba(0, 0, 0, 0.65)", "color: rgb(128, 128, 128)") + "<div style=\"color: rgb(128, 128, 128); font-size: 10.5pt; line-height: 2; \">" + question.getDecipherment().replace("<p>", "").replace("</p>", "") + "</div>" + tagVO.getDivEnd() + mergeInfo);
}
if (group == 2 && (EditionEnum.TEACHER.getEdition().equals(edition) || EditionEnum.ANSWER.getEdition().equals(edition))) {
if (StringUtils.isNotBlank((CharSequence)question.getListeningText())) {
contentList.add(tagVO.getListeningText() + tagVO.getDivStart() + question.getListeningText() + tagVO.getDivEnd() + mergeInfo);
}
if (StringUtils.isNotBlank((CharSequence)question.getChineseText())) {
contentList.add(tagVO.getChineseText() + tagVO.getDivStart() + question.getChineseText() + tagVO.getDivEnd() + mergeInfo);
}
}
}
private static String joinQuestionNum(String numStr, String originalContent) {
return Optional.ofNullable(numStr).orElse("") + Optional.ofNullable(originalContent).orElse("");
}
private static String joinQuestionNum2(String numStr, String originalContent) {
Document doc = Jsoup.parse((String)originalContent);
Elements pNodes = doc.select("p");
if (pNodes.isEmpty()) {
return numStr + originalContent;
}
StringBuilder sb = new StringBuilder();
sb.append(numStr);
for (Element p : pNodes) {
String content = p.html();
sb.append(content);
}
return sb.toString();
}
private static String joinContent(String content1, String content2) {
String result = Optional.ofNullable(content1).orElse("") + " " + Optional.ofNullable(content2).orElse("");
if (StringUtils.isBlank((CharSequence)result)) {
return result;
}
Document doc = Jsoup.parse((String)result);
doc.outputSettings().prettyPrint(false);
Elements pNodes = doc.select(TagEnum.P.getName());
for (Element p : pNodes) {
p.tagName(TagEnum.SPAN.getName());
}
return doc.body().html();
}
private static boolean checkContentStyle(String content) {
String pattern = "^(<div.*?>)?(<p>.*?</p>(;<p>.*?</p>)+)(</div>)?$";
return content != null && content.matches(pattern);
}
private static void dealQuestionAnswerExplationStyle(QuestionDetailVO question) {
String answerExplanation;
String answer = question.getAnswer();
String string = answerExplanation = CollectionUtils.isEmpty((Collection)question.getAnswerExplanation()) ? null : (String)question.getAnswerExplanation().get(0);
if (FileServiceImpl.checkContentStyle(answer)) {
answer = answer.replace("<p>", "<span>").replace("</p>", "</span>");
question.setAnswer(answer);
}
if (FileServiceImpl.checkContentStyle(answerExplanation)) {
answerExplanation = answerExplanation.replace("<p>", "<span>").replace("</p>", "</span>");
question.setAnswerExplanation(Collections.singletonList(answerExplanation));
}
}
}