浏览代码

feat:智能陪练一期

Joburgess 3 年之前
父节点
当前提交
273bc40daf

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysMusicCompareRecordDao.java

@@ -23,6 +23,15 @@ public interface SysMusicCompareRecordDao extends BaseDAO<Long, SysMusicCompareR
                                                   @Param("endTime") String endTime);
 
     /**
+     * @describe 获取用户最后一次评测数据
+     * @author Joburgess
+     * @date 2021/8/23 0023
+     * @param userId:
+     * @return com.ym.mec.biz.dal.entity.SysMusicCompareRecord
+     */
+    SysMusicCompareRecord getUserLastEvaluationData(@Param("userId") Integer userId);
+
+    /**
      * @describe 获取用户训练总览
      * @author Joburgess
      * @date 2021/8/11 0011

+ 41 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/MusicalNotesPlayStatDto.java

@@ -0,0 +1,41 @@
+package com.ym.mec.biz.dal.dto;
+
+import com.ym.mec.biz.dal.enums.MusicalErrorTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Author Joburgess
+ * @Date 2021/8/23 0023
+ */
+public class MusicalNotesPlayStatDto {
+
+    @ApiModelProperty("音符数")
+    private int musicalNotesIndex;
+
+    @ApiModelProperty("错误类型")
+    private MusicalErrorTypeEnum musicalErrorType;
+
+    public MusicalNotesPlayStatDto() {
+    }
+
+    public MusicalNotesPlayStatDto(int musicalNotesIndex, MusicalErrorTypeEnum musicalErrorType) {
+        this.musicalNotesIndex = musicalNotesIndex;
+        this.musicalErrorType = musicalErrorType;
+    }
+
+    public int getMusicalNotesIndex() {
+        return musicalNotesIndex;
+    }
+
+    public void setMusicalNotesIndex(int musicalNotesIndex) {
+        this.musicalNotesIndex = musicalNotesIndex;
+    }
+
+    public MusicalErrorTypeEnum getMusicalErrorType() {
+        return musicalErrorType;
+    }
+
+    public void setMusicalErrorType(MusicalErrorTypeEnum musicalErrorType) {
+        this.musicalErrorType = musicalErrorType;
+    }
+}

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

