|
@@ -1887,6 +1887,407 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> importXueJianWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
|
|
|
+ Map<String,Object> result = new HashMap<>();
|
|
|
+ List<QuestionAddBo> list = new ArrayList<>();
|
|
|
+ String errorLog = ""; //错误提示
|
|
|
+ String buffer = "";
|
|
|
+ String importNo = ServletUtils.getEncoded("IMPORT");
|
|
|
+ Long sort = 1L;
|
|
|
+ if(Validator.isEmpty(file)){
|
|
|
+ throw new CustomException("请选择文件");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Long nowTime = DateUtils.getNowTime();
|
|
|
+ String path = file.getOriginalFilename();
|
|
|
+ if (path.endsWith(".doc")) {
|
|
|
+ throw new CustomException("不支持doc格式");
|
|
|
+ } else if (path.endsWith("docx")) {
|
|
|
+ InputStream is = file.getInputStream();
|
|
|
+ XWPFDocument doc = new XWPFDocument(is);
|
|
|
+ List<XWPFParagraph> paragraphList = doc.getParagraphs();
|
|
|
+ int type = -1; //题目类型
|
|
|
+ boolean isOption = false; //是否判断题
|
|
|
+ List<QuestionChildAddBo> optionsList = new ArrayList<>(); //题目选项
|
|
|
+ String content = ""; //每行正文
|
|
|
+ String qContent = ""; //题目正文
|
|
|
+ String answerQuestion = null; //答案
|
|
|
+ String analysisContent = ""; //解析文本
|
|
|
+ int index = 1; //题目序列号
|
|
|
+ List<QuestionBusinessAddBo> businessList = new ArrayList<>();
|
|
|
+ QuestionBusinessAddBo questionBusinessAddBo = new QuestionBusinessAddBo();
|
|
|
+ questionBusinessAddBo.setEducationTypeId(eduId);
|
|
|
+ questionBusinessAddBo.setProjectId(projectId);
|
|
|
+ questionBusinessAddBo.setBusinessId(businessId);
|
|
|
+ questionBusinessAddBo.setSubjectId(subjectId);
|
|
|
+ businessList.add(questionBusinessAddBo);
|
|
|
+
|
|
|
+ List<QuestionAddBo> list1 = new ArrayList<>(); //单选列表
|
|
|
+ List<QuestionAddBo> list2 = new ArrayList<>(); //多选列表
|
|
|
+ List<QuestionAddBo> list3 = new ArrayList<>(); //简答列表
|
|
|
+ List<QuestionAddBo> list4 = new ArrayList<>(); //判断列表
|
|
|
+
|
|
|
+ Integer nowPart = -1;//0正文 1选项A 2选项B 3选项C 4选项D 5选项E 6选项F
|
|
|
+ String strContent = "";
|
|
|
+ String imgUrl = "";
|
|
|
+ boolean hasQuestion = false;
|
|
|
+ boolean hasRightTag = false;
|
|
|
+ boolean hasError = false;
|
|
|
+ for (XWPFParagraph paragraph : paragraphList) {
|
|
|
+ content = paragraph.getText();
|
|
|
+ List<XWPFRun> runs = paragraph.getRuns();
|
|
|
+ imgUrl = null;
|
|
|
+ for (XWPFRun run : runs) {
|
|
|
+ Node node = run.getCTR().getDomNode();
|
|
|
+
|
|
|
+ // drawing 一个绘画的图片
|
|
|
+ Node drawingNode = getChildNode(node, "w:drawing");
|
|
|
+ if (drawingNode == null && content == null) {
|
|
|
+ imgUrl = null;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //上传图片
|
|
|
+ if (Validator.isNotEmpty(drawingNode)) {
|
|
|
+ // 绘画图片的宽和高
|
|
|
+ Node extentNode = getChildNode(drawingNode, "wp:extent");
|
|
|
+ NamedNodeMap extentAttrs = extentNode.getAttributes();
|
|
|
+ int wPx = ToolsUtils.emuToPx(Double.valueOf(extentAttrs.getNamedItem("cx").getNodeValue()));
|
|
|
+ // System.out.println("宽:".concat(extentAttrs.getNamedItem("cx").getNodeValue()).concat("emu"));
|
|
|
+ // System.out.println("高:".concat(extentAttrs.getNamedItem("cy").getNodeValue()).concat("emu"));
|
|
|
+ int HPx = ToolsUtils.emuToPx(Double.valueOf(extentAttrs.getNamedItem("cy").getNodeValue()));
|
|
|
+
|
|
|
+ // 绘画图片具体引用
|
|
|
+ Node blipNode = getChildNode(drawingNode, "a:blip");
|
|
|
+ NamedNodeMap blipAttrs = blipNode.getAttributes();
|
|
|
+ String rid = blipAttrs.getNamedItem("r:embed").getNodeValue();
|
|
|
+ // System.out.println("word中图片ID:".concat(rid));
|
|
|
+
|
|
|
+ // 获取图片信息
|
|
|
+ PackagePart part = doc.getPartById(rid);
|
|
|
+ String ossPath = null;
|
|
|
+ try {
|
|
|
+ ossPath = ossService.uploadInputStream(part.getInputStream(), 8);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ imgUrl = ossPath + "?x-oss-process=image/resize,w_" + wPx + ",h_" + HPx;
|
|
|
+ if(isOptionStart(content)||(nowPart>0&&nowPart<7&&!isNotOptionStart(content))){
|
|
|
+ //选项图片路径不用处理
|
|
|
+
|
|
|
+ }else{
|
|
|
+ //正文图片
|
|
|
+ content = content +"<br />" +"<p><img src=\"" + ossHost + "/" + imgUrl + "\"></p>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ content = dealTxt(content);
|
|
|
+ if (content.startsWith("#")||isQuestionStart(content)) {
|
|
|
+ if(hasQuestion){
|
|
|
+ index++;
|
|
|
+ hasQuestion = false;
|
|
|
+ //插入上一条
|
|
|
+ QuestionAddBo addBo = new QuestionAddBo();
|
|
|
+ qContent = removeNo(qContent);
|
|
|
+ if (Validator.isEmpty(qContent)) {
|
|
|
+ hasError = true;
|
|
|
+ errorLog += "第" + index + "条题目内容错误\n";
|
|
|
+ continue;
|
|
|
+
|
|
|
+ }
|
|
|
+ QuestionAddBo bo = new QuestionAddBo();
|
|
|
+ if (type == -1) {
|
|
|
+ hasError = true;
|
|
|
+ errorLog += "第" + index + "条题目选项错误\n";
|
|
|
+ continue;
|
|
|
+
|
|
|
+ }
|
|
|
+ if(!hasError){
|
|
|
+ if (Validator.isEmpty(answerQuestion)) {
|
|
|
+ errorLog += "第" + index + "正确答案错误\n";
|
|
|
+ continue;
|
|
|
+
|
|
|
+ }
|
|
|
+ if(type==5){
|
|
|
+ answerQuestion = null;
|
|
|
+ }
|
|
|
+ bo.setType(type);
|
|
|
+ bo.setStatus(1);
|
|
|
+ bo.setContent(qContent);
|
|
|
+ bo.setAnswerQuestion(answerQuestion);
|
|
|
+ bo.setAnalysisContent(analysisContent);
|
|
|
+ bo.setOptionsList(copyList(optionsList));
|
|
|
+ bo.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ bo.setImportNo(importNo);
|
|
|
+ bo.setPublishStatus(1);
|
|
|
+ bo.setBusinessList(businessList);
|
|
|
+ bo.setCreateTime(nowTime);
|
|
|
+ if(type==1){
|
|
|
+ list1.add(bo);
|
|
|
+ }
|
|
|
+ if(type==2){
|
|
|
+ list2.add(bo);
|
|
|
+ }
|
|
|
+ if(type==3){
|
|
|
+ list4.add(bo);
|
|
|
+ }
|
|
|
+ if(type==5){
|
|
|
+ list3.add(bo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sort++;
|
|
|
+ hasError = false;
|
|
|
+ //清空数据
|
|
|
+ isOption = false;
|
|
|
+ type = -1;
|
|
|
+ qContent = "";
|
|
|
+ answerQuestion = null;
|
|
|
+ analysisContent = "";
|
|
|
+ optionsList.clear();
|
|
|
+ nowPart = -1;
|
|
|
+ hasRightTag= false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (content.startsWith("正确答案:")){
|
|
|
+ if(!hasRightTag){
|
|
|
+ hasRightTag = true;
|
|
|
+ }else{
|
|
|
+ errorLog += "第" + index + "题目序号可能错误\n";
|
|
|
+ hasRightTag =false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (content.startsWith("#")) { //导入结束
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(content)||content.equals("")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (isQuestionStart(content)||(nowPart==0&&!isLineStart(content))) {
|
|
|
+ hasQuestion = true;
|
|
|
+ if(nowPart!=0){
|
|
|
+ qContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 0;
|
|
|
+ //新题开头
|
|
|
+ qContent = qContent + content +"<br />";
|
|
|
+ }
|
|
|
+ //第一个选项
|
|
|
+ if(content.startsWith("А.")||content.startsWith("A.")||(nowPart==1&&!isLineStart(content))) {
|
|
|
+ hasQuestion = true;
|
|
|
+ if(nowPart!=1){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ isOption = true; //是选择题
|
|
|
+ nowPart = 1;
|
|
|
+ strContent = strContent + content ;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<1){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(1L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("A.", "").replace("А.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(0);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("A.", "").replace("А.", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第二个选项
|
|
|
+ if (content.startsWith("B.")||(nowPart==2&&!isLineStart(content))) {
|
|
|
+ if (optionsList.size()<1) {
|
|
|
+ errorLog += "第" + index + "条题目选项A错误\n";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(nowPart!=2){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 2;
|
|
|
+ strContent = strContent + content ;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<2){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(2L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("B.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(1);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("B.", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第三个选项
|
|
|
+ if (content.startsWith("C.")||(nowPart==3&&!isLineStart(content))) {
|
|
|
+ if(nowPart!=3){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 3;
|
|
|
+ strContent = strContent + content;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<3){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(3L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("C.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(2);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("C.", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第四个选项
|
|
|
+ if (content.startsWith("D.")||(nowPart==4&&!isLineStart(content))) {
|
|
|
+ if(nowPart!=4){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 4;
|
|
|
+ strContent = strContent + content ;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<4){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(4L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("D.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(3);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("D.", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第五个选项
|
|
|
+ if (content.startsWith("E.")||(nowPart==5&&!isLineStart(content))) {
|
|
|
+ if(nowPart!=5){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 5;
|
|
|
+ strContent = strContent + content ;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<5){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(5L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("E.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(4);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("E.", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第六个选项
|
|
|
+ if (content.startsWith("F.")||(nowPart==6&&!isLineStart(content))) {
|
|
|
+ if(nowPart!=6){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+ nowPart = 6;
|
|
|
+ strContent = strContent + content ;
|
|
|
+ QuestionChildAddBo bo1;
|
|
|
+ if(optionsList.size()<6){
|
|
|
+ bo1 = new QuestionChildAddBo();
|
|
|
+ bo1.setOptionsId(6L);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("F.", ""));
|
|
|
+ optionsList.add(bo1);
|
|
|
+ }else{
|
|
|
+ bo1 = optionsList.get(5);
|
|
|
+ bo1.setImgUrl(imgUrl);
|
|
|
+ bo1.setContent(strContent.replace("F.", ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //答案和题型
|
|
|
+ if (content.startsWith("正确答案:")||(nowPart==7&&!isLineStart(content))) {
|
|
|
+ if(nowPart!=7){
|
|
|
+ strContent = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ nowPart = 7;
|
|
|
+
|
|
|
+ if(Validator.isNotEmpty(answerQuestion)){
|
|
|
+ answerQuestion = answerQuestion + "<br />" + content ;
|
|
|
+ }else{
|
|
|
+ answerQuestion = content.replace("正确答案:", "");
|
|
|
+ }
|
|
|
+ if (isOption) {
|
|
|
+ //选择题
|
|
|
+ answerQuestion = dealImportAnswer(answerQuestion);
|
|
|
+ if (answerQuestion.length() > 1) {
|
|
|
+ type = 2; //多选
|
|
|
+ } else {
|
|
|
+ type = 1; //单选
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("正确".equals(answerQuestion)) {
|
|
|
+ answerQuestion = "1";
|
|
|
+ type = 3; //判断
|
|
|
+ } else if ("错误".equals(answerQuestion)) {
|
|
|
+ answerQuestion = "0";
|
|
|
+ type = 3;
|
|
|
+ } else {
|
|
|
+ analysisContent = answerQuestion; //简答题把正确答案填充到解析文本
|
|
|
+ type = 5; //简答题
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (content.startsWith("解题思路")||(nowPart==8&&!isLineStart(content))) {
|
|
|
+ nowPart = 8;
|
|
|
+ analysisContent = analysisContent + content +"<br />";
|
|
|
+ }
|
|
|
+ else if (content.startsWith("考查考点")||(nowPart==9&&!isLineStart(content))) {
|
|
|
+ nowPart = 9;
|
|
|
+ analysisContent = analysisContent + content +"<br />";
|
|
|
+ }
|
|
|
+ else if (content.startsWith("老师解答")||(nowPart==10&&!isLineStart(content))) {
|
|
|
+ nowPart = 10;
|
|
|
+ analysisContent = analysisContent + content +"<br />";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //遍历正文
|
|
|
+ int importSort = 1;
|
|
|
+ Collections.reverse(list4);
|
|
|
+ Collections.reverse(list3);
|
|
|
+ Collections.reverse(list2);
|
|
|
+ Collections.reverse(list1);
|
|
|
+ for(QuestionAddBo addBo : list3){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ for(QuestionAddBo addBo : list4){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ for(QuestionAddBo addBo : list2){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ for(QuestionAddBo addBo : list1){
|
|
|
+ addBo.setImportSort(importSort + addBo.getCreateTime());
|
|
|
+ list.add(addBo);
|
|
|
+ importSort++;
|
|
|
+ }
|
|
|
+ // buffer = extractor.getText();
|
|
|
+ //extractor.close();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new CustomException("请导入word文件!");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println("此文件不是word文件!" + e.getMessage() + e.toString() + e.getLocalizedMessage());
|
|
|
+ }
|
|
|
+ Collections.reverse(list);
|
|
|
+ result.put("list",list);
|
|
|
+ result.put("errorLog",errorLog);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> importJJWordQuestionList(MultipartFile file, Long eduId, Long projectId, Long businessId, Long subjectId) {
|
|
|
Map<String,Object> result = new HashMap<>();
|
|
@@ -2247,6 +2648,8 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean batchDelQuestion(QuestionBatchDelBo bo) {
|