|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginService;
|
|
|
import com.microsvc.toolkit.middleware.rtc.message.TencentRequest;
|
|
@@ -23,6 +24,7 @@ import com.yonge.cooleshow.common.entity.BaseResponse;
|
|
|
import com.yonge.cooleshow.common.enums.ErrorEnum;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.utils.date.DateUtil;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -31,11 +33,11 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.support.TransactionTemplate;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -85,7 +87,6 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
private ImService imService;
|
|
|
@Resource
|
|
|
private TransactionTemplate transactionTemplate;
|
|
|
-
|
|
|
@Override
|
|
|
public ImNetworkRoomDao getDao() {
|
|
|
return this.baseMapper;
|
|
@@ -114,9 +115,8 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
|
|
|
ImNetworkRoomResult joinRoomResult = new ImNetworkRoomResult();
|
|
|
String imUserId = imGroupService.getImUserId(sysUser.getUserId(), userRole);
|
|
|
- List<CourseScheduleStudentMusicSheetResult> studentMusicSheetResults =
|
|
|
- courseScheduleStudentMusicSheetService.getDao().queryBySheetIdAndCourseId(null,
|
|
|
- Long.parseLong(roomId), null, null, null);
|
|
|
+ List<CourseScheduleStudentMusicSheetResult> studentMusicSheetResults = this.initCourseScheduleStudentMusicScore(courseScheduleStudentMusicSheetService.getDao()
|
|
|
+ .queryBySheetIdAndCourseId(null,Long.parseLong(roomId), null, null, null));
|
|
|
//获取学员列表
|
|
|
List<CourseScheduleStudentPayment> studentPayments =
|
|
|
courseScheduleStudentPaymentService.lambdaQuery().eq(CourseScheduleStudentPayment::getCourseId,roomId).list();
|
|
@@ -184,6 +184,42 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
return BaseResponse.success(joinRoomResult);
|
|
|
}
|
|
|
|
|
|
+ private List<CourseScheduleStudentMusicSheetResult> initCourseScheduleStudentMusicScore(List<CourseScheduleStudentMusicSheetResult> scheduleStudentMusicScores) {
|
|
|
+ List<CourseScheduleStudentMusicSheetResult> result = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isEmpty(scheduleStudentMusicScores)){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<Long> musicSheetSoundIds = scheduleStudentMusicScores.stream().map(e->Long.parseLong(e.getMusicScoreAccompanimentId()))
|
|
|
+ .distinct().collect(Collectors.toList());
|
|
|
+ List<CbsMusicSheetWrapper.MusicSheetAccApplication> sheetApplications = this.getSheetApplications(musicSheetSoundIds);
|
|
|
+ Map<Long, CbsMusicSheetWrapper.MusicSheetAccApplication> sheetApplicationMap = sheetApplications.stream()
|
|
|
+ .collect(Collectors.toMap(CbsMusicSheetWrapper.MusicSheetAccApplication::getMusicSheetSoundId, Function.identity()));
|
|
|
+ for (CourseScheduleStudentMusicSheetResult studentMusicScore : scheduleStudentMusicScores) {
|
|
|
+ CbsMusicSheetWrapper.MusicSheetAccApplication sheetApplication =
|
|
|
+ sheetApplicationMap.get(Long.parseLong(studentMusicScore.getMusicScoreAccompanimentId()));
|
|
|
+ if(sheetApplication == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ studentMusicScore.setMusicScoreName(sheetApplication.getName());
|
|
|
+ //管乐迷的历史问题,原音和伴奏反过来
|
|
|
+ studentMusicScore.setMp3Url(sheetApplication.getUrl());
|
|
|
+ studentMusicScore.setUrl(sheetApplication.getMp3Url());
|
|
|
+ result.add(studentMusicScore);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CbsMusicSheetWrapper.MusicSheetAccApplication> getSheetApplications(List<Long> musicSheetSoundIds){
|
|
|
+ CbsMusicSheetWrapper.MusicSheetApplicationQuery query = musicSheetService.getMusicSheetApplicationQuery();
|
|
|
+ query.setRows(musicSheetSoundIds.size());
|
|
|
+ query.setMusicSheetSoundIds(musicSheetSoundIds);
|
|
|
+ List<CbsMusicSheetWrapper.MusicSheetAccApplication> applications = musicSheetService.queryCbsMusicSheetSoundApplication(query).getRows();
|
|
|
+ if (CollectionUtils.isEmpty(applications)) {
|
|
|
+ throw new BizException("曲目信息不存在");
|
|
|
+ }
|
|
|
+ return applications;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public BaseResponse<ImNetworkRoomResult> roomInfo(ImNetworkBaseDto imNetworkBaseDto) {
|
|
|
// 当前登录用户ID
|
|
@@ -211,7 +247,8 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
ImNetworkRoomMember roomMember = imNetworkRoomMemberService.lambdaQuery().eq(ImNetworkRoomMember::getRoomId,roomId)
|
|
|
.eq(ImNetworkRoomMember::getUserId,imUserId).last("LIMIT 1").one();
|
|
|
List<CourseScheduleStudentMusicSheetResult> studentMusicSheetResults =
|
|
|
- courseScheduleStudentMusicSheetService.getDao().queryBySheetIdAndCourseId(null, Long.parseLong(roomId), null, null, null);
|
|
|
+ this.initCourseScheduleStudentMusicScore(courseScheduleStudentMusicSheetService.getDao()
|
|
|
+ .queryBySheetIdAndCourseId(null, Long.parseLong(roomId), null, null, null));
|
|
|
if(!CollectionUtils.isEmpty(studentMusicSheetResults)){
|
|
|
List<CourseScheduleStudentMusicSheetResult> musicScores = studentMusicSheetResults.stream().
|
|
|
filter(e -> e.getUserId().equals(userId)).collect(Collectors.toList());
|
|
@@ -249,8 +286,8 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
}
|
|
|
|
|
|
private void setMusicSheetList(List<ImNetworkRoomMemberResult> roomMemberList,Long courseScheduleId){
|
|
|
- List<CourseScheduleStudentMusicSheetResult> musicSheetResults = courseScheduleStudentMusicSheetService.getDao().
|
|
|
- queryBySheetIdAndCourseId(null,courseScheduleId,null,null,null);
|
|
|
+ List<CourseScheduleStudentMusicSheetResult> musicSheetResults = this.initCourseScheduleStudentMusicScore(courseScheduleStudentMusicSheetService.getDao().
|
|
|
+ queryBySheetIdAndCourseId(null,courseScheduleId,null,null,null));
|
|
|
if (!CollectionUtils.isEmpty(musicSheetResults)) {
|
|
|
//分组塞到学员列表中
|
|
|
Map<String, List<CourseScheduleStudentMusicSheetResult>> musicSheetResultMap = musicSheetResults.stream().
|
|
@@ -380,14 +417,15 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void pushDownloadMusicSheetMsg(ImNetworkMusicSheetDto musicSheetDto) throws Exception {
|
|
|
String roomId = Optional.ofNullable(musicSheetDto).map(ImNetworkBaseDto::getRoomId).orElseThrow(() -> new BizException("房间编号不能为空"));
|
|
|
- Long accompanimentId = Optional.of(musicSheetDto).map(ImNetworkMusicSheetDto::getMusicScoreAccompanimentId).orElseThrow(() -> new BizException("伴奏编号不能为空"));
|
|
|
+ String accompanimentId = Optional.of(musicSheetDto).map(ImNetworkMusicSheetDto::getMusicScoreAccompanimentId).orElseThrow(() -> new BizException("伴奏编号不能为空"));
|
|
|
log.info("pushDownloadMusicSheetMsg: roomId:{} ,accompanimentId:{}", roomId,accompanimentId);
|
|
|
Long userId = sysUserService.getUserId();
|
|
|
- MusicSheetAccompaniment accompaniment = musicSheetAccompanimentService.getById(accompanimentId);
|
|
|
List<CourseScheduleStudentMusicSheetResult> scheduleStudentMusicSheetResults = courseScheduleStudentMusicSheetService.getDao().
|
|
|
queryBySheetIdAndCourseId(accompanimentId, Long.parseLong(roomId), null, null, 0);
|
|
|
|
|
|
- if (scheduleStudentMusicSheetResults.isEmpty()) {
|
|
|
+ //获取曲目信息
|
|
|
+ CbsMusicSheetWrapper.MusicSheetAccApplication sheetApplication = this.getSheetApplication(accompanimentId);
|
|
|
+ if (CollectionUtils.isEmpty(scheduleStudentMusicSheetResults)) {
|
|
|
//第一次下载,生成数据
|
|
|
List<CourseScheduleStudentPayment> studentPayments =
|
|
|
courseScheduleStudentPaymentService.lambdaQuery().eq(CourseScheduleStudentPayment::getCourseId,roomId).list();
|
|
@@ -395,7 +433,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
studentIds.forEach(e -> {
|
|
|
CourseScheduleStudentMusicSheetResult musicSheet = new CourseScheduleStudentMusicSheetResult();
|
|
|
musicSheet.setMusicScoreAccompanimentId(accompanimentId);
|
|
|
- musicSheet.setSpeed(accompaniment.getSpeed());
|
|
|
+ musicSheet.setSpeed(sheetApplication.getPlaySpeed());
|
|
|
musicSheet.setCourseScheduleId(Long.parseLong(roomId));
|
|
|
musicSheet.setUserId(e);
|
|
|
musicSheet.setUserType(0);
|
|
@@ -403,7 +441,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
});
|
|
|
CourseScheduleStudentMusicSheetResult musicSheet = new CourseScheduleStudentMusicSheetResult();
|
|
|
musicSheet.setMusicScoreAccompanimentId(accompanimentId);
|
|
|
- musicSheet.setSpeed(accompaniment.getSpeed());
|
|
|
+ musicSheet.setSpeed(sheetApplication.getPlaySpeed());
|
|
|
musicSheet.setCourseScheduleId(Long.parseLong(roomId));
|
|
|
musicSheet.setUserId(userId);
|
|
|
musicSheet.setUserType(1);
|
|
@@ -413,20 +451,14 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
//通知学员下载伴奏
|
|
|
// IM用户ID
|
|
|
String imUserId = imGroupService.getImUserId(userId,musicSheetDto.getClientType());
|
|
|
+ MusicSheetAccompaniment accompaniment = musicSheetAccompanimentService.initSysMusicScoreAccompaniment(sheetApplication);
|
|
|
+ accompaniment.setId(accompanimentId);
|
|
|
ImNetworkMusicSheetDownloadMessageContent content = JSON.parseObject(JSON.toJSONString(accompaniment), ImNetworkMusicSheetDownloadMessageContent.class);
|
|
|
if(StringUtils.isNotEmpty(accompaniment.getMusicSubjectId())){
|
|
|
content.setSubjectId(Integer.parseInt(accompaniment.getMusicSubjectId()));
|
|
|
}
|
|
|
content.setMp3Url(accompaniment.getAudioFileUrl());
|
|
|
- if(accompaniment.getMusicSheetId() != null){
|
|
|
- content.setExamSongId(accompaniment.getMusicSheetId().intValue());
|
|
|
- MusicSheet musicSheet = musicSheetService.getById(accompaniment.getMusicSheetId());
|
|
|
- if(musicSheet != null){
|
|
|
- content.setUrl(StringUtils.isNotEmpty(musicSheet.getAudioFileUrl())?musicSheet.getAudioFileUrl()
|
|
|
- :StringUtils.isNotEmpty(musicSheet.getMetronomeUrl())?musicSheet.getMetronomeUrl()
|
|
|
- :musicSheet.getUrl());
|
|
|
- }
|
|
|
- }
|
|
|
+ content.setUrl(accompaniment.getMetronomeUrl());
|
|
|
BasicUserInfo basicUserInfo = teacherDao.getBasicUserInfo(userId);
|
|
|
basicUserInfo.setImUserId(imUserId);
|
|
|
CourseSchedule courseSchedule = courseScheduleService.getById(roomId);
|
|
@@ -543,7 +575,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
long scheduleId = Long.parseLong(roomId);
|
|
|
switch (deviceControl.getDeviceType()) {
|
|
|
case MUSIC_SHEET:
|
|
|
- Integer musicSheetId = Optional.ofNullable(deviceControl.getMusicScoreAccompanimentId()).
|
|
|
+ String musicSheetId = Optional.ofNullable(deviceControl.getMusicScoreAccompanimentId()).
|
|
|
orElseThrow(()-> new BizException("请选择曲目"));
|
|
|
//关闭所有曲目播放
|
|
|
courseScheduleStudentMusicSheetService.getDao().closePlayStatus(scheduleId,userId);
|
|
@@ -551,7 +583,7 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
courseScheduleStudentMusicSheetService.getDao().openPlayStatus(scheduleId,musicSheetId,userId);
|
|
|
break;
|
|
|
case ACCOMPANIMENT:
|
|
|
- Integer musicSheetAccompanimentId = Optional.ofNullable(deviceControl.getMusicScoreAccompanimentId()).
|
|
|
+ String musicSheetAccompanimentId = Optional.ofNullable(deviceControl.getMusicScoreAccompanimentId()).
|
|
|
orElseThrow(()-> new BizException("请选择曲目"));
|
|
|
//关闭所有曲目播放
|
|
|
courseScheduleStudentMusicSheetService.getDao().closePlayStatus(scheduleId,userId);
|
|
@@ -649,17 +681,15 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void musicSheetDownNotify(ImNetworkMusicSheetDto musicSheetDto) throws Exception {
|
|
|
String roomId = Optional.ofNullable(musicSheetDto).map(ImNetworkBaseDto::getRoomId).orElseThrow(() -> new BizException("房间编号不能为空"));
|
|
|
- Long accompanimentId = Optional.of(musicSheetDto).map(ImNetworkMusicSheetDto::getMusicScoreAccompanimentId).orElseThrow(() -> new BizException("伴奏编号不能为空"));
|
|
|
+ String accompanimentId = Optional.of(musicSheetDto).map(ImNetworkMusicSheetDto::getMusicScoreAccompanimentId).orElseThrow(() -> new BizException("伴奏编号不能为空"));
|
|
|
Integer status = Optional.of(musicSheetDto).map(ImNetworkMusicSheetDto::getStatus).orElseThrow(() -> new BizException("伴奏下载状态不能为空"));
|
|
|
log.info("musicSheetDownNotify: roomId:{} ,accompanimentId:{} ,status:{}", roomId,accompanimentId,status);
|
|
|
Long userId = sysUserService.getUserId();
|
|
|
- List<CourseScheduleStudentMusicSheetResult> studentMusicSheetResults = courseScheduleStudentMusicSheetService.getDao().
|
|
|
- queryBySheetIdAndCourseId(accompanimentId, Long.parseLong(roomId),userId, null, null);
|
|
|
+ List<CourseScheduleStudentMusicSheetResult> studentMusicSheetResults = this.initCourseScheduleStudentMusicScore(courseScheduleStudentMusicSheetService.getDao().
|
|
|
+ queryBySheetIdAndCourseId(accompanimentId, Long.parseLong(roomId),userId, null, null));
|
|
|
if(CollectionUtils.isEmpty(studentMusicSheetResults)){
|
|
|
return;
|
|
|
}
|
|
|
- Optional.ofNullable(musicSheetAccompanimentService.getById(accompanimentId)).
|
|
|
- orElseThrow(()-> new BizException("曲目信息不存在"));
|
|
|
//修改下载状态
|
|
|
CourseScheduleStudentMusicSheetResult musicSheetResult = studentMusicSheetResults.get(0);
|
|
|
musicSheetResult.setDownStatus(status);
|
|
@@ -691,4 +721,15 @@ public class ImNetworkRoomServiceImpl extends ServiceImpl<ImNetworkRoomDao, ImNe
|
|
|
return Boolean.TRUE;
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ private CbsMusicSheetWrapper.MusicSheetAccApplication getSheetApplication(String musicSheetSoundId){
|
|
|
+ CbsMusicSheetWrapper.MusicSheetApplicationQuery query = musicSheetService.getMusicSheetApplicationQuery();
|
|
|
+ query.setRows(1);
|
|
|
+ query.setMusicSheetSoundId(Long.parseLong(musicSheetSoundId));
|
|
|
+ List<CbsMusicSheetWrapper.MusicSheetAccApplication> applications = musicSheetService.queryCbsMusicSheetSoundApplication(query).getRows();
|
|
|
+ if (org.apache.commons.collections.CollectionUtils.isEmpty(applications)) {
|
|
|
+ throw new BizException("曲目信息不存在");
|
|
|
+ }
|
|
|
+ return applications.get(0);
|
|
|
+ }
|
|
|
}
|