Merge remote-tracking branch 'origin/feature-BOX一期' into feature-BOX一期
This commit is contained in:
commit
c91daba0d4
@ -5,6 +5,18 @@ package com.qiuguo.iot.base.constans;
|
||||
* **/
|
||||
public class RedisConstans {
|
||||
|
||||
public static Long ONE_DAY = 86400l;
|
||||
public static Long ONE_HOUR = 3600l;
|
||||
|
||||
public static Long ONE_MINUTE = 60l;
|
||||
|
||||
public static Long TEN_SECOND = 10l;
|
||||
|
||||
public static Long ONE_WEEK = ONE_DAY * 7;
|
||||
|
||||
public static Long ONE_MONTH_30 = ONE_DAY * 30;
|
||||
|
||||
public static Long HALF_MONTH_15 = ONE_DAY * 15;
|
||||
public static String DEVICE_INFO = "device::info::";
|
||||
|
||||
public static String IOT_TOKEN = "iot_token:";
|
||||
|
||||
@ -7,8 +7,8 @@
|
||||
<artifactId>iot-common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>iot-third</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>iot-third</name>
|
||||
<description>iot-third</description>
|
||||
<properties>
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
<modules>
|
||||
<module>iot-base</module>
|
||||
<module>iot-data</module>
|
||||
<module>iot-third</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
# 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
||||
override-none: true
|
||||
# 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
||||
allow-override: true
|
||||
# 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
||||
override-system-properties: false
|
||||
# config:
|
||||
# # 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
||||
# override-none: true
|
||||
# # 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
||||
# allow-override: true
|
||||
# # 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
||||
# override-system-properties: false
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
|
||||
@ -2,6 +2,8 @@ package com.qiuguo.iot.user.api.controller.device;
|
||||
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.qiuguo.iot.base.constans.RedisConstans;
|
||||
import com.qiuguo.iot.base.enums.DeviceTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
|
||||
@ -14,6 +16,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
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;
|
||||
|
||||
@ -38,6 +42,9 @@ public class DeviceController {
|
||||
@Resource
|
||||
private TuyaDeviceConnector tuyaDeviceConnector;
|
||||
|
||||
@Resource
|
||||
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
|
||||
|
||||
|
||||
@Value("${device.timeout}")
|
||||
private Long timeOut;//2分钟
|
||||
@ -93,12 +100,18 @@ public class DeviceController {
|
||||
}else{
|
||||
entity.setKey( com.qiuguo.iot.base.utils.StringUtils.getRandomStr(10));//重新生成Key
|
||||
mono1 = deviceInfoService.updateDeviceInfoById(entity);
|
||||
|
||||
|
||||
}
|
||||
return mono1.map(m ->{
|
||||
return entity;
|
||||
});
|
||||
}).map(o -> {
|
||||
DeviceInfoEntity deviceInfoEntity = (DeviceInfoEntity)o;
|
||||
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
|
||||
operations.set(RedisConstans.DEVICE_INFO + deviceInfoEntity.getSn()
|
||||
, JSONObject.toJSONString(deviceInfoEntity)
|
||||
, RedisConstans.ONE_HOUR).subscribe();
|
||||
DeviceInitResp resp = new DeviceInitResp();
|
||||
resp.setKey(deviceInfoEntity.getKey());
|
||||
resp.setSn(deviceInfoEntity.getSn());
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
# 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
||||
override-none: true
|
||||
# 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
||||
allow-override: true
|
||||
# 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
||||
override-system-properties: false
|
||||
# config:
|
||||
# # 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
||||
# override-none: true
|
||||
# # 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
||||
# allow-override: true
|
||||
# # 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
||||
# override-system-properties: false
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
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;
|
||||
@ -23,11 +25,16 @@ public class WebsocketController {
|
||||
CustomerWebSocketHandler customerWebSocketHandler;
|
||||
@GetMapping("/push/message")
|
||||
public Mono<String> pushMessage(@RequestParam String message, @RequestParam String id, @RequestParam Integer type) {
|
||||
|
||||
if(type == 0){
|
||||
//设备推送
|
||||
BoxSession boxSession = boxWebSocketHandler.getBoxSessionWithSn(id);
|
||||
if(boxSession != null){
|
||||
boxSession.getSink().next(boxSession.getSession().textMessage(message));
|
||||
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(0);
|
||||
resp.setText(message);
|
||||
boxSession.getSink().next(boxSession.getSession().textMessage(JSONObject.toJSONString(resp)));
|
||||
return Mono.just("推送成功");
|
||||
}
|
||||
return Mono.just("设备未上线");
|
||||
@ -35,7 +42,10 @@ public class WebsocketController {
|
||||
//用户推送
|
||||
UserSession userSession = customerWebSocketHandler.getUserSessionWithSn(id);
|
||||
if(userSession != null){
|
||||
userSession.getSink().next(userSession.getSession().textMessage(message));
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(0);
|
||||
resp.setText(message);
|
||||
userSession.getSink().next(userSession.getSession().textMessage(JSONObject.toJSONString(resp)));
|
||||
return Mono.just("推送成功");
|
||||
}
|
||||
return Mono.just("用户未上线");
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
package com.qiuguo.iot.box.websocket.api.domain.box.resp;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ActionResp {
|
||||
Integer type;
|
||||
Date time;
|
||||
String sound;
|
||||
|
||||
String image;//圖片地址
|
||||
String action;//動作内容 json
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.qiuguo.iot.box.websocket.api.domain.box.resp;
|
||||
|
||||
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 BoxMessageResp {
|
||||
Integer type;//响应类型:0,问答响应 1:iOT操作结果响应 2:设置闹钟 3:天气 4:固件升级
|
||||
String text;//播放文本内容
|
||||
|
||||
|
||||
//其他動作
|
||||
ActionResp action;
|
||||
}
|
||||
@ -67,7 +67,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
request.setSn(sn);
|
||||
return deviceInfoService.selectDeviceInfoByRequest(request).defaultIfEmpty(new DeviceInfoEntity()).map(dv -> {
|
||||
if(dv.getId() != null){
|
||||
operations.set(RedisConstans.DEVICE_INFO + dv.getSn(), JSONObject.toJSONString(dv)).subscribe();//直接提交订阅
|
||||
operations.set(RedisConstans.DEVICE_INFO + dv.getSn(), JSONObject.toJSONString(dv), RedisConstans.ONE_HOUR).subscribe();//直接提交订阅
|
||||
}
|
||||
|
||||
return dv;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
# 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
||||
override-none: true
|
||||
# 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
||||
allow-override: true
|
||||
# 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
||||
override-system-properties: false
|
||||
# config:
|
||||
# # 如果本地配置优先级高,那么 override-none 设置为 true,包括系统环境变量、本地配置文件等配置
|
||||
# override-none: true
|
||||
# # 如果想要远程配置优先级高,那么 allow-override 设置为 false,如果想要本地配置优先级高那么 allow-override 设置为 true
|
||||
# allow-override: true
|
||||
# # 只有系统环境变量或者系统属性才能覆盖远程配置文件的配置,本地配置文件中配置优先级低于远程配置;注意本地配置文件不是系统属性
|
||||
# override-system-properties: false
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user