Parcourir la source

feat:云教练评测视频上传

Joburgess il y a 4 ans
Parent
commit
fe875b9b14

+ 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";
 
 }

+ 17 - 3
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
@@ -129,7 +132,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)){
@@ -174,6 +180,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;
         }
@@ -219,6 +233,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
     @Override
     public void afterConnectionClosed(WebSocketSession session, String phone){
         createHeader(phone);
+        userSoundInfoMap.remove(phone);
     }
 
     /**
@@ -277,8 +292,6 @@ public class SoundCompareHandler implements WebSocketEventHandler {
         if(Objects.nonNull(userSoundInfoMap.get(phone).getFile())){
             userSoundInfoMap.get(phone).getFile().delete();
         }
-
-        userSoundInfoMap.remove(phone);
     }
 
     /**
@@ -548,6 +561,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);

+ 6 - 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()));
 	}

+ 24 - 10
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>