Merge branch 'feature-BOX一期' into test

This commit is contained in:
wulin 2023-10-25 10:05:30 +08:00
commit dad4e20ece
19 changed files with 174 additions and 187 deletions

View File

@ -54,6 +54,10 @@
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>

View File

@ -77,7 +77,7 @@ public class SystemTalkAnswerConfigEntity extends GenericEntity<Long> {
@Column(name = "play_type", nullable = false)
private Integer playType;
@Comment("处理Bean名字")
@Comment("处理Bean名字,空使用qianWenActionCommand动词后的量词、关键字等除外200400")
@Column(name = "bean_name", nullable = false)
private String beanName;

View File

@ -2,9 +2,9 @@ package com.qiuguo.iot.data.service.device;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockRecordEntity;
import com.qiuguo.iot.data.request.device.DeviceAlarmClockRecordRequest;
import com.qiuguo.iot.base.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.ezorm.core.param.Sort;
import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;

View File

@ -16,9 +16,11 @@ import org.hswebframework.ezorm.rdb.operator.dml.query.SortOrder;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.hswebframework.web.crud.service.GenericReactiveCrudService;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.Arrays;
import java.util.Date;
@ -36,7 +38,8 @@ import java.util.Date;
@Slf4j
public class DeviceInfoService extends GenericReactiveCrudService<DeviceInfoEntity, Long> {
@Resource
ReactiveStringRedisTemplate reactiveStringRedisTemplate;
public Mono<DeviceInfoEntity> selectDeviceInfoByRequest(DeviceInfoRequest request){
ReactiveQuery<DeviceInfoEntity> reactiveQuery = createQuery();
reactiveQuery = reactiveQuery.and("is_delete", 0);
@ -390,4 +393,17 @@ public class DeviceInfoService extends GenericReactiveCrudService<DeviceInfoEnti
.where("sn", sn)
.execute();
}
public Mono<DeviceInfoEntity> getDeviceInfo(String sn){
DeviceInfoRequest request = new DeviceInfoRequest();
request.setSn(sn);
return selectDeviceInfoByRequest(request).defaultIfEmpty(new DeviceInfoEntity()).map(dv -> {
if(dv.getId() != null){
String redis = JSONObject.toJSONString(dv);
reactiveStringRedisTemplate.opsForValue().set(RedisConstans.DEVICE_INFO + dv.getSn(), redis, Duration.ofHours(1)).subscribe();//直接提交订阅
}
return dv;
});
}
}

View File

@ -694,7 +694,9 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
actions.setName("");
action.setLbs(new ArrayList<>());
action.setAsk(actions.getRecordText());
}
}/*else{
action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity());
}*/
int index = Integer.parseInt(key.replace(">", ""));
action.setDeviceUserBindEntity(includs.get(index));
actions.setName("");

View File

@ -52,12 +52,15 @@ public class Actions {
public void setLastSystemTalkAnswerConfigEntity(SystemTalkAnswerConfigEntity systemTalkAnswerConfigEntity){
if(systemTalkAnswerConfigEntity != null){
lastSystemTalkAnswerConfigEntity = systemTalkAnswerConfigEntity;
for(Action action : actions){
if(action.getSystemTalkAnswerConfigEntity() == null
&& StringUtils.isNotEmpty(action.getName())){
action.setSystemTalkAnswerConfigEntity(systemTalkAnswerConfigEntity);
action.setAction(systemTalkAnswerConfigEntity.getAskKey());
}
}
}
}
}

View File

@ -24,15 +24,15 @@ import com.qiuguo.iot.data.service.device.DeviceUserTalkRecordService;
import com.qiuguo.iot.third.service.TuyaDeviceConnector;
import com.qiuguo.iot.user.api.resp.device.DeviceInitResp;
import com.qiuguo.iot.user.api.rest.device.SetDeviceBindInfoRest;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.data.redis.core.ReactiveValueOperations;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.exception.BusinessException;
import javax.annotation.Resource;
import java.time.LocalDateTime;

View File

