deason 5 jaren geleden
bovenliggende
commit
42d2937f5f

+ 3 - 8
examcloud-core-questions-api-provider/src/main/java/cn/com/qmth/examcloud/core/questions/api/PaperController.java

@@ -569,7 +569,7 @@ public class PaperController extends ControllerSupport {
     @PostMapping(value = "/checkRadioFile/{paperId}")
     public ResponseEntity<Object> checkRadioFile(@PathVariable String paperId, @RequestBody List<String> filesName) {
         Map<String, String> errorMessage = paperService.checkRadioFile(paperId, filesName);
-        return new ResponseEntity<Object>(errorMessage, HttpStatus.OK);
+        return new ResponseEntity<>(errorMessage, HttpStatus.OK);
     }
 
     @ResponseBody
@@ -577,13 +577,8 @@ public class PaperController extends ControllerSupport {
     @PostMapping(value = "/uploadRadio/{paperId}")
     public ResponseEntity<Object> uploadRadio(List<MultipartFile> files, @PathVariable String paperId) {
         User user = getAccessUser();
-        try {
-            paperService.uploadRadio(files, paperId, user);
-            return new ResponseEntity<Object>(HttpStatus.OK);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return new ResponseEntity<Object>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
-        }
+        paperService.uploadRadio(files, paperId, user);
+        return new ResponseEntity<>(HttpStatus.OK);
     }
 
     @Naked

+ 1 - 3
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/PaperService.java

@@ -9,7 +9,6 @@ import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperExp;
 import org.springframework.data.domain.Page;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -243,9 +242,8 @@ public interface PaperService {
      *
      * @param files
      * @param paperId
-     * @throws IOException
      */
-    public void uploadRadio(List<MultipartFile> files, String paperId, User user) throws IOException;
+    public void uploadRadio(List<MultipartFile> files, String paperId, User user);
 
     /**
      * 计算试卷难度

+ 18 - 6
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/impl/PaperServiceImpl.java

@@ -1041,7 +1041,7 @@ public class PaperServiceImpl implements PaperService {
      * @return
      */
     public Map<String, String> checkRadioFile(String paperId, List<String> filesName) {
-        Map<String, String> messageMap = new HashMap<String, String>();
+        Map<String, String> messageMap = new HashMap<>();
         //判断文件名中格式是否正确
         for (String fileName : filesName) {
             String[] fileNames = fileName.split("\\.");
@@ -1050,30 +1050,36 @@ public class PaperServiceImpl implements PaperService {
                 messageMap.put("errorMsg", fileName + ",文件格式不正确,当前支持格式:" + upYunProperty.getRadioType());
                 return messageMap;
             }
+
             String pattern_01 = "\\d+_1_\\d{1,2}";                //题干正则
             String pattern_02 = "\\d+_2_[A-Z|a-z]_\\d{1,2}";    //选项正则
-            if (!(Pattern.matches(pattern_01, fileNames[0]) ||
-                    Pattern.matches(pattern_02, fileNames[0]))) {
+            if (!(Pattern.matches(pattern_01, fileNames[0]) || Pattern.matches(pattern_02, fileNames[0]))) {
                 messageMap.put("errorMsg", fileName + "文件名格式不正确,请检查");
                 return messageMap;
             }
         }
+
         //根据试卷id,查询该试卷
         Paper paper = Model.of(paperRepo.findById(paperId));
+
         //根据试卷查询所有的小题
         List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
+
         String names = "";
         for (PaperDetailUnit paperDetailUnit : paperDetailUnits) {
             names = names + paperDetailUnit.getNumber().toString() + ",";
         }
+
         for (String fileName : filesName) {
             String fileNames[] = fileName.split("_");
+
             //先判断小题号是否正确
             String fileNameFirst = fileNames[0];
             if (!names.contains(fileNameFirst)) {
                 messageMap.put("errorMsg", fileName + "文件,试卷中没有对应的小题");
                 return messageMap;
             }
+
             //再判断题干中是否存在ABCD
             String fileNameSecond = fileNames[1];
             if (fileNameSecond.equals("1")) {
@@ -1085,6 +1091,7 @@ public class PaperServiceImpl implements PaperService {
                     }
                 }
             }
+
             //判断选项
             else if (fileNameSecond.equals("2")) {
                 messageMap = checkOptions(paperDetailUnits, fileNames, fileName);
@@ -1097,6 +1104,7 @@ public class PaperServiceImpl implements PaperService {
                 return messageMap;
             }
         }
+
         messageMap.put("errorMsg", "OK");
         return messageMap;
     }
@@ -1140,7 +1148,7 @@ public class PaperServiceImpl implements PaperService {
      * @param paperId
      * @throws IOException
      */
-    public void uploadRadio(List<MultipartFile> files, String paperId, User user) throws IOException {
+    public void uploadRadio(List<MultipartFile> files, String paperId, User user) {
         //根据试卷id,查询该试卷
         Paper paper = Model.of(paperRepo.findById(paperId));
 
@@ -1173,8 +1181,12 @@ public class PaperServiceImpl implements PaperService {
 
         //删除服务器文件夹
         String mp3DirectoryPath = TEMP_FILE_EXP + File.separator + paperId;
-        File mp3Directory = new File(mp3DirectoryPath);
-        FileUtils.deleteDirectory(mp3Directory);
+        try {
+            File mp3Directory = new File(mp3DirectoryPath);
+            FileUtils.deleteDirectory(mp3Directory);
+        } catch (IOException e) {
+            log.error(e.getMessage(), e);
+        }
     }
 
     /**