Эх сурвалжийг харах

修改化学试卷不符合标准的内容,修改考试内容上传bug

4228306 5 жил өмнө
parent
commit
d6cb430478

BIN
doc/化学中考专项诊断.docx


+ 9 - 5
src/main/java/com/yaoxiang/diagnosis/controller/PaperController.java

@@ -89,7 +89,9 @@ public class PaperController {
     //    @PreAuthorize("hasRole('ROLE_ADMIN')")
     @ApiOperation(value = "上传试卷")
     @PostMapping("uploadPaper")
-    @ApiImplicitParam(name = "paperTemplateId", value = "试卷模板Id 默认1")
+    @ApiImplicitParams({@ApiImplicitParam(name = "paperTemplateId", paramType = "query", value = "试卷模板Id 默认1"),
+            @ApiImplicitParam(name = "useAbility", paramType = "query", defaultValue = "false")
+    })
     public Result uploadPaper(PaperVo paperVo,
                               @RequestParam(defaultValue = "1") Long paperTemplateId,
                               @RequestBody MultipartFile file) throws IOException {
@@ -108,12 +110,14 @@ public class PaperController {
         return paperService.uploadPaper(paperVo, paperTemplateId, url, data);
     }
 
-    @ApiOperation(value = "测试上传试卷")
+    @ApiOperation(value = "测试上传试卷,不会保存试卷")
     @PostMapping("uploadPaperTest")
-    @ApiImplicitParam(name = "paperTemplateId", value = "试卷模板Id 默认1")
+    @ApiImplicitParams({@ApiImplicitParam(name = "paperTemplateId", paramType = "query", value = "试卷模板Id 默认1"),
+            @ApiImplicitParam(name = "useAbility", paramType = "query", defaultValue = "false")
+    })
     public Result uploadPaperTest(PaperVo paperVo,
-                              @RequestParam(defaultValue = "1") Long paperTemplateId,
-                              @RequestBody MultipartFile file) throws IOException {
+                                  @RequestParam(defaultValue = "1") Long paperTemplateId,
+                                  @RequestBody MultipartFile file) throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         FileCopyUtils.copy(file.getInputStream(), baos);
         int suffixIndex = file.getOriginalFilename().lastIndexOf(".");

+ 10 - 0
src/main/java/com/yaoxiang/diagnosis/model/PaperVo.java

@@ -20,6 +20,8 @@ public class PaperVo {
     private Long typeId;
     @ApiModelProperty("科目类别Id 2")
     private Long subjectId;
+    @ApiModelProperty
+    private Boolean useAbility;
 
     public String getName() {
         return name;
@@ -84,4 +86,12 @@ public class PaperVo {
     public void setSubjectId(Long subjectId) {
         this.subjectId = subjectId;
     }
+
+    public Boolean getUseAbility() {
+        return useAbility;
+    }
+
+    public void setUseAbility(Boolean useAbility) {
+        this.useAbility = useAbility;
+    }
 }

+ 2 - 2
src/main/java/com/yaoxiang/diagnosis/service/PaperService.java

@@ -398,8 +398,8 @@ public class PaperService {
             paper.setGrade(g + (first ? "X" : "Y"));
             sb.append(g).append("年级").append(first ? "上学期" : "下学期");
         }
-        boolean A = name.endsWith("A");
-        sb.append(A ? "A卷" : "B卷");
+        //取最后一个字为卷,一般为A、B卷
+        sb.append(name.substring(name.length() -1)).append("卷");
         paper.setName(sb.toString());
     }
 

+ 3 - 2
src/main/java/com/yaoxiang/diagnosis/service/QuestionService.java

@@ -135,8 +135,9 @@ public class QuestionService {
         Question question = new Question();
         question.setCreatetime(new Date());
         question.setScore(1D);
-        question.setNumber(startNumber + number);
-        question.setCode(number);
+        question.setNumber(number);
+        //更改code
+        question.setCode(number - startNumber);
         question.setDuration(60);
         question.setSection(section);
         return question;

+ 12 - 4
src/main/java/com/yaoxiang/diagnosis/word/WordService.java

@@ -269,12 +269,20 @@ public class WordService {
     public void parsePicture(XWPFParagraph p, String picturePattern) {
         String text = p.getText();
         Matcher matcher = Pattern.compile(picturePattern).matcher(text);
-        if (!matcher.find()) {
+        //如果没有图片 并且 没有标签 直接跳过
+        boolean hasPicture = WordUtil.hasPicture(p);
+        if (!hasPicture && !matcher.find()) {
             logger.info("parsePicture,before parse run ,no picture: {}", text);
             return;
+        } else if (!hasPicture && matcher.find()) {
+            String msg = "parsePicture error,find tag but not picture: " + text;
+            logger.error(msg, new RuntimeException(msg));
+            return;
+        }
+        String size = Constants.PICTURE_SIZE_MIDDLE;
+        if (matcher.find()) {
+            size = matcher.group().replaceAll("#", "");
         }
-        String size = matcher.group().replaceAll("#", "");
-
         logger.info("parsePicture,before parse run: " + text);
         List<XWPFRun> runs = p.getRuns();
         int i = 0;
@@ -284,7 +292,7 @@ public class WordService {
             logger.debug("run pos " + (i++) + " embed picture size " + pictures.size());
 //            String img = "<img src=\"%s\" style=\"width: %spt;height: %spt\" />";
             //图片水平居中
-            String img = "<p style=\"text-align:center\"><img src=\"%s\" style=\"max-width:100%; width:%spx; center\" /></p>";
+            String img = "<p style=\"text-align:center\"><img src=\"%s\" style=\"max-width:100%%; width:%spx; center\" /></p>";
             if (CommonUtil.notEmpty(pictures)) {
                 //只处理第一张图片
                 XWPFPicture pp = pictures.get(0);

+ 11 - 3
src/main/java/com/yaoxiang/diagnosis/word/WordUtil.java

@@ -134,16 +134,24 @@ public class WordUtil {
         }
     }
 
-    public static boolean hasContent(XWPFParagraph paragraph, String text) {
+    public static boolean hasContent(XWPFParagraph p, String text) {
         if (StringUtils.isNotBlank(text)) {
             return true;
         }
-        for (XWPFRun run : paragraph.getRuns()) {
+        return hasPicture(p) || hasFormula(p);
+    }
+
+    public static boolean hasPicture(XWPFParagraph p) {
+        for (XWPFRun run : p.getRuns()) {
             if (run.getEmbeddedPictures().size() > 0) {
                 return true;
             }
         }
-        return paragraph.getCTP().getOMathList().size() > 0;
+        return false;
+    }
+
+    public static boolean hasFormula(XWPFParagraph p) {
+        return p.getCTP().getOMathList().size() > 0;
     }
 
     public static boolean notContent(XWPFParagraph paragraph, String text) {

+ 6 - 0
src/test/java/com/yaoxiang/diagnosis/service/StringTest.java

@@ -29,4 +29,10 @@ public class StringTest {
         String t = "您的%s处于有待开发的阶段。对%s进行专项训练可以帮助您快速提高%s成绩。";
         System.out.println(String.format(t, (Object[]) a));
     }
+
+    @Test
+    public void testString3(){
+        String text = "asdf";
+        System.out.println(text.substring(text.length()));
+    }
 }