Browse Source

Merge remote-tracking branch 'origin/master'

zouxuan 4 years ago
parent
commit
6e55497b93

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/SoundCompareHelper.java

@@ -36,6 +36,9 @@ public class SoundCompareHelper implements PitchDetectionHandler {
     @ApiModelProperty(value = "声部编号")
     private Integer subjectId;
 
+    @ApiModelProperty(value = "评测记录编号")
+    private Long recordId;
+
     @ApiModelProperty(value = "评测等级")
     private HeardLevelEnum heardLevel = HeardLevelEnum.ADVANCED;
 
@@ -104,6 +107,14 @@ public class SoundCompareHelper implements PitchDetectionHandler {
         this.musicalNotePitchMap = musicalNotePitchMap;
     }
 
+    public Long getRecordId() {
+        return recordId;
+    }
+
+    public void setRecordId(Long recordId) {
+        this.recordId = recordId;
+    }
+
     public String getBehaviorId() {
         return behaviorId;
     }

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysMusicCompareRecord.java

@@ -51,6 +51,8 @@ public class SysMusicCompareRecord {
 	/** 录音文件地址 */
 	private String recordFilePath;
 
+	private String videoFilePath;
+
 	/** 周一日期 */
 	private String monday = LocalDate.now().with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()).toString();
 
@@ -177,6 +179,14 @@ public class SysMusicCompareRecord {
 		this.recordFilePath = recordFilePath;
 	}
 
+	public String getVideoFilePath() {
+		return videoFilePath;
+	}
+
+	public void setVideoFilePath(String videoFilePath) {
+		this.videoFilePath = videoFilePath;
+	}
+
 	public DeviceTypeEnum getDeviceType() {
 		return deviceType;
 	}

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/SoundSocketService.java

@@ -15,5 +15,6 @@ public interface SoundSocketService {
     String RECORD_CANCEL = "recordCancel";
     String PROXY_MESSAGE = "proxyMessage";
     String OFFSET_TIME = "offsetTime";
+    String VIDEO_UPDATE = "videoUpdate";
 
 }

+ 36 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SoundCompareHandler.java

@@ -9,6 +9,7 @@ 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.entity.SysMusicCompareRecord;
 import com.ym.mec.biz.dal.enums.DeviceTypeEnum;
 import com.ym.mec.biz.dal.enums.HeardLevelEnum;
 import com.ym.mec.biz.dal.enums.MusicalErrorTypeEnum;
@@ -43,6 +44,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 +93,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);
@@ -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();
+                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,14 @@ public class SoundCompareHandler implements WebSocketEventHandler {
                     calOffsetTime(phone, offsetTime);
                 }
                 break;
+            case VIDEO_UPDATE:
+                if(bodyObject.containsKey("filePath")){
+                    SysMusicCompareRecord update = new SysMusicCompareRecord();
+                    update.setId(userSoundInfoMap.get(phone).getRecordId());
+                    update.setVideoFilePath(bodyObject.getString("filePath"));
+                    sysMusicCompareRecordService.update(update);
+                }
+                break;
             default:
                 break;
         }
@@ -218,7 +235,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 +264,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 +292,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 +445,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 +466,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;
                     }
@@ -548,6 +573,7 @@ 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);

+ 7 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysMusicCompareRecordServiceImpl.java

@@ -100,7 +100,12 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
 			sysMusicCompareRecord.setPlayTime(soundCompareInfo.getFile().length()/(SoundCompareHandler.soundCompareConfig.audioFormat.getFrameSize()*SoundCompareHandler.soundCompareConfig.audioFormat.getFrameRate()));
 		}
 		sysMusicCompareRecord.setFeature(FeatureType.CLOUD_STUDY_EVALUATION);
-		sysMusicCompareRecordDao.insert(sysMusicCompareRecord);
+		sysMusicCompareRecord.setId(soundCompareInfo.getRecordId());
+		if(Objects.nonNull(sysMusicCompareRecord.getId())){
+			sysMusicCompareRecordDao.update(sysMusicCompareRecord);
+		}else{
+			sysMusicCompareRecordDao.insert(sysMusicCompareRecord);
+		}
 		studentDao.addStudentCloudStudySequenceDays(user.getId());
 		sysMusicCompareWeekDataService.updateUserWeekTrainData(user.getId(), LocalDate.now().with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue()));
 	}
@@ -127,6 +132,7 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
 		jsonObject.put("intonation", userLastEvaluationData.getIntonation());
 		jsonObject.put("integrity", userLastEvaluationData.getIntegrity());
 		jsonObject.put("heardLevel", userLastEvaluationData.getHeardLevel());
