Skip to content

Commit

Permalink
event engine and search tool
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanrongman committed Aug 26, 2024
1 parent d95a9b8 commit f1b0507
Show file tree
Hide file tree
Showing 63 changed files with 2,360 additions and 103 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@
<artifactId>dom4j</artifactId>
<version>2.0.0</version>
</dependency>
<!--网页抓取工具-->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.23.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<!--工具类-->
<dependency>
<groupId>org.nutz</groupId>
Expand Down
45 changes: 41 additions & 4 deletions src/main/java/top/rslly/iot/controllers/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import top.rslly.iot.param.request.Product;
import top.rslly.iot.param.request.ProductData;
import top.rslly.iot.param.request.ProductDevice;
import top.rslly.iot.param.request.ProductModel;
import top.rslly.iot.param.request.*;
import top.rslly.iot.services.*;
import top.rslly.iot.utility.result.JsonResult;
import top.rslly.iot.utility.result.ResultTool;
Expand All @@ -45,6 +42,10 @@ public class Auth {
@Autowired
ProductDataServiceImpl productDataService;
@Autowired
EventDataServiceImpl eventDataService;
@Autowired
ProductEventServiceImpl productEventService;
@Autowired
MqttUserServiceImpl mqttUserService;


Expand Down Expand Up @@ -100,6 +101,24 @@ public JsonResult<?> ProductModel(@RequestParam("id") int id) {
return productModelService.deleteProductModel(id);
}

@Operation(summary = "获取事件", description = "获取物模型的事件")
@RequestMapping(value = "/ProductEvent", method = RequestMethod.GET)
public JsonResult<?> ProductEvent() {
return productEventService.getProductEvent();
}

@Operation(summary = "提交事件", description = "提交物模型的事件")
@RequestMapping(value = "/ProductEvent", method = RequestMethod.POST)
public JsonResult<?> ProductEvent(@RequestBody ProductEvent productEvent) {
return productEventService.postProductEvent(productEvent);
}

@Operation(summary = "删除事件", description = "删除物模型的事件")
@RequestMapping(value = "/ProductEvent", method = RequestMethod.DELETE)
public JsonResult<?> ProductEvent(@RequestParam("id") int id) {
return productEventService.deleteProductEvent(id);
}

@Operation(summary = "获取设备", description = "获取物模型的设备")
@RequestMapping(value = "/ProductDevice", method = RequestMethod.GET)
public JsonResult<?> ProductDevice() {
Expand Down Expand Up @@ -136,6 +155,24 @@ public JsonResult<?> ProductData(@RequestParam("id") int id) {
return productDataService.deleteProductData(id);
}

@Operation(summary = "获取事件入参", description = "获取事件入参")
@RequestMapping(value = "/EventData", method = RequestMethod.GET)
public JsonResult<?> EventData() {
return eventDataService.getEventData();
}

@Operation(summary = "提交事件入参", description = "提交事件入参")
@RequestMapping(value = "/EventData", method = RequestMethod.POST)
public JsonResult<?> EventData(@RequestBody EventData eventData) {
return eventDataService.postEventData(eventData);
}

@Operation(summary = "删除事件入参", description = "删除事件入参")
@RequestMapping(value = "/EventData", method = RequestMethod.DELETE)
public JsonResult<?> EventData(@RequestParam("id") int id) {
return eventDataService.deleteEventData(id);
}



}
19 changes: 15 additions & 4 deletions src/main/java/top/rslly/iot/controllers/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import top.rslly.iot.param.request.MetaData;
import top.rslly.iot.param.request.ReadData;
import top.rslly.iot.services.DataServiceImpl;
import top.rslly.iot.services.EventStorageServiceImpl;
import top.rslly.iot.services.HardWareServiceImpl;
import top.rslly.iot.services.OtaServiceImpl;
import top.rslly.iot.utility.RedisUtil;
Expand All @@ -55,6 +56,8 @@ public class Tool {
@Autowired
private DataServiceImpl dataService;
@Autowired
private EventStorageServiceImpl eventStorageService;
@Autowired
private HardWareServiceImpl hardWareService;
@Autowired
private OtaServiceImpl otaService;
Expand All @@ -77,8 +80,17 @@ public JsonResult<?> control(@RequestBody ControlParam controlParam) throws Mqtt
@Operation(summary = "用于获取物联网一段时间的设备数据", description = "时间参数请使用两个毫秒时间戳")
@RequestMapping(value = "/readData", method = RequestMethod.POST)
public JsonResult<?> readData(@RequestBody ReadData readData) {
return dataService.findAllByTimeBetweenAndDeviceName(readData.getTime1(), readData.getTime2(),
readData.getName());
return dataService.findAllByTimeBetweenAndDeviceNameAndJsonKey(readData.getTime1(),
readData.getTime2(),
readData.getName(), readData.getJsonKey());
}

@Operation(summary = "用于获取物联网一段时间的设备事件数据", description = "时间参数请使用两个毫秒时间戳")
@RequestMapping(value = "/readEvent", method = RequestMethod.POST)
public JsonResult<?> readEvent(@RequestBody ReadData readData) {
return eventStorageService.findAllByTimeBetweenAndDeviceNameAndJsonKey(readData.getTime1(),
readData.getTime2(),
readData.getName(), readData.getJsonKey());
}

@Operation(summary = "获取属性实时数据", description = "高性能接口(带redis缓存)")
Expand All @@ -91,8 +103,7 @@ public JsonResult<?> metaData(@RequestBody MetaData metaData) {
@RequestMapping(value = "/aiControl", method = RequestMethod.POST)
public JsonResult<?> aiControl(@RequestBody AiControl aiControl) {
var answer =
router.response(aiControl.getContent(), aiControl.getChatId(), aiControl.getProductId(),
"1234");
router.response(aiControl.getContent(), aiControl.getChatId(), aiControl.getProductId());
return ResultTool.success(answer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import java.util.List;

public interface TimeDataRepository extends InfluxDBBaseMapper<DataEntity> {
public interface DataTimeRepository extends InfluxDBBaseMapper<DataEntity> {
@Select(value = "SELECT * FROM \"data\" where time >=#{time1}ms and time <=#{time2}ms",
resultType = DataEntity.class)
List<DataEntity> findAllByTimeBetween(@Param("time1") Long time1, @Param("time2") Long time2);
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/top/rslly/iot/dao/EventDataRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import top.rslly.iot.models.EventDataEntity;

import javax.transaction.Transactional;
import java.util.List;

public interface EventDataRepository extends JpaRepository<EventDataEntity, Long> {
List<EventDataEntity> findAllByModelId(int modelId);

List<EventDataEntity> findAllByModelIdAndJsonKey(int modelId, String jsonKey);

@Transactional
List<EventDataEntity> deleteById(int id);
}
47 changes: 47 additions & 0 deletions src/main/java/top/rslly/iot/dao/EventStorageRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.transaction.annotation.Transactional;
import top.rslly.iot.models.EventStorageEntity;

import java.util.List;

public interface EventStorageRepository extends JpaRepository<EventStorageEntity, Long>,
JpaSpecificationExecutor<EventStorageEntity>, QueryByExampleExecutor<EventStorageEntity> {
List<EventStorageEntity> findAllByTimeBetweenAndDeviceIdAndJsonKey(long time, long time2,
int deviceId,
String jsonKey);

List<EventStorageEntity> findAllByTimeBetweenAndDeviceId(long time, long time2, int deviceId);

@Query(
value = "SELECT * FROM event_storage WHERE device_id =?1 And json_key=?2 ORDER BY time DESC LIMIT 1",
nativeQuery = true)
List<EventStorageEntity> findAllBySort(int deviceId, String jsonKey);

@Transactional
List<EventStorageEntity> deleteAllByTimeBeforeAndDeviceIdAndJsonKey(long time, int deviceId,
String jsonKey);
}
53 changes: 53 additions & 0 deletions src/main/java/top/rslly/iot/dao/EventStorageTimeRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.dao;

import top.rslly.iot.models.EventStorageEntity;
import top.rslly.iot.utility.influxdb.InfluxDBBaseMapper;
import top.rslly.iot.utility.influxdb.ano.Delete;
import top.rslly.iot.utility.influxdb.ano.Param;
import top.rslly.iot.utility.influxdb.ano.Select;

import java.util.List;

public interface EventStorageTimeRepository extends InfluxDBBaseMapper<EventStorageEntity> {
@Select(
value = "SELECT * FROM \"event_storage\" where time >=#{time}ms and time <=#{time2}ms and deviceId='#{deviceId}'",
resultType = EventStorageEntity.class)
List<EventStorageEntity> findAllByTimeBetweenAndDeviceId(@Param("time") long time,
@Param("time2") long time2, @Param("deviceId") int deviceId);

@Select(
value = "SELECT * FROM \"event_storage\" where time >=#{time}ms and time <=#{time2}ms and deviceId='#{deviceId}' and jsonKey=#{jsonKey}",
resultType = EventStorageEntity.class)
List<EventStorageEntity> findAllByTimeBetweenAndDeviceIdAndJsonKey(@Param("time") long time,
@Param("time2") long time2, @Param("deviceId") int deviceId,
@Param("jsonKey") String jsonKey);

@Select(
value = "SELECT * FROM \"event_storage\" WHERE deviceId='#{deviceId}' and jsonKey=#{jsonKey} ORDER BY time DESC LIMIT 1",
resultType = EventStorageEntity.class)
List<EventStorageEntity> findAllBySort(int deviceId, String jsonKey);

@Delete(
value = "DELETE FROM \"event_storage\" where time <=#{time}ms and deviceId='#{deviceId}' and jsonKey=#{jsonKey}")
void deleteAllByTimeBeforeAndDeviceIdAndJsonKey(@Param("time") long time,
@Param("deviceId") int deviceId, @Param("jsonKey") String jsonKey);
}
40 changes: 40 additions & 0 deletions src/main/java/top/rslly/iot/dao/ProductEventRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import top.rslly.iot.models.ProductEventEntity;
import top.rslly.iot.models.ProductModelEntity;

import javax.transaction.Transactional;
import java.util.List;

public interface ProductEventRepository extends JpaRepository<ProductEventEntity, Long> {

List<ProductEventEntity> findAllByModelIdAndName(int modelId, String name);

List<ProductEventEntity> findAllByName(String name);


List<ProductEventEntity> findAllById(int id);

@Transactional
List<ProductEventEntity> deleteById(int id);
}
Loading

0 comments on commit f1b0507

Please sign in to comment.