设备登录增加redis缓存

This commit is contained in:
wulin 2023-09-28 13:58:11 +08:00
parent c2f19ee805
commit 6a0e082e2b
26 changed files with 27352 additions and 113 deletions

View File

@ -17,7 +17,14 @@ public class RedisConstans {
public static Long ONE_MONTH_30 = ONE_DAY * 30;
public static Long HALF_MONTH_15 = ONE_DAY * 15;
/*
* 10年
* */
public static Long TEN_YEAR = ONE_DAY * 365 * 10;
public static String DEVICE_INFO = "device::info::";
public static String IOT_TOKEN = "iot_token:";
public static String USER_BOX_INFO = "user_box_info:";
}

View File

@ -0,0 +1,26 @@
package com.qiuguo.iot.base.model;
import lombok.Data;
/**
* redis用户设备缓存数据接口
*/
@Data
public class UserDeviceInfoModel {
/**
* 设备id
*/
Long deviceId;
/**
* 用户id
*/
Long userId;
/**
* 设备序列号
*/
String sn;
/**
* 设备状态 0 离线 1 在线
*/
Integer status;
}

View File

@ -0,0 +1,53 @@
package com.qiuguo.iot.base.utils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.util.Map;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
public class WebClientUtils {
private static WebClient webClient = WebClient.builder().defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE).build();
public static Mono<JSONObject> get(String url) {
return get(url, null);
}
public static Mono<JSONObject> post(String url, JSONObject body) {
return post(url, body, null);
}
public static Mono<JSONObject> get(String url, Map<String, String> headers) {
if(headers == null || headers.size() == 0) {
return webClient.get().uri(url).retrieve().bodyToMono(JSONObject.class);
}else{
return webClient.get().uri(url).headers(httpHeaders -> {
for (String key:headers.keySet()
) {
httpHeaders.set(key, headers.get(key));
}
}).retrieve().bodyToMono(JSONObject.class);
}
}
public static Mono<JSONObject> post(String url, JSONObject body, Map<String, String> headers) {
if(headers == null || headers.size() == 0) {
return webClient.post().uri(url).bodyValue(body.toString()).retrieve().bodyToMono(JSONObject.class);
}else{
return webClient.post().uri(url).bodyValue(body.toString()).headers(httpHeaders -> {
for (String key:headers.keySet()
) {
httpHeaders.set(key, headers.get(key));
}
}).retrieve().bodyToMono(JSONObject.class);
}
}
}

View File

@ -0,0 +1,44 @@
package com.qiuguo.iot.data.entity.system;
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-28
*/
@Data
@Comment("同性词表(同性词非语言中的同义词,而是指正反一词和同一个结果的词)")
@Table(name = "system_same_talk")
@EnableEntityEvent
public class SystemSameTalkEntity 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 = "name", length = 100, nullable = false)
private String name;
@Comment("备注说明")
@Column(name = "remark", length = 255)
private String remark;
}

View File

@ -45,6 +45,34 @@ public class SystemTalkBindDeviceEntity extends GenericEntity<Long> {
@Column(name = "category_code", length = 20, nullable = false)
private String categoryCode;
@Comment("动作后的变量,名词")
@Column(name = "ask_common", length = 100, nullable = false)
private String askCommon;
@Comment("回答内容传给box")
@Column(name = "answer_value", length = 255, nullable = false)
private String answerValue;
@Comment("执行失败所对应动作")
@Column(name = "answer_value_faild", length = 255, nullable = false)
private String answerValueFaild;
@Comment("回答时的动作(数字人的口型以外动作)")
@Column(name = "answer_action", length = 255)
private String answerAction;
@Comment("执行失败所对应动作")
@Column(name = "answer_action_faild", length = 255, nullable = false)
private String answerActionFaild;
@Comment("回答时的背景音乐URL")
@Column(name = "answer_back_sound", length = 255)
private String answerBackSound;
@Comment("回答时的背景图片、视屏、动画URL")
@Column(name = "answer_back_img", length = 255)
private String answerBackImg;
@Comment("备注")
@Column(name = "remark", length = 255)
private String remark;

View File

@ -0,0 +1,43 @@
package com.qiuguo.iot.data.request.system;
import lombok.Data;
import java.util.Date;
/**
* <p>
*同性词同性词非语言中的同义词而是指正反一词和同一个结果的词请求类
* @author wulin
* @since 2023-09-28
*/
@Data
public class SystemSameTalkRequest 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 String name;
//备注说明
private String remark;
}

View File

@ -45,6 +45,24 @@ public class SystemTalkBindDeviceRequest implements java.io.Serializable {
private Long userHandlingId;
//分类字段名称
private String categoryCode;
//动作后的变量名词
private String askCommon;
//回答内容传给box
private String answerValue;
//回答时的动作(数字人的口型以外动作)
//执行失败所对应动作
private String answerValueFaild;
//回答时的动作(数字人的口型以外动作)
private String answerAction;
//执行失败所对应动作
private String answerActionFaild;
//回答时的背景音乐URL
private String answerBackSound;
//回答时的背景图片视屏动画URL
private String answerBackImg;
//备注
private String remark;
}

View File

