优化NLP

This commit is contained in:
wulin 2023-09-27 19:53:02 +08:00
parent 7aef742387
commit 8d613e2f6e
24 changed files with 14585 additions and 669 deletions

View File

@ -6,10 +6,15 @@ package com.qiuguo.iot.base.enums;
* */
// 动作类型0文本播放 1音频播放 2 U3D动作 3物联网设备动作
public enum AskTypeEnum {
TTS(0, "文本大语言播放"),
SOUND(1, "音频播放"),
U3D(2, "U3D动作"),
DEVICE(3, "物联网设备动作")
TTS(0, "文本播放"),
IOT(1, "IOT控制"),
ALARM_CLOCK(3, "闹钟"),
WEATHER(2, "天气"),
U3D(4, "U3D动作"),
MUSIC(5, "音乐,声音"),
UPDATE(100, "固件升级"),
;
AskTypeEnum(Integer c, String n){
code = c;

View File

@ -1,51 +0,0 @@
package com.qiuguo.iot.base.enums;
/*
* 动作类型
* 作者吴林
* */
// 动作类型0文本播放 1音频播放 2 U3D动作 3物联网设备动作
public enum WebSocketReqTypeEnum {
TTS(0, "文本播放"),
IOT(1, "IOT控制"),
ALARM_CLOCK(3, "闹钟"),
WEATHER(2, "天气"),
U3D(4, "U3D动作"),
UPDATE(100, "固件升级"),
;
WebSocketReqTypeEnum(Integer c, String n){
code = c;
name = n;
}
private Integer code;
private String name;
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
public static WebSocketReqTypeEnum getEnumWithCode(Integer c){
for (WebSocketReqTypeEnum e:values()
) {
if(e.getCode().compareTo(c) == 0){
return e;
}
}
return null;
}
public static WebSocketReqTypeEnum getEnumWithName(String name){
for (WebSocketReqTypeEnum e:values()
) {
if(e.getName().equals(name)){
return e;
}
}
return null;
}
}

View File

@ -49,7 +49,7 @@ public class DeviceUserTalkRecordEntity extends GenericEntity<Long> {
@Column(name = "ask_value", length = 255, nullable = false)
private String askValue;
@Comment("回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D")
@Comment("回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级")
@Column(name = "ask_type", nullable = false)
private Integer askType;

View File

@ -69,7 +69,7 @@ public class SystemTalkAnswerConfigEntity extends GenericEntity<Long> {
@Column(name = "key_order", nullable = false)
private Long keyOrder;
@Comment("回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D")
@Comment("回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级")
@Column(name = "answer_type", nullable = false)
private Integer answerType;

View File

@ -36,7 +36,7 @@ public class DeviceUserTalkRecordRequest implements java.io.Serializable {
private Long deviceId;
//问话内容
private String askValue;
//问答类型 0 大预言普通问答 1 天气 2 音乐 3 闹钟 4talk_answer_config配置回答
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级talk_answer_config配置回答
private Integer askType;
//问题关键字
private String askKey;

View File

@ -54,6 +54,6 @@ public class SystemTalkAnswerConfigRequest implements java.io.Serializable {
//关键字的排序越小越第一个匹配上
private Long keyOrder;
//"回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D"
//"回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级"
private Integer answerType;
}

View File

@ -26,7 +26,7 @@ public class DeviceTalkRecordResp {
private Long deviceId;
//问话内容
private String text;
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级
private Integer askType;
private Integer AskOrAnswer = 0;

View File

@ -32,6 +32,6 @@ public class SystemTalkAnswerConfigResp {
//关键字的排序越小越第一个匹配上
private Long keyOrder;
//"回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D"
//"回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 100固件升级"
private Integer answerType;
}

View File

@ -1,5 +1,6 @@
package com.qiuguo.iot.third.nlp.action;
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
@ -8,6 +9,9 @@ import java.util.List;
@Data
public class Action {
//匹配系统的动作
private SystemTalkAnswerConfigEntity systemTalkAnswerConfigEntity;
private String action;//动作(动词)
private List<String> name;//动作对象(名词)可能存在多个如果有关系词连接
private String status;//动作程度结果名词量词

View File

@ -18,41 +18,6 @@ public class Actions {
public Actions() {}
public Actions(Nlp nlp, String ask){
actions = new ArrayList<>();
nlp.getKeys().sort(Comparator.comparing(NlpKey::getType)); //解析,按照type从小到大排序
Action action = new Action();
String name = "";
action.setName(new ArrayList<>());
action.setLbs(new ArrayList<>());
action.setAsk(ask);
for (NlpKey key : nlp.getKeys()
) {
if(key.getType().equals(ChinesePartSpeechEnum.v.getCode())){
action.setAction(key.getKey());
}else if(key.getType().equals(ChinesePartSpeechEnum.n.getCode())){
name += key.getKey();
//action.getName().add(key.getKey());
}else if(key.getType().equals(ChinesePartSpeechEnum.m.getCode())){
action.setStatus(key.getKey());
//action.getName().add(key.getKey());
}else if(key.getType().equals(ChinesePartSpeechEnum.c.getCode())){
//action.setStatus(key.getKey());
if(StringUtils.isNotEmpty(name)){
action.getName().add(name);
}
name = "";
}else if(key.getType().equals(ChinesePartSpeechEnum.nt.getCode())){
//action.setStatus(key.getKey());
action.getLbs().add(key.getKey());
}else if(key.getType().equals(ChinesePartSpeechEnum.t.getCode())){
//解析时间关键字
//action.setTime(key.getKey());
}
}
if(StringUtils.isNotEmpty(name)){
action.getName().add(name);
}
actions.add(action);
}
}

View File

@ -63,7 +63,7 @@ public class LacNlpService implements INlp {
Nlp nlp = new Nlp();
JSONObject o = jsonArray.getJSONObject(0);
nlp.setKeys(getKeys(o));
nlp.getKeys().sort(Comparator.comparing(NlpKey::getType));
//nlp.getKeys().sort(Comparator.comparing(NlpKey::getType));
return nlp;
});
return nlpKeyMono;

View File

@ -1,12 +1,21 @@
package com.qiuguo.iot.third.service;
import com.qiuguo.iot.base.enums.ChinesePartSpeechEnum;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
import com.qiuguo.iot.third.nlp.INlp;
import com.qiuguo.iot.third.nlp.NlpKey;
import com.qiuguo.iot.third.nlp.action.Action;
import com.qiuguo.iot.third.nlp.action.Actions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@Service
@Slf4j
@ -14,9 +23,85 @@ public class NlpService {
@Resource
private LacNlpService liguoNlpService;
@Resource
private SystemTalkAnswerConfigService systemTalkAnswerConfigService;
public Mono<Actions> getActionWithLacSingle(String text){
return liguoNlpService.geSingletNlp(text).map(nlp -> {
return new Actions(nlp, text);
Actions actions = new Actions();
actions.setActions(new ArrayList<>());
nlp.getKeys().sort(Comparator.comparing(NlpKey::getType)); //解析,按照type从小到大排序
Action action = new Action();
String name = "";
action.setName(new ArrayList<>());
action.setLbs(new ArrayList<>());
action.setAsk(text);
List<SystemTalkAnswerConfigEntity> systemTalkAnswerConfigEntities = new ArrayList<>();
for (NlpKey key : nlp.getKeys()
) {
if(key.getType().equals(ChinesePartSpeechEnum.v.getCode())){
action.setAction(key.getKey());
}else if(key.getType().equals(ChinesePartSpeechEnum.n.getCode())){
//匹配到关键词就不能作为名词加入未匹配到的分割前的都加入名词
SystemTalkAnswerConfigEntity entity = systemTalkAnswerConfigService.getSystemTalkWithKey(key.getKey());
if(entity != null){
systemTalkAnswerConfigEntities.add(entity);
if(StringUtils.isNotEmpty(name)){//已记录的加进去
//
entity = systemTalkAnswerConfigService.getSystemTalkWithKey(name);
if(entity != null){
systemTalkAnswerConfigEntities.add(entity);
}else{
action.getName().add(name);//加入分割前的名词
name = "";
}
}
}else{
name += key.getKey();
}
}else if(key.getType().equals(ChinesePartSpeechEnum.m.getCode())){
action.setStatus(key.getKey());
}else if(key.getType().equals(ChinesePartSpeechEnum.c.getCode())){
if(StringUtils.isNotEmpty(name)){
action.getName().add(name);
}
name = "";
}else if(key.getType().equals(ChinesePartSpeechEnum.nt.getCode())){
action.getLbs().add(key.getKey());
}else if(key.getType().equals(ChinesePartSpeechEnum.t.getCode())){
//解析时间关键字
//action.setTime(key.getKey());
}
}
if(StringUtils.isNotEmpty(name)){
SystemTalkAnswerConfigEntity entity = systemTalkAnswerConfigService.getSystemTalkWithKey(name);
if(entity != null){
systemTalkAnswerConfigEntities.add(entity);
}else{
action.getName().add(name);
}
}
if(StringUtils.isNotEmpty(action.getAction())){
SystemTalkAnswerConfigEntity entity = systemTalkAnswerConfigService.getSystemTalkWithKey(action.getAction());
if(entity != null){
systemTalkAnswerConfigEntities.add(entity);
}
}
if(systemTalkAnswerConfigEntities.size() > 0){//指令按照优先级排序
systemTalkAnswerConfigEntities.sort(Comparator.comparing(SystemTalkAnswerConfigEntity::getKeyOrder));
action.setSystemTalkAnswerConfigEntity(systemTalkAnswerConfigEntities.get(0));
action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey());
}
actions.getActions().add(action);
return actions;
});
}
}

View File

@ -7,6 +7,11 @@ import reactor.core.publisher.FluxSink;
@Data
public class BaseSession {
/***
* 设备序列号
*/
protected String sn;
protected WebSocketSession session;
protected FluxSink<WebSocketMessage> sink;

View File

@ -8,6 +8,6 @@ import reactor.core.publisher.FluxSink;
@Data
public class BoxSession extends BaseSession {
String sn;
}

View File

@ -1,33 +1,27 @@
package com.qiuguo.iot.box.websocket.api.handler;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.enums.AskTypeEnum;
import com.qiuguo.iot.base.enums.RespCodeEnum;
import com.qiuguo.iot.base.enums.WebSocketReqTypeEnum;
import com.qiuguo.iot.base.utils.StringUtils;
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.box.websocket.api.service.WebsocketService;
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
import com.qiuguo.iot.data.entity.device.DeviceUserTalkRecordEntity;
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
import com.qiuguo.iot.data.request.system.SystemTalkBindDeviceRequest;
import com.qiuguo.iot.data.request.third.ThirdWeatherInfoRequest;
import com.qiuguo.iot.data.resp.third.weather.TianqiapiItemResp;
import com.qiuguo.iot.data.resp.third.weather.WeatherResp;
import com.qiuguo.iot.data.service.device.DeviceUserBindService;
import com.qiuguo.iot.data.service.device.DeviceUserTalkRecordService;
import com.qiuguo.iot.data.service.system.SystemAddressService;
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
import com.qiuguo.iot.third.enums.WeatherEnum;
import com.qiuguo.iot.third.nlp.action.Action;
import com.qiuguo.iot.third.nlp.action.Actions;
import com.qiuguo.iot.third.query.TuyaQuery;
import com.qiuguo.iot.third.service.NlpService;
import com.qiuguo.iot.third.service.TuyaDeviceService;
import com.qiuguo.iot.third.service.WeatherService;
import lombok.extern.slf4j.Slf4j;
@ -41,8 +35,6 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class BaseWebSocketProcess {
@Resource
protected SystemTalkAnswerConfigService systemTalkAnswerConfigService;
@Resource
protected DeviceUserBindService deviceUserBindService;
@ -71,16 +63,15 @@ public class BaseWebSocketProcess {
//目前只处理第一条动作
Action action = actions.getActions().get(0);
SystemTalkAnswerConfigEntity talkAnswerConfigEntity =
systemTalkAnswerConfigService.getSystemTalkWithKey(action.getAction());
log.info("匹配到自定义指令{}", talkAnswerConfigEntity);
if(talkAnswerConfigEntity == null){
log.info("调用千问");
sendMessage(action, baseSession, 0, "这里会调用千问回答");
}
else if(talkAnswerConfigEntity.getAnswerType().equals(WebSocketReqTypeEnum.IOT.getCode())){
if(action.getName().size() == 0){
log.info("匹配到自定义指令{}", action.getSystemTalkAnswerConfigEntity());
if(action.getSystemTalkAnswerConfigEntity() == null){
log.info("调用千问");
sendMessage(action, baseSession, 0, "暂时无法理解,我还在努力学习中");
}
else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.IOT.getCode())){
if(action.getName().size() > 0){
String deviceName = action.getName().get(0);
DeviceUserBindRequest deviceUserBindRequest = new DeviceUserBindRequest();
deviceUserBindRequest.setUserId(userId);
@ -93,22 +84,22 @@ public class BaseWebSocketProcess {
.map(binds ->{
if(binds.getTotal() == 0){
//返回告诉没有备
sendMessage(action, baseSession, talkAnswerConfigEntity.getAnswerType(), "未找到相关设备,无法操做!");
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), "未找到相关设备,无法操做!");
}else if(binds.getTotal() > 1){
//返回告诉有多个设备请详细说明具体说明设备
sendMessage(action, baseSession, talkAnswerConfigEntity.getAnswerType(), "您有多个相同设备,请明确说明");
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), "您有多个相同设备,请明确说明");
}else{
//查询是否有相关指令绑定
DeviceUserBindEntity deviceUserBindEntity = binds.getData().get(0);
SystemTalkBindDeviceRequest systemTalkBindDeviceRequest = new SystemTalkBindDeviceRequest();
systemTalkBindDeviceRequest.setCategoryCode(deviceUserBindEntity.getCategoryCode());
systemTalkBindDeviceRequest.setSystemTalkId(talkAnswerConfigEntity.getId());
systemTalkBindDeviceRequest.setSystemTalkId(action.getSystemTalkAnswerConfigEntity().getId());
systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(systemTalkBindDeviceRequest)
.defaultIfEmpty(new SystemTalkBindDeviceEntity())
.map(systemTalkBindDeviceEntity -> {
if(systemTalkBindDeviceEntity.getId() == null){
//通知不支持的指令
sendMessage(action, baseSession, talkAnswerConfigEntity.getAnswerType(), deviceName + "不支持" + action.getAction() + "指令!");
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), deviceName + "不支持" + action.getAction() + "指令!");
}else{
//调用涂鸦
@ -120,7 +111,7 @@ public class BaseWebSocketProcess {
String msg = "";
if(isOk.getCode().equals(RespCodeEnum.SUCESS.getCode())){
//通知打开灯成功
msg = talkAnswerConfigEntity.getAnswerValue().replaceAll("#name#", deviceName);
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValue().replaceAll("#name#", deviceName);
if(StringUtils.isNotEmpty(action.getStatus())){
msg.replace("#value#", action.getStatus());
}
@ -128,10 +119,10 @@ public class BaseWebSocketProcess {
log.info("执行指令");
}else{
//通知开灯失败;
msg = talkAnswerConfigEntity.getAnswerValueFaild().replaceAll("#name#", deviceName);
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValueFaild().replaceAll("#name#", deviceName);
log.info("执行指令失败");
}
sendMessage(action, baseSession, talkAnswerConfigEntity.getAnswerType(), msg);
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), msg);
return isOk;
}).subscribe();
@ -143,12 +134,12 @@ public class BaseWebSocketProcess {
return Mono.empty();
}).subscribe();
}else{
sendMessage(action, baseSession, talkAnswerConfigEntity.getAnswerType(), "未找到对应的设备");
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), "未找到对应的设备");
}
}else if(talkAnswerConfigEntity.getAnswerType().equals(WebSocketReqTypeEnum.WEATHER.getCode())){
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.WEATHER.getCode())){
ThirdWeatherInfoRequest req = new ThirdWeatherInfoRequest();
//String city = "";
if(action.getLbs() != null && action.getLbs().size() > 0){
@ -175,11 +166,11 @@ public class BaseWebSocketProcess {
+ ",湿度" + item.getHumidity() + ",最低气温" + item.getTem2();
}else{
msg = talkAnswerConfigEntity.getAnswerValueFaild();
msg = action.getSystemTalkAnswerConfigEntity().getAnswerValueFaild();
log.info("执行指令失败");
}
sendMessage(action, baseSession, talkAnswerConfigEntity.getAnswerType(), msg);
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType(), msg);
return t;
}).subscribe();
}
@ -197,16 +188,28 @@ public class BaseWebSocketProcess {
talkRecord.setAnswerValue(message);
talkRecord.setUserId(baseSession.getUserId());
talkRecord.setDeviceId(baseSession.getDeviceId());
if(type.equals(AskTypeEnum.MUSIC.getCode())) {
if(this instanceof CustomerWebSocketHandler) {
log.info("推送Box播放音乐");
BoxSession boxSession = getBoxSessionWithSn(baseSession.getSn());
if(boxSession != null){
boxSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
}else{
log.info("设备sn{}不在线,无法播放", baseSession.getSn());
resp.setText("设备不在线,无法播放");
}
}
}
deviceUserTalkRecordService.insertDeviceUserTalkRecord(talkRecord).map(i ->{
baseSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
if(this instanceof BoxWebSocketHandler){
log.info("推送通知到客户端");
UserSession userSession = getUserSessionWithUserId(baseSession.getUserId());
if(userSession != null){
userSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
}
}
baseSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
return Mono.empty();
}).subscribe();//保存聊天记录

View File

@ -6,37 +6,20 @@ import com.qiuguo.iot.base.annotation.WebSocketMapping;
import com.qiuguo.iot.base.constans.RedisConstans;
import com.qiuguo.iot.base.enums.DeviceCodeEnum;
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
import com.qiuguo.iot.base.enums.WebSocketReqTypeEnum;
import com.qiuguo.iot.base.enums.YesNo;
import com.qiuguo.iot.base.utils.StringUtils;
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.data.entity.device.DeviceInfoEntity;
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
import com.qiuguo.iot.data.request.device.DeviceInfoRequest;
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
import com.qiuguo.iot.data.request.system.SystemTalkBindDeviceRequest;
import com.qiuguo.iot.data.request.user.UserHandlingDeviceRequest;
import com.qiuguo.iot.data.service.device.DeviceInfoService;
import com.qiuguo.iot.data.service.device.DeviceUserBindService;
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
import com.qiuguo.iot.data.service.user.UserHandlingDeviceService;
import com.qiuguo.iot.third.nlp.action.Action;
import com.qiuguo.iot.third.nlp.action.Actions;
import com.qiuguo.iot.third.query.TuyaQuery;
import com.qiuguo.iot.third.service.NlpService;
import com.qiuguo.iot.third.service.TuyaDeviceConnector;
import com.qiuguo.iot.third.service.TuyaDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.slf4j.MDC;
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;
@ -46,8 +29,6 @@ import org.springframework.web.reactive.socket.*;
import reactor.core.publisher.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Component
@WebSocketMapping("/websocket/box")
@ -104,7 +85,7 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
//处理
if(actions.getActions() == null || actions.getActions().size() == 0){
//调用千问回答
log.info("未匹配到自定义命令,调用千问");
log.info("暂时无法理解,我还在努力学习中");
}else{
processAction(actions, userId, boxSession);
}
@ -146,7 +127,14 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
DeviceInfoEntity dv = JSONObject.parseObject(s, DeviceInfoEntity.class);
return Mono.just(dv);
}catch (Exception e){
log.info("转换异常{}", e);
log.info("转换异常清除redis。下次连接成功{}", e);
//清除异常redis
operations.set(RedisConstans.DEVICE_INFO + sn, "").subscribe();//不需要时间
BoxSession boxSession = getBoxSessionWithSn(sn);
if(boxSession != null){
boxSession.getSink().next(boxSession.getSession().textMessage("异常,请重新登录"));
boxSession.getSession().close().subscribe();
}
}
}
DeviceInfoRequest request = new DeviceInfoRequest();

