mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-18 17:05:55 +08:00
增加时序数据库TDengine存储设备日志和设备监测数据
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?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.mapper.DatabaseMapper">
|
||||
|
||||
<!-- 创建数据库-->
|
||||
<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="createsTable">
|
||||
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>
|
||||
|
||||
<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>
|
||||
@@ -0,0 +1,139 @@
|
||||
<?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.mapper.TDDeviceLogMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ruoyi.iot.domain.DeviceLog">
|
||||
<id column="ts" property="ts"/>
|
||||
<result column="log_id" property="logId"/>
|
||||
<result column="device_name" property="deviceName"/>
|
||||
<result column="serial_number" property="serialNumber"/>
|
||||
<result column="log_type" property="logType"/>
|
||||
<result column="log_value" property="logValue"/>
|
||||
<result column="identity" property="identity"/>
|
||||
<result column="is_monitor" property="isMonitor"/>
|
||||
<result column="create_by" property="createBy"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.ruoyi.iot.model.MonitorModel" id="MonitorResult">
|
||||
<result property="value" column="log_value" />
|
||||
<result property="time" column="create_time" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.ruoyi.iot.domain.DeviceLog" id="DeviceLogResult">
|
||||
<result property="logId" column="log_id" />
|
||||
<result property="logType" column="log_type" />
|
||||
<result property="logValue" column="log_value" />
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="deviceName" column="device_name" />
|
||||
<result property="serialNumber" column="serial_number" />
|
||||
<result property="identity" column="identity" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="isMonitor" column="is_monitor" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<update id="createDB">
|
||||
create database if not exists ${database};
|
||||
</update>
|
||||
|
||||
<update id="createSTable">
|
||||
|
||||
create STABLE if not exists ${database}.device_log
|
||||
(
|
||||
ts timestamp,
|
||||
log_id BIGINT,
|
||||
log_type TINYINT,
|
||||
`identity` BINARY(100),
|
||||
`log_value` BINARY(100),
|
||||
is_monitor TINYINT,
|
||||
create_by BINARY(100),
|
||||
create_time timestamp,
|
||||
remark BINARY(500)
|
||||
|
||||
)
|
||||
TAGS(
|
||||
device_id BIGINT,
|
||||
device_name BINARY(100),
|
||||
serial_number BINARY(50));
|
||||
</update>
|
||||
|
||||
<update id="createTable">
|
||||
create TABLE if not exists ${database}.${tableName}
|
||||
USING ${database}.device_${deviceId} TAGS(log_type,is_monitor,create_by,create_time,remark)
|
||||
(ts2 timestamp,
|
||||
log_type BINARY(100)
|
||||
);
|
||||
</update>
|
||||
|
||||
<select id="selectSTable" resultMap="BaseResultMap">
|
||||
select
|
||||
*
|
||||
from ${database}.device_log
|
||||
order by ts desc
|
||||
</select>
|
||||
|
||||
<insert id="save" parameterType="com.ruoyi.iot.domain.DeviceLog">
|
||||
INSERT INTO ${database}.device_${device.serialNumber} USING device_log
|
||||
TAGS (#{device.deviceId},#{device.deviceName},#{device.serialNumber})
|
||||
VALUES (now, #{device.logId}, #{device.logType},#{device.identity},#{device.logValue},#{device.isMonitor},#{device.createBy},now,#{device.remark} );
|
||||
</insert>
|
||||
|
||||
<delete id="delete" parameterType="com.ruoyi.iot.domain.DeviceLog">
|
||||
delete from ${database}.device_${device.serialNumber}
|
||||
<where>
|
||||
<if test="logId !=null">
|
||||
log_id = #{logId}
|
||||
</if>
|
||||
<if test="deviceId !=null and deviceId!=''">
|
||||
device_id = #{deviceId}
|
||||
</if>
|
||||
<if test="serialNumber !=null and serialNumber!=''">
|
||||
serial_number = #{serialNumber}
|
||||
</if>
|
||||
</where>
|
||||
</delete>
|
||||
|
||||
<select id="selectLogList" resultMap="BaseResultMap">
|
||||
select * from ${database}.device_log
|
||||
<where>
|
||||
<if test="deviceId != null "> and device_id = #{deviceId}</if>
|
||||
<if test="serialNumber != null and serialNumber!=''"> and serial_number = #{serialNumber}</if>
|
||||
<if test="isMonitor != null "> and is_monitor = #{isMonitor}</if>
|
||||
<if test="logType != null "> and log_type = #{logType}</if>
|
||||
|
||||
<if test="beginDate != null "> and create_time <= #{beginDate}</if>
|
||||
<if test="endDate != null "> and create_time >= #{endDate}</if>
|
||||
|
||||
</where>
|
||||
order by ts desc
|
||||
</select>
|
||||
|
||||
<select id="selectMonitorList" parameterType="com.ruoyi.iot.domain.DeviceLog" resultMap="MonitorResult">
|
||||
select log_value, create_time from ${database}.device_log
|
||||
<where>
|
||||
is_monitor=1
|
||||
<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>
|
||||
|
||||
order by ts desc
|
||||
limit 2000
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceLogList" parameterType="com.ruoyi.iot.domain.DeviceLog" resultMap="DeviceLogResult">
|
||||
select * from ${database}.device_log
|
||||
<where>
|
||||
is_monitor !=1
|
||||
<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.identity != null and device.identity != ''"> and identity like concat('%', #{device.identity}, '%')</if>
|
||||
</where>
|
||||
order by ts desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user