@ -0,0 +1,34 @@
package com.qiuguo.iot.data.resp.system;
import com.qiuguo.iot.data.entity.system.SystemSameTalkEntity;
import lombok.Data;
import java.util.Date;
/**
* <p>
* </p>*同性词同性词非语言中的同义词而是指正反一词和同一个结果的词返回类
* @author wulin
* @since 2023-09-28
*/
@Data
public class SystemSameTalkResp {
public SystemSameTalkResp(){
}
public SystemSameTalkResp(SystemSameTalkEntity entity){
id = entity.getId();
createTime = entity.getCreateTime();
modifyTime = entity.getModifyTime();
name = entity.getName();
remark = entity.getRemark();
}
//
private Long id;
//创建时间
private Date createTime;
//修改时间
private Date modifyTime;
//名称
private String name;
//备注说明
private String remark;
}

View File

@ -1,6 +1,9 @@
package com.qiuguo.iot.data.resp.system;
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
import lombok.Data;
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
import javax.persistence.Column;
import java.util.Date;
/**
* <p>
@ -34,6 +37,24 @@ public class SystemTalkBindDeviceResp {
private Long userHandlingId;
//分类字段名称
private String categoryCode;
//动作后的变量名词
private String askCommon;
//回答内容传给box
private String answerValue;
//回答时的动作(数字人的口型以外动作)
//执行失败所对应动作
private String answerValueFaild;
//回答时的动作(数字人的口型以外动作)
private String answerAction;
//执行失败所对应动作
private String answerActionFaild;
//回答时的背景音乐URL
private String answerBackSound;
//回答时的背景图片视屏动画URL
private String answerBackImg;
//备注
private String remark;
}

View File

@ -0,0 +1,170 @@
package com.qiuguo.iot.data.service.system;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.data.entity.system.SystemSameTalkEntity;
import com.qiuguo.iot.data.request.system.SystemSameTalkRequest;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;
import org.hswebframework.ezorm.rdb.mapping.ReactiveUpdate;
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.stereotype.Service;
import reactor.core.publisher.Mono;
import java.util.Date;
/**
* <p>
* 同性词同性词非语言中的同义词而是指正反一词和同一个结果的词服务类
* </p>
*
* @author wulin
* @since 2023-09-28
*/
@Service
@Slf4j
public class SystemSameTalkService extends GenericReactiveCrudService<SystemSameTalkEntity, Long> {
public Mono<SystemSameTalkEntity> selectSystemSameTalkByRequest(SystemSameTalkRequest request){
ReactiveQuery<SystemSameTalkEntity> reactiveQuery = createQuery();
reactiveQuery = reactiveQuery.and("is_delete", 0);
if(request.getId() != null){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getId, request.getId());
}
if(request.getIsDelete() != null){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getIsDelete, request.getIsDelete());
}
if(request.getCreateTime() != null){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getCreateTime, request.getCreateTime());
}
if(request.getModifyTime() != null){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getModifyTime, request.getModifyTime());
}
if(StringUtils.isNotEmpty(request.getName())){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getName, request.getName());
}
if(StringUtils.isNotEmpty(request.getRemark())){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getRemark, request.getRemark());
}
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<SystemSameTalkEntity>> selectSystemSameTalksByRequest(SystemSameTalkRequest request){
ReactiveQuery<SystemSameTalkEntity> reactiveQuery = createQuery();
reactiveQuery = reactiveQuery.and("is_delete", 0);
if(request.getId() != null){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getId, request.getId());
}
if(request.getIsDelete() != null){
reactiveQuery = reactiveQuery.and(SystemSameTalkRequest::getIsDelete, request.getIsDelete());
}
if(request.getCreateTimeStart() != null){
reactiveQuery = reactiveQuery.gte(SystemSameTalkRequest::getCreateTime, request.getCreateTimeStart());
}
if(request.getCreateTimeEnd() != null){
reactiveQuery = reactiveQuery.lte(SystemSameTalkRequest::getCreateTime, request.getCreateTimeEnd());
}
if(request.getModifyTimeStart() != null){
reactiveQuery = reactiveQuery.gte(SystemSameTalkRequest::getModifyTime, request.getModifyTimeStart());
}
if(request.getModifyTimeEnd() != null){
reactiveQuery = reactiveQuery.lte(SystemSameTalkRequest::getModifyTime, request.getModifyTimeEnd());
}
if(StringUtils.isNotEmpty(request.getName())){
reactiveQuery = reactiveQuery.$like$(SystemSameTalkRequest::getName, request.getName());
}
if(StringUtils.isNotEmpty(request.getRemark())){
reactiveQuery = reactiveQuery.$like$(SystemSameTalkRequest::getRemark, request.getRemark());
}
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<SystemSameTalkEntity> selectSystemSameTalkById(Long id){
return createQuery()
.and("is_delete", 0)
.and("id", id)
.fetchOne();
}
public Mono<Integer> insertSystemSameTalk(SystemSameTalkEntity entity){
entity.setId(null);
entity.setCreateTime(null);
entity.setModifyTime(null);
return insert(entity);
}
public Mono<Integer> updateSystemSameTalkById(SystemSameTalkEntity entity){
ReactiveUpdate<SystemSameTalkEntity> update = createUpdate()
.set(SystemSameTalkEntity::getModifyTime, new Date());
if(entity.getIsDelete() != null){
update = update.set(SystemSameTalkEntity::getIsDelete, entity.getIsDelete());
}
if(StringUtils.isNotEmpty(entity.getName())){
update = update.set(SystemSameTalkEntity::getName, entity.getName());
}
if(StringUtils.isNotEmpty(entity.getRemark())){
update = update.set(SystemSameTalkEntity::getRemark, entity.getRemark());
}
return update.where(SystemSameTalkEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
public Mono<Integer> updateCoverSystemSameTalkById(SystemSameTalkEntity entity){
ReactiveUpdate<SystemSameTalkEntity> update = createUpdate()
.set(SystemSameTalkEntity::getModifyTime, new Date());
update = update.set(SystemSameTalkEntity::getIsDelete, entity.getIsDelete());
update = update.set(SystemSameTalkEntity::getName, entity.getName());
update = update.set(SystemSameTalkEntity::getRemark, entity.getRemark());
return update.where(SystemSameTalkEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
public Mono<Integer> deleteSystemSameTalkById(Long id){
return createUpdate()
.set("is_delete", 1)
.set("modify_time", new Date())
.where("id", id)
.execute();
}
}

View File

@ -4,6 +4,8 @@ package com.qiuguo.iot.data.service.system;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
import com.qiuguo.iot.data.request.system.SystemTalkBindDeviceRequest;
import com.qiuguo.iot.data.request.system.SystemTalkBindDeviceRequest;
import lombok.extern.slf4j.Slf4j;
import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;
@ -54,6 +56,27 @@ public class SystemTalkBindDeviceService extends GenericReactiveCrudService<Syst
if(StringUtils.isNotEmpty(request.getCategoryCode())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getCategoryCode, request.getCategoryCode());
}
if(StringUtils.isNotEmpty(request.getAskCommon())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAskCommon, request.getAskCommon());
}
if(StringUtils.isNotEmpty(request.getAnswerValue())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerValue, request.getAnswerValue());
}
if(StringUtils.isNotEmpty(request.getAnswerValueFaild())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerValueFaild, request.getAnswerValueFaild());
}
if(StringUtils.isNotEmpty(request.getAnswerAction())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerAction, request.getAnswerAction());
}
if(StringUtils.isNotEmpty(request.getAnswerActionFaild())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerActionFaild, request.getAnswerActionFaild());
}
if(StringUtils.isNotEmpty(request.getAnswerBackSound())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerBackSound, request.getAnswerBackSound());
}
if(StringUtils.isNotEmpty(request.getAnswerBackImg())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerBackImg, request.getAnswerBackImg());
}
if(StringUtils.isNotEmpty(request.getRemark())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getRemark, request.getRemark());
}
@ -101,6 +124,27 @@ public class SystemTalkBindDeviceService extends GenericReactiveCrudService<Syst
if(StringUtils.isNotEmpty(request.getCategoryCode())){
reactiveQuery = reactiveQuery.$like$(SystemTalkBindDeviceRequest::getCategoryCode, request.getCategoryCode());
}
if(StringUtils.isNotEmpty(request.getAskCommon())){
reactiveQuery = reactiveQuery.$like$(SystemTalkBindDeviceRequest::getAskCommon, request.getAskCommon());
}
if(StringUtils.isNotEmpty(request.getAnswerValue())){
reactiveQuery = reactiveQuery.$like$(SystemTalkBindDeviceRequest::getAnswerValue, request.getAnswerValue());
}
if(StringUtils.isNotEmpty(request.getAnswerValueFaild())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerValueFaild, request.getAnswerValueFaild());
}
if(StringUtils.isNotEmpty(request.getAnswerAction())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerAction, request.getAnswerAction());
}
if(StringUtils.isNotEmpty(request.getAnswerActionFaild())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getAnswerActionFaild, request.getAnswerActionFaild());
}
if(StringUtils.isNotEmpty(request.getAnswerBackSound())){
reactiveQuery = reactiveQuery.$like$(SystemTalkBindDeviceRequest::getAnswerBackSound, request.getAnswerBackSound());
}
if(StringUtils.isNotEmpty(request.getAnswerBackImg())){
reactiveQuery = reactiveQuery.$like$(SystemTalkBindDeviceRequest::getAnswerBackImg, request.getAnswerBackImg());
}
if(StringUtils.isNotEmpty(request.getRemark())){
reactiveQuery = reactiveQuery.$like$(SystemTalkBindDeviceRequest::getRemark, request.getRemark());
}
@ -156,6 +200,27 @@ public class SystemTalkBindDeviceService extends GenericReactiveCrudService<Syst
if(StringUtils.isNotEmpty(entity.getCategoryCode())){
update = update.set(SystemTalkBindDeviceEntity::getCategoryCode, entity.getCategoryCode());
}
if(StringUtils.isNotEmpty(entity.getAskCommon())){
update = update.set(SystemTalkBindDeviceEntity::getAskCommon, entity.getAskCommon());
}
if(StringUtils.isNotEmpty(entity.getAnswerValue())){
update = update.set(SystemTalkBindDeviceEntity::getAnswerValue, entity.getAnswerValue());
}
if(StringUtils.isNotEmpty(entity.getAnswerAction())){
update = update.set(SystemTalkBindDeviceEntity::getAnswerAction, entity.getAnswerAction());
}
if(StringUtils.isNotEmpty(entity.getAnswerValueFaild())){
update = update.set(SystemTalkBindDeviceEntity::getAnswerValueFaild, entity.getAnswerValueFaild());
}
if(StringUtils.isNotEmpty(entity.getAnswerActionFaild())){
update = update.set(SystemTalkBindDeviceEntity::getAnswerActionFaild, entity.getAnswerActionFaild());
}
if(StringUtils.isNotEmpty(entity.getAnswerBackSound())){
update = update.set(SystemTalkBindDeviceEntity::getAnswerBackSound, entity.getAnswerBackSound());
}
if(StringUtils.isNotEmpty(entity.getAnswerBackImg())){
update = update.set(SystemTalkBindDeviceEntity::getAnswerBackImg, entity.getAnswerBackImg());
}
if(StringUtils.isNotEmpty(entity.getRemark())){
update = update.set(SystemTalkBindDeviceEntity::getRemark, entity.getRemark());
}
@ -171,6 +236,13 @@ public class SystemTalkBindDeviceService extends GenericReactiveCrudService<Syst
update = update.set(SystemTalkBindDeviceEntity::getSystemTalkId, entity.getSystemTalkId());
update = update.set(SystemTalkBindDeviceEntity::getUserHandlingId, entity.getUserHandlingId());
update = update.set(SystemTalkBindDeviceEntity::getCategoryCode, entity.getCategoryCode());
update = update.set(SystemTalkBindDeviceEntity::getAskCommon, entity.getAskCommon());
update = update.set(SystemTalkBindDeviceEntity::getAnswerValue, entity.getAnswerValue());
update = update.set(SystemTalkBindDeviceEntity::getAnswerAction, entity.getAnswerAction());
update = update.set(SystemTalkBindDeviceEntity::getAnswerValueFaild, entity.getAnswerValueFaild());
update = update.set(SystemTalkBindDeviceEntity::getAnswerActionFaild, entity.getAnswerActionFaild());
update = update.set(SystemTalkBindDeviceEntity::getAnswerBackSound, entity.getAnswerBackSound());
update = update.set(SystemTalkBindDeviceEntity::getAnswerBackImg, entity.getAnswerBackImg());
update = update.set(SystemTalkBindDeviceEntity::getRemark, entity.getRemark());
return update.where(SystemTalkBindDeviceEntity::getId, entity.getId()).and("is_delete", 0).execute();
}