View File

@ -1,88 +0,0 @@
package com.admin.service.impl;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
/**
* <p>
* 设备信息对话记录Controller类
* </p>
*
* @author wulin
* @since 2023-09-27
*/
@RestController
@Slf4j
@RequestMapping("/DeviceUserTalkRecord")
public class DeviceUserTalkRecordController{
@Autowired
private DeviceUserTalkRecordService deviceUserTalkRecordService;
@PostMapping("/info")
public Mono<DeviceUserTalkRecordResp> selectDeviceUserTalkRecordByRequest(@RequestBody DeviceUserTalkRecordRequest request){
return deviceUserTalkRecordService.selectDeviceUserTalkRecordByRequest(request).map(d -> {return new DeviceUserTalkRecordResp(d);});
}
@PostMapping("/list")
public Mono<PagerResult<DeviceUserTalkRecordResp>> selectDeviceUserTalkRecordsByRequest(@RequestBody DeviceUserTalkRecordRequest request){
return deviceUserTalkRecordService.selectDeviceInfosByRequest(request).map(d -> {
PagerResult<DeviceUserTalkRecordResp> result = new PagerResult<>();
result.setPageIndex(d.getPageIndex());
result.setPageSize(d.getPageSize());
result.setTotal(d.getTotal());
List<DeviceUserTalkRecordResp> ds = d.getData().stream().map(new Function<DeviceUserTalkRecordEntity, DeviceUserTalkRecordResp>() {
@Override
public DeviceInfoResp apply(DeviceUserTalkRecordEntity entity) {
return new DeviceUserTalkRecordResp(entity);
}
}
).collect(Collectors.toList());
result.setData(ds);
return result;
});
}
@GetMapping("/id")
public Mono<DeviceUserTalkRecordResp> selectDeviceUserTalkRecordById(@RequestParam Long id){
return deviceUserTalkRecordService.selectDeviceUserTalkRecordById(id).map(d -> {return new DeviceUserTalkRecordResp(d);});
}
@PostMapping("/save")
public Mono<Integer> insertDeviceUserTalkRecord(@RequestBody DeviceUserTalkRecordEntity entity){
return deviceUserTalkRecordService.insertDeviceUserTalkRecord(entity);
}
@PostMapping("/update")
public Mono<Integer> updateDeviceUserTalkRecordById(@RequestBody DeviceUserTalkRecordEntity entity){
return deviceUserTalkRecordService.updateDeviceUserTalkRecordById(entity);
}
@PostMapping("/updateCover")
public Mono<Integer> updateCoverDeviceUserTalkRecordById(@RequestBody DeviceUserTalkRecordEntity entity){
return deviceUserTalkRecordService.updateCoverDeviceUserTalkRecordById(entity);
}
@PostMapping("/delete")
public Mono<Integer> deleteDeviceUserTalkRecordById(@RequestParam Long id){
return deviceUserTalkRecordService.deleteDeviceUserTalkRecordById(id);
}
}

