Merge remote-tracking branch 'origin/master' into version1.2

This commit is contained in:
kerwincui
2022-05-25 16:22:39 +08:00
7 changed files with 74 additions and 76 deletions

View File

@@ -24,7 +24,7 @@
- EMQ管理 Mqtt客户端、监听器、消息主题、消息订阅、插件管理、规则引擎、资源 - EMQ管理 Mqtt客户端、监听器、消息主题、消息订阅、插件管理、规则引擎、资源
- 硬件 SDK 支持WIFI和MQTT连接、物模型响应、实时监测、定时上报监测数据、AES加密、NTP时间等 - 硬件 SDK 支持WIFI和MQTT连接、物模型响应、实时监测、定时上报监测数据、AES加密、NTP时间等
- 物模型管理: 属性(设备状态和监测数据),功能(执行特定任务),事件(设备主动上报给云端) - 物模型管理: 属性(设备状态和监测数据),功能(执行特定任务),事件(设备主动上报给云端)
- 其他开发中第三方登录设备分享、设备告警、场景联动进度50%; 智能音箱、多租户、APP界面自定义进度40%; 时序数据库、分布式集群部署、Granfa监控进度30%; 视频流处理、桌面端模拟器/监控、安卓端模拟器/监控进度20% - 其他(部分开发中第三方登录设备分享、设备告警、场景联动进度50%; 智能音箱、多租户、APP界面自定义进度40%; 时序数据库、分布式集群部署、Granfa监控进度30%; 视频流处理、桌面端模拟器/监控、安卓端模拟器/监控进度20%
### 四、技术栈 ### 四、技术栈

View File

@@ -36,6 +36,8 @@ public class TDengineConfig {
@Value("${spring.datasource.druid.tdengine-server.dbName}") @Value("${spring.datasource.druid.tdengine-server.dbName}")
private String dbName; private String dbName;
@Value("${spring.datasource.druid.tdengine-server.url}")
private String jdbc;
@Bean(name = "tDengineDataSource") @Bean(name = "tDengineDataSource")

View File

@@ -1,25 +0,0 @@
package com.ruoyi.iot.tdengine.dao;
import org.springframework.stereotype.Repository;
/**
* @package com.ruoyi.mysql.mysql.tdengine
* 类名: DatabaseMapper
* 描述: TODO
* 时间: 2022/5/16,0016 1:27
* 开发人: wxy
*/
@Repository
public interface DatabaseDAO {
int createDB();
int dropDatabase();
int useDatabase();
int createTable();
}

View File

@@ -1,8 +1,11 @@
package com.ruoyi.iot.tdengine.init; package com.ruoyi.iot.tdengine.init;
import com.alibaba.druid.pool.DruidDataSource;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.iot.tdengine.config.TDengineConfig; import com.ruoyi.iot.tdengine.config.TDengineConfig;
import com.ruoyi.iot.tdengine.dao.TDDeviceLogDAO; import com.ruoyi.iot.tdengine.dao.TDDeviceLogDAO;
import com.taosdata.jdbc.TSDBDriver;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -12,6 +15,13 @@ import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
/** /**
* 类名: ApplicationStarted * 类名: ApplicationStarted
* 描述: TODO * 描述: TODO
@@ -26,13 +36,22 @@ public class ApplicationStarted implements ApplicationRunner {
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
private DruidDataSource dataSource;
private TDengineConfig dengineConfig;
private TDDeviceLogDAO deviceLogMapper;
@Override @Override
public void run(ApplicationArguments args) { public void run(ApplicationArguments args) {
//先获取TDengine的配置检测TDengine是否已经配置 //先获取TDengine的配置检测TDengine是否已经配置
if (containBean(TDengineConfig.class)) { if (containBean(TDengineConfig.class)) {
TDengineConfig tDengineConfig = applicationContext.getBean(TDengineConfig.class); this.dengineConfig = applicationContext.getBean(TDengineConfig.class);
TDDeviceLogDAO tDDeviceLogDAO = applicationContext.getBean(TDDeviceLogDAO.class); this.dataSource = applicationContext.getBean("tDengineDataSource", DruidDataSource.class);
initTDengine(tDengineConfig, tDDeviceLogDAO); this.deviceLogMapper= applicationContext.getBean(TDDeviceLogDAO.class);
initTDengine(this.dengineConfig.getDbName());
LOGGER.info("使用TDengine存储设备数据初始化成功"); LOGGER.info("使用TDengine存储设备数据初始化成功");
}else{ }else{
LOGGER.info("使用MySql存储设备数据初始化成功"); LOGGER.info("使用MySql存储设备数据初始化成功");
@@ -47,12 +66,13 @@ public class ApplicationStarted implements ApplicationRunner {
* @date 2022/5/22,0022 14:27 * @date 2022/5/22,0022 14:27
* @author wxy * @author wxy
*/ */
public void initTDengine(TDengineConfig dengineConfig, TDDeviceLogDAO deviceLogMapper) { public void initTDengine(String dbName) {
try { try {
String dbName = dengineConfig.getDbName(); createDatabase();
// TODO 目前还不支持自动创建数据库 //创建数据库
int db = deviceLogMapper.createDB(dbName);
deviceLogMapper.createSTable(dbName); deviceLogMapper.createSTable(dbName);
System.out.println("完成超级表的创建");
LOGGER.info("完成超级表的创建");
} catch (Exception e) { } catch (Exception e) {
LOGGER.info("错误",e.getMessage()); LOGGER.info("错误",e.getMessage());
e.printStackTrace(); e.printStackTrace();
@@ -60,6 +80,43 @@ public class ApplicationStarted implements ApplicationRunner {
} }
/**
* @Method
* @Description 根据数据库连接自动创建数据库
* @Param null
* @return
* @date 2022/5/24,0024 14:32
* @author wxy
*
*/
private void createDatabase(){
try {
String dbName = dengineConfig.getDbName();
String jdbcUrl = dataSource.getRawJdbcUrl();
String username = dataSource.getUsername();
String password = dataSource.getPassword();
jdbcUrl += ("&user=" + username);
jdbcUrl += ("&password=" + password);
int startIndex = jdbcUrl.indexOf('/',12);
int endIndex = jdbcUrl.indexOf('?');
String newJdbcUrl = jdbcUrl.substring(0,startIndex);
newJdbcUrl= newJdbcUrl+jdbcUrl.substring(endIndex);
System.out.println(newJdbcUrl);
Properties connProps = new Properties();
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
Connection conn = DriverManager.getConnection(newJdbcUrl, connProps);
conn.createStatement().execute(String.format("create database if not exists %s;",dbName));
conn.close();
LOGGER.info("完成数据库创建");
} catch (Exception e) {
LOGGER.info("错误",e.getMessage());
e.printStackTrace();
}
}
/** /**
* @return * @return
* @Method containBean * @Method containBean
@@ -76,4 +133,6 @@ public class ApplicationStarted implements ApplicationRunner {
return true; return true;
} }
} }
} }

View File

@@ -49,6 +49,9 @@ public class TdengineLogServiceImpl implements ILogService {
@Override @Override
public List<MonitorModel> selectMonitorList(DeviceLog deviceLog) { public List<MonitorModel> selectMonitorList(DeviceLog deviceLog) {
if(deviceLog.getIdentity()!=null){
deviceLog.setIdentity("%"+deviceLog.getIdentity()+"%");
}
return tdDeviceLogDAO.selectMonitorList(dbName,deviceLog); return tdDeviceLogDAO.selectMonitorList(dbName,deviceLog);
} }
} }

View File

@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.iot.tdengine.dao.DatabaseDAO">
<!-- 创建数据库-->
<update id="createDB" parameterType="java.lang.String">
create database if not exists ${dbName};
</update>
<!-- 删除数据库-->
<update id="dropDatabase" parameterType="java.lang.String">
DROP database if exists ${dbName};
</update>
<!-- 使用数据库-->
<update id="useDatabase" parameterType="java.lang.String">
use ${dbName};
</update>
<update id="createTable">
create stable if not exists ${tableName}
(ts timestamp,
log_id BIGINT,
identity NCHAR(100),
log_type NCHAR(20),
log_value NCHAR(100),
device_id BIGINT,
device_name NCHAR(100),
serial_number NCHAR(100),
is_monitor int,
create_by NCHAR(100),
create_time timestamp,
remark NCHAR(1000),
);
</update>
</mapper>

View File

@@ -42,7 +42,6 @@
</update> </update>
<update id="createSTable"> <update id="createSTable">
create STABLE if not exists ${database}.device_log create STABLE if not exists ${database}.device_log
( (
ts timestamp, ts timestamp,
@@ -118,7 +117,7 @@
<where> <where>
is_monitor=1 is_monitor=1
<if test="device.deviceId!=null"> and device_id = #{device.deviceId} </if> <if test="device.deviceId!=null"> and device_id = #{device.deviceId} </if>
<if test="device.identity != null and device.identity != ''"> and identity like concat('%', #{device.identity}, '%')</if> <if test="device.identity != null and device.identity != ''"> and identity like #{device.identity}</if>
order by ts desc order by ts desc
limit 2000 limit 2000
@@ -131,7 +130,7 @@
is_monitor !=1 is_monitor !=1
<if test="device.deviceId!=null"> and device_id = #{device.deviceId} </if> <if test="device.deviceId!=null"> and device_id = #{device.deviceId} </if>
<if test="device.logType != null "> and log_type = #{device.logType}</if> <if test="device.logType != null "> and log_type = #{device.logType}</if>
<if test="device.identity != null and device.identity != ''"> and identity like concat('%', #{device.identity}, '%')</if> <if test="device.identity != null and device.identity != ''"> and identity like #{device.identity}</if>
</where> </where>
order by ts desc order by ts desc
</select> </select>