|
@@ -9,10 +9,8 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.biz.dal.config.SoundCompareConfig;
|
|
|
import com.ym.mec.biz.dal.dao.SysMusicScoreAccompanimentDao;
|
|
|
import com.ym.mec.biz.dal.dto.*;
|
|
|
-import com.ym.mec.biz.dal.enums.DeviceTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.HeardLevelEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.MusicalErrorTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.WebsocketTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
|
|
|
+import com.ym.mec.biz.dal.enums.*;
|
|
|
import com.ym.mec.biz.handler.WebSocketHandler;
|
|
|
import com.ym.mec.biz.service.SoundSocketService;
|
|
|
import com.ym.mec.biz.service.SysMusicCompareRecordService;
|
|
@@ -43,6 +41,8 @@ import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.ym.mec.biz.service.SoundSocketService.VIDEO_UPDATE;
|
|
|
+
|
|
|
/**
|
|
|
* @Author Joburgess
|
|
|
* @Date 2021/8/5 0005
|
|
@@ -90,6 +90,9 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
|
|
|
switch (message.getHeader().getCommond()){
|
|
|
case SoundSocketService.MUSIC_XML:
|
|
|
+ if(userSoundInfoMap.containsKey(phone)){
|
|
|
+ createHeader(phone, false);
|
|
|
+ }
|
|
|
userSoundInfoMap.put(phone, new SoundCompareHelper());
|
|
|
userSoundInfoMap.get(phone).setClientId(((OAuth2Authentication)session.getPrincipal()).getOAuth2Request().getClientId());
|
|
|
List<MusicPitchDetailDto> musicXmlInfos = JSON.parseArray(bodyObject.getString("musicXmlInfos"), MusicPitchDetailDto.class);
|
|
@@ -114,6 +117,9 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
if(bodyObject.containsKey("heardLevel")){
|
|
|
userSoundInfoMap.get(phone).setHeardLevel(HeardLevelEnum.valueOf(bodyObject.getString("heardLevel")));
|
|
|
}
|
|
|
+ if(bodyObject.containsKey("speed")){
|
|
|
+ userSoundInfoMap.get(phone).setSpeed(bodyObject.getIntValue("speed"));
|
|
|
+ }
|
|
|
List<Integer> subjectIds = sysMusicScoreAccompanimentDao.findSubjectByMusicScoreId(userSoundInfoMap.get(phone).getMusicScoreId(), null);
|
|
|
if(!CollectionUtils.isEmpty(subjectIds)){
|
|
|
userSoundInfoMap.get(phone).setSubjectId(subjectIds.get(0));
|
|
@@ -129,7 +135,10 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
musicPitchDetailDto.setDontEvaluating(dc == userMeasureXmlInfoEntry.getValue().size());
|
|
|
userSoundInfoMap.get(phone).getMeasureEndTime().put(userMeasureXmlInfoEntry.getKey(), musicPitchDetailDto);
|
|
|
}
|
|
|
-
|
|
|
+ SysMusicCompareRecord sysMusicCompareRecord = new SysMusicCompareRecord(FeatureType.CLOUD_STUDY_EVALUATION);
|
|
|
+ sysMusicCompareRecordService.insert(sysMusicCompareRecord);
|
|
|
+ LOGGER.info("评测记录编号:{}", sysMusicCompareRecord.getId());
|
|
|
+ userSoundInfoMap.get(phone).setRecordId(sysMusicCompareRecord.getId());
|
|
|
break;
|
|
|
case SoundSocketService.RECORD_START:
|
|
|
if(!userSoundInfoMap.containsKey(phone)){
|
|
@@ -163,10 +172,10 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
} finally {
|
|
|
calTotalScore(phone);
|
|
|
}
|
|
|
- createHeader(phone);
|
|
|
+ createHeader(phone, true);
|
|
|
break;
|
|
|
case SoundSocketService.RECORD_CANCEL:
|
|
|
- createHeader(phone);
|
|
|
+ createHeader(phone, false);
|
|
|
break;
|
|
|
case SoundSocketService.PROXY_MESSAGE:
|
|
|
if(DeviceTypeEnum.IOS.equals(userSoundInfoMap.get(phone).getDeviceType())&&bodyObject.containsKey(SoundSocketService.OFFSET_TIME)){
|
|
@@ -174,6 +183,16 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
calOffsetTime(phone, offsetTime);
|
|
|
}
|
|
|
break;
|
|
|
+ case VIDEO_UPDATE:
|
|
|
+ SysMusicCompareRecord update = null;
|
|
|
+ if(bodyObject.containsKey("recordId")){
|
|
|
+ update = sysMusicCompareRecordService.get(bodyObject.getLong("recordId"));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(update)&&bodyObject.containsKey("filePath")){
|
|
|
+ update.setVideoFilePath(bodyObject.getString("filePath"));
|
|
|
+ sysMusicCompareRecordService.update(update);
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -218,7 +237,10 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
|
|
|
@Override
|
|
|
public void afterConnectionClosed(WebSocketSession session, String phone){
|
|
|
- createHeader(phone);
|
|
|
+ if(userSoundInfoMap.containsKey(phone)&&Objects.nonNull(userSoundInfoMap.get(phone).getFile())){
|
|
|
+ createHeader(phone, false);
|
|
|
+ }
|
|
|
+ userSoundInfoMap.remove(phone);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -244,7 +266,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
* @param phone:
|
|
|
* @return void
|
|
|
*/
|
|
|
- private void createHeader(String phone){
|
|
|
+ private void createHeader(String phone, boolean saveData){
|
|
|
if(!userSoundInfoMap.containsKey(phone)){
|
|
|
return;
|
|
|
}
|
|
@@ -272,13 +294,18 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
userSoundInfoMap.get(phone).setRecordFilePath(url);
|
|
|
}
|
|
|
//存储评分数据
|
|
|
- sysMusicCompareRecordService.saveMusicCompareData(phone, userSoundInfoMap.get(phone));
|
|
|
+ if(saveData){
|
|
|
+ sysMusicCompareRecordService.saveMusicCompareData(phone, userSoundInfoMap.get(phone));
|
|
|
+ userSoundInfoMap.get(phone).setRecordId(null);
|
|
|
+ }else if(Objects.nonNull(userSoundInfoMap.get(phone).getRecordId())){
|
|
|
+ sysMusicCompareRecordService.delete(userSoundInfoMap.get(phone).getRecordId());
|
|
|
+ }
|
|
|
|
|
|
if(Objects.nonNull(userSoundInfoMap.get(phone).getFile())){
|
|
|
userSoundInfoMap.get(phone).getFile().delete();
|
|
|
+ userSoundInfoMap.get(phone).setFile(null);
|
|
|
+ userSoundInfoMap.get(phone).setAccessFile(null);
|
|
|
}
|
|
|
-
|
|
|
- userSoundInfoMap.remove(phone);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -420,7 +447,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
//音准、完成度
|
|
|
if (cadenceRight && !CollectionUtils.isEmpty(measureSoundPitchInfos)){
|
|
|
//音准
|
|
|
- Double avgPitch = measureSoundPitchInfos.stream().filter(pitch -> Math.abs((pitch.getFrequency()-musicXmlInfo.getFrequency()))<5).collect(Collectors.averagingDouble(pitch -> pitch.getFrequency()));
|
|
|
+ Double avgPitch = measureSoundPitchInfos.stream().filter(pitch -> Math.abs((pitch.getFrequency()-musicXmlInfo.getFrequency()))<15).collect(Collectors.averagingDouble(pitch -> pitch.getFrequency()));
|
|
|
//音分
|
|
|
double recordCents = 0;
|
|
|
if (avgPitch > 0){
|
|
@@ -441,7 +468,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
intonationRight = score>70;
|
|
|
|
|
|
if(score>0){
|
|
|
- integrityValidNum = measureSoundPitchInfos.stream().filter(pitch -> Math.abs((pitch.getFrequency()-musicXmlInfo.getFrequency()))<5).count();
|
|
|
+ integrityValidNum = measureSoundPitchInfos.stream().filter(pitch -> Math.abs((pitch.getFrequency()-musicXmlInfo.getFrequency()))<15).count();
|
|
|
}else{
|
|
|
integrityValidNum = 0;
|
|
|
}
|
|
@@ -539,7 +566,9 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
WebSocketInfo webSocketInfo = new WebSocketInfo();
|
|
|
webSocketInfo.setHeader(new WebSocketInfo.Head(command));
|
|
|
Map<String, Object> result = new HashMap<>(5);
|
|
|
+ //打击乐只看节奏分
|
|
|
BigDecimal score = cadence;
|
|
|
+ //非打击乐总分为平均分
|
|
|
if(Objects.isNull(userSoundInfoMap.get(phone).getSubjectId())||userSoundInfoMap.get(phone).getSubjectId()!=23){
|
|
|
score = intonation.add(cadence).add(integrity).divide(new BigDecimal(3), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0, BigDecimal.ROUND_UP);
|
|
|
}
|
|
@@ -548,11 +577,12 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
result.put("cadence", cadence);
|
|
|
result.put("integrity", integrity);
|
|
|
result.put("measureIndex", measureIndex);
|
|
|
+ result.put("recordId", userSoundInfoMap.get(phone).getRecordId());
|
|
|
webSocketInfo.setBody(result);
|
|
|
|
|
|
userSoundInfoMap.get(phone).getUserMeasureScoreMap().put(measureIndex, result);
|
|
|
|
|
|
- LOGGER.info("小节频分:{}", JSON.toJSONString(webSocketInfo));
|
|
|
+ LOGGER.info("{}小节评分:{}", phone, JSON.toJSONString(webSocketInfo));
|
|
|
|
|
|
//推送结果
|
|
|
WebSocketHandler.sendTextMessage(phone, webSocketInfo);
|