Merge branch 'feature-BOX一期' into test

This commit is contained in:
wulin 2023-10-25 22:25:34 +08:00
commit bd0e160811
8 changed files with 33 additions and 45 deletions

View File

@ -18,7 +18,7 @@ import java.util.ArrayList;
@Service @Service
@Slf4j @Slf4j
public class AudioService { public class AudioService {
@Value("${nlp.tts.url:}") @Value("${tts.url:}")
private String url; private String url;
public Mono<String> getAudioUrl(String v){ public Mono<String> getAudioUrl(String v){
AudioRequest request = new AudioRequest(); AudioRequest request = new AudioRequest();

View File

@ -34,9 +34,9 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@Service @Service
@Slf4j @Slf4j
public class LacNlpService implements INlp { public class LacNlpService implements INlp {
@Value("${nlp.lac.huburl:}") @Value("${lac.huburl:}")
private String hubUrl; private String hubUrl;
@Value("${nlp.lac.suanfaurl:}") @Value("${lac.suanfaurl:}")
private String suanfaUrl; private String suanfaUrl;

View File

@ -1,10 +1,14 @@
package com.qiuguo.iot.box.websocket.api.config.properties; package com.qiuguo.iot.box.websocket.api.config.properties;
import lombok.Data; import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/** /**
* Xss配置. * Xss配置.
* *
@ -14,12 +18,13 @@ import org.springframework.stereotype.Component;
@Data @Data
@Component @Component
@RefreshScope @RefreshScope
@ConfigurationProperties(prefix = "nlp.lac")
public class LacProperties { public class LacProperties {
/** /**
* 调用LAC类型 * Lac类型.
*/ */
@Value("${lac.type}")
private String type; private String type;
} }

View File

@ -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;
}

View File

@ -24,6 +24,7 @@ import com.qiuguo.iot.third.service.NlpService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value; 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.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -37,6 +38,7 @@ import java.time.Duration;
@Component @Component
@WebSocketMapping("/websocket/box") @WebSocketMapping("/websocket/box")
//@RefreshScope 自定义注解会导致失效
@Slf4j @Slf4j
public class BoxWebSocketHandler implements WebSocketHandler { public class BoxWebSocketHandler implements WebSocketHandler {
@Value("${device.checkTimeout}") @Value("${device.checkTimeout}")
@ -60,6 +62,9 @@ public class BoxWebSocketHandler implements WebSocketHandler {
@Resource @Resource
private BaseWebSocketService baseWebSocketService; private BaseWebSocketService baseWebSocketService;
/**
* 调用LAC类型
*/
@Resource @Resource
private LacProperties lacProperties; private LacProperties lacProperties;

View File

@ -23,6 +23,7 @@ import com.qiuguo.iot.third.service.NlpService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.HandshakeInfo;
@ -38,6 +39,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Component @Component
//@RefreshScope 自定义注解会导致失效
@WebSocketMapping("/websocket/customer") @WebSocketMapping("/websocket/customer")
@Slf4j @Slf4j
public class CustomerWebSocketHandler implements WebSocketHandler { public class CustomerWebSocketHandler implements WebSocketHandler {
@ -124,7 +126,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
return nlpService.getActionWithLacSingle( return nlpService.getActionWithLacSingle(
userSession.getUserId(), userSession.getUserId(),
userTalkMessage.getMessage(), userTalkMessage.getMessage(),
lacProperties.getType() lacProperties.getType()
).defaultIfEmpty(new Actions()).flatMap(actions -> { ).defaultIfEmpty(new Actions()).flatMap(actions -> {
//处理 //处理
userSession.setRequestId(userSession.getRequestId() + 1); userSession.setRequestId(userSession.getRequestId() + 1);

View File

@ -6,7 +6,6 @@ import com.qiuguo.iot.base.enums.AskTypeEnum;
import com.qiuguo.iot.base.enums.YesNo; import com.qiuguo.iot.base.enums.YesNo;
import com.qiuguo.iot.base.utils.Md5Utils; import com.qiuguo.iot.base.utils.Md5Utils;
import com.qiuguo.iot.base.utils.StringUtils; 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.BaseMessageResp;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession; 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.box.BoxSession;
@ -21,7 +20,7 @@ import com.qiuguo.iot.third.service.AudioService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; 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.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Service; 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<Long, UserSession> userGroup = new ConcurrentHashMap<>(); protected static ConcurrentHashMap<Long, UserSession> userGroup = new ConcurrentHashMap<>();
@ -241,7 +243,7 @@ public class BaseWebSocketService {
if(userSession != null){ if(userSession != null){
sendMsg(userSession, baseMessageResp); sendMsg(userSession, baseMessageResp);
} }
if(ttsProperties.getSuanfa()){ if(suanfa){
String text = removeStringChars(baseMessageResp.getText()); String text = removeStringChars(baseMessageResp.getText());
if(text.length() > ONE_MAX_TEXT){ if(text.length() > ONE_MAX_TEXT){

View File

@ -45,13 +45,13 @@ tianqiapi:
qiuguo: qiuguo:
checktoken: checktoken:
url: https://qiuguo-app.pre.qiuguojihua.com/pre-api/user/user/getUser url: https://qiuguo-app.pre.qiuguojihua.com/pre-api/user/user/getUser
nlp: tts:
tts: #suanfa: true #nacos控制变化
url: http://192.168.8.211:18000/run/predict #算法语音合成 url: http://192.168.8.211:18000/run/predict #算法语音合成
lac: lac:
type: suanfa #type: suanfa #nacos控制变化
huburl: http://192.168.8.175:8866/predict/lac huburl: http://192.168.8.175:8866/predict/lac
suanfaurl: http://192.168.8.211:6000/qg_human/lac_word suanfaurl: http://192.168.8.211:6000/qg_human/lac_word
Ali: Ali:
qianwen: 'sk-8d64677afaf6404cb83ce1910b5b2558' qianwen: 'sk-8d64677afaf6404cb83ce1910b5b2558'