完成音乐其他指令

This commit is contained in:
wulin 2023-10-07 10:54:57 +08:00
parent b47c49df82
commit a0a0ce78c0
12 changed files with 7753 additions and 29 deletions

View File

@ -73,4 +73,8 @@ public class SystemTalkAnswerConfigEntity extends GenericEntity<Long> {
@Column(name = "answer_type", nullable = false)
private Integer answerType;
@Comment("音频时播放状态0 开始播放 1 暂停 2 继续 3 停止 10无此资源")
@Column(name = "play_type", nullable = false)
private Integer playType;
}

View File

@ -56,4 +56,10 @@ public class SystemTalkAnswerConfigRequest implements java.io.Serializable {
//"回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级"
private Integer answerType;
/**
* 音频时播放状态0 开始播放 1 暂停 2 继续 3 停止 10无此资源
*/
private Integer playType;
}

View File

@ -34,4 +34,10 @@ public class SystemTalkAnswerConfigResp {
//"回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级"
private Integer answerType;
/**
* 音频时播放状态0 开始播放 1 暂停 2 继续 3 停止 10无此资源
*/
private Integer playType;
}

View File

@ -101,6 +101,10 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
if(request.getAnswerType() != null){
reactiveQuery = reactiveQuery.and(SystemTalkAnswerConfigRequest::getAnswerType, request.getAnswerType());
}
if(request.getPlayType() != null){
reactiveQuery = reactiveQuery.and(SystemTalkAnswerConfigRequest::getPlayType, request.getPlayType());
}
SortOrder sortOrder = null;
if(StringUtils.isNotEmpty(request.getOrder())){
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
@ -166,6 +170,9 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
if(request.getKeyOrder() != null){
reactiveQuery = reactiveQuery.and(SystemTalkAnswerConfigRequest::getKeyOrder, request.getKeyOrder());
}
if(request.getPlayType() != null){
reactiveQuery = reactiveQuery.and(SystemTalkAnswerConfigRequest::getPlayType, request.getPlayType());
}
SortOrder sortOrder = null;
if(StringUtils.isNotEmpty(request.getOrder())){
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
@ -239,6 +246,9 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
if(entity.getAnswerType() != null){
update = update.set(SystemTalkAnswerConfigEntity::getAnswerType, entity.getAnswerType());
}
if(entity.getPlayType() != null){
update = update.set(SystemTalkAnswerConfigEntity::getPlayType, entity.getPlayType());
}
return update.where(SystemTalkAnswerConfigEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
@ -258,6 +268,7 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
update = update.set(SystemTalkAnswerConfigEntity::getAnswerBackImg, entity.getAnswerBackImg());
update = update.set(SystemTalkAnswerConfigEntity::getKeyOrder, entity.getKeyOrder());
update = update.set(SystemTalkAnswerConfigEntity::getAnswerType, entity.getAnswerType());
update = update.set(SystemTalkAnswerConfigEntity::getPlayType, entity.getPlayType());
return update.where(SystemTalkAnswerConfigEntity::getId, entity.getId()).and("is_delete", 0).execute();
}

View File

@ -1,5 +1,6 @@
package com.qiuguo.iot.box.websocket.api.domain;
import com.qiuguo.iot.data.resp.third.MusicResp;
import lombok.Data;
import org.springframework.web.reactive.socket.WebSocketMessage;
import org.springframework.web.reactive.socket.WebSocketSession;
@ -15,9 +16,15 @@ public class BaseSession {
protected WebSocketSession session;
protected FluxSink<WebSocketMessage> sink;
protected String logId;//当前请求日志ID
/**
* 当前请求日志ID
*/
protected String logId;
protected String customerIP;//客户端IP
/**
* 客户端IP
*/
protected String customerIP;
/***
* 用户id
*/
@ -25,5 +32,11 @@ public class BaseSession {
/***
* 当前使用的BoxId如果未绑定那么就是0
*/
protected Long deviceId = 0l;
protected Long deviceId = 0L;
/***
* 当前歌曲状态正常客户端同步
* 用户登录时同步
*/
MusicResp music;
}

View File

@ -10,8 +10,5 @@ import reactor.core.publisher.FluxSink;
@Data
public class BoxSession extends BaseSession {
/***
* 设备序列号
*/
MusicResp music;//当前歌曲状态正常客户端同步
}

View File

@ -39,6 +39,7 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import javax.swing.*;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
@ -222,28 +223,43 @@ public class BaseWebSocketProcess {
if(StringUtils.isNotEmpty(action.getPName())){
search = search.replaceAll(action.getPName(), "");
}
musicService.searchMusic(search, 1).defaultIfEmpty(new ArrayList<>()).map(resultSongs -> {
BoxMessageResp resp = new BoxMessageResp();
MusicResp musicResp = new MusicResp();
if(resultSongs.size() > 0){
//
SongInfoResponse.ResultSong song = resultSongs.get(0);
musicResp.setPlay(PlayEnum.START.getCode());
musicResp.setName(song.getName());
musicResp.setUrl(song.getUrl());
musicResp.setSinger(song.getArtistName());
resp.setText("现在为您播放" + song.getName() +
(StringUtils.isNotEmpty(song.getArtistName()) ? ("来自" + song.getArtistName()) : ""));
}else{
musicResp.setPlay(PlayEnum.NONE.getCode());
resp.setText("未找到相关资源");
}
resp.setMusic(musicResp);
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
BoxMessageResp resp = new BoxMessageResp();
if(action.getSystemTalkAnswerConfigEntity().getPlayType().equals(PlayEnum.START.getCode())){
musicService.searchMusic(search, 1).defaultIfEmpty(new ArrayList<>()).map(resultSongs -> {
//BoxMessageResp resp = new BoxMessageResp();
MusicResp musicResp = new MusicResp();
if(resultSongs.size() > 0){
//
SongInfoResponse.ResultSong song = resultSongs.get(0);
musicResp.setPlay(PlayEnum.START.getCode());
musicResp.setName(song.getName());
musicResp.setUrl(song.getUrl());
musicResp.setSinger(song.getArtistName());
resp.setText("现在为您播放" + song.getName() +
(StringUtils.isNotEmpty(song.getArtistName()) ? ("来自" + song.getArtistName()) : ""));
}else{
musicResp.setPlay(PlayEnum.NONE.getCode());
resp.setText("未找到相关资源");
}
resp.setMusic(musicResp);
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
sendMessage(action, baseSession, resp);
return resultSongs;
}).subscribe();
}else if(baseSession.getMusic() != null){
//做相应的动作
baseSession.getMusic().setPlay(action.getSystemTalkAnswerConfigEntity().getPlayType());
resp.setMusic(baseSession.getMusic());
resp.setText("" + action.getAction() + baseSession.getMusic().getSinger());
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
sendMessage(action, baseSession, resp);
return resultSongs;
}).subscribe();
}else{
resp.setType(AskTypeEnum.TTS.getCode());
resp.setText("目前无播放资源,无法操作");
sendMessage(action, baseSession, resp);
}
}
}
}
@ -258,15 +274,42 @@ public class BaseWebSocketProcess {
talkRecord.setUserId(baseSession.getUserId());
talkRecord.setDeviceId(baseSession.getDeviceId());
if(resp.getType().equals(AskTypeEnum.MUSIC.getCode())) {
//客户端推送的
if(this instanceof CustomerWebSocketHandler) {
log.info("推送Box播放音乐");
BaseSession boxSession = getBoxSessionWithSn(baseSession.getSn());
BoxSession boxSession = getBoxSessionWithSn(baseSession.getSn());
if(boxSession != null){
boxSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
//记录音乐状态
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
//去掉内存中音乐同步对象
boxSession.setMusic(null);
baseSession.setMusic(null);
}else{
boxSession.setMusic(resp.getMusic());
}
}else{
log.info("设备sn{}不在线,无法播放", baseSession.getSn());
resp.setText("设备不在线,无法播放");
}
}else{//果box的
//记录音乐状态
BaseSession userSession = getUserSessionWithUserId(baseSession.getUserId());
//记录音乐状态
if(resp.getMusic().getPlay().equals(PlayEnum.STOP.getCode())){
//去掉内存中音乐同步对象
if(userSession != null){
userSession.setMusic(null);
//如果在线推送用户端
}
baseSession.setMusic(null);
}else{
if(userSession != null){
userSession.setMusic(resp.getMusic());
//如果在线推送用户端
}
baseSession.setMusic(resp.getMusic());
}
}
}
deviceUserTalkRecordService.insertDeviceUserTalkRecord(talkRecord).map(i ->{

View File

@ -167,7 +167,7 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
String signalMd5 = MD5.create().digestHex(snMd5 + wifiMd5 + btMd5 + linkTime + dv.getKey()).toUpperCase();
BaseSession boxSession = getBoxSessionWithSn(sn);
if(!signalMd5.equals(signature)){
log.info("设备{},验签失败", sn);
log.info("设备{},验签失败传入signature{}计算得到的为signalMd5{}", sn, signature, signalMd5);
//session.send(session.textMessage(""));
if(boxSession != null){

View File

@ -5,6 +5,7 @@ import com.qiuguo.iot.base.annotation.WebSocketMapping;
import com.qiuguo.iot.base.enums.YesNo;
import com.qiuguo.iot.base.utils.WebClientUtils;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
import com.qiuguo.iot.box.websocket.api.domain.user.UserTalkMessage;
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
@ -84,6 +85,11 @@ public class CustomerWebSocketHandler extends BaseWebSocketProcess implements We
userSession.setDeviceId(deviceUserBindEntity.getDeviceId());
userSession.setSn(deviceUserBindEntity.getOtherDeviceId());
}
BoxSession boxSession = getBoxSessionWithSn(deviceUserBindEntity.getOtherDeviceId());
if(boxSession != null){
log.info("主设备在线,同步主设备信息。比如音乐");
userSession.setMusic(boxSession.getMusic());
}
}
return Mono.empty();
}).subscribe();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff