播放音乐
This commit is contained in:
parent
e542f711e6
commit
d1aa9a6b54
@ -0,0 +1,24 @@
|
||||
package com.qiuguo.iot.base.enums;
|
||||
|
||||
/*
|
||||
* 是否
|
||||
* 作者:吴林
|
||||
* */
|
||||
// 播放音乐相关
|
||||
public enum PlayEnum {
|
||||
START(0),//开始
|
||||
PASUE(1),//暂停
|
||||
GO(2),//继续
|
||||
STOP(3),//停止
|
||||
|
||||
NONE(10),//无此资源
|
||||
;
|
||||
PlayEnum(Integer c){
|
||||
code = c;
|
||||
}
|
||||
private Integer code;
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.qiuguo.iot.data.resp.third;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class MusicResp {
|
||||
|
||||
/**
|
||||
* 播放状态
|
||||
* 0 开始播放 1 暂停 2 继续 3 停止 10无此资源
|
||||
*/
|
||||
Integer play;
|
||||
/**
|
||||
* 歌唱者
|
||||
*/
|
||||
String singer;
|
||||
/**
|
||||
* 音频文件
|
||||
*/
|
||||
String url;
|
||||
|
||||
/**
|
||||
* 歌词
|
||||
*/
|
||||
String lyric;
|
||||
/**
|
||||
* 歌名
|
||||
*/
|
||||
String name;
|
||||
}
|
||||
@ -18,8 +18,12 @@ public class Action {
|
||||
|
||||
private ActionTime time;//具体时间
|
||||
private List<String> lbs;//一些城市地狱名词
|
||||
/**
|
||||
* 人名
|
||||
*/
|
||||
private String pName;
|
||||
|
||||
/***
|
||||
/**
|
||||
* 原始记录话语
|
||||
*/
|
||||
private String ask;//原话
|
||||
|
||||
@ -3,6 +3,7 @@ package com.qiuguo.iot.third.service;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.utils.WebClientUtils;
|
||||
import com.qiuguo.iot.third.nlp.INlp;
|
||||
import com.qiuguo.iot.third.nlp.Nlp;
|
||||
import com.qiuguo.iot.third.nlp.NlpKey;
|
||||
@ -32,23 +33,19 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LacNlpService implements INlp {
|
||||
private static WebClient webClient = WebClient.builder()
|
||||
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE).build();
|
||||
//免得注入没有相关配置报错
|
||||
// @Value("${lac.url}")
|
||||
// private String url;
|
||||
|
||||
private Mono<JSONObject> getNlpFromLac(LacRequest request){
|
||||
|
||||
return webClient.post().uri(SpringUtil.getProperty("lac.url") + "/predict/lac").bodyValue(JSONObject.toJSON(request))
|
||||
.retrieve()
|
||||
.bodyToMono(JSONObject.class).doOnNext(res -> {
|
||||
if (!Objects.equals(res.getInteger("status"), 0)) {
|
||||
throw new RuntimeException(res.getString("info"));
|
||||
return WebClientUtils.post(SpringUtil.getProperty("lac.url") + "/predict/lac", (JSONObject) JSONObject.toJSON(request)).map(
|
||||
jsonObject -> {
|
||||
if (!Objects.equals(jsonObject.getInteger("status"), 0)) {
|
||||
throw new RuntimeException(jsonObject.getString("info"));
|
||||
}
|
||||
//log.info("", res);
|
||||
//log.info("res{}", res.toString());
|
||||
});
|
||||
return jsonObject;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -34,6 +34,13 @@ import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
||||
public class MusicService {
|
||||
|
||||
// 网易云音乐
|
||||
|
||||
/**
|
||||
*
|
||||
* @param keyword 关键字
|
||||
* @param type 1:歌名 100 歌手
|
||||
* @return
|
||||
*/
|
||||
public Mono<List<SongInfoResponse.ResultSong>> searchMusic(String keyword, Integer type) {
|
||||
if (ObjectUtils.isEmpty(type)) {
|
||||
type = 1;
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.qiuguo.iot.box.websocket.api.domain.box.resp;
|
||||
|
||||
import com.qiuguo.iot.data.resp.third.MusicResp;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ActionResp {
|
||||
@ -9,4 +11,5 @@ public class ActionResp {
|
||||
|
||||
String image;//圖片地址
|
||||
String action;//動作内容 json
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.qiuguo.iot.box.websocket.api.domain.box.resp;
|
||||
|
||||
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;
|
||||
@ -13,4 +14,6 @@ public class BoxMessageResp {
|
||||
|
||||
//其他動作
|
||||
ActionResp action;
|
||||
|
||||
MusicResp music;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.qiuguo.iot.box.websocket.api.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.enums.AskTypeEnum;
|
||||
import com.qiuguo.iot.base.enums.PlayEnum;
|
||||
import com.qiuguo.iot.base.enums.RespCodeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
|
||||
@ -14,6 +15,7 @@ import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
|
||||
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
|
||||
import com.qiuguo.iot.data.request.system.SystemTalkBindDeviceRequest;
|
||||
import com.qiuguo.iot.data.request.third.ThirdWeatherInfoRequest;
|
||||
import com.qiuguo.iot.data.resp.third.MusicResp;
|
||||
import com.qiuguo.iot.data.resp.third.weather.TianqiapiItemResp;
|
||||
import com.qiuguo.iot.data.service.device.DeviceUserBindService;
|
||||
import com.qiuguo.iot.data.service.device.DeviceUserTalkRecordService;
|
||||
@ -22,6 +24,7 @@ import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
|
||||
import com.qiuguo.iot.third.nlp.action.Action;
|
||||
import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.query.TuyaQuery;
|
||||
import com.qiuguo.iot.third.service.MusicService;
|
||||
import com.qiuguo.iot.third.service.NlpService;
|
||||
import com.qiuguo.iot.third.service.TuyaDeviceService;
|
||||
import com.qiuguo.iot.third.service.WeatherService;
|
||||
@ -34,6 +37,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Slf4j
|
||||
@ -59,6 +63,9 @@ public class BaseWebSocketProcess {
|
||||
@Autowired
|
||||
protected DeviceUserTalkRecordService deviceUserTalkRecordService;
|
||||
|
||||
@Autowired
|
||||
protected MusicService musicService;
|
||||
|
||||
|
||||
protected static ConcurrentHashMap<Long, BaseSession> userGroup = new ConcurrentHashMap<>();
|
||||
|
||||
@ -68,194 +75,182 @@ public class BaseWebSocketProcess {
|
||||
protected static String apiToken = "api-token";
|
||||
|
||||
protected void processAction(Actions actions, Long userId, BaseSession baseSession) {
|
||||
//目前只处理第一条动作
|
||||
Action action = actions.getActions().get(0);
|
||||
for (Action action : actions.getActions()
|
||||
) {
|
||||
log.info("匹配到自定义指令{}", action.getSystemTalkAnswerConfigEntity());
|
||||
if(action.getSystemTalkAnswerConfigEntity() == null){
|
||||
log.info("调用千问");
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(0);
|
||||
resp.setText("暂时无法理解,我还在努力学习中");
|
||||
sendMessage(action, baseSession, resp);
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.IOT.getCode())){
|
||||
|
||||
if(action.getName().size() > 0){
|
||||
String deviceName = action.getName().get(0);
|
||||
DeviceUserBindRequest deviceUserBindRequest = new DeviceUserBindRequest();
|
||||
deviceUserBindRequest.setUserId(userId);
|
||||
deviceUserBindRequest.setPageSize(2);
|
||||
deviceUserBindRequest.setBindName(deviceName);
|
||||
|
||||
log.info("匹配到自定义指令{}", action.getSystemTalkAnswerConfigEntity());
|
||||
if(action.getSystemTalkAnswerConfigEntity() == null){
|
||||
log.info("调用千问");
|
||||
sendMessage(action, baseSession, 0, "暂时无法理解,我还在努力学习中");
|
||||
}
|
||||
else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.IOT.getCode())){
|
||||
//查询是否有相关设备
|
||||
deviceUserBindService.selectDeviceUserBindsByRequest(deviceUserBindRequest)
|
||||
.defaultIfEmpty(new PagerResult<>(0, null))
|
||||
.map(binds ->{
|
||||
if(binds.getTotal() == 0){
|
||||
//返回告诉没有备
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
resp.setText("未找到相关设备,无法操做!");
|
||||
sendMessage(action, baseSession, resp);
|
||||
}else if(binds.getTotal() > 1){
|
||||
//返回告诉有多个设备,请详细说明具体说明设备
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
resp.setText("您有多个相同设备,请明确说明");
|
||||
sendMessage(action, baseSession, resp);
|
||||
}else{
|
||||
//查询是否有相关指令绑定
|
||||
DeviceUserBindEntity deviceUserBindEntity = binds.getData().get(0);
|
||||
SystemTalkBindDeviceRequest systemTalkBindDeviceRequest = new SystemTalkBindDeviceRequest();
|
||||
systemTalkBindDeviceRequest.setCategoryCode(deviceUserBindEntity.getCategoryCode());
|
||||
systemTalkBindDeviceRequest.setSystemTalkId(action.getSystemTalkAnswerConfigEntity().getId());
|
||||
systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(systemTalkBindDeviceRequest)
|
||||
.defaultIfEmpty(new SystemTalkBindDeviceEntity())
|
||||
.map(systemTalkBindDeviceEntity -> {
|
||||
if(systemTalkBindDeviceEntity.getId() == null){
|
||||
//通知不支持的指令
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
resp.setText(deviceName + "不支持" + action.getAction() + "指令!");
|
||||
sendMessage(action, baseSession, resp);
|
||||
|
||||
if(action.getName().size() > 0){
|
||||
String deviceName = action.getName().get(0);
|
||||
DeviceUserBindRequest deviceUserBindRequest = new DeviceUserBindRequest();
|
||||
deviceUserBindRequest.setUserId(userId);
|
||||
deviceUserBindRequest.setPageSize(2);
|
||||
deviceUserBindRequest.setBindName(deviceName);
|
||||
}else{
|
||||
//调用涂鸦
|
||||
TuyaQuery query = new TuyaQuery();
|
||||
query.setDeviceId(deviceUserBindEntity.getOtherDeviceId());
|
||||
query.setValue(action.getStatus());
|
||||
query.setUserHandlingDeviceId(systemTalkBindDeviceEntity.getUserHandlingId());
|
||||
tuyaDeviceService.controlDevice(query).map(isOk ->{
|
||||
String msg = "";
|
||||
if(isOk.getCode().equals(RespCodeEnum.SUCESS.getCode())){
|
||||
//通知打开灯成功
|
||||
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValue().replaceAll("#name#", deviceName);
|
||||
if(StringUtils.isNotEmpty(action.getStatus())){
|
||||
msg = msg.replace("#value#", action.getStatus());
|
||||
}
|
||||
|
||||
//查询是否有相关设备
|
||||
deviceUserBindService.selectDeviceUserBindsByRequest(deviceUserBindRequest)
|
||||
.defaultIfEmpty(new PagerResult<>(0, null))
|
||||
.map(binds ->{
|
||||
if(binds.getTotal() == 0){
|
||||
//返回告诉没有备
|
||||
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), "未找到相关设备,无法操做!");
|
||||
}else if(binds.getTotal() > 1){
|
||||
//返回告诉有多个设备,请详细说明具体说明设备
|
||||
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), "您有多个相同设备,请明确说明");
|
||||
}else{
|
||||
//查询是否有相关指令绑定
|
||||
DeviceUserBindEntity deviceUserBindEntity = binds.getData().get(0);
|
||||
SystemTalkBindDeviceRequest systemTalkBindDeviceRequest = new SystemTalkBindDeviceRequest();
|
||||
systemTalkBindDeviceRequest.setCategoryCode(deviceUserBindEntity.getCategoryCode());
|
||||
systemTalkBindDeviceRequest.setSystemTalkId(action.getSystemTalkAnswerConfigEntity().getId());
|
||||
systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(systemTalkBindDeviceRequest)
|
||||
.defaultIfEmpty(new SystemTalkBindDeviceEntity())
|
||||
.map(systemTalkBindDeviceEntity -> {
|
||||
if(systemTalkBindDeviceEntity.getId() == null){
|
||||
//通知不支持的指令
|
||||
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), deviceName + "不支持" + action.getAction() + "指令!");
|
||||
|
||||
}else{
|
||||
//调用涂鸦
|
||||
TuyaQuery query = new TuyaQuery();
|
||||
query.setDeviceId(deviceUserBindEntity.getOtherDeviceId());
|
||||
query.setValue(action.getStatus());
|
||||
query.setUserHandlingDeviceId(systemTalkBindDeviceEntity.getUserHandlingId());
|
||||
tuyaDeviceService.controlDevice(query).map(isOk ->{
|
||||
String msg = "";
|
||||
if(isOk.getCode().equals(RespCodeEnum.SUCESS.getCode())){
|
||||
//通知打开灯成功
|
||||
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValue().replaceAll("#name#", deviceName);
|
||||
if(StringUtils.isNotEmpty(action.getStatus())){
|
||||
msg = msg.replace("#value#", action.getStatus());
|
||||
log.info("执行指令");
|
||||
}else{
|
||||
//通知开灯失败;
|
||||
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValueFaild().replaceAll("#name#", deviceName);
|
||||
log.info("执行指令失败");
|
||||
}
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
resp.setText(msg);
|
||||
sendMessage(action, baseSession, resp);
|
||||
|
||||
log.info("执行指令");
|
||||
}else{
|
||||
//通知开灯失败;
|
||||
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValueFaild().replaceAll("#name#", deviceName);
|
||||
log.info("执行指令失败");
|
||||
}
|
||||
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), msg);
|
||||
return isOk;
|
||||
}).subscribe();
|
||||
}
|
||||
return systemTalkBindDeviceEntity;
|
||||
}).subscribe();
|
||||
|
||||
return isOk;
|
||||
}).subscribe();
|
||||
}
|
||||
return systemTalkBindDeviceEntity;
|
||||
}).subscribe();
|
||||
}
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
}else{
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
resp.setText("未找到对应的设备");
|
||||
sendMessage(action, baseSession, resp);
|
||||
}
|
||||
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.WEATHER.getCode())){
|
||||
ThirdWeatherInfoRequest req = new ThirdWeatherInfoRequest();
|
||||
//String city = "";
|
||||
if(action.getLbs() != null && action.getLbs().size() > 0){
|
||||
//根据地址查询天气
|
||||
// city = ;
|
||||
req.setCity(action.getLbs().get(action.getLbs().size() - 1));
|
||||
}else{
|
||||
//使用IP查询天气
|
||||
req.setIp("115.205.2.137");
|
||||
}
|
||||
weatherService.tianqiApi(req).map(t ->{
|
||||
log.info("查询的天气{}", JSONObject.toJSONString(t));
|
||||
TianqiapiItemResp item = null;
|
||||
|
||||
if(StringUtils.isNotEmpty(action.getTime().getDateTime())){
|
||||
//匹配对应的日期
|
||||
for (TianqiapiItemResp itemResp : t.getData())
|
||||
{
|
||||
if(action.getTime().getDateTime().equals(itemResp.getDate())){
|
||||
item = itemResp;
|
||||
break;
|
||||
}
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
}else{
|
||||
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), "未找到对应的设备");
|
||||
}
|
||||
}
|
||||
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.WEATHER.getCode())){
|
||||
ThirdWeatherInfoRequest req = new ThirdWeatherInfoRequest();
|
||||
//String city = "";
|
||||
if(action.getLbs() != null && action.getLbs().size() > 0){
|
||||
//根据地址查询天气
|
||||
// city = ;
|
||||
req.setCity(action.getLbs().get(action.getLbs().size() - 1));
|
||||
}else{
|
||||
//使用IP查询天气
|
||||
req.setIp("115.205.2.137");
|
||||
}
|
||||
weatherService.tianqiApi(req).map(t ->{
|
||||
log.info("查询的天气{}", JSONObject.toJSONString(t));
|
||||
TianqiapiItemResp item = null;
|
||||
|
||||
if(StringUtils.isNotEmpty(action.getTime().getDateTime())){
|
||||
//匹配对应的日期
|
||||
for (TianqiapiItemResp itemResp : t.getData())
|
||||
{
|
||||
if(action.getTime().getDateTime().equals(itemResp.getDate())){
|
||||
item = itemResp;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
item = t.getData().get(0);
|
||||
}
|
||||
String msg = "";
|
||||
if(item != null){
|
||||
//返回给客户端播报内容
|
||||
msg = t.getCity() + action.getTime().getTime() + "天气"
|
||||
+ item.getNarrative().replace("每 km / h", "千米每小时")
|
||||
+ ",空气质量" + item.getAir_level()
|
||||
+ ",湿度" + item.getHumidity() + ",最低气温" + item.getTem2();
|
||||
|
||||
}else{
|
||||
item = t.getData().get(0);
|
||||
}else{
|
||||
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValueFaild();
|
||||
|
||||
log.info("执行指令失败");
|
||||
}
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
resp.setText(msg);
|
||||
sendMessage(action, baseSession, resp);
|
||||
return t;
|
||||
}).subscribe();
|
||||
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.MUSIC.getCode())){
|
||||
|
||||
String search = action.getAsk().replaceAll(action.getAction(), "").replaceAll("的", "");
|
||||
if(StringUtils.isNotEmpty(action.getPName())){
|
||||
search = search.replaceAll(action.getPName(), "");
|
||||
}
|
||||
String msg = "";
|
||||
if(item != null){
|
||||
//返回给客户端播报内容
|
||||
msg = t.getCity() + action.getTime().getTime() + "天气"
|
||||
+ item.getNarrative().replace("每 km / h", "千米每小时")
|
||||
+ ",空气质量" + item.getAir_level()
|
||||
+ ",湿度" + item.getHumidity() + ",最低气温" + item.getTem2();
|
||||
musicService.searchMusic(search, 1).defaultIfEmpty(new ArrayList<>()).map(resultSongs -> {
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
MusicResp musicResp = new MusicResp();
|
||||
if(resultSongs.size() > 0){
|
||||
//
|
||||
musicResp.setPlay(PlayEnum.START.getCode());
|
||||
resp.setText("");
|
||||
}else{
|
||||
musicResp.setPlay(PlayEnum.NONE.getCode());
|
||||
resp.setText("未找到相关资源");
|
||||
}
|
||||
resp.setMusic(musicResp);
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
|
||||
}else{
|
||||
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValueFaild();
|
||||
|
||||
log.info("执行指令失败");
|
||||
}
|
||||
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), msg);
|
||||
return t;
|
||||
}).subscribe();
|
||||
sendMessage(action, baseSession, resp);
|
||||
return resultSongs;
|
||||
}).subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*protected Mono<Void> sessionProcess(WebSocketSession session, Long userId, String ip, int type) {
|
||||
Mono<Void> input = session.receive().map(webSocketMessage ->{
|
||||
//MDC.put(LogMdcConfiguration.PRINT_LOG_ID, getBoxSessionWithSn().getLogId());
|
||||
String text = webSocketMessage.getPayloadAsText();
|
||||
log.info("收到消息:{}", text);
|
||||
UserTalkMessage userTalkMessage = JSONObject.parseObject(text, UserTalkMessage.class);
|
||||
nlpService.getActionWithLacSingle(userTalkMessage.getMessage()).defaultIfEmpty(new Actions()).map(actions -> {
|
||||
BaseSession baseSession = null;
|
||||
if(type == 0){
|
||||
private void sendMessage(Action action, BaseSession baseSession, BoxMessageResp resp){
|
||||
|
||||
baseSession = getUserSessionWithUserId(userTalkMessage.getUserId());
|
||||
}else{
|
||||
baseSession = getUserSessionWithUserId(userTalkMessage.getUserId());
|
||||
}
|
||||
|
||||
//处理
|
||||
if(actions.getActions() == null || actions.getActions().size() == 0){
|
||||
//调用千问回答
|
||||
log.info("未匹配到自定义命令,调用千问");
|
||||
}else if(baseSession == null){
|
||||
log.info("未匹配到用户session,可能传错用户id");
|
||||
session.close().subscribe();
|
||||
}else{
|
||||
processAction(actions, userId, baseSession);
|
||||
}
|
||||
|
||||
return Mono.empty();
|
||||
}).subscribe();
|
||||
log.info("收到用户userId:{},消息:{}", userTalkMessage.getUserId(), userTalkMessage.getMessage());
|
||||
//MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
|
||||
return Mono.empty();
|
||||
}).then();
|
||||
BaseSession userSession = new BaseSession();
|
||||
userSession.setUserId(userId);
|
||||
userSession.setSession(session);
|
||||
userSession.setCustomerIP(ip);
|
||||
userSession.setLogId(MDC.get(LogMdcConfiguration.PRINT_LOG_ID));
|
||||
userGroup.put(userId, userSession);
|
||||
Mono<Void> output = session.send(Flux.create(sink -> userSession.setSink(sink))).then();
|
||||
|
||||
// Mono.zip() 会将多个 Mono 合并为一个新的 Mono,任何一个 Mono 产生 error 或 complete 都会导致合并后的 Mono
|
||||
// 也随之产生 error 或 complete,此时其它的 Mono 则会被执行取消操作。
|
||||
|
||||
return Mono.zip(input, output).doFinally(signalType -> {
|
||||
// MDC.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
|
||||
userGroup.remove(userSession.getUserId());//断链后及时移除
|
||||
log.info("断开连接SN:{}", userSession.getUserId());
|
||||
// MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
|
||||
}).then();
|
||||
}*/
|
||||
|
||||
private void sendMessage(Action action, BaseSession baseSession, Integer type, String message){
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(type);
|
||||
resp.setText(message);
|
||||
DeviceUserTalkRecordEntity talkRecord = new DeviceUserTalkRecordEntity();
|
||||
talkRecord.setAskType(type);
|
||||
talkRecord.setAskType(resp.getType());
|
||||
talkRecord.setAskValue(action.getAsk());
|
||||
talkRecord.setAskKey(action.getAction());
|
||||
talkRecord.setAnswerValue(message);
|
||||
talkRecord.setAnswerValue(resp.getText());
|
||||
talkRecord.setUserId(baseSession.getUserId());
|
||||
talkRecord.setDeviceId(baseSession.getDeviceId());
|
||||
if(type.equals(AskTypeEnum.MUSIC.getCode())) {
|
||||
if(resp.getType().equals(AskTypeEnum.MUSIC.getCode())) {
|
||||
if(this instanceof CustomerWebSocketHandler) {
|
||||
log.info("推送Box播放音乐");
|
||||
BaseSession boxSession = getBoxSessionWithSn(baseSession.getSn());
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user