修复自定义注解导致的部分动态配置失效

This commit is contained in:
wulin 2023-10-25 22:25:09 +08:00
parent 851b8ec364
commit 58608ab19b
8 changed files with 33 additions and 45 deletions

View File

@ -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<String> getAudioUrl(String v){
AudioRequest request = new AudioRequest();

View File

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

View File

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

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

View File

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

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.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<Long, UserSession> 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){

View File

@ -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'