From 58608ab19b70dbc98cbfff64e91e5940c4846d25 Mon Sep 17 00:00:00 2001 From: wulin Date: Wed, 25 Oct 2023 22:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E5=AF=BC=E8=87=B4=E7=9A=84=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E9=85=8D=E7=BD=AE=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/third/service/AudioService.java | 2 +- .../iot/third/service/LacNlpService.java | 4 +-- .../api/config/properties/LacProperties.java | 11 +++++--- .../api/config/properties/TtsProperties.java | 26 ------------------- .../api/handler/BoxWebSocketHandler.java | 5 ++++ .../api/handler/CustomerWebSocketHandler.java | 4 ++- .../api/service/BaseWebSocketService.java | 12 +++++---- .../src/main/resources/bootstrap-dev.yml | 14 +++++----- 8 files changed, 33 insertions(+), 45 deletions(-) delete mode 100644 iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/TtsProperties.java diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/AudioService.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/AudioService.java index ca39e2a..34d5825 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/AudioService.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/AudioService.java @@ -18,7 +18,7 @@ import java.util.ArrayList; @Service @Slf4j public class AudioService { - @Value("${nlp.tts.url:}") + @Value("${tts.url:}") private String url; public Mono getAudioUrl(String v){ AudioRequest request = new AudioRequest(); diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/LacNlpService.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/LacNlpService.java index f5bdd43..4d05451 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/LacNlpService.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/LacNlpService.java @@ -34,9 +34,9 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Service @Slf4j public class LacNlpService implements INlp { - @Value("${nlp.lac.huburl:}") + @Value("${lac.huburl:}") private String hubUrl; - @Value("${nlp.lac.suanfaurl:}") + @Value("${lac.suanfaurl:}") private String suanfaUrl; diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/LacProperties.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/LacProperties.java index 15d6081..c46e956 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/LacProperties.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/LacProperties.java @@ -1,10 +1,14 @@ package com.qiuguo.iot.box.websocket.api.config.properties; import lombok.Data; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.List; + /** * Xss配置. * @@ -14,12 +18,13 @@ import org.springframework.stereotype.Component; @Data @Component @RefreshScope -@ConfigurationProperties(prefix = "nlp.lac") public class LacProperties { - + /** - * 调用LAC类型 + * Lac类型. */ + @Value("${lac.type}") private String type; + } diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/TtsProperties.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/TtsProperties.java deleted file mode 100644 index e45cc8b..0000000 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/config/properties/TtsProperties.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.qiuguo.iot.box.websocket.api.config.properties; - -import lombok.Data; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.cloud.context.config.annotation.RefreshScope; -import org.springframework.stereotype.Component; - -/** - * Xss配置. - * - * @author yangning - * @since 2023/4/7 18:31 - */ -@Data -@Component -@RefreshScope -public class TtsProperties { - - /** - * 调用LAC类型 - */ - @Value("${nlp.tts.suanfa}") - private Boolean suanfa; - -} 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 e4c26fb..5e4fa02 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 @@ -24,6 +24,7 @@ import com.qiuguo.iot.third.service.NlpService; import lombok.extern.slf4j.Slf4j; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Component; @@ -37,6 +38,7 @@ import java.time.Duration; @Component @WebSocketMapping("/websocket/box") +//@RefreshScope 自定义注解会导致失效 @Slf4j public class BoxWebSocketHandler implements WebSocketHandler { @Value("${device.checkTimeout}") @@ -60,6 +62,9 @@ public class BoxWebSocketHandler implements WebSocketHandler { @Resource private BaseWebSocketService baseWebSocketService; + /** + * 调用LAC类型 + */ @Resource private LacProperties lacProperties; diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/CustomerWebSocketHandler.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/CustomerWebSocketHandler.java index 50af12b..8ba7f34 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/CustomerWebSocketHandler.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/CustomerWebSocketHandler.java @@ -23,6 +23,7 @@ import com.qiuguo.iot.third.service.NlpService; import lombok.extern.slf4j.Slf4j; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Component; import org.springframework.web.reactive.socket.HandshakeInfo; @@ -38,6 +39,7 @@ import java.util.HashMap; import java.util.Map; @Component +//@RefreshScope 自定义注解会导致失效 @WebSocketMapping("/websocket/customer") @Slf4j public class CustomerWebSocketHandler implements WebSocketHandler { @@ -124,7 +126,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler { return nlpService.getActionWithLacSingle( userSession.getUserId(), userTalkMessage.getMessage(), - lacProperties.getType() + lacProperties.getType() ).defaultIfEmpty(new Actions()).flatMap(actions -> { //处理 userSession.setRequestId(userSession.getRequestId() + 1); diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java index 4436b1f..b0c60df 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java @@ -6,7 +6,6 @@ import com.qiuguo.iot.base.enums.AskTypeEnum; import com.qiuguo.iot.base.enums.YesNo; import com.qiuguo.iot.base.utils.Md5Utils; import com.qiuguo.iot.base.utils.StringUtils; -import com.qiuguo.iot.box.websocket.api.config.properties.TtsProperties; import com.qiuguo.iot.box.websocket.api.domain.BaseMessageResp; import com.qiuguo.iot.box.websocket.api.domain.BaseSession; import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession; @@ -21,7 +20,7 @@ import com.qiuguo.iot.third.service.AudioService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.stereotype.Service; @@ -37,8 +36,11 @@ public class BaseWebSocketService { /** * 调用算法开关 */ - @Resource - private TtsProperties ttsProperties; + /** + * 调用LAC类型 + */ + @Value("${tts.suanfa}") + private Boolean suanfa; protected static ConcurrentHashMap userGroup = new ConcurrentHashMap<>(); @@ -241,7 +243,7 @@ public class BaseWebSocketService { if(userSession != null){ sendMsg(userSession, baseMessageResp); } - if(ttsProperties.getSuanfa()){ + if(suanfa){ String text = removeStringChars(baseMessageResp.getText()); if(text.length() > ONE_MAX_TEXT){ diff --git a/iot-modules/iot-box-websocket-api/src/main/resources/bootstrap-dev.yml b/iot-modules/iot-box-websocket-api/src/main/resources/bootstrap-dev.yml index 26982e9..2d74340 100644 --- a/iot-modules/iot-box-websocket-api/src/main/resources/bootstrap-dev.yml +++ b/iot-modules/iot-box-websocket-api/src/main/resources/bootstrap-dev.yml @@ -45,13 +45,13 @@ tianqiapi: qiuguo: checktoken: url: https://qiuguo-app.pre.qiuguojihua.com/pre-api/user/user/getUser -nlp: - tts: - url: http://192.168.8.211:18000/run/predict #算法语音合成 - lac: - type: suanfa - huburl: http://192.168.8.175:8866/predict/lac - suanfaurl: http://192.168.8.211:6000/qg_human/lac_word +tts: + #suanfa: true #nacos控制变化 + url: http://192.168.8.211:18000/run/predict #算法语音合成 +lac: + #type: suanfa #nacos控制变化 + huburl: http://192.168.8.175:8866/predict/lac + suanfaurl: http://192.168.8.211:6000/qg_human/lac_word Ali: qianwen: 'sk-8d64677afaf6404cb83ce1910b5b2558'