修改pom引用

This commit is contained in:
wulin 2023-09-25 20:59:33 +08:00
parent 8b35c9b3f3
commit 69205be463
16 changed files with 3624 additions and 15 deletions

View File

@ -0,0 +1,48 @@
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-25
*/
@Data
@Comment("自定义命令和设备动作绑定表")
@Table(name = "system_talk_bind_device")
@EnableEntityEvent
public class SystemTalkBindDeviceEntity 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("自定义命令id")
@Column(name = "system_talk_id", nullable = false)
private Long systemTalkId;
@Comment("设备操控id")
@Column(name = "user_handling_id", nullable = false)
private Long userHandlingId;
@Comment("备注")
@Column(name = "remark", length = 255)
private String remark;
}

View File

@ -0,0 +1,45 @@
package com.qiuguo.iot.data.request.system;
import lombok.Data;
import java.util.Date;
/**
* <p>
*自定义命令和设备动作绑定请求类
* @author wulin
* @since 2023-09-25
*/
@Data
public class SystemTalkBindDeviceRequest 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;
//自定义命令id
private Long systemTalkId;
//设备操控id
private Long userHandlingId;
//备注
private String remark;
}

View File

@ -0,0 +1,37 @@
package com.qiuguo.iot.data.resp.system;
import com.qiuguo.iot.data.entity.system.SystemTalkBindDeviceEntity;
import lombok.Data;
import java.util.Date;
/**
* <p>
* </p>*自定义命令和设备动作绑定返回类
* @author wulin
* @since 2023-09-25
*/
@Data
public class SystemTalkBindDeviceResp {
public SystemTalkBindDeviceResp(){
}
public SystemTalkBindDeviceResp(SystemTalkBindDeviceEntity entity){
id = entity.getId();
createTime = entity.getCreateTime();
modifyTime = entity.getModifyTime();
systemTalkId = entity.getSystemTalkId();
userHandlingId = entity.getUserHandlingId();
remark = entity.getRemark();
}
//
private Long id;
//创建时间
private Date createTime;
//修改时间
private Date modifyTime;
//自定义命令id
private Long systemTalkId;
//设备操控id
private Long userHandlingId;
//备注
private String remark;
}

View File

