Ver Fonte

feat:云教练评测视频上传

Joburgess há 4 anos atrás
pai
commit
4705d54a33

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

@@ -63,6 +63,8 @@ public class SysMusicCompareRecord {
 
 	private DeviceTypeEnum deviceType;
 
+	private float sourceTime = 0;
+
 	private float playTime = 0;
 
 	private String clientId;
@@ -195,6 +197,14 @@ public class SysMusicCompareRecord {
 		this.deviceType = deviceType;
 	}
 
+	public float getSourceTime() {
+		return sourceTime;
+	}
+
+	public void setSourceTime(float sourceTime) {
+		this.sourceTime = sourceTime;
+	}
+
 	public float getPlayTime() {
 		return playTime;
 	}

+ 11 - 7
mec-biz/src/main/java/com/ym/mec/biz/handler/WebSocketHandler.java

@@ -56,6 +56,9 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
     @Override
     public void afterConnectionEstablished(WebSocketSession session) throws Exception {
         String phone = session.getPrincipal().getName().split(":")[1];
+        if(WS_CLIENTS.containsKey(phone)){
+            WS_CLIENTS.get(phone).getSession().close();
+        }
         LOGGER.info("{}上线", phone);
         WS_CLIENTS.put(phone, new WebSocketClientDetail(session, System.currentTimeMillis()));
         appMap.values().forEach(e->e.afterConnectionEstablished(session, phone));
@@ -96,13 +99,13 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
     public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
         String phone = session.getPrincipal().getName().split(":")[1];
         session.close();
-        LOGGER.info("发生了错误,移除客户端: {}", phone, exception);
-        appMap.values().forEach(e->e.afterConnectionClosed(session, phone));
-        exception.printStackTrace();
-        if(!WS_CLIENTS.containsKey(phone)){
-            return;
-        }
-        WS_CLIENTS.remove(phone);
+        LOGGER.info("{}异常: {}", phone, exception);
+//        appMap.values().forEach(e->e.afterConnectionClosed(session, phone));
+//        exception.printStackTrace();
+//        if(!WS_CLIENTS.containsKey(phone)){
+//            return;
+//        }
+//        WS_CLIENTS.remove(phone);
     }
 
     @Override
@@ -111,6 +114,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
         String phone = session.getPrincipal().getName().split(":")[1];
         LOGGER.info("{}离线: {}s", phone, (System.currentTimeMillis() - WS_CLIENTS.get(phone).getLoginTime())/1000);
         appMap.values().forEach(e->e.afterConnectionClosed(session, phone));
+        session.close();
         WS_CLIENTS.remove(phone);
     }
 

+ 1 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SoundCompareHandler.java

@@ -294,8 +294,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
         //存储评分数据
         if(saveData){
             sysMusicCompareRecordService.saveMusicCompareData(phone, userSoundInfoMap.get(phone));
-            userSoundInfoMap.get(phone).setRecordId(null);
-        }else if(Objects.nonNull(userSoundInfoMap.get(phone).getRecordId())){
+        }else if(Objects.nonNull(userSoundInfoMap.get(phone).getFile())){
             sysMusicCompareRecordService.delete(userSoundInfoMap.get(phone).getRecordId());
         }
 

+ 8 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysMusicCompareRecordServiceImpl.java

@@ -8,9 +8,11 @@ import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.IndexBaseMonthData;
 import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
 import com.ym.mec.biz.dal.entity.SysMusicScore;
-import com.ym.mec.biz.dal.enums.*;
+import com.ym.mec.biz.dal.enums.FeatureType;
+import com.ym.mec.biz.dal.enums.HeardLevelEnum;
+import com.ym.mec.biz.dal.enums.IndexDataType;
+import com.ym.mec.biz.dal.enums.MessageTypeEnum;
 import com.ym.mec.biz.dal.page.SysMusicCompareRecordQueryInfo;
-import com.ym.mec.biz.service.SysConfigService;
 import com.ym.mec.biz.service.SysMessageService;
 import com.ym.mec.biz.service.SysMusicCompareRecordService;
 import com.ym.mec.biz.service.SysMusicCompareWeekDataService;
@@ -20,7 +22,6 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
-import io.swagger.models.auth.In;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -96,6 +97,10 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
 		sysMusicCompareRecord.setRecordFilePath(soundCompareInfo.getRecordFilePath());
 		sysMusicCompareRecord.setDeviceType(soundCompareInfo.getDeviceType());
 		sysMusicCompareRecord.setClientId(soundCompareInfo.getClientId());
+		if(!CollectionUtils.isEmpty(soundCompareInfo.getMusicXmlInfos())){
+			MusicPitchDetailDto lastMeasure = soundCompareInfo.getMusicXmlInfos().stream().max(Comparator.comparing(MusicPitchDetailDto::getTimeStamp)).get();
+			sysMusicCompareRecord.setSourceTime((lastMeasure.getTimeStamp()+lastMeasure.getDuration())/1000);
+		}
 		if(Objects.nonNull(soundCompareInfo.getFile())){
 			sysMusicCompareRecord.setPlayTime(soundCompareInfo.getFile().length()/(SoundCompareHandler.soundCompareConfig.audioFormat.getFrameSize()*SoundCompareHandler.soundCompareConfig.audioFormat.getFrameRate()));
 		}

+ 6 - 2
mec-biz/src/main/resources/config/mybatis/SysMusicCompareRecordMapper.xml

@@ -23,6 +23,7 @@
 		<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="source_time_" property="sourceTime"/>
 		<result column="play_time_" property="playTime"/>
 		<result column="feature_" property="feature" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
 		<result column="monday_" property="monday"/>
@@ -48,11 +49,11 @@
 		-->
 		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_,video_file_path_,device_type_,client_id_,play_time_,monday_,
-											feature_,create_time_,update_time_)
+												source_time_,feature_,create_time_,update_time_)
 		VALUES(#{id},#{userId},#{sysMusicScoreId},#{heardLevel,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{behaviorId},#{scoreData},
 		       #{score},#{intonation},#{cadence},#{integrity},
 		       #{recordFilePath},#{videoFilePath},#{deviceType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{clientId},#{playTime},#{monday},
-		       #{feature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, NOW(), NOW())
+		       #{sourceTime},#{feature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, NOW(), NOW())
 	</insert>
 
 	<!-- 根据主键查询一条记录 -->
@@ -94,6 +95,9 @@
 		<if test="deviceType!=null">
 			device_type_ = #{deviceType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
 		</if>
+		<if test="sourceTime != null">
+			source_time_ = #{sourceTime},
+		</if>
 		<if test="playTime != null">
 			play_time_ = #{playTime},
 		</if>