@@ -63,6 +63,9 @@ public class SoundCompareHelper implements PitchDetectionHandler {
     @ApiModelProperty(value = "音符频率字典")
     private Map<Integer, Float> musicalNotePitchMap = new HashMap<>();
 
+    @ApiModelProperty(value = "每个音符评测结果")
+    private List<MusicalNotesPlayStatDto> musicalNotesPlayStats = new ArrayList<>();
+
     @ApiModelProperty(value = "偏移时间量,解决客户端录音播放不同步导致的声音留白")
     private int offsetTime = -1;
 
@@ -186,6 +189,14 @@ public class SoundCompareHelper implements PitchDetectionHandler {
         this.measureEndTime = measureEndTime;
     }
 
+    public List<MusicalNotesPlayStatDto> getMusicalNotesPlayStats() {
+        return musicalNotesPlayStats;
+    }
+
+    public void setMusicalNotesPlayStats(List<MusicalNotesPlayStatDto> musicalNotesPlayStats) {
+        this.musicalNotesPlayStats = musicalNotesPlayStats;
+    }
+
     public List<MusicPitchDetailDto> getRecordMeasurePithInfo() {
         return recordMeasurePithInfo;
     }

+ 38 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/MusicalErrorTypeEnum.java

@@ -0,0 +1,38 @@
+package com.ym.mec.biz.dal.enums;
+
+import com.ym.mec.common.enums.BaseEnum;
+
+/**
+ * 员工角色枚举
+ */
+public enum MusicalErrorTypeEnum implements BaseEnum<String, MusicalErrorTypeEnum> {
+	RIGHT("RIGHT", "演奏正确"),
+	WRONG("WRONG", "错音"),
+	NOT_PLAY("NOT_PLAY", "未演奏");
+
+	private String code;
+
+	private String msg;
+
+	MusicalErrorTypeEnum(String code, String msg) {
+		this.code = code;
+		this.msg = msg;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getMsg() {
+		return msg;
+	}
+
+	public void setMsg(String msg) {
+		this.msg = msg;
+	}
+
+	@Override
+	public String getCode() {
+		return this.code;
+	}
+}

+ 11 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/SysMusicCompareRecordService.java

@@ -1,14 +1,12 @@
 package com.ym.mec.biz.service;
 
-import com.ym.mec.biz.dal.dto.CountStudentTrainDataDto;
-import com.ym.mec.biz.dal.dto.MusicCompareRankingDto;
-import com.ym.mec.biz.dal.dto.SoundCompareHelper;
-import com.ym.mec.biz.dal.dto.StatDto;
+import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
 import com.ym.mec.biz.dal.page.SysMusicCompareRecordQueryInfo;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 
+import java.util.List;
 import java.util.Map;
 
 public interface SysMusicCompareRecordService extends BaseService<Long, SysMusicCompareRecord> {
@@ -24,6 +22,15 @@ public interface SysMusicCompareRecordService extends BaseService<Long, SysMusic
     void saveMusicCompareData(String phone, SoundCompareHelper soundCompareInfo);
 
     /**
+     * @describe 用户最后一次评测数据
+     * @author Joburgess
+     * @date 2021/8/23 0023
+     * @param userId:
+     * @return java.util.List<com.ym.mec.biz.dal.dto.MusicalNotesPlayStatDto>
+     */
+    List<MusicalNotesPlayStatDto> getLastEvaluationMusicalNotesPlayStats(Integer userId);
+
+    /**
      * @describe 云教练排行榜
      * @author Joburgess
      * @date 2021/8/11 0011

+ 15 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SoundCompareHandler.java

@@ -8,11 +8,9 @@ import com.alibaba.fastjson.JSON;
 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.MusicPitchDetailDto;
-import com.ym.mec.biz.dal.dto.SoundCompareHelper;
-import com.ym.mec.biz.dal.dto.WavHeader;
-import com.ym.mec.biz.dal.dto.WebSocketInfo;
+import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.enums.DeviceTypeEnum;
+import com.ym.mec.biz.dal.enums.MusicalErrorTypeEnum;
 import com.ym.mec.biz.dal.enums.WebsocketTypeEnum;
 import com.ym.mec.biz.handler.WebSocketHandler;
 import com.ym.mec.biz.service.SoundSocketService;
@@ -390,6 +388,9 @@ public class SoundCompareHandler implements WebSocketEventHandler {
                     userSoundInfoMap.get(phone).getMusicalNotePitchMap().put(musicXmlInfo.getMusicalNotesIndex(), (float) pitch);
                 }
 
+                boolean cadenceRight = false;
+                boolean intonationRight = false;
+
                 //有效节奏占比
                 float cadenceDuty = cadenceValidNum/compareNum;
                 //如果频率出现断层或这个音量出现断层,则当前音符节奏无效
@@ -399,6 +400,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
                 //节奏
                 if(cadenceDuty>=soundCompareConfig.cadenceValidDuty){
                     cadenceNum++;
+                    cadenceRight = true;
                 }
                 //音准
                 if (!CollectionUtils.isEmpty(measureSoundPitchInfos)){
@@ -420,6 +422,7 @@ public class SoundCompareHandler implements WebSocketEventHandler {
                     }
                     intonationScore += score;
                     musicXmlInfo.setAvgFrequency(avgPitch.floatValue());
+                    intonationRight = score>70;
                 }
                 //完成度
                 if(integrityValidNum > compareNum){
@@ -427,6 +430,14 @@ public class SoundCompareHandler implements WebSocketEventHandler {
                 }
                 float integrityDuty = integrityValidNum/compareNum;
                 integrityScore += integrityDuty;
+
+                if(cadenceRight&&intonationRight){
+                    userSoundInfoMap.get(phone).getMusicalNotesPlayStats().add(new MusicalNotesPlayStatDto(musicXmlInfo.getMusicalNotesIndex(), MusicalErrorTypeEnum.RIGHT));
+                }else if(cadenceRight&&!intonationRight){
+                    userSoundInfoMap.get(phone).getMusicalNotesPlayStats().add(new MusicalNotesPlayStatDto(musicXmlInfo.getMusicalNotesIndex(), MusicalErrorTypeEnum.WRONG));
+                }else{
+                    userSoundInfoMap.get(phone).getMusicalNotesPlayStats().add(new MusicalNotesPlayStatDto(musicXmlInfo.getMusicalNotesIndex(), MusicalErrorTypeEnum.NOT_PLAY));
+                }
             }
 
             BigDecimal measureNum = new BigDecimal(totalCompareNum);

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

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.StudentDao;
 import com.ym.mec.biz.dal.dao.SysMusicCompareRecordDao;
@@ -15,6 +16,7 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
@@ -56,7 +58,10 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
 		sysMusicCompareRecord.setUserId(user.getId());
 		sysMusicCompareRecord.setSysMusicScoreId(soundCompareInfo.getMusicScoreId());
 		sysMusicCompareRecord.setBehaviorId(soundCompareInfo.getBehaviorId());
-		sysMusicCompareRecord.setScoreData(JSON.toJSONString(soundCompareInfo.getUserMeasureScoreMap()));
+		Map<String, Object> scoreData = new HashMap<>();
+		scoreData.put("userMeasureScore", soundCompareInfo.getUserMeasureScoreMap());
+		scoreData.put("musicalNotesPlayStats", soundCompareInfo.getMusicalNotesPlayStats());
+		sysMusicCompareRecord.setScoreData(JSON.toJSONString(scoreData));
 		if (Objects.nonNull(soundCompareInfo.getUserMeasureScoreMap()) && soundCompareInfo.getUserMeasureScoreMap().containsKey(-1)){
 			Map<String, Object> finalScore = soundCompareInfo.getUserMeasureScoreMap().get(-1);
 			sysMusicCompareRecord.setScore((BigDecimal) finalScore.get("score"));
@@ -76,6 +81,19 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
 	}
 
 	@Override
+	public List<MusicalNotesPlayStatDto> getLastEvaluationMusicalNotesPlayStats(Integer userId) {
+		SysMusicCompareRecord userLastEvaluationData = sysMusicCompareRecordDao.getUserLastEvaluationData(userId);
+		if(StringUtils.isBlank(userLastEvaluationData.getScoreData())){
+			return Collections.emptyList();
+		}
+		JSONObject jsonObject = JSON.parseObject(userLastEvaluationData.getScoreData());
+		if(!jsonObject.containsKey("musicalNotesPlayStats")){
+			return Collections.emptyList();
+		}
+		return jsonObject.getObject("musicalNotesPlayStats", List.class);
+	}
+
+	@Override
 	public StatDto rankingList(Integer headUserId,int type, String startDate, String endDate) {
 		StatDto result = new StatDto();
 		MusicCompareRankingDto head = new MusicCompareRankingDto();

+ 4 - 0
mec-biz/src/main/resources/config/mybatis/SysMusicCompareRecordMapper.xml

@@ -372,4 +372,8 @@
 							   DATE( smcr.create_time_ ))= CURDATE()) t
 		GROUP BY t.organ_id_
 	</select>
+
+    <select id="getUserLastEvaluationData" resultMap="SysMusicCompareRecord">
+		SELECT * FROM sys_music_compare_record WHERE user_id_=#{userId} ORDER BY create_time_ DESC LIMIT 1
+	</select>
 </mapper>

+ 13 - 0
mec-student/src/main/java/com/ym/mec/student/controller/SysMusicCompareRecordController.java

@@ -2,6 +2,7 @@ package com.ym.mec.student.controller;
 
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.dto.MusicalNotesPlayStatDto;
 import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
 import com.ym.mec.biz.service.SysMusicCompareRecordService;
 import com.ym.mec.common.controller.BaseController;
@@ -10,10 +11,12 @@ import com.ym.mec.common.exception.BizException;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -45,4 +48,14 @@ public class SysMusicCompareRecordController extends BaseController {
         return succeed(sysMusicCompareRecordService.insert(record));
     }
 
+    @ApiOperation(value = "用户最后一次评测数据")
+    @GetMapping("getLastEvaluationMusicalNotesPlayStats")
+    public HttpResponseResult<List<MusicalNotesPlayStatDto>> getLastEvaluationMusicalNotesPlayStats(){
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if(sysUser == null){
+            throw new BizException("请登录");
+        }
+        return succeed(sysMusicCompareRecordService.getLastEvaluationMusicalNotesPlayStats(sysUser.getId()));
+    }
+
 }

+ 13 - 0
mec-teacher/src/main/java/com/ym/mec/teacher/controller/SysMusicCompareRecordController.java

@@ -2,6 +2,7 @@ package com.ym.mec.teacher.controller;
 
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.dto.MusicalNotesPlayStatDto;
 import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
 import com.ym.mec.biz.service.SysMusicCompareRecordService;
 import com.ym.mec.common.controller.BaseController;
@@ -10,10 +11,12 @@ import com.ym.mec.common.exception.BizException;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -45,4 +48,14 @@ public class SysMusicCompareRecordController extends BaseController {
         return succeed(sysMusicCompareRecordService.insert(record));
     }
 
+    @ApiOperation(value = "用户最后一次评测数据")
+    @GetMapping("getLastEvaluationMusicalNotesPlayStats")
+    public HttpResponseResult<List<MusicalNotesPlayStatDto>> getLastEvaluationMusicalNotesPlayStats(){
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if(sysUser == null){
+            throw new BizException("请登录");
+        }
+        return succeed(sysMusicCompareRecordService.getLastEvaluationMusicalNotesPlayStats(sysUser.getId()));
+    }
+
 }

+ 13 - 0
mec-web/src/main/java/com/ym/mec/web/controller/education/SysMusicCompareRecordController.java

@@ -2,6 +2,7 @@ package com.ym.mec.web.controller.education;
 
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.dto.MusicalNotesPlayStatDto;
 import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
 import com.ym.mec.biz.service.SysMusicCompareRecordService;
 import com.ym.mec.common.controller.BaseController;
@@ -10,10 +11,12 @@ import com.ym.mec.common.exception.BizException;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -45,4 +48,14 @@ public class SysMusicCompareRecordController extends BaseController {
         return succeed(sysMusicCompareRecordService.insert(record));
     }
 
+    @ApiOperation(value = "用户最后一次评测数据")
+    @GetMapping("getLastEvaluationMusicalNotesPlayStats")
+    public HttpResponseResult<List<MusicalNotesPlayStatDto>> getLastEvaluationMusicalNotesPlayStats(){
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if(sysUser == null){
+            throw new BizException("请登录");
+        }
+        return succeed(sysMusicCompareRecordService.getLastEvaluationMusicalNotesPlayStats(sysUser.getId()));
+    }
+
 }