@ -0,0 +1,180 @@
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.request.system.SystemTalkBindDeviceRequest;
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-25
*/
@Service
@Slf4j
public class SystemTalkBindDeviceService extends GenericReactiveCrudService<SystemTalkBindDeviceEntity, Long> {
public Mono<SystemTalkBindDeviceEntity> selectSystemTalkBindDeviceByRequest(SystemTalkBindDeviceRequest request){
ReactiveQuery<SystemTalkBindDeviceEntity> reactiveQuery = createQuery();
reactiveQuery = reactiveQuery.and("is_delete", 0);
if(request.getId() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getId, request.getId());
}
if(request.getIsDelete() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getIsDelete, request.getIsDelete());
}
if(request.getCreateTime() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getCreateTime, request.getCreateTime());
}
if(request.getModifyTime() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getModifyTime, request.getModifyTime());
}
if(request.getSystemTalkId() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getSystemTalkId, request.getSystemTalkId());
}
if(request.getUserHandlingId() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getUserHandlingId, request.getUserHandlingId());
}
if(StringUtils.isNotEmpty(request.getRemark())){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::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<SystemTalkBindDeviceEntity>> selectSystemTalkBindDevicesByRequest(SystemTalkBindDeviceRequest request){
ReactiveQuery<SystemTalkBindDeviceEntity> reactiveQuery = createQuery();
reactiveQuery = reactiveQuery.and("is_delete", 0);
if(request.getId() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getId, request.getId());
}
if(request.getIsDelete() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getIsDelete, request.getIsDelete());
}
if(request.getCreateTimeStart() != null){
reactiveQuery = reactiveQuery.gte(SystemTalkBindDeviceRequest::getCreateTime, request.getCreateTimeStart());
}
if(request.getCreateTimeEnd() != null){
reactiveQuery = reactiveQuery.lte(SystemTalkBindDeviceRequest::getCreateTime, request.getCreateTimeEnd());
}
if(request.getModifyTimeStart() != null){
reactiveQuery = reactiveQuery.gte(SystemTalkBindDeviceRequest::getModifyTime, request.getModifyTimeStart());
}
if(request.getModifyTimeEnd() != null){
reactiveQuery = reactiveQuery.lte(SystemTalkBindDeviceRequest::getModifyTime, request.getModifyTimeEnd());
}
if(request.getSystemTalkId() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getSystemTalkId, request.getSystemTalkId());
}
if(request.getUserHandlingId() != null){
reactiveQuery = reactiveQuery.and(SystemTalkBindDeviceRequest::getUserHandlingId, request.getUserHandlingId());
}
if(StringUtils.isNotEmpty(request.getRemark())){
reactiveQuery = reactiveQuery.$like$(SystemTalkBindDeviceRequest::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<SystemTalkBindDeviceEntity> selectSystemTalkBindDeviceById(Long id){
return createQuery()
.and("is_delete", 0)
.and("id", id)
.fetchOne();
}
public Mono<Integer> insertSystemTalkBindDevice(SystemTalkBindDeviceEntity entity){
entity.setId(null);
entity.setCreateTime(null);
entity.setModifyTime(null);
return insert(entity);
}
public Mono<Integer> updateSystemTalkBindDeviceById(SystemTalkBindDeviceEntity entity){
ReactiveUpdate<SystemTalkBindDeviceEntity> update = createUpdate()
.set(SystemTalkBindDeviceEntity::getModifyTime, new Date());
if(entity.getIsDelete() != null){
update = update.set(SystemTalkBindDeviceEntity::getIsDelete, entity.getIsDelete());
}
if(entity.getSystemTalkId() != null){
update = update.set(SystemTalkBindDeviceEntity::getSystemTalkId, entity.getSystemTalkId());
}
if(entity.getUserHandlingId() != null){
update = update.set(SystemTalkBindDeviceEntity::getUserHandlingId, entity.getUserHandlingId());
}
if(StringUtils.isNotEmpty(entity.getRemark())){
update = update.set(SystemTalkBindDeviceEntity::getRemark, entity.getRemark());
}
return update.where(SystemTalkBindDeviceEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
public Mono<Integer> updateCoverSystemTalkBindDeviceById(SystemTalkBindDeviceEntity entity){
ReactiveUpdate<SystemTalkBindDeviceEntity> update = createUpdate()
.set(SystemTalkBindDeviceEntity::getModifyTime, new Date());
update = update.set(SystemTalkBindDeviceEntity::getIsDelete, entity.getIsDelete());
update = update.set(SystemTalkBindDeviceEntity::getSystemTalkId, entity.getSystemTalkId());
update = update.set(SystemTalkBindDeviceEntity::getUserHandlingId, entity.getUserHandlingId());
update = update.set(SystemTalkBindDeviceEntity::getRemark, entity.getRemark());
return update.where(SystemTalkBindDeviceEntity::getId, entity.getId()).and("is_delete", 0).execute();
}
public Mono<Integer> deleteSystemTalkBindDeviceById(Long id){
return createUpdate()
.set("is_delete", 1)
.set("modify_time", new Date())
.where("id", id)
.execute();
}
}

View File

@ -70,10 +70,6 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>

View File

@ -63,6 +63,7 @@
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@ -1,12 +1,16 @@
package com.qiuguo.iot.box.websocket.api;
import com.tuya.connector.spring.annotations.ConnectorScan;
import org.hswebframework.web.crud.annotation.EnableEasyormRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@SpringBootApplication(scanBasePackages = {"com.qiuguo.iot.box.websocket.api", "com.qiuguo.iot.data.service", "com.qiuguo.iot.third.service"})
@EnableEasyormRepository(value = "com.qiuguo.iot.data.entity.*")
@ConnectorScan(basePackages = "com.qiuguo.iot.third.service")
@EnableAspectJAutoProxy
public class IotBoxWebsocketApplication {
public static void main(String[] args) {

View File

@ -4,13 +4,17 @@ import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSONObject;
import com.qiuguo.iot.base.annotation.WebSocketMapping;
import com.qiuguo.iot.base.constans.RedisConstans;
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.filter.LogMdcConfiguration;
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.request.device.DeviceInfoRequest;
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
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.third.service.NlpService;
import lombok.extern.slf4j.Slf4j;
@ -24,6 +28,7 @@ import org.springframework.web.reactive.socket.*;
import reactor.core.publisher.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Component
@ -47,6 +52,9 @@ public class BoxWebSocketHandler implements WebSocketHandler {
@Resource
private NlpService nlpService;
@Resource
private DeviceUserBindService deviceUserBindService;
public static ConcurrentHashMap<String, BoxSession> group = new ConcurrentHashMap<>();
@Override
@ -61,9 +69,15 @@ public class BoxWebSocketHandler implements WebSocketHandler {
log.info("设备{},请求数据已超时", sn);
return session.close();
}
String token = headers.get("signature").get(0);
//校验token
checkToken(sn, linkTime, token);
String signature = headers.get("signature").get(0);
String token = null;
List<String> tokens = headers.get("token");
if(tokens != null && tokens.size() > 0){
token = tokens.get(0);//用户token
}
//校验
checkToken(sn, linkTime, signature, token);
//
log.info("登录成功SN:{}", sn);
@ -77,6 +91,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
if(actions.getActions().size() > 0){
SystemTalkAnswerConfigEntity talkAnswerConfigEntity =
systemTalkAnswerConfigService.getSystemTalkWithKey(actions.getActions().get(0).getAction());
log.info("匹配到自定义指令{}", talkAnswerConfigEntity);
}else{
//调用千问回答
@ -111,7 +126,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
}).then();
}
private void checkToken(String sn, Long linkTime, String token){
private void checkToken(String sn, Long linkTime, String signature, String token){
ReactiveValueOperations<String, String> operations = reactiveStringRedisTemplate.opsForValue();
operations.get(RedisConstans.DEVICE_INFO + sn).defaultIfEmpty("").flatMap(s -> {
if(com.qiuguo.iot.base.utils.StringUtils.isNotBlank(s)){
@ -136,7 +151,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
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();
if(!signalMd5.equals(token)){
if(!signalMd5.equals(signature)){
log.info("设备{},验签失败", sn);
//session.send(session.textMessage(""));
BoxSession boxSession = getBoxSessionWithSn(sn);
@ -144,11 +159,39 @@ public class BoxWebSocketHandler implements WebSocketHandler {
boxSession.getSink().next(boxSession.getSession().textMessage("验签失败"));
}
boxSession.getSession().close().subscribe();
}else{
bindBox(dv, token);
}
return Mono.empty();
}).subscribe();
}
private void bindBox(DeviceInfoEntity dv, String token){
if(StringUtils.isNotEmpty(token)){
log.info("开始绑定设备userToken:{} SN{}", token, dv);
Long userId = getUserIdWithToken(token);
DeviceUserBindRequest request = new DeviceUserBindRequest();
request.setUserId(userId);
request.setDeviceId(dv.getId());
deviceUserBindService.selectDeviceUserBindByRequest(request).thenEmpty(other ->{
DeviceUserBindEntity entity = new DeviceUserBindEntity();
entity.setUserId(userId);
entity.setDeviceId(dv.getId());
deviceUserBindService.insertDeviceUserBind(entity).map(l ->{
log.info("绑定成功userToken:{} SN{} userId:{}", token, dv, userId);
return Mono.empty();
}).subscribe();
}).subscribe();
}
}
private Long getUserIdWithToken(String token){
//暂时勰思灯token写过来在写入
return 6025l;
}
public BoxSession getBoxSessionWithSn(String sn) {
return group.get(sn);
}

View File

@ -31,7 +31,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
<version>8.0.29</version>
</dependency>
</dependencies>

View File

@ -37,7 +37,7 @@ public class MysqlMain {
// public static String save_path ="C:\\workspace\\life";
public static String save_path = System.getProperty("user.dir");
public static String mysql_url = "jdbc:mysql://172.24.218.235:3306/qiuguo_iot?useSSL=false&serverZoneId=Asia/Shanghai";
public static String mysql_url = "jdbc:mysql://192.168.8.146:30416/qiuguo_iot?useSSL=false&serverZoneId=Asia/Shanghai";
public static String pre = "";
@ -46,7 +46,7 @@ public class MysqlMain {
public static String mysql_dbname = "qiuguo_iot";
public static String mysql_username = "root";
public static String mysql_password = "!pHuRvGKIsbiqcX1";
public static String mysql_password = "123456";
public static String dto_exclude = ",is_delete,";//生成dto时排除字段前后都要加英文逗号
public static String req_exclude = ",,";//生成Req时排除字段前后都要加英文逗号
@ -82,8 +82,8 @@ public class MysqlMain {
}
List<TablesBean> list = new ArrayList<>();
list.add(new TablesBean("device_info"));
list.add(new TablesBean("user_room"));
list.add(new TablesBean("system_talk_bind_device"));
//list.add(new TablesBean("user_room"));
List<TablesBean> list2 = new ArrayList<TablesBean>();
Map<String, String> map = MysqlUtil2ShowCreateTable.getComments();

View File

@ -79,7 +79,7 @@ public class MysqlUtilTable2Service {
content += "\n";
content += "\n";
content += "\n";
content += TAB + "public Mono<PagerResult<" + realName + "Entity> select" + realName + "sByRequest(" + realName + "Request request){\n";
content += TAB + "public Mono<PagerResult<" + realName + "Entity>> select" + realName + "sByRequest(" + realName + "Request request){\n";
content += TAB + TAB + "ReactiveQuery<" + realName + "Entity> reactiveQuery = createQuery();\n";
content += TAB + TAB + "reactiveQuery = reactiveQuery.and(\"is_delete\", 0);\n";
for (FieldBean tb : list) {

View File

@ -0,0 +1,88 @@
package com.admin.service.impl;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
/**
* <p>
* 自定义命令和设备动作绑定Controller类
* </p>
*
* @author wulin
* @since 2023-09-25
*/
@RestController
@Slf4j
@RequestMapping("/SystemTalkBindDevice")
public class SystemTalkBindDeviceController{
@Autowired
private SystemTalkBindDeviceService systemTalkBindDeviceService;
@PostMapping("/info")
public Mono<SystemTalkBindDeviceResp> selectSystemTalkBindDeviceByRequest(@RequestBody SystemTalkBindDeviceRequest request){
return systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(request).map(d -> {return new SystemTalkBindDeviceResp(d);});
}
@PostMapping("/list")
public Mono<PagerResult<SystemTalkBindDeviceResp>> selectSystemTalkBindDevicesByRequest(@RequestBody SystemTalkBindDeviceRequest request){
return systemTalkBindDeviceService.selectDeviceInfosByRequest(request).map(d -> {
PagerResult<SystemTalkBindDeviceResp> result = new PagerResult<>();
result.setPageIndex(d.getPageIndex());
result.setPageSize(d.getPageSize());
result.setTotal(d.getTotal());
List<SystemTalkBindDeviceResp> ds = d.getData().stream().map(new Function<SystemTalkBindDeviceEntity, SystemTalkBindDeviceResp>() {
@Override
public DeviceInfoResp apply(SystemTalkBindDeviceEntity entity) {
return new SystemTalkBindDeviceResp(entity);
}
}
).collect(Collectors.toList());
result.setData(ds);
return result;
});
}
@GetMapping("/id")
public Mono<SystemTalkBindDeviceResp> selectSystemTalkBindDeviceById(@RequestParam Long id){
return systemTalkBindDeviceService.selectSystemTalkBindDeviceById(id).map(d -> {return new SystemTalkBindDeviceResp(d);});
}
@PostMapping("/save")
public Mono<Integer> insertSystemTalkBindDevice(@RequestBody SystemTalkBindDeviceEntity entity){
return systemTalkBindDeviceService.insertSystemTalkBindDevice(entity);
}
@PostMapping("/update")
public Mono<Integer> updateSystemTalkBindDeviceById(@RequestBody SystemTalkBindDeviceEntity entity){
return systemTalkBindDeviceService.updateSystemTalkBindDeviceById(entity);
}
@PostMapping("/updateCover")
public Mono<Integer> updateCoverSystemTalkBindDeviceById(@RequestBody SystemTalkBindDeviceEntity entity){
return systemTalkBindDeviceService.updateCoverSystemTalkBindDeviceById(entity);
}
@PostMapping("/delete")
public Mono<Integer> deleteSystemTalkBindDeviceById(@RequestParam Long id){
return systemTalkBindDeviceService.deleteSystemTalkBindDeviceById(id);
}
}

View File

@ -98,6 +98,11 @@
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- 涂鸦用到 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
</dependencies>

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