|
@@ -1,8 +1,10 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.service;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.BeanCopierUtil;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.IoUtils;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.Model;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.enums.PaperStatus;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
@@ -29,10 +31,7 @@ import org.springframework.data.domain.Example;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.OutputStream;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -98,12 +97,25 @@ public class ImportPaperService {
|
|
|
* @param file
|
|
|
* @return
|
|
|
*/
|
|
|
- public File getUploadFile(CommonsMultipartFile file) throws Exception {
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
- File tempFile = new File(DocxProcessUtil.TEMP_FILE_IMP + fileName);
|
|
|
- OutputStream os = new FileOutputStream(tempFile);
|
|
|
- IOUtils.copyLarge(file.getInputStream(), os);
|
|
|
- IOUtils.closeQuietly(os);
|
|
|
+ public File getUploadFile(CommonsMultipartFile file) {
|
|
|
+ File tempFile = new File(DocxProcessUtil.TEMP_FILE_IMP + file.getOriginalFilename());
|
|
|
+
|
|
|
+ OutputStream os;
|
|
|
+ try {
|
|
|
+ os = new FileOutputStream(tempFile);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new StatusException("500", "文件操作失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ try (InputStream is = file.getInputStream();) {
|
|
|
+ IOUtils.copyLarge(is, os);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(os);
|
|
|
+ }
|
|
|
+
|
|
|
return tempFile;
|
|
|
}
|
|
|
|
|
@@ -1821,7 +1833,7 @@ public class ImportPaperService {
|
|
|
}
|
|
|
//重新上传新的音频文件
|
|
|
upyun.writeFile(upYunProperty.getRadioUploadPath() + newAudioFileName, audioFile, true);
|
|
|
- audioFile.delete();
|
|
|
+ IoUtils.removeFile(audioFile);
|
|
|
|
|
|
//拷贝旧对象
|
|
|
QuestionAudio newAudio = new QuestionAudio(newQuestion.getId(), oldAudio.getFileName(), upYunProperty.getRadioUploadPath() + newAudioFileName);
|
|
@@ -1830,7 +1842,8 @@ public class ImportPaperService {
|
|
|
questionAudioService.saveQuestionAudio(newAudio, user);
|
|
|
}
|
|
|
//删除文件夹
|
|
|
- copyAudioDir.delete();
|
|
|
+ IoUtils.removeFile(copyAudioDir);
|
|
|
+
|
|
|
//查询新音频
|
|
|
List<QuestionAudio> newQuestionAudios = questionAudioService.findQuestionAudiosByQuestionId(newQuestion.getId());
|
|
|
Map<String, String> newMap = new HashMap<>();
|