|
@@ -19,6 +19,9 @@ import com.ym.mec.biz.service.SysMusicCompareRecordService;
|
|
|
import com.ym.mec.biz.service.WebSocketEventHandler;
|
|
|
import com.ym.mec.common.constant.CommonConstants;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
+import com.ym.mec.thirdparty.storage.StoragePluginContext;
|
|
|
+import com.ym.mec.thirdparty.storage.provider.KS3StoragePlugin;
|
|
|
+import com.ym.mec.util.upload.UploadUtil;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -64,6 +67,8 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
public static final SoundCompareConfig soundCompareConfig = new SoundCompareConfig();
|
|
|
|
|
|
@Autowired
|
|
|
+ private StoragePluginContext storagePluginContext;
|
|
|
+ @Autowired
|
|
|
private SysMusicCompareRecordService sysMusicCompareRecordService;
|
|
|
@Autowired
|
|
|
private SysMusicScoreAccompanimentDao sysMusicScoreAccompanimentDao;
|
|
@@ -124,6 +129,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
}
|
|
|
try {
|
|
|
File file = new File(tmpDir+phone + "_"+ userSoundInfoMap.get(phone).getMusicScoreId() +"_"+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) +".wav");
|
|
|
+ userSoundInfoMap.get(phone).setFile(file);
|
|
|
userSoundInfoMap.get(phone).setAccessFile(new RandomAccessFile(file, "rw"));
|
|
|
userSoundInfoMap.get(phone).setRecordFilePath(file.getAbsolutePath());
|
|
|
} catch (FileNotFoundException e) {
|
|
@@ -204,7 +210,6 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
@Override
|
|
|
public void afterConnectionClosed(WebSocketSession session, String phone){
|
|
|
createHeader(phone);
|
|
|
- userSoundInfoMap.remove(phone);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -246,6 +251,21 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
}
|
|
|
userSoundInfoMap.get(phone).setAccessFile(null);
|
|
|
}
|
|
|
+
|
|
|
+ String url = null;
|
|
|
+ try {
|
|
|
+ String folder = UploadUtil.getFileFloder();
|
|
|
+ url = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME,"soundCompare/" + folder, userSoundInfoMap.get(phone).getFile());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("录音文件上传失败:{}", e);
|
|
|
+ }
|
|
|
+ userSoundInfoMap.get(phone).setRecordFilePath(url);
|
|
|
+ //存储评分数据
|
|
|
+ sysMusicCompareRecordService.saveMusicCompareData(phone, userSoundInfoMap.get(phone));
|
|
|
+
|
|
|
+ if(Objects.nonNull(userSoundInfoMap.get(phone).getFile())){
|
|
|
+ userSoundInfoMap.get(phone).getFile().deleteOnExit();
|
|
|
+ }
|
|
|
userSoundInfoMap.remove(phone);
|
|
|
}
|
|
|
|
|
@@ -467,9 +487,6 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
//计算分数并推送
|
|
|
createPushInfo(phone, "overall", -1, intonation, cadence, integrity);
|
|
|
|
|
|
- //存储评分数据
|
|
|
- sysMusicCompareRecordService.saveMusicCompareData(phone, userSoundInfoMap.get(phone));
|
|
|
-
|
|
|
LOGGER.info("评分数据:{}", JSON.toJSONString(userSoundInfoMap.get(phone)));
|
|
|
}
|
|
|
|