View File

@ -1,76 +0,0 @@
package com.qiuguo.iot.data.entity;
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
import org.hswebframework.web.api.crud.entity.GenericEntity;
import javax.persistence.Column;
import javax.persistence.Table;import lombok.Data;
import java.util.Date;
/**
* <p>
* </p>*设备信息对话记录表
* @author wulin
* @since 2023-09-27
*/
@Data
@Comment("设备信息对话记录表")
@Table(name = "device_user_talk_record")
@EnableEntityEvent
public class DeviceUserTalkRecordEntity extends GenericEntity<Long> {
@Comment("id")
@Column(name = "id", length = 11, nullable = false, unique = true)
private Long id;
@Comment("是否删除0 否 1 删除")
@Column(name = "is_delete", nullable = false)
private Integer isDelete;
@Comment("创建时间")
@Column(name = "create_time")
private Date createTime;
@Comment("修改时间")
@Column(name = "modify_time")
private Date modifyTime;
@Comment("当前用户当前设备问话一次标识(考虑到可能有多个第三方回答)")
@Column(name = "ask_number")
private Integer askNumber;
@Comment("用户id")
@Column(name = "user_id", nullable = false)
private Long userId;
@Comment("设备id")
@Column(name = "device_id", nullable = false)
private Long deviceId;
@Comment("问话内容")
@Column(name = "ask_value", length = 255, nullable = false)
private String askValue;
@Comment("回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 和system_talk_answer_config中answer_type保持一致")
@Column(name = "ask_type", nullable = false)
private Integer askType;
@Comment("问题关键字")
@Column(name = "ask_key", length = 100)
private String askKey;
@Comment("回答内容传给box")
@Column(name = "answer_value", length = 255, nullable = false)
private String answerValue;
@Comment("回答第三方模型third_config_infoask_type=4时为talk_answer_config的id")
@Column(name = "answer_third_id", nullable = false)
private Long answerThirdId;
@Comment("第三方回答原始内容")
@Column(name = "answer_third_value", length = 255)
private String answerThirdValue;
@Comment("是否返回给用户0 否 1 是")
@Column(name = "is_return", nullable = false)
private Integer isReturn;
}

