|
@@ -1143,33 +1143,31 @@ public class PaperServiceImpl implements PaperService {
|
|
public void uploadRadio(List<MultipartFile> files, String paperId, User user) throws IOException {
|
|
public void uploadRadio(List<MultipartFile> files, String paperId, User user) throws IOException {
|
|
//根据试卷id,查询该试卷
|
|
//根据试卷id,查询该试卷
|
|
Paper paper = Model.of(paperRepo.findById(paperId));
|
|
Paper paper = Model.of(paperRepo.findById(paperId));
|
|
|
|
+
|
|
for (MultipartFile file : files) {
|
|
for (MultipartFile file : files) {
|
|
//判断文件大小
|
|
//判断文件大小
|
|
long fileSize = file.getSize();
|
|
long fileSize = file.getSize();
|
|
int size = Integer.parseInt(upYunProperty.getAudioMaxsize());
|
|
int size = Integer.parseInt(upYunProperty.getAudioMaxsize());
|
|
if (fileSize > size * 1048576) {
|
|
if (fileSize > size * 1048576) {
|
|
- throw new RuntimeException("音频文件大小超过5M,不能上传");
|
|
|
|
|
|
+ throw new IllegalArgumentException("音频文件大小超过5M,不能上传");
|
|
}
|
|
}
|
|
|
|
+
|
|
//根据试卷查询所有的小题,根据文件名匹配出当前小题ID
|
|
//根据试卷查询所有的小题,根据文件名匹配出当前小题ID
|
|
- Question question = null;
|
|
|
|
String numbers[] = file.getOriginalFilename().split("_");
|
|
String numbers[] = file.getOriginalFilename().split("_");
|
|
- /**
|
|
|
|
- * 注释代码功能,查询试卷中某个试题
|
|
|
|
- * 循环耗时,直接从数据查询对象
|
|
|
|
- */
|
|
|
|
- /*List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
|
- for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
|
- if(paperDetailUnit.getNumber().toString().equals(numbers[0])){
|
|
|
|
- question = paperDetailUnit.getQuestion();
|
|
|
|
- }
|
|
|
|
- }*/
|
|
|
|
- question = paperDetailUnitRepo.findByPaperAndNumber(paper, Integer.valueOf(numbers[0])).getQuestion();
|
|
|
|
|
|
+
|
|
|
|
+ PaperDetailUnit unit = paperDetailUnitRepo.findByPaperAndNumber(paper, Integer.valueOf(numbers[0]));
|
|
|
|
+ if (unit == null || unit.getQuestion() == null) {
|
|
|
|
+ throw new IllegalArgumentException("音频文件大小超过5M,不能上传");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Question question = unit.getQuestion();
|
|
uploadAudioFile(paperId, question.getId(), file, user);
|
|
uploadAudioFile(paperId, question.getId(), file, user);
|
|
appendAudioTag(file.getOriginalFilename(), question.getId());
|
|
appendAudioTag(file.getOriginalFilename(), question.getId());
|
|
|
|
|
|
//清除缓存
|
|
//清除缓存
|
|
this.clearQuestionCache(question.getId());
|
|
this.clearQuestionCache(question.getId());
|
|
}
|
|
}
|
|
|
|
+
|
|
//删除服务器文件夹
|
|
//删除服务器文件夹
|
|
String mp3DirectoryPath = TEMP_FILE_EXP + File.separator + paperId;
|
|
String mp3DirectoryPath = TEMP_FILE_EXP + File.separator + paperId;
|
|
File mp3Directory = new File(mp3DirectoryPath);
|
|
File mp3Directory = new File(mp3DirectoryPath);
|
|
@@ -1178,10 +1176,6 @@ public class PaperServiceImpl implements PaperService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 上传音频文件至又拍云
|
|
* 上传音频文件至又拍云
|
|
- *
|
|
|
|
- * @param paperId
|
|
|
|
- * @param questionId
|
|
|
|
- * @param file
|
|
|
|
*/
|
|
*/
|
|
private void uploadAudioFile(String paperId, String questionId, MultipartFile file, User user) {
|
|
private void uploadAudioFile(String paperId, String questionId, MultipartFile file, User user) {
|
|
try {
|
|
try {
|
|
@@ -1213,17 +1207,14 @@ public class PaperServiceImpl implements PaperService {
|
|
//保存记录
|
|
//保存记录
|
|
questionAudioService.saveQuestionAudio(new QuestionAudio(questionId, file.getOriginalFilename(), upYunProperty.getRadioUploadPath() + mp3FileNameString), user);
|
|
questionAudioService.saveQuestionAudio(new QuestionAudio(questionId, file.getOriginalFilename(), upYunProperty.getRadioUploadPath() + mp3FileNameString), user);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 音频文件插入到标签
|
|
* 音频文件插入到标签
|
|
- *
|
|
|
|
- * @param fileName
|
|
|
|
- * @param questionId
|
|
|
|
*/
|
|
*/
|
|
- public void appendAudioTag(String fileName, String questionId) {
|
|
|
|
|
|
+ private void appendAudioTag(String fileName, String questionId) {
|
|
QuestionAudio questionAudio = questionAudioService.findByQuestionIdAndFileName(questionId, fileName);
|
|
QuestionAudio questionAudio = questionAudioService.findByQuestionIdAndFileName(questionId, fileName);
|
|
if (questionAudio != null) {
|
|
if (questionAudio != null) {
|
|
String numbers[] = fileName.split("_");
|
|
String numbers[] = fileName.split("_");
|
|
@@ -1231,8 +1222,7 @@ public class PaperServiceImpl implements PaperService {
|
|
if (numbers[1].equals("1")) {
|
|
if (numbers[1].equals("1")) {
|
|
String quesBody = question.getQuesBody();
|
|
String quesBody = question.getQuesBody();
|
|
if (!quesBody.contains(fileName)) {
|
|
if (!quesBody.contains(fileName)) {
|
|
- String quesBodyNew = quesBody.substring(0, quesBody.lastIndexOf("</p>"))
|
|
|
|
- + "<a id=\"" + questionAudio.getId() + "\" name=\"" + fileName + "\"></a></p>";
|
|
|
|
|
|
+ String quesBodyNew = quesBody.substring(0, quesBody.lastIndexOf("</p>")) + "<a id=\"" + questionAudio.getId() + "\" name=\"" + fileName + "\"></a></p>";
|
|
question.setQuesBody(quesBodyNew);
|
|
question.setQuesBody(quesBodyNew);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|