+		jsonObject.put("videoFilePath", userLastEvaluationData.getVideoFilePath());
 
 		SysMusicScore sysMusicScore = sysMusicScoreDao.get(userLastEvaluationData.getSysMusicScoreId());
 		if(Objects.nonNull(sysMusicScore)){

+ 25 - 11
mec-biz/src/main/resources/config/mybatis/SysMusicCompareRecordMapper.xml

@@ -20,6 +20,7 @@
 		<result column="cadence_" property="cadence" />
 		<result column="integrity_" property="integrity" />
 		<result column="record_file_path_" property="recordFilePath" />
+		<result column="video_file_path_" property="videoFilePath" />
 		<result column="device_type_" property="deviceType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
 		<result column="client_id_" property="clientId" />
 		<result column="play_time_" property="playTime"/>
@@ -46,12 +47,12 @@
 		</selectKey>
 		-->
 		INSERT INTO sys_music_compare_record (id_,user_id_,sys_music_score_id_,heard_level_,behavior_id_,score_data_,score_,intonation_,cadence_,integrity_,
-		                                      record_file_path_,device_type_,client_id_,play_time_,monday_,
-											feature_,create_time_)
+		                                      record_file_path_,video_file_path_,device_type_,client_id_,play_time_,monday_,
+											feature_,create_time_,update_time_)
 		VALUES(#{id},#{userId},#{sysMusicScoreId},#{heardLevel,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{behaviorId},#{scoreData},
 		       #{score},#{intonation},#{cadence},#{integrity},
-		       #{recordFilePath},#{deviceType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{clientId},#{playTime},#{monday},
-		       #{feature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, NOW())
+		       #{recordFilePath},#{videoFilePath},#{deviceType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{clientId},#{playTime},#{monday},
+		       #{feature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, NOW(), NOW())
 	</insert>
 
 	<!-- 根据主键查询一条记录 -->
@@ -60,39 +61,52 @@
 		<if test="userId != null">
 			user_id_ = #{userId},
 		</if>
-		<if test="id != null">
-			id_ = #{id},
-		</if>
 		<if test="sysMusicScoreId != null">
 			sys_music_score_id_ = #{sysMusicScoreId},
 		</if>
+		<if test="behaviorId!=null">
+			behavior_id_ = #{behaviorId},
+		</if>
 		<if test="scoreData != null">
 			score_data_ = #{scoreData},
 		</if>
 		<if test="score != null">
 			score_ = #{score},
 		</if>
+		<if test="intonation!=null">
+			intonation_ = #{intonation},
+		</if>
 		<if test="integrity != null">
 			integrity_ = #{integrity},
 		</if>
 		<if test="cadence != null">
 			cadence_ = #{cadence},
 		</if>
-		<if test="sysMusicScoreId != null">
-			sys_music_score_id_ = #{sysMusicScoreId},
-		</if>
 		<if test="recordFilePath != null">
 			record_file_path_ = #{recordFilePath},
 		</if>
+		<if test="videoFilePath != null">
+			video_file_path_ = #{videoFilePath},
+		</if>
 		<if test="clientId != null">
 			client_id_ = #{clientId},
 		</if>
+		<if test="deviceType!=null">
+			device_type_ = #{deviceType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+		</if>
 		<if test="playTime != null">
 			play_time_ = #{playTime},
 		</if>
 		<if test="monday != null">
 			monday_ = #{monday},
 		</if>
+		<if test="feature!=null">
+			feature_ = #{feature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+		</if>
+		<if test="heardLevel!=null">
+			heard_level_ = #{heardLevel,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+		</if>
+		update_time_ = NOW()
 	</set> WHERE id_ = #{id}
 	</update>
 
@@ -124,7 +138,7 @@
 			smcr.id_, smcr.user_id_, smcr.sys_music_score_id_, smcr.heard_level_,
 			LOCATE('musicalNotesPlayStats', smcr.score_data_) notes_data_index_,
 		       smcr.score_, smcr.intonation_, smcr.cadence_,
-		       smcr.integrity_, smcr.record_file_path_, smcr.client_id_, smcr.device_type_, smcr.play_time_,
+		       smcr.integrity_, smcr.record_file_path_, smcr.video_file_path_, smcr.client_id_, smcr.device_type_, smcr.play_time_,
 		       smcr.monday_, smcr.create_time_,
 			sms.name_ sys_music_score_name_
 		FROM sys_music_compare_record smcr