View File

@ -39,6 +39,7 @@ public class LacNlpService implements INlp {
// private String url;
private Mono<JSONObject> getNlpFromLac(LacRequest request){
return webClient.post().uri(SpringUtil.getProperty("lac.url") + "/predict/lac").bodyValue(JSONObject.toJSON(request))
.retrieve()
.bodyToMono(JSONObject.class).doOnNext(res -> {

View File

@ -28,21 +28,59 @@ public class NlpService {
private SystemTalkAnswerConfigService systemTalkAnswerConfigService;
public Mono<Actions> getActionWithLacSingle(String text){
//20230928日记后期改成先匹配用户的设备名称再找动词
return liguoNlpService.geSingletNlp(text).map(nlp -> {
Actions actions = new Actions();
actions.setActions(new ArrayList<>());
nlp.getKeys().sort(Comparator.comparing(NlpKey::getType)); //解析,按照type从小到大排序
Action action = new Action();
//nlp.getKeys().sort(Comparator.comparing(NlpKey::getType)); //解析,按照type从小到大排序
Action action = null;
String name = "";
/*new Action();
action.setName(new ArrayList<>());
action.setLbs(new ArrayList<>());
action.setAsk(text);
action.setAsk(text);*/
int a = 1, b = 1;
List<SystemTalkAnswerConfigEntity> systemTalkAnswerConfigEntities = new ArrayList<>();
SystemTalkAnswerConfigEntity lastSystemTalkAnswerConfigEntity = null;
String lastName = null;
for (NlpKey key : nlp.getKeys()
) {
if(a + b == 2){
a = 0;
b = 0;
if(systemTalkAnswerConfigEntities.size() > 0){//指令按照优先级排序
systemTalkAnswerConfigEntities.sort(Comparator.comparing(SystemTalkAnswerConfigEntity::getKeyOrder));
lastSystemTalkAnswerConfigEntity = systemTalkAnswerConfigEntities.get(0);
action.setSystemTalkAnswerConfigEntity(lastSystemTalkAnswerConfigEntity);
action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey());
systemTalkAnswerConfigEntities.clear();
}else if(lastSystemTalkAnswerConfigEntity != null){
action.setSystemTalkAnswerConfigEntity(lastSystemTalkAnswerConfigEntity);
action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey());
}
if(StringUtils.isNotEmpty(name)){
action.getName().add(name);
lastName = name;
}else if(action != null && StringUtils.isNotEmpty(lastName)){
action.getName().add(lastName);
}
action = new Action();
name = "";
action.setName(new ArrayList<>());
action.setLbs(new ArrayList<>());
action.setAsk(text);
actions.getActions().add(action);
}
if(key.getType().equals(ChinesePartSpeechEnum.v.getCode())){
action.setAction(key.getKey());
SystemTalkAnswerConfigEntity entity = systemTalkAnswerConfigService.getSystemTalkWithKey(action.getAction());
if(entity != null){
systemTalkAnswerConfigEntities.add(entity);
}
a = 1;
}else if(key.getType().equals(ChinesePartSpeechEnum.n.getCode())){
//匹配到关键词就不能作为名词加入未匹配到的分割前的都加入名词
SystemTalkAnswerConfigEntity entity = systemTalkAnswerConfigService.getSystemTalkWithKey(key.getKey());
@ -57,12 +95,11 @@ public class NlpService {
action.getName().add(name);//加入分割前的名词
name = "";
}
}
}else{
name += key.getKey();
}
b = 1;
}else if(key.getType().equals(ChinesePartSpeechEnum.m.getCode())){
action.setStatus(key.getKey());
@ -78,6 +115,7 @@ public class NlpService {
action.setTime(new ActionTime());
action.getTime().setTime(key.getKey());
}
}
if(StringUtils.isNotEmpty(name)){
@ -87,11 +125,9 @@ public class NlpService {
}else{
action.getName().add(name);
}
}
if(StringUtils.isNotEmpty(action.getAction())){
SystemTalkAnswerConfigEntity entity = systemTalkAnswerConfigService.getSystemTalkWithKey(action.getAction());
if(entity != null){
systemTalkAnswerConfigEntities.add(entity);
}else{
if(StringUtils.isNotEmpty(lastName)){
action.getName().add(lastName);
}
}
@ -99,10 +135,11 @@ public class NlpService {
systemTalkAnswerConfigEntities.sort(Comparator.comparing(SystemTalkAnswerConfigEntity::getKeyOrder));
action.setSystemTalkAnswerConfigEntity(systemTalkAnswerConfigEntities.get(0));
action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey());
}else if(lastSystemTalkAnswerConfigEntity != null){
action.setSystemTalkAnswerConfigEntity(lastSystemTalkAnswerConfigEntity);
action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey());
}
actions.getActions().add(action);
return actions;
});
}

View File

@ -1,8 +1,9 @@
package com.qiuguo.iot.third.service;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.utils.StringUtils;
import com.qiuguo.iot.base.utils.WebClientUtils;
import com.qiuguo.iot.data.request.third.ThirdWeatherInfoRequest;
import com.qiuguo.iot.data.resp.third.ThirdIpInfoResp;
import com.qiuguo.iot.data.resp.third.ThirdRpcResp;
@ -43,8 +44,7 @@ public class WeatherService {
@Value("https://api.caiyunapp.com/v2.6/ilUeAnf1vNkphxYS/")
private String queryWeatherUrl;
private static WebClient webClient = WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON_VALUE).build();
@Resource
private IpService ipService;
@ -111,8 +111,10 @@ public class WeatherService {
queryWeatherUrl = queryWeatherUrl + r.getLng().toString() + "," + r.getLat().toString() + "/daily?dailysteps=" + querySize;
}
return webClient.get().uri(queryWeatherUrl).retrieve().bodyToMono(WeatherResp.class);
return WebClientUtils.get(queryWeatherUrl).map(jsonObject -> {
return jsonObject.toJavaObject(WeatherResp.class);
});
//return webClient.get().uri(queryWeatherUrl).retrieve().bodyToMono(WeatherResp.class);
});
}
@ -124,7 +126,8 @@ public class WeatherService {
}else{
url += "&city=" + req.getCity();
}
return webClient.get().uri(url).retrieve()
.bodyToMono(TianqiapiResp.class);
return WebClientUtils.get(url).map(jsonObject -> {
return jsonObject.toJavaObject(TianqiapiResp.class);
});
}
}

View File

@ -1,17 +1,9 @@
package com.qiuguo.iot.box.websocket.api.controller;
import com.alibaba.fastjson.JSONObject;
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.handler.BoxWebSocketHandler;
import com.qiuguo.iot.box.websocket.api.handler.CustomerWebSocketHandler;
import com.qiuguo.iot.box.websocket.api.service.WebsocketService;
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
import com.qiuguo.iot.third.nlp.Nlp;
import com.qiuguo.iot.third.service.LacNlpService;
import com.qiuguo.iot.third.service.NlpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

View File

@ -1,13 +0,0 @@
package com.qiuguo.iot.box.websocket.api.domain.box;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
import lombok.Data;
import org.springframework.web.reactive.socket.WebSocketMessage;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.FluxSink;
@Data
public class BoxSession extends BaseSession {
}

View File

@ -1,12 +0,0 @@
package com.qiuguo.iot.box.websocket.api.domain.user;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
import lombok.Data;
import org.springframework.web.reactive.socket.WebSocketMessage;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.FluxSink;
@Data
public class UserSession extends BaseSession {
}

View File

@ -5,9 +5,9 @@ import com.qiuguo.iot.base.enums.AskTypeEnum;
import com.qiuguo.iot.base.enums.RespCodeEnum;
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.domain.user.UserTalkMessage;
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
import com.qiuguo.iot.data.entity.device.DeviceUserTalkRecordEntity;
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
@ -22,11 +22,15 @@ import com.qiuguo.iot.data.service.system.SystemTalkBindDeviceService;
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;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
@ -55,9 +59,13 @@ public class BaseWebSocketProcess {
@Autowired
protected DeviceUserTalkRecordService deviceUserTalkRecordService;
protected static ConcurrentHashMap<Long, UserSession> userGroup = new ConcurrentHashMap<>();
protected static ConcurrentHashMap<String, BoxSession> boxGroup = new ConcurrentHashMap<>();
protected static ConcurrentHashMap<Long, BaseSession> userGroup = new ConcurrentHashMap<>();
protected static ConcurrentHashMap<String, BaseSession> boxGroup = new ConcurrentHashMap<>();
protected static String apiType = "api-type";
protected static String apiToken = "api-token";
protected void processAction(Actions actions, Long userId, BaseSession baseSession) {
//目前只处理第一条动作
@ -169,7 +177,7 @@ public class BaseWebSocketProcess {
if(item != null){
//返回给客户端播报内容
msg = t.getCity() + action.getTime().getTime() + "天气"
+ item.getNarrative().replace("km / h", "千米每小时")
+ item.getNarrative().replace("km / h", "千米每小时")
+ ",空气质量" + item.getAir_level()
+ ",湿度" + item.getHumidity() + ",最低气温" + item.getTem2();
@ -185,6 +193,57 @@ public class BaseWebSocketProcess {
}
/*protected Mono<Void> sessionProcess(WebSocketSession session, Long userId, String ip, int type) {
Mono<Void> input = session.receive().map(webSocketMessage ->{
//MDC.put(LogMdcConfiguration.PRINT_LOG_ID, getBoxSessionWithSn().getLogId());
String text = webSocketMessage.getPayloadAsText();
log.info("收到消息:{}", text);
UserTalkMessage userTalkMessage = JSONObject.parseObject(text, UserTalkMessage.class);
nlpService.getActionWithLacSingle(userTalkMessage.getMessage()).defaultIfEmpty(new Actions()).map(actions -> {
BaseSession baseSession = null;
if(type == 0){
baseSession = getUserSessionWithUserId(userTalkMessage.getUserId());
}else{
baseSession = getUserSessionWithUserId(userTalkMessage.getUserId());
}
//处理
if(actions.getActions() == null || actions.getActions().size() == 0){
//调用千问回答
log.info("未匹配到自定义命令,调用千问");
}else if(baseSession == null){
log.info("未匹配到用户session可能传错用户id");
session.close().subscribe();
}else{
processAction(actions, userId, baseSession);
}
return Mono.empty();
}).subscribe();
log.info("收到用户userId:{},消息:{}", userTalkMessage.getUserId(), userTalkMessage.getMessage());
//MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
return Mono.empty();
}).then();
BaseSession userSession = new BaseSession();
userSession.setUserId(userId);
userSession.setSession(session);
userSession.setCustomerIP(ip);
userSession.setLogId(MDC.get(LogMdcConfiguration.PRINT_LOG_ID));
userGroup.put(userId, userSession);
Mono<Void> output = session.send(Flux.create(sink -> userSession.setSink(sink))).then();
// Mono.zip() 会将多个 Mono 合并为一个新的 Mono任何一个 Mono 产生 error complete 都会导致合并后的 Mono
// 也随之产生 error complete此时其它的 Mono 则会被执行取消操作
return Mono.zip(input, output).doFinally(signalType -> {
// MDC.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
userGroup.remove(userSession.getUserId());//断链后及时移除
log.info("断开连接SN{}", userSession.getUserId());
// MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
}).then();
}*/
private void sendMessage(Action action, BaseSession baseSession, Integer type, String message){
BoxMessageResp resp = new BoxMessageResp();
resp.setType(type);
@ -199,7 +258,7 @@ public class BaseWebSocketProcess {
if(type.equals(AskTypeEnum.MUSIC.getCode())) {
if(this instanceof CustomerWebSocketHandler) {
log.info("推送Box播放音乐");
BoxSession boxSession = getBoxSessionWithSn(baseSession.getSn());
BaseSession boxSession = getBoxSessionWithSn(baseSession.getSn());
if(boxSession != null){
boxSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
}else{
@ -211,7 +270,7 @@ public class BaseWebSocketProcess {
deviceUserTalkRecordService.insertDeviceUserTalkRecord(talkRecord).map(i ->{
if(this instanceof BoxWebSocketHandler){
log.info("推送通知到客户端");
UserSession userSession = getUserSessionWithUserId(baseSession.getUserId());
BaseSession userSession = getUserSessionWithUserId(baseSession.getUserId());
if(userSession != null){
userSession.getSink().next(baseSession.getSession().textMessage(JSONObject.toJSONString(resp)));
}
@ -223,14 +282,14 @@ public class BaseWebSocketProcess {
}
public BoxSession getBoxSessionWithSn(String sn) {
public BaseSession getBoxSessionWithSn(String sn) {
if(boxGroup.containsKey(sn)){
return boxGroup.get(sn);
}
return null;
}
public UserSession getUserSessionWithUserId(Long userId) {
public BaseSession getUserSessionWithUserId(Long userId) {
if(userGroup.containsKey(userId)){
return userGroup.get(userId);
}

View File

@ -7,7 +7,8 @@ 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.YesNo;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
import com.qiuguo.iot.base.model.UserDeviceInfoModel;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxTalkMessage;
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
@ -75,17 +76,21 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
//
log.info("登录成功SN:{}", sn);
Mono<Void> input = session.receive().map(webSocketMessage ->{
//MDC.put(LogMdcConfiguration.PRINT_LOG_ID, getBoxSessionWithSn().getLogId());
String text = webSocketMessage.getPayloadAsText();
log.info("设备端收到消息:{}", text);
BoxTalkMessage boxTalkMessage = JSONObject.parseObject(text, BoxTalkMessage.class);
nlpService.getActionWithLacSingle(boxTalkMessage.getMessage()).defaultIfEmpty(new Actions()).map(actions -> {
BoxSession boxSession = getBoxSessionWithSn(boxTalkMessage.getSn());
BaseSession boxSession = getBoxSessionWithSn(boxTalkMessage.getSn());
//处理
if(actions.getActions() == null || actions.getActions().size() == 0){
//调用千问回答
log.info("暂时无法理解,我还在努力学习中");
}else if(boxSession == null){
log.info("未匹配到用户session可能传错用户id");
session.close().subscribe();
}else{
processAction(actions, userId, boxSession);
}
@ -97,7 +102,7 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
//MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
return Mono.empty();
}).then();
BoxSession boxSession = new BoxSession();
BaseSession boxSession = new BaseSession();
boxSession.setSn(sn);
boxSession.setCustomerIP(ip);
boxSession.setSession(session);
@ -113,6 +118,14 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
// MDC.put(LogMdcConfiguration.PRINT_LOG_ID, requestId);
boxGroup.remove(boxSession.getSn());//断链后及时移除
log.info("设备断开连接SN{}", boxSession.getSn());
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
UserDeviceInfoModel userDeviceInfoModel = new UserDeviceInfoModel();
userDeviceInfoModel.setStatus(YesNo.NO.getCode());
userDeviceInfoModel.setUserId(userId);
userDeviceInfoModel.setSn(sn);
operations.set(RedisConstans.USER_BOX_INFO + userId,
JSONObject.toJSONString(userDeviceInfoModel),
RedisConstans.TEN_YEAR).subscribe();
// MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
}).then();
}
@ -130,7 +143,7 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
log.info("转换异常清除redis。下次连接成功{}", e);
//清除异常redis
operations.set(RedisConstans.DEVICE_INFO + sn, "").subscribe();//不需要时间
BoxSession boxSession = getBoxSessionWithSn(sn);
BaseSession boxSession = getBoxSessionWithSn(sn);
if(boxSession != null){
boxSession.getSink().next(boxSession.getSession().textMessage("异常,请重新登录"));
boxSession.getSession().close().subscribe();
@ -151,7 +164,7 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
String wifiMd5 = MD5.create().digestHex(dv.getWifiMac()).toUpperCase();
String btMd5 = MD5.create().digestHex(dv.getBtMac()).toUpperCase();
String signalMd5 = MD5.create().digestHex(snMd5 + wifiMd5 + btMd5 + linkTime + dv.getKey()).toUpperCase();
BoxSession boxSession = getBoxSessionWithSn(sn);
BaseSession boxSession = getBoxSessionWithSn(sn);
if(!signalMd5.equals(signature)){
log.info("设备{},验签失败", sn);
//session.send(session.textMessage(""));
@ -187,13 +200,21 @@ public class BoxWebSocketHandler extends BaseWebSocketProcess implements WebSock
entity.setDeviceId(dv.getId());
//设置未主设备
entity.setIsMain(YesNo.YES.getCode());
entity.setOtherDeviceId(dv.getSn());
entity.setCategoryCode(DeviceCodeEnum.BOX.getName());
deviceUserBindService.setNoMain(userId, DeviceTypeEnum.GUO_BOX.getCode()).defaultIfEmpty(0).map(m ->{
log.info("解除历史isMain标注个数{}", m);
deviceUserBindService.insertDeviceUserBind(entity).map(l ->{
log.info("绑定成功SN{} userId:{}", dv, userId);
//下面所有的以前未主设备改成非主设备
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
UserDeviceInfoModel userDeviceInfoModel = new UserDeviceInfoModel();
userDeviceInfoModel.setStatus(YesNo.YES.getCode());
userDeviceInfoModel.setUserId(userId);
userDeviceInfoModel.setSn(entity.getOtherDeviceId());
operations.set(RedisConstans.USER_BOX_INFO + userId,
JSONObject.toJSONString(userDeviceInfoModel),
RedisConstans.TEN_YEAR).subscribe();
return Mono.empty();
}).subscribe();
return Mono.empty();

View File

@ -2,11 +2,9 @@ package com.qiuguo.iot.box.websocket.api.handler;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.annotation.WebSocketMapping;
import com.qiuguo.iot.base.constans.RedisConstans;
import com.qiuguo.iot.base.enums.YesNo;
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.user.UserSession;
import com.qiuguo.iot.base.utils.WebClientUtils;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
import com.qiuguo.iot.box.websocket.api.domain.user.UserTalkMessage;
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
@ -18,8 +16,6 @@ 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.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.data.redis.core.ReactiveValueOperations;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.HandshakeInfo;
@ -29,8 +25,8 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.HashMap;
import java.util.Map;
@Component
@WebSocketMapping("/websocket/customer")
@ -44,20 +40,20 @@ public class CustomerWebSocketHandler extends BaseWebSocketProcess implements We
@Resource
protected DeviceUserBindService deviceUserBindService;
@Resource
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
@Resource
private NlpService nlpService;
@Value("${qiuguo.checktoken.url}")
private String checkTokenUrl;
@Override
public Mono<Void> handle(WebSocketSession session) {
HandshakeInfo handshakeInfo = session.getHandshakeInfo();
HttpHeaders headers = handshakeInfo.getHeaders();
//List<String> tokens = headers.get("token");
String type = headers.get("api-type").get(0);
String token = headers.get("api-token").get(0);
String type = headers.get(apiType).get(0);
String token = headers.get(apiToken).get(0);
Long userId = Long.valueOf(headers.get("userId").get(0));
Long linkTime = Long.parseLong(headers.get("time").get(0));
if(checkTimeout && System.currentTimeMillis() - linkTime > timeOut){
@ -66,18 +62,14 @@ public class CustomerWebSocketHandler extends BaseWebSocketProcess implements We
return session.close();
}
String ip = headers.get(LogWebFilter.HEAD_IP).get(0);
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
operations.get(RedisConstans.DEVICE_INFO + userId).defaultIfEmpty("ec3299ec9dd4c45517639999aeb4bad7").flatMap(s -> {
if(com.qiuguo.iot.base.utils.StringUtils.isNotBlank(s)){
if(!token.equals(s)){
log.info("验签失败{}", userId);
UserSession userSession = getUserSessionWithUserId(userId);
if(userSession != null){
userSession.getSink().next(session.textMessage("非法登录"));
}
session.close().subscribe();
}else{
//
Map<String, String> reqHead = new HashMap<>();
reqHead.put(apiType, type);
reqHead.put(apiToken, token);
WebClientUtils.get(checkTokenUrl, reqHead).defaultIfEmpty(new JSONObject()).map(jsonObject -> {
log.info("验签获取的数据{}", jsonObject);
if(jsonObject.getInteger("code").equals(YesNo.YES.getCode())){
Long userId1 = jsonObject.getJSONObject("data").getLong("id");
if(userId1.equals(userId)){
log.info("验签成功{}", userId);
DeviceUserBindRequest request = new DeviceUserBindRequest();
request.setUserId(userId);
@ -87,18 +79,25 @@ public class CustomerWebSocketHandler extends BaseWebSocketProcess implements We
.map(deviceUserBindEntity -> {
if(deviceUserBindEntity.getId() != null){
log.info("用户绑定信息为{}", deviceUserBindEntity);
UserSession userSession = getUserSessionWithUserId(userId);
BaseSession userSession = getUserSessionWithUserId(userId);
if(userSession != null){
userSession.setDeviceId(deviceUserBindEntity.getDeviceId());
userSession.setSn(deviceUserBindEntity.getOtherDeviceId());
}
}
return Mono.empty();
}).subscribe();
return Mono.empty();
}
}
log.info("验签失败{}", userId);
BaseSession userSession = getUserSessionWithUserId(userId);
if(userSession != null){
userSession.getSink().next(session.textMessage("非法登录"));
}
session.close().subscribe();
return Mono.empty();
}).subscribe();
log.info("用户成功userId:{}", userId);
Mono<Void> input = session.receive().map(webSocketMessage ->{
@ -107,7 +106,7 @@ public class CustomerWebSocketHandler extends BaseWebSocketProcess implements We
log.info("收到用户消息:{}", text);
UserTalkMessage userTalkMessage = JSONObject.parseObject(text, UserTalkMessage.class);
nlpService.getActionWithLacSingle(userTalkMessage.getMessage()).defaultIfEmpty(new Actions()).map(actions -> {
UserSession userSession = getUserSessionWithUserId(userTalkMessage.getUserId());
BaseSession userSession = getUserSessionWithUserId(userTalkMessage.getUserId());
//处理
if(actions.getActions() == null || actions.getActions().size() == 0){
//调用千问回答
@ -122,7 +121,7 @@ public class CustomerWebSocketHandler extends BaseWebSocketProcess implements We
//MDC.remove(LogMdcConfiguration.PRINT_LOG_ID);
return Mono.empty();
}).then();
UserSession userSession = new UserSession();
BaseSession userSession = new BaseSession();
userSession.setUserId(userId);
userSession.setSession(session);
userSession.setCustomerIP(ip);
@ -142,4 +141,6 @@ public class CustomerWebSocketHandler extends BaseWebSocketProcess implements We
}
}

View File

@ -1,21 +1,13 @@
package com.qiuguo.iot.box.websocket.api.service;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
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.handler.BoxWebSocketHandler;
import com.qiuguo.iot.box.websocket.api.handler.CustomerWebSocketHandler;
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
import com.qiuguo.iot.third.nlp.Nlp;
import com.qiuguo.iot.third.service.LacNlpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
@Service
@ -31,7 +23,7 @@ public class WebsocketService {
if(type == 0){
//设备推送
BoxSession boxSession = boxWebSocketHandler.getBoxSessionWithSn(id);
BaseSession boxSession = boxWebSocketHandler.getBoxSessionWithSn(id);
if(boxSession != null){
BoxMessageResp resp = new BoxMessageResp();
@ -43,7 +35,7 @@ public class WebsocketService {
return Mono.just("设备未上线");
}else{
//用户推送
UserSession userSession = customerWebSocketHandler.getUserSessionWithUserId(Long.parseLong(id));
BaseSession userSession = customerWebSocketHandler.getUserSessionWithUserId(Long.parseLong(id));
if(userSession != null){
BoxMessageResp resp = new BoxMessageResp();
resp.setType(0);

View File

@ -36,4 +36,9 @@ spring:
password: 123456
timeout: 5000
tianqiapi:
url: https://v0.yiketianqi.com/api?unescape=1&version=v91&appid=23293151&appsecret=Lj6ZMcqn&ext=life
url: https://v0.yiketianqi.com/api?unescape=1&version=v91&appid=23293151&appsecret=Lj6ZMcqn&ext=life
qiuguo:
checktoken:
url: https://exper.qiuguojihua.com/data/api.auth.center/get
lac:
url: http://192.168.8.175:8866

View File

@ -82,8 +82,8 @@ public class MysqlMain {
}
List<TablesBean> list = new ArrayList<>();
list.add(new TablesBean("device_user_talk_record"));
//list.add(new TablesBean("user_room"));
list.add(new TablesBean("system_talk_answer_config"));
list.add(new TablesBean("system_same_talk"));
List<TablesBean> list2 = new ArrayList<TablesBean>();
Map<String, String> map = MysqlUtil2ShowCreateTable.getComments();

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