天气异常解决

This commit is contained in:
wulin 2023-10-26 15:20:20 +08:00
parent e9cc91e87b
commit 5fff0c7fb4
14 changed files with 62 additions and 28 deletions

View File

@ -23,6 +23,7 @@ public enum AskTypeEnum {
BOX_OFF_LINE(102, "Box离线"),
DEVICE_UNBIND(103, "设备解绑"),
DEVICE_BIND(104, "设备绑定成功"),
BOX_OPT(105, "推送Box配置给Box"),
COMMAND_N(200, "指令后必须跟的名称词"),
QIU_GUO(300, "秋果专有名词"),
USER_CONFIG(301, "根据用户编号回答不同"),

View File

@ -103,4 +103,8 @@ public class DeviceUserBindEntity extends GenericEntity<Long> {
@Column(name = "tts", length = 11)
private String tts;
@Comment("Box的配置Json格式固定音频地址")
@Column(name = "box_opt", length = 11)
private String boxOpt;
}

View File

@ -84,5 +84,10 @@ public class DeviceUserBindRequest implements java.io.Serializable {
*/
private String tts;
/**
*Box的配置Json格式固定音频地址
*/
private String boxOpt;
}

View File

@ -99,4 +99,9 @@ public class DeviceUserBindResp {
*/
private String tts;
/**
*Box的配置Json格式固定音频地址
*/
private String boxOpt;
}

View File

@ -112,6 +112,9 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
if(StringUtils.isNotEmpty(request.getTts())){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getTts, request.getTts());
}
if(StringUtils.isNotEmpty(request.getBoxOpt())){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getBoxOpt, request.getBoxOpt());
}
SortOrder sortOrder = null;
if(StringUtils.isNotEmpty(request.getOrder())){
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
@ -206,6 +209,9 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
if(StringUtils.isNotEmpty(request.getTts())){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getTts, request.getTts());
}
if(StringUtils.isNotEmpty(request.getBoxOpt())){
reactiveQuery = reactiveQuery.and(DeviceUserBindRequest::getBoxOpt, request.getBoxOpt());
}
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
if(StringUtils.isNotEmpty(request.getOrder())){
Sort sort = new Sort();
@ -304,6 +310,9 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
if(StringUtils.isNotEmpty(entity.getTts())){
update = update.set(DeviceUserBindEntity::getTts, entity.getTts());
}
if(StringUtils.isNotEmpty(entity.getBoxOpt())){
update = update.set(DeviceUserBindEntity::getBoxOpt, entity.getBoxOpt());
}
return update.where(DeviceUserBindEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
@ -331,6 +340,7 @@ public class DeviceUserBindService extends GenericReactiveCrudService<DeviceUser
update = update.set(DeviceUserBindEntity::getU3dId, entity.getU3dId());
update = update.set(DeviceUserBindEntity::getScenceId, entity.getScenceId());
update = update.set(DeviceUserBindEntity::getTts, entity.getTts());
update = update.set(DeviceUserBindEntity::getBoxOpt, entity.getBoxOpt());
return update.where(DeviceUserBindEntity::getId, entity.getId()).and("is_delete", 0).execute();
}

View File

@ -20,11 +20,11 @@ import java.util.ArrayList;
public class AudioService {
@Value("${tts.url:}")
private String url;
public Mono<String> getAudioUrl(String v){
public Mono<String> getAudioUrl(String v, String scl){
AudioRequest request = new AudioRequest();
request.setData(new ArrayList<>(4));
request.getData().add(v);
request.getData().add("scl");
request.getData().add(scl);
request.getData().add("简体中文");
request.getData().add(1);

View File

@ -44,7 +44,7 @@ public class WeatherService {
@Value("https://api.caiyunapp.com/v2.6/ilUeAnf1vNkphxYS/")
private String queryWeatherUrl;
@Value("tianqiapi.url:")
@Value("${tianqiapi.url:}")
private String tianqiUrl;
@Resource

View File

@ -1,41 +1,26 @@
package com.qiuguo.iot.box.websocket.api.command;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.constans.Log4Constans;
import com.qiuguo.iot.base.enums.*;
import com.qiuguo.iot.base.utils.StringUtils;
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.QueueMessage;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
import com.qiuguo.iot.box.websocket.api.domain.box.resp.BoxMessageResp;
import com.qiuguo.iot.box.websocket.api.domain.user.UserSession;
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
import com.qiuguo.iot.box.websocket.api.service.BaseWebSocketService;
import com.qiuguo.iot.data.constants.YunxiRabbitConst;
import com.qiuguo.iot.data.entity.device.DeviceUserTalkRecordEntity;
import com.qiuguo.iot.data.request.qwen.TongYiCommunicationRest;
import com.qiuguo.iot.data.service.device.DeviceUserBindService;
import com.qiuguo.iot.data.service.device.DeviceUserTalkRecordService;
import com.qiuguo.iot.data.service.mq.MqService;
import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
import com.qiuguo.iot.data.service.system.SystemTalkBindU3dService;
import com.qiuguo.iot.data.service.system.SystemTalkBindUserService;
import com.qiuguo.iot.third.nlp.action.Action;
import com.qiuguo.iot.third.nlp.action.Actions;
import com.qiuguo.iot.third.service.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.Queue;
@Slf4j
public abstract class ActionCommand {
@ -93,7 +78,7 @@ public abstract class ActionCommand {
String message = "";
if(queue.getQueue().size() > 0){
message = queue.getQueue().poll();
message = baseWebSocketService.getSendStr(sb, message);
message = baseWebSocketService.getSendStr(sb, message, false);
}else if(queue.getStatus() == YesNo.NO.getCode().intValue()){
if(sb.length() == 0){
//结束了

View File

@ -48,4 +48,9 @@ public class BaseSession {
* 问题Id每次++
*/
protected Long requestId = 0L;
/**
* TTS合成声音的声音标识
*/
String ttsId;
}

View File

@ -1,4 +1,4 @@
package com.qiuguo.iot.box.websocket.api.command;
package com.qiuguo.iot.box.websocket.api.domain;
import lombok.Data;

View File

@ -6,10 +6,7 @@ import lombok.Data;
@Data
public class BoxSession extends BaseSession {
/**
* TTS合成声音的声音标识
*/
String ttsId;
/**
* 阿里token
*/

View File

@ -1,5 +1,6 @@
package com.qiuguo.iot.box.websocket.api.domain.box.resp;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.box.websocket.api.domain.BaseMessageResp;
import com.qiuguo.iot.data.resp.third.MusicResp;
import lombok.Data;
@ -29,4 +30,9 @@ public class BoxMessageResp extends BaseMessageResp {
* 音频播放地址
*/
String audio;
/**
* Box相关配置
*/
JSONObject boxOpt;
}

View File

@ -6,11 +6,13 @@ import com.qiuguo.iot.base.constans.HttpHeaderConstans;
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.box.websocket.api.command.ActionCommand;
import com.qiuguo.iot.box.websocket.api.config.properties.LacProperties;
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.BoxTalkMessage;
import com.qiuguo.iot.box.websocket.api.domain.box.resp.BoxMessageResp;
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
import com.qiuguo.iot.box.websocket.api.service.BaseWebSocketService;
@ -194,6 +196,14 @@ public class BoxWebSocketHandler implements WebSocketHandler {
if(oldBoxSession != null){
return baseWebSocketService.closeSendMsg(oldBoxSession, "您在其他地方登录", AskTypeEnum.TTS.getCode());
}
if(StringUtils.isNotEmpty(db.getBoxOpt())){
log.info("推送配置给Box:{}", db.getBoxOpt());
BoxMessageResp resp = new BoxMessageResp();
resp.setType(AskTypeEnum.BOX_OPT.getCode());
resp.setBoxOpt(JSONObject.parseObject(db.getBoxOpt()));
baseWebSocketService.sendMsg(boxSession, JSONObject.toJSONString(resp));
}
return Mono.empty();
});
}

View File

@ -101,8 +101,12 @@ public class BaseWebSocketService {
* @param message
* @return
*/
public String getSendStr(StringBuilder sb, String message){
public String getSendStr(StringBuilder sb, String message, Boolean isEnd){
String old = sb.toString() + message;
if(isEnd){
sb.setLength(0);
return old;
}
int d = old.lastIndexOf("");
int j = old.lastIndexOf("");
int a = old.lastIndexOf("");
@ -330,7 +334,7 @@ public class BaseWebSocketService {
if(n == length){
status = 1;
}
message = getSendStr(builder, message);
message = getSendStr(builder, message, status == 1 ? true : false);
int m = n;
if(StringUtils.isNotEmpty(message)){
BoxMessageResp boxMessageResp = new BoxMessageResp();
@ -361,7 +365,9 @@ public class BaseWebSocketService {
sendMsg(baseSession, JSONObject.toJSONString(boxMessageResp));
return Mono.just("");
}
return audioService.getAudioUrl(boxMessageResp.getText()).map(s ->{
return audioService.getAudioUrl(boxMessageResp.getText(),
StringUtils.isNotEmpty(baseSession.getTtsId()) ? baseSession.getTtsId() : "scl"
).map(s ->{
boxMessageResp.setAudio(s);
sendMsg(baseSession, JSONObject.toJSONString(boxMessageResp));