From 75fed7ac6f44b597c14677aad46994cfd5e22553 Mon Sep 17 00:00:00 2001 From: wulin Date: Mon, 20 Nov 2023 17:44:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B5=8B=E8=AF=95=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E4=BA=BA=E5=9B=9E=E7=AD=94=E8=87=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SystemTalkAnswerConfigService.java | 1 + .../command/UserConfigActionCommand.java | 25 +++++++++++++------ .../iot/third/enums/ActionPartSpeechEnum.java | 10 ++++---- .../api/handler/BoxWebSocketHandler.java | 25 ++++++++++++++++++- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java index 515efbd..a1d1522 100644 --- a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java +++ b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java @@ -64,6 +64,7 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService reactiveQuery = createQuery(); reactiveQuery = reactiveQuery.and("is_delete", 0); reactiveQuery = reactiveQuery.lte("answer_type", AskTypeEnum.EXCOMMAND.getCode()); diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/command/UserConfigActionCommand.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/command/UserConfigActionCommand.java index 29a08a9..77c3497 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/command/UserConfigActionCommand.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/command/UserConfigActionCommand.java @@ -1,6 +1,7 @@ package com.qiuguo.iot.third.command; import com.qiuguo.iot.base.enums.AskTypeEnum; +import com.qiuguo.iot.base.utils.StringUtils; import com.qiuguo.iot.data.domain.BaseSession; import com.qiuguo.iot.data.domain.IActionSendMessage; import com.qiuguo.iot.data.entity.system.SystemTalkBindUserEntity; @@ -30,15 +31,23 @@ public class UserConfigActionCommand extends ActionCommand implements IActionCo return systemTalkBindUserService.selectSystemTalkBindUserByRequest(request).defaultIfEmpty(new SystemTalkBindUserEntity()) .flatMap(entity -> { if(entity.getUserId() == null){ + log.info("调用默认的回答"); - return sendMessage(action, - baseSession, - action.getSystemTalkAnswerConfigEntity().getAnswerValue(), - AskTypeEnum.TTS.getCode(), - actionSendMessage).flatMap(m ->{ - //自定义只能到这里截止 - return Mono.empty(); - }); + if(StringUtils.isNotEmpty(action.getSystemTalkAnswerConfigEntity().getAnswerValue())) { + return sendMessage(action, + baseSession, + action.getSystemTalkAnswerConfigEntity().getAnswerValue(), + AskTypeEnum.TTS.getCode(), + actionSendMessage).flatMap(m -> { + //自定义只能到这里截止 + return Mono.empty(); + }); + }else{ + log.info("用户自定义调用千问回答"); + return toTongYi(action, baseSession, AskTypeEnum.TTS.getCode(), actionSendMessage).flatMap(b -> { + return Mono.empty(); + }); + } }else{ log.info("调用用户匹配的回答"); return sendMessage(action, diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java index c1e1a98..690dc43 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java @@ -33,7 +33,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{ List includs, List commands){ action.setAction(key); - SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(action.getAction(), keyGroup, action.getNoTimeAsk()); + SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(action.getAction(), keyGroup, action.getAsk()); if(entity != null){ systemTalkAnswerConfigEntities.add(entity); @@ -176,7 +176,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{ List includs, List commands){ //匹配到关键词就不能作为名词加入,未匹配到的,分割前的都加入名词 - SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(key, keyGroup, action.getNoTimeAsk()); + SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(key, keyGroup, action.getAsk()); if(entity != null){ if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){ systemTalkAnswerConfigEntities.add(entity); @@ -184,7 +184,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{ //已记录的加进去 if(StringUtils.isNotEmpty(actions.getName())){ // - entity = getSystemTalkWithKey(actions.getName(), keyGroup, action.getNoTimeAsk()); + entity = getSystemTalkWithKey(actions.getName(), keyGroup, action.getAsk()); if(entity != null){ systemTalkAnswerConfigEntities.add(entity); actions.setA(1); @@ -253,7 +253,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{ List includs, List commands){ if(StringUtils.isNotEmpty(actions.getName())){ - SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(actions.getName(), keyGroup, action.getNoTimeAsk()); + SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(actions.getName(), keyGroup, action.getAsk()); if(entity != null){ if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){ systemTalkAnswerConfigEntities.add(entity); @@ -414,7 +414,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{ List systemTalkAnswerConfigEntities, List includs, List commands){ - SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(key, keyGroup, action.getNoTimeAsk()); + SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(key, keyGroup, action.getAsk()); if(entity != null){ if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){ systemTalkAnswerConfigEntities.add(entity); diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BoxWebSocketHandler.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BoxWebSocketHandler.java index 25ea4f3..9f5f245 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BoxWebSocketHandler.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BoxWebSocketHandler.java @@ -8,6 +8,8 @@ import com.qiuguo.iot.base.constans.RedisConstans; import com.qiuguo.iot.base.enums.*; import com.qiuguo.iot.base.model.UserDeviceInfoModel; import com.qiuguo.iot.base.utils.StringUtils; +import com.qiuguo.iot.data.domain.BaseMessageResp; +import com.qiuguo.iot.data.resp.third.MusicResp; import com.qiuguo.iot.third.command.ActionCommand; import com.qiuguo.iot.box.websocket.api.config.properties.SomeProperties; import com.qiuguo.iot.data.domain.BaseSession; @@ -164,10 +166,31 @@ public class BoxWebSocketHandler implements WebSocketHandler { if(alarm.getId() == null){ log.info("未找到相关闹钟"); return Mono.empty(); - }else{ + }else if(alarm.getAlarmType().equals(YesNo.YES.getCode())){ boxTalkMessage.setMessage(alarm.getAction()); boxSession.setListen(YesNo.NO.getCode()); return processMessage(boxSession, boxTalkMessage); + }else{ + if(StringUtils.isNotEmpty(alarm.getReadText())){ + BaseMessageResp resp = new BaseMessageResp(); + resp.setText(alarm.getReadText()); + resp.setListen(0); + resp.setType(AskTypeEnum.TTS.getCode()); + return baseWebSocketService.sendMsgWithMono(boxSession, resp).flatMap(b -> { + return Mono.empty(); + }); + }else{ + BaseMessageResp resp = new BaseMessageResp(); + MusicResp musicResp = new MusicResp(); + musicResp.setPlay(0); + musicResp.setUrl(alarm.getSound()); + resp.setMusic(musicResp); + resp.setListen(0); + resp.setType(AskTypeEnum.MUSIC.getCode()); + return baseWebSocketService.sendMsgWithMono(boxSession, JSONObject.toJSONString(resp)).flatMap(b -> { + return Mono.empty(); + }); + } } });