@ -35,6 +35,7 @@ public class IotActionCommand extends ActionCommand implements IActionCommand{
public Mono<Boolean> process(Action action, BaseSession baseSession) {
log.info("IOT物联网 Action{}", action.getAsk());
if(StringUtils.isNotEmpty(action.getName())){
if(action.getDeviceUserBindEntity() == null){
log.info("匹配时未找到对应的设备,模糊匹配{}", action.getName());

View File

@ -10,7 +10,7 @@ import reactor.core.publisher.Mono;
@Slf4j
public class QianWenActionCommand extends ActionCommand implements IActionCommand{
public Mono<Boolean> process(Action action, BaseSession baseSession) {
log.info("千问 Action{}", action.getAsk());
return toQianWen(action, baseSession, AskTypeEnum.TTS.getCode()).flatMap(vo ->{
//千问只调一次

View File

@ -10,6 +10,7 @@ import reactor.core.publisher.Mono;
@Slf4j
public class QiuGuoActionCommand extends ActionCommand implements IActionCommand{
public Mono<Boolean> process(Action action, BaseSession baseSession) {
log.info("自定义关键词Time Action{}", action.getAsk());
return baseWebSocketService.sendMessage(action,
baseSession,
action.getSystemTalkAnswerConfigEntity().getAnswerValue(),

View File

@ -22,6 +22,7 @@ public class WeatherActionCommand extends ActionCommand implements IActionComma
@Resource
protected WeatherService weatherService;
public Mono<Boolean> process(Action action, BaseSession baseSession) {
log.info("天气 Action{}", action.getAsk());
ThirdWeatherInfoRequest req = new ThirdWeatherInfoRequest();
//String city = "";
if(action.getLbs() != null && action.getLbs().size() > 0){

View File

@ -9,6 +9,7 @@ import com.qiuguo.iot.base.enums.AskTypeEnum;
import com.qiuguo.iot.base.utils.Md5Utils;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
import com.qiuguo.iot.box.websocket.api.service.BaseWebSocketService;
import com.qiuguo.iot.box.websocket.api.service.WebsocketService;
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
import com.qiuguo.iot.data.request.device.DeviceInfoRequest;
@ -41,15 +42,15 @@ public class WebsocketController {
@Autowired
LacNlpService lacNlpService;
@Autowired
BaseWebSocketService baseWebSocketService;
@Autowired
SystemTalkAnswerConfigService systemTalkAnswerConfigService;
@Autowired
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
@Resource
private DeviceInfoService deviceInfoService;
@Value("${device.checkTimeout}")
private Boolean checkTimeout;
@ -82,18 +83,7 @@ public class WebsocketController {
return lacNlpService.geSingletNlp(value);
}
private Mono<DeviceInfoEntity> getDeviceInfo(String sn){
DeviceInfoRequest request = new DeviceInfoRequest();
request.setSn(sn);
return deviceInfoService.selectDeviceInfoByRequest(request).defaultIfEmpty(new DeviceInfoEntity()).map(dv -> {
if(dv.getId() != null){
String redis = JSONObject.toJSONString(dv);
reactiveStringRedisTemplate.opsForValue().set(RedisConstans.DEVICE_INFO + dv.getSn(), redis, Duration.ofHours(1)).subscribe();//直接提交订阅
}
return dv;
});
}
@GetMapping("/tts/token")
public Mono<String> getTtsToken(ServerHttpRequest serverHttpRequest) {
@ -107,64 +97,35 @@ public class WebsocketController {
log.info("设备{},请求数据已超时", sn);
return Mono.just("请求超时");
}
return reactiveStringRedisTemplate.opsForValue()
.get(RedisConstans.DEVICE_INFO + sn).defaultIfEmpty("")
.flatMap(s -> {
if(com.qiuguo.iot.base.utils.StringUtils.isNotBlank(s)){
try{
DeviceInfoEntity dv = JSONObject.parseObject(s, DeviceInfoEntity.class);
if(dv.getId() == null){
log.info("redis设备缓存异常清楚");
return getDeviceInfo(sn);
return baseWebSocketService.checkBoxSignature(sn, signature, linkTime).flatMap(b -> {
if(b.getId() != null){
return reactiveStringRedisTemplate.opsForValue()
.get(RedisConstans.ALI_TTS_TOKEN).defaultIfEmpty("")
.flatMap(toen -> {
if(StringUtils.isNotBlank(toen)){
return Mono.just(toen);
}
return Mono.just(dv);
}catch (Exception e){
log.info("转换异常清除redis。下次连接成功{}", e);
try {
AccessToken accessToken = new AccessToken(aliAccessKeyId, aliAccessSecret);
}
accessToken.apply();
}
return getDeviceInfo(sn);
}).flatMap(dv ->{
String signalMd5 = Md5Utils.getBoxSignal(sn, dv.getWifiMac(), dv.getBtMac(), dv.getKey(), linkTime);
if(!signalMd5.equals(signature)){
log.info("设备{},验签失败。正常签:{}", sn, signalMd5);
return Mono.just("验签失败");
}else{
log.info("设备{},验签成功", sn);
return reactiveStringRedisTemplate.opsForValue()
.get(RedisConstans.ALI_TTS_TOKEN).defaultIfEmpty("")
.flatMap(toen -> {
if(StringUtils.isNotBlank(toen)){
return Mono.just(toen);
}
try {
AccessToken accessToken = new AccessToken(aliAccessKeyId, aliAccessSecret);
accessToken.apply();
String token = accessToken.getToken();
long expireTime = accessToken.getExpireTime() - 600000L;//提前10分钟更新
//return Mono.just(token);
return reactiveStringRedisTemplate.opsForValue().set(RedisConstans.ALI_TTS_TOKEN,
token, Duration.ofMillis(expireTime)).flatMap(t -> {
return Mono.just(token);
});
}catch (Exception e){
log.info("获取阿里Token异常{}", e);
}
return Mono.just("获取token异常");
String token = accessToken.getToken();
long expireTime = accessToken.getExpireTime() - 600000L;//提前10分钟更新
return reactiveStringRedisTemplate.opsForValue().set(RedisConstans.ALI_TTS_TOKEN,
token, Duration.ofMillis(expireTime)).flatMap(t -> {
return Mono.just(token);
});
}
});
}catch (Exception e){
log.info("获取阿里Token异常{}", e);
}
return Mono.just("获取token异常");
});
}
return Mono.just("验签错误");
});
}
}

View File

@ -7,6 +7,7 @@ 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.Md5Utils;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.box.websocket.api.command.ActionCommand;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
@ -107,7 +108,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
//校验
checkToken(boxSession, sn, linkTime, signature, userId, isBind).contextWrite(context -> {
checkToken(boxSession, linkTime, signature, isBind).contextWrite(context -> {
Context contextTmp = context.put(LogMdcConfiguration.PRINT_LOG_ID, boxSession.getLogId());
return contextTmp;
@ -140,18 +141,14 @@ public class BoxWebSocketHandler implements WebSocketHandler {
String text = webSocketMessage.getPayloadAsText();
log.info("设备端收到消息:{}", text);
BoxTalkMessage boxTalkMessage = JSONObject.parseObject(text, BoxTalkMessage.class);
BoxSession boxSession1 = baseWebSocketService.getBoxSessionWithSn(boxTalkMessage.getSn());
if(boxSession != boxSession1){
log.info("消息发送异常或者未验签就收到信息不是同一个链接。可能传错SN");
return baseWebSocketService.closeSendMsg(boxSession, "请等待验签结束或者SN可能错误", AskTypeEnum.TTS.getCode()).flatMap(b -> {
return Mono.empty();
});
}
boxTalkMessage.setSn(boxSession.getSn());
log.info("收到SN:{},消息:{}", boxTalkMessage.getSn(), boxTalkMessage.getMessage());
return nlpService.getActionWithLacSingle(boxSession.getUserId(), boxTalkMessage.getMessage()).defaultIfEmpty(new Actions()).flatMap(actions -> {
return nlpService.getActionWithLacSingle(
boxSession.getUserId(),
boxTalkMessage.getMessage()
).defaultIfEmpty(new Actions()).flatMap(actions -> {
boxSession.setRequestId(boxSession.getRequestId() + 1);
return ActionCommand.processAction(actions, boxSession);
//return Mono.empty();
});
}
@ -177,70 +174,26 @@ public class BoxWebSocketHandler implements WebSocketHandler {
});
}
log.info("被踢下线断开连接:{}", boxSession.getSn());
log.info("下线断开连接:{}", boxSession.getSn());
return Mono.empty();
}
private Mono<Void> errorLogin(BaseSession boxSession, String sn){
//清除异常redis
return reactiveStringRedisTemplate.opsForValue().delete(RedisConstans.DEVICE_INFO + sn).flatMap(i -> {
return baseWebSocketService.closeSendMsg(boxSession, "异常,请重新登录", AskTypeEnum.TTS.getCode());
});
}
private Mono<Void> checkToken(BoxSession boxSession, String sn, Long linkTime, String signature, Long userId, Integer isBind){
return reactiveStringRedisTemplate.opsForValue().get(RedisConstans.DEVICE_INFO + sn).defaultIfEmpty("").flatMap(s -> {
if(com.qiuguo.iot.base.utils.StringUtils.isNotBlank(s)){
try{
DeviceInfoEntity dv = JSONObject.parseObject(s, DeviceInfoEntity.class);
if(dv.getId() == null){
log.info("redis设备缓存异常清楚");
return errorLogin(boxSession, sn).flatMap(v -> {
return Mono.empty();
});
private Mono<Void> checkToken(BoxSession boxSession, Long linkTime, String signature, Integer isBind){
return baseWebSocketService.checkBoxSignature(boxSession.getSn(), signature, linkTime).flatMap(dv -> {
if(dv.getId() != null){
boxSession.setDeviceId(dv.getId());
BoxSession oldBoxSession = baseWebSocketService.putBoxSession(boxSession.getSn(), boxSession);
return bindBox(boxSession, dv, boxSession.getUserId(), isBind).flatMap(db ->{
if(oldBoxSession != null){
return baseWebSocketService.closeSendMsg(oldBoxSession, "您在其他地方登录", AskTypeEnum.TTS.getCode());
}
return Mono.just(dv);
}catch (Exception e){
log.info("转换异常清除redis。下次连接成功{}", e);
return errorLogin(boxSession, sn).flatMap(v -> {
return Mono.empty();
});
}
return Mono.empty();
});
}
DeviceInfoRequest request = new DeviceInfoRequest();
request.setSn(sn);
return deviceInfoService.selectDeviceInfoByRequest(request).defaultIfEmpty(new DeviceInfoEntity()).map(dv -> {
if(dv.getId() != null){
String redis = JSONObject.toJSONString(dv);
reactiveStringRedisTemplate.opsForValue().set(RedisConstans.DEVICE_INFO + dv.getSn(), redis, Duration.ofHours(1)).subscribe();//直接提交订阅
}
return dv;
});
}).flatMap(dv ->{
String signalMd5 = Md5Utils.getBoxSignal(sn, dv.getWifiMac(), dv.getBtMac(), dv.getKey(), linkTime);
if(!signalMd5.equals(signature)){
log.info("设备{},验签失败。正常签:{}", sn, signalMd5);
if(boxSession != null){
return baseWebSocketService.closeSendMsg(boxSession, "验签失败", AskTypeEnum.TTS.getCode());
}
return Mono.just(dv);
}else{
log.info("设备{},验签成功", sn);
return Mono.just(dv);
if(boxSession != null){
return baseWebSocketService.closeSendMsg(boxSession, "验签失败", AskTypeEnum.TTS.getCode());
}
}).flatMap(d -> {
DeviceInfoEntity dv = (DeviceInfoEntity)d;
boxSession.setDeviceId(dv.getId());
BoxSession oldBoxSession = baseWebSocketService.putBoxSession(sn, boxSession);
return bindBox(boxSession, dv, userId, isBind).flatMap(db ->{
if(oldBoxSession != null){
return baseWebSocketService.closeSendMsg(oldBoxSession, "您在其他地方登录", AskTypeEnum.TTS.getCode());
}
return Mono.empty();
});
return Mono.empty();
});
}
@ -273,8 +226,6 @@ public class BoxWebSocketHandler implements WebSocketHandler {
}else{
boxSession.setTtsId(entity.getTts());
if(entity.getIsBind().equals(YesNo.YES.getCode())){
//通知用户端设备绑定成功
sendNoticeToUser(userId, "设备联网成功,设备序列号:" + dv.getSn(), AskTypeEnum.BOX_ON_LINE.getCode());

View File

@ -90,7 +90,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
}).then();
checkToken(userSession, type, token, userId).contextWrite(context -> {
checkToken(userSession, type, token).contextWrite(context -> {
Context contextTmp = context.put(LogMdcConfiguration.PRINT_LOG_ID, userSession.getLogId());
return contextTmp;
@ -115,16 +115,12 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
String text = webSocketMessage.getPayloadAsText();
log.info("收到用户消息:{}", text);
UserTalkMessage userTalkMessage = JSONObject.parseObject(text, UserTalkMessage.class);
UserSession userSession1 = baseWebSocketService.getUserSessionWithUserId(userTalkMessage.getUserId());
if(!userSession.equals(userSession1)){
log.info("消息发送异常或者未验签就收到信息不是同一个链接。可能传错用户ID");
return baseWebSocketService.closeSendMsg(userSession, "请等待验签结束或者用户ID可能错误", AskTypeEnum.TTS.getCode()).flatMap(b -> {
return Mono.empty();
});
}
userTalkMessage.setUserId(userSession.getUserId());
log.info("收到用户userId:{},消息:{}", userTalkMessage.getUserId(), userTalkMessage.getMessage());
return nlpService.getActionWithLacSingle(userSession.getUserId(), userTalkMessage.getMessage())
.defaultIfEmpty(new Actions()).flatMap(actions -> {
return nlpService.getActionWithLacSingle(
userSession.getUserId(),
userTalkMessage.getMessage()
).defaultIfEmpty(new Actions()).flatMap(actions -> {
//处理
userSession.setRequestId(userSession.getRequestId() + 1);
return ActionCommand.processAction(actions, userSession);
@ -141,7 +137,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
return Mono.empty();
}
private Mono<Void> checkToken(UserSession userSession, String type, String token, Long userId){
private Mono<Void> checkToken(UserSession userSession, String type, String token){
Map<String, String> reqHead = new HashMap<>();
reqHead.put(HttpHeaderConstans.API_TYPE, type);
reqHead.put(HttpHeaderConstans.API_TOKEN, token);
@ -149,12 +145,12 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
log.info("验签获取的数据{}", jsonObject);
if(jsonObject.getInteger("code").equals(ResponeEnum.SUCESS.getCode())){
Long userId1 = jsonObject.getJSONObject("data").getLong("id");
if(userId1.equals(userId)){
log.info("验签成功{}", userId);
if(userId1.equals(userSession.getUserId())){
log.info("验签成功{}", userSession.getUserId());
DeviceUserBindRequest request = new DeviceUserBindRequest();
request.setUserId(userId);
request.setUserId(userSession.getUserId());
request.setDeviceType(DeviceTypeEnum.GUO_BOX.getCode());
request.setIsMain(YesNo.YES.getCode());
@ -170,7 +166,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
}else{
baseWebSocketService.normalSendMsg(userSession, "您暂未绑定果宝儿Box快去绑定吧", AskTypeEnum.TTS.getCode());
}
UserSession oldUserSession = baseWebSocketService.putUserSession(userId, userSession);
UserSession oldUserSession = baseWebSocketService.putUserSession(userSession.getUserId(), userSession);
if(oldUserSession != null){
return baseWebSocketService.closeSendMsg(oldUserSession, "您在其他地方登录", AskTypeEnum.TTS.getCode());
@ -179,7 +175,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
});
}
}
log.info("验签失败{}", userId);
log.info("验签失败{}", userSession.getUserId());
return baseWebSocketService.closeSendMsg(userSession, "非法登录", AskTypeEnum.TTS.getCode()).flatMap(b -> {
return Mono.empty();
});

View File

@ -1,25 +1,34 @@
package com.qiuguo.iot.box.websocket.api.service;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nls.client.AccessToken;
import com.qiuguo.iot.base.constans.RedisConstans;
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.domain.BaseMessageResp;
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.resp.BoxMessageResp;
import com.qiuguo.iot.box.websocket.api.domain.user.UserSession;
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
import com.qiuguo.iot.data.entity.device.DeviceUserTalkRecordEntity;
import com.qiuguo.iot.data.request.device.DeviceInfoRequest;
import com.qiuguo.iot.data.service.device.DeviceInfoService;
import com.qiuguo.iot.data.service.device.DeviceUserTalkRecordService;
import com.qiuguo.iot.third.nlp.action.Action;
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.beans.factory.annotation.Value;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.concurrent.ConcurrentHashMap;
@Service
@ -37,12 +46,20 @@ public class BaseWebSocketService {
@Resource
AudioService audioService;
@Resource
DeviceInfoService deviceInfoService;
@Resource
protected DeviceUserTalkRecordService deviceUserTalkRecordService;
@Autowired
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
protected static int ONE_MAX_TEXT = 30;
public BoxSession getBoxSessionWithSn(String sn) {
if(boxGroup.containsKey(sn)){
return boxGroup.get(sn);
@ -200,6 +217,14 @@ public class BaseWebSocketService {
//标点符号起始会导致合成的声音第一句话有杂音
text = text.substring(1);
}
if(text.endsWith("") ||
text.endsWith("") ||
text.endsWith("") ||
text.endsWith("") ||
text.endsWith("") ||
text.endsWith(" ")){
text = text.substring(0, text.length() - 1);
}
if(text.length() > ONE_MAX_TEXT){
StringBuilder builder = new StringBuilder();
sendAudioMessage(baseSession,
@ -212,6 +237,7 @@ public class BaseWebSocketService {
}else{
BoxMessageResp boxMessageResp = new BoxMessageResp();
BeanUtils.copyProperties(baseMessageResp, boxMessageResp);
boxMessageResp.setText(text);
sendAudioMessage(baseSession, boxMessageResp).subscribe();
}
return;
@ -305,4 +331,37 @@ public class BaseWebSocketService {
return s;
});//.subscribeOn(Schedulers.single()).subscribe();
}
public Mono<DeviceInfoEntity> checkBoxSignature(String sn, String signature, Long linkTime){
return reactiveStringRedisTemplate.opsForValue()
.get(RedisConstans.DEVICE_INFO + sn).defaultIfEmpty("")
.flatMap(s -> {
if(StringUtils.isNotBlank(s)){
try{
DeviceInfoEntity dv = JSONObject.parseObject(s, DeviceInfoEntity.class);
if(dv.getId() != null){
return Mono.just(dv);
}
log.info("redis设备缓存异常清楚");
}catch (Exception e){
log.info("转换异常清除redis。下次连接成功{}", e);
}
}
return deviceInfoService.getDeviceInfo(sn);
}).map(dv ->{
if(dv.getId() != null){
String signalMd5 = Md5Utils.getBoxSignal(sn, dv.getWifiMac(), dv.getBtMac(), dv.getKey(), linkTime);
if(!signalMd5.equals(signature)){
log.info("设备{},验签失败。正常签:{}", sn, signalMd5);
return new DeviceInfoEntity();
}else{
log.info("设备{},验签成功", sn);
}
}else{
log.info("设备不存在{}", sn);
}
return dv;
});
}
}

View File

@ -43,7 +43,7 @@ qiuguo:
checktoken:
url: https://qiuguo-app.pre.qiuguojihua.com/pre-api/user/user/getUser
tts:
suanfa: true
suanfa: false
url: http://192.168.8.211:18000/run/predict #算法语音合成
downurl: http://192.168.8.211:8880 #算法语音合成后资源下载路径前缀
lac:

View File

@ -125,8 +125,11 @@ public class MysqlUtilTable2Contoller {
List<FieldBean> list = tableBean.getFieldList();
try {
String content = "package com.admin.service.impl;\n\n\n\n" +
"import org.apache.commons.lang3.StringUtils;\n" +
"import java.util.Date;\n";
"import java.util.Date;\n" +
"import reactor.core.publisher.Mono;\n" +
"import lombok.extern.slf4j.Slf4j;\n" +
"import org.hswebframework.web.api.crud.entity.PagerResult;\n" +
"import org.hswebframework.web.exception.BusinessException;\n";
content += "/**\n";

View File

@ -31,6 +31,19 @@ public class MysqlUtilTable2Service {
List<FieldBean> list = tableBean.getFieldList();
try {
String content = "package com.admin.service.impl;\n\n\n\n" +
"import java.util.Date;\n" + "import com.qiuguo.iot.base.utils.StringUtils;\n" +
"import lombok.extern.slf4j.Slf4j;\n" +
"import org.hswebframework.ezorm.core.param.Sort;\n" +
"import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;\n" +
"import org.hswebframework.ezorm.rdb.mapping.ReactiveUpdate;\n" +
"import org.hswebframework.ezorm.rdb.operator.dml.query.SortOrder;\n" +
"import org.hswebframework.web.api.crud.entity.PagerResult;\n" +
"import org.hswebframework.web.api.crud.entity.QueryParamEntity;\n" +
"import org.hswebframework.web.crud.service.GenericReactiveCrudService;\n" +
"import org.springframework.stereotype.Service;\n" +
"import reactor.core.publisher.Mono;\n" +
"\n" +
"import java.util.Arrays;\n" +
"import java.util.Date;\n";

View File

@ -39,12 +39,6 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
<version>${spring.cloud.version}</version>
</dependency>
<dependency>
@ -56,12 +50,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
<version>${redis.boot.reactor.version}</version>
</dependency>
@ -69,24 +57,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 下面都是響應式數據庫相關 r2dbc啓動類-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
<version>${spring.boot.version}</version>
</dependency>
<!-- ORM工具數據 -->