View File

@ -1,59 +0,0 @@
package com.qiuguo.iot.data.entity;
import lombok.Data;
import java.util.Date;
/**
* <p>
*设备信息对话记录请求类
* @author wulin
* @since 2023-09-27
*/
@Data
public class DeviceUserTalkRecordRequest implements java.io.Serializable {
private int currPage = 1;
private int pageSize = 10;
private String sort;
private String order;
//
private Long id;
//是否删除0 1 删除
private Integer isDelete;
//创建时间
private Date createTime;
//创建时间搜索开始
private Date createTimeStart;
//创建时间搜索结束
private Date createTimeEnd;
//修改时间
private Date modifyTime;
//修改时间搜索开始
private Date modifyTimeStart;
//修改时间搜索结束
private Date modifyTimeEnd;
//当前用户当前设备问话一次标识考虑到可能有多个第三方回答
private Integer askNumber;
//用户id
private Long userId;
//设备id
private Long deviceId;
//问话内容
private String askValue;
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 和system_talk_answer_config中answer_type保持一致
private Integer askType;
//问题关键字
private String askKey;
//回答内容传给box
private String answerValue;
//回答第三方模型third_config_infoask_type=4时为talk_answer_config的id
private Long answerThirdId;
//第三方回答原始内容
private String answerThirdValue;
//是否返回给用户0 1
private Integer isReturn;
}

