|
@@ -21,6 +21,8 @@ import org.apache.commons.io.FileUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.socket.BinaryMessage;
|
|
@@ -52,7 +54,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
|
|
|
private final String tmpDir = FileUtils.getTempDirectoryPath() + "/soundCompare/";
|
|
|
/**
|
|
|
- * @describe 用户对应评分信息------------------------------------------------------------------------------
|
|
|
+ * @describe 用户对应评分信息
|
|
|
*/
|
|
|
private Map<String, SoundCompareHelper> userSoundInfoMap = new ConcurrentHashMap<>();
|
|
|
/**
|
|
@@ -72,13 +74,12 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void afterConnectionEstablished(WebSocketSession session) {
|
|
|
- System.out.println("已登录:+++++++++++++++++++++++++++++++++++++++++++++++++++");
|
|
|
+ public void afterConnectionEstablished(WebSocketSession session, String phone) {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void receiveTextMessage(WebSocketSession session, TextMessage message) {
|
|
|
- String phone = session.getPrincipal().getName().split(":")[1];
|
|
|
+ public void receiveTextMessage(WebSocketSession session, String phone, TextMessage message) {
|
|
|
WebSocketInfo webSocketInfo = JSON.parseObject(message.getPayload(), WebSocketInfo.class);
|
|
|
JSONObject bodyObject = (JSONObject) webSocketInfo.getBody();
|
|
|
|
|
@@ -89,6 +90,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
switch (commond){
|
|
|
case SoundSocketService.MUSIC_XML:
|
|
|
userSoundInfoMap.put(phone, new SoundCompareHelper());
|
|
|
+ userSoundInfoMap.get(phone).setClientId(((OAuth2Authentication)session.getPrincipal()).getOAuth2Request().getClientId());
|
|
|
List<MusicPitchDetailDto> musicXmlInfos = JSON.parseArray(bodyObject.getString("musicXmlInfos"), MusicPitchDetailDto.class);
|
|
|
userSoundInfoMap.get(phone).setMusicXmlInfos(musicXmlInfos);
|
|
|
musicXmlInfos = musicXmlInfos.stream().filter(m->!m.getDontEvaluating()).collect(Collectors.toList());
|
|
@@ -153,8 +155,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void receiveBinaryMessage(WebSocketSession session, BinaryMessage message) {
|
|
|
- String phone = session.getPrincipal().getName().split(":")[1];
|
|
|
+ public void receiveBinaryMessage(WebSocketSession session, String phone, BinaryMessage message) {
|
|
|
if(!userSoundInfoMap.containsKey(phone)){
|
|
|
return;
|
|
|
}
|
|
@@ -191,9 +192,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void afterConnectionClosed(WebSocketSession session){
|
|
|
- String phone = session.getPrincipal().getName().split(":")[1];
|
|
|
- LOGGER.info("发生了错误,移除客户端: {}", phone);
|
|
|
+ public void afterConnectionClosed(WebSocketSession session, String phone){
|
|
|
createHeader(phone);
|
|
|
userSoundInfoMap.remove(phone);
|
|
|
}
|
|
@@ -439,7 +438,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
* @param phone:
|
|
|
* @return void
|
|
|
*/
|
|
|
- private void calTotalScore(String phone) throws IOException {
|
|
|
+ private void calTotalScore(String phone) {
|
|
|
int totalCompareNum = userSoundInfoMap.get(phone).getMeasureXmlInfoMap().keySet().size();
|
|
|
int currentCompareNum = totalCompareNum-userSoundInfoMap.get(phone).getMeasureEndTime().keySet().size();
|
|
|
BigDecimal intonation = BigDecimal.ZERO;
|
|
@@ -478,10 +477,8 @@ public class SoundCompareHandler implements WebSocketEventHandler {
|
|
|
HashMap<String, String> header = new HashMap<>();
|
|
|
header.put("commond", command);
|
|
|
webSocketInfo.setHeader(header);
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
-// BigDecimal score = intonation.multiply(new BigDecimal(0.5)).add(cadence.multiply(new BigDecimal(0.5))).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ Map<String, Object> result = new HashMap<>(5);
|
|
|
BigDecimal score = intonation.add(cadence).add(integrity).divide(new BigDecimal(3), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0, BigDecimal.ROUND_UP);
|
|
|
-// BigDecimal score = integrity.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
result.put("score", score);
|
|
|
result.put("intonation", intonation);
|
|
|
result.put("cadence", cadence);
|