View File

@ -1,57 +0,0 @@
package com.qiuguo.iot.data.entity;
import lombok.Data;
import java.util.Date;
/**
* <p>
* </p>*设备信息对话记录返回类
* @author wulin
* @since 2023-09-27
*/
@Data
public class DeviceUserTalkRecordResp {
public DeviceUserTalkRecordResp(){
}
public DeviceUserTalkRecordResp(DeviceUserTalkRecordEntity entity){
id = entity.getId();
createTime = entity.getCreateTime();
modifyTime = entity.getModifyTime();
askNumber = entity.getAskNumber();
userId = entity.getUserId();
deviceId = entity.getDeviceId();
askValue = entity.getAskValue();
askType = entity.getAskType();
askKey = entity.getAskKey();
answerValue = entity.getAnswerValue();
answerThirdId = entity.getAnswerThirdId();
answerThirdValue = entity.getAnswerThirdValue();
isReturn = entity.getIsReturn();
}
//
private Long id;
//创建时间
private Date createTime;
//修改时间
private Date modifyTime;
//当前用户当前设备问话一次标识考虑到可能有多个第三方回答
private Integer askNumber;
//用户id
private Long userId;
//设备id
private Long deviceId;
//问话内容
private String askValue;
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 和system_talk_answer_config中answer_type保持一致
private Integer askType;
//问题关键字
private String askKey;
//回答内容传给box
private String answerValue;
//回答第三方模型third_config_infoask_type=4时为talk_answer_config的id
private Long answerThirdId;
//第三方回答原始内容
private String answerThirdValue;
//是否返回给用户0 1
private Integer isReturn;
}

View File

@ -1,238 +0,0 @@
package com.admin.service.impl;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
/**
* <p>
* 设备信息对话记录服务类
* </p>
*
* @author wulin
* @since 2023-09-27
*/
@Service
@Slf4j
public class DeviceUserTalkRecordService extends GenericReactiveCrudService<DeviceUserTalkRecordEntity, Long> {
public Mono<DeviceUserTalkRecordEntity> selectDeviceUserTalkRecordByRequest(DeviceUserTalkRecordRequest request){
ReactiveQuery<DeviceUserTalkRecordEntity> reactiveQuery = createQuery();
reactiveQuery = reactiveQuery.and("is_delete", 0);
if(request.getId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getId, request.getId());
}
if(request.getIsDelete() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getIsDelete, request.getIsDelete());
}
if(request.getCreateTime() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getCreateTime, request.getCreateTime());
}
if(request.getModifyTime() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getModifyTime, request.getModifyTime());
}
if(request.getAskNumber() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAskNumber, request.getAskNumber());
}
if(request.getUserId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getUserId, request.getUserId());
}
if(request.getDeviceId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getDeviceId, request.getDeviceId());
}
if(StringUtils.isNotEmpty(request.getAskValue())){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAskValue, request.getAskValue());
}
if(request.getAskType() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAskType, request.getAskType());
}
if(StringUtils.isNotEmpty(request.getAskKey())){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAskKey, request.getAskKey());
}
if(StringUtils.isNotEmpty(request.getAnswerValue())){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAnswerValue, request.getAnswerValue());
}
if(request.getAnswerThirdId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAnswerThirdId, request.getAnswerThirdId());
}
if(StringUtils.isNotEmpty(request.getAnswerThirdValue())){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAnswerThirdValue, request.getAnswerThirdValue());
}
if(request.getIsReturn() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getIsReturn, request.getIsReturn());
}
SortOrder sortOrder = null;
if(StringUtils.isNotEmpty(request.getOrder())){
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
sortOrder = SortOrder.desc(request.getOrder());
}else{
sortOrder = SortOrder.asc(request.getOrder());
}
reactiveQuery = reactiveQuery.orderBy(sortOrder);
}
return reactiveQuery.fetchOne();
}
public Mono<PagerResult<DeviceUserTalkRecordEntity>> selectDeviceUserTalkRecordsByRequest(DeviceUserTalkRecordRequest request){
ReactiveQuery<DeviceUserTalkRecordEntity> reactiveQuery = createQuery();
reactiveQuery = reactiveQuery.and("is_delete", 0);
if(request.getId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getId, request.getId());
}
if(request.getIsDelete() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getIsDelete, request.getIsDelete());
}
if(request.getCreateTimeStart() != null){
reactiveQuery = reactiveQuery.gte(DeviceUserTalkRecordRequest::getCreateTime, request.getCreateTimeStart());
}
if(request.getCreateTimeEnd() != null){
reactiveQuery = reactiveQuery.lte(DeviceUserTalkRecordRequest::getCreateTime, request.getCreateTimeEnd());
}
if(request.getModifyTimeStart() != null){
reactiveQuery = reactiveQuery.gte(DeviceUserTalkRecordRequest::getModifyTime, request.getModifyTimeStart());
}
if(request.getModifyTimeEnd() != null){
reactiveQuery = reactiveQuery.lte(DeviceUserTalkRecordRequest::getModifyTime, request.getModifyTimeEnd());
}
if(request.getAskNumber() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAskNumber, request.getAskNumber());
}
if(request.getUserId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getUserId, request.getUserId());
}
if(request.getDeviceId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getDeviceId, request.getDeviceId());
}
if(StringUtils.isNotEmpty(request.getAskValue())){
reactiveQuery = reactiveQuery.$like$(DeviceUserTalkRecordRequest::getAskValue, request.getAskValue());
}
if(request.getAskType() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAskType, request.getAskType());
}
if(StringUtils.isNotEmpty(request.getAskKey())){
reactiveQuery = reactiveQuery.$like$(DeviceUserTalkRecordRequest::getAskKey, request.getAskKey());
}
if(StringUtils.isNotEmpty(request.getAnswerValue())){
reactiveQuery = reactiveQuery.$like$(DeviceUserTalkRecordRequest::getAnswerValue, request.getAnswerValue());
}
if(request.getAnswerThirdId() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getAnswerThirdId, request.getAnswerThirdId());
}
if(StringUtils.isNotEmpty(request.getAnswerThirdValue())){
reactiveQuery = reactiveQuery.$like$(DeviceUserTalkRecordRequest::getAnswerThirdValue, request.getAnswerThirdValue());
}
if(request.getIsReturn() != null){
reactiveQuery = reactiveQuery.and(DeviceUserTalkRecordRequest::getIsReturn, request.getIsReturn());
}
SortOrder sortOrder = null;
if(StringUtils.isNotEmpty(request.getOrder())){
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
sortOrder = SortOrder.desc(request.getOrder());
}else{
sortOrder = SortOrder.asc(request.getOrder());
}
reactiveQuery = reactiveQuery.orderBy(sortOrder);
}
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
param.setPageIndex(request.getCurrPage());
param.setPageSize(request.getPageSize());
param.setPaging(true);
param.setFirstPageIndex(1);
return queryPager(param);
}
public Mono<DeviceUserTalkRecordEntity> selectDeviceUserTalkRecordById(Long id){
return createQuery()
.and("is_delete", 0)
.and("id", id)
.fetchOne();
}
public Mono<Integer> insertDeviceUserTalkRecord(DeviceUserTalkRecordEntity entity){
entity.setId(null);
entity.setCreateTime(null);
entity.setModifyTime(null);
return insert(entity);
}
public Mono<Integer> updateDeviceUserTalkRecordById(DeviceUserTalkRecordEntity entity){
ReactiveUpdate<DeviceUserTalkRecordEntity> update = createUpdate()
.set(DeviceUserTalkRecordEntity::getModifyTime, new Date());
if(entity.getIsDelete() != null){
update = update.set(DeviceUserTalkRecordEntity::getIsDelete, entity.getIsDelete());
}
if(entity.getAskNumber() != null){
update = update.set(DeviceUserTalkRecordEntity::getAskNumber, entity.getAskNumber());
}
if(entity.getUserId() != null){
update = update.set(DeviceUserTalkRecordEntity::getUserId, entity.getUserId());
}
if(entity.getDeviceId() != null){
update = update.set(DeviceUserTalkRecordEntity::getDeviceId, entity.getDeviceId());
}
if(StringUtils.isNotEmpty(entity.getAskValue())){
update = update.set(DeviceUserTalkRecordEntity::getAskValue, entity.getAskValue());
}
if(entity.getAskType() != null){
update = update.set(DeviceUserTalkRecordEntity::getAskType, entity.getAskType());
}
if(StringUtils.isNotEmpty(entity.getAskKey())){
update = update.set(DeviceUserTalkRecordEntity::getAskKey, entity.getAskKey());
}
if(StringUtils.isNotEmpty(entity.getAnswerValue())){
update = update.set(DeviceUserTalkRecordEntity::getAnswerValue, entity.getAnswerValue());
}
if(entity.getAnswerThirdId() != null){
update = update.set(DeviceUserTalkRecordEntity::getAnswerThirdId, entity.getAnswerThirdId());
}
if(StringUtils.isNotEmpty(entity.getAnswerThirdValue())){
update = update.set(DeviceUserTalkRecordEntity::getAnswerThirdValue, entity.getAnswerThirdValue());
}
if(entity.getIsReturn() != null){
update = update.set(DeviceUserTalkRecordEntity::getIsReturn, entity.getIsReturn());
}
return update.where(DeviceUserTalkRecordEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
public Mono<Integer> updateCoverDeviceUserTalkRecordById(DeviceUserTalkRecordEntity entity){
ReactiveUpdate<DeviceUserTalkRecordEntity> update = createUpdate()
.set(DeviceUserTalkRecordEntity::getModifyTime, new Date());
update = update.set(DeviceUserTalkRecordEntity::getIsDelete, entity.getIsDelete());
update = update.set(DeviceUserTalkRecordEntity::getAskNumber, entity.getAskNumber());
update = update.set(DeviceUserTalkRecordEntity::getUserId, entity.getUserId());
update = update.set(DeviceUserTalkRecordEntity::getDeviceId, entity.getDeviceId());
update = update.set(DeviceUserTalkRecordEntity::getAskValue, entity.getAskValue());
update = update.set(DeviceUserTalkRecordEntity::getAskType, entity.getAskType());
update = update.set(DeviceUserTalkRecordEntity::getAskKey, entity.getAskKey());
update = update.set(DeviceUserTalkRecordEntity::getAnswerValue, entity.getAnswerValue());
update = update.set(DeviceUserTalkRecordEntity::getAnswerThirdId, entity.getAnswerThirdId());
update = update.set(DeviceUserTalkRecordEntity::getAnswerThirdValue, entity.getAnswerThirdValue());
update = update.set(DeviceUserTalkRecordEntity::getIsReturn, entity.getIsReturn());
return update.where(DeviceUserTalkRecordEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
public Mono<Integer> deleteDeviceUserTalkRecordById(Long id){
return createUpdate()
.set("is_delete", 1)
.set("modify_time", new Date())
.where("id", id)
.execute();
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long