mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-20 01:45:55 +08:00
feat(时序数据库集成): tdengine\influxdb\iotdb数据库集成
This commit is contained in:
@@ -16,7 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="deviceName" column="device_name" />
|
||||
<result property="serialNumber" column="serial_number" />
|
||||
<result property="identity" column="identify" />
|
||||
<result property="identify" column="identify" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="isMonitor" column="is_monitor" />
|
||||
<result property="mode" column="mode" />
|
||||
@@ -31,7 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<resultMap type="com.fastbee.iot.model.HistoryModel" id="HistoryResult">
|
||||
<result property="value" column="log_value" />
|
||||
<result property="time" column="create_time" />
|
||||
<result property="identity" column="identify" />
|
||||
<result property="identify" column="identify" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDeviceLogVo">
|
||||
@@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select log_value, create_time from iot_device_log
|
||||
<where>
|
||||
<if test="1==1"> and is_monitor=1</if>
|
||||
<if test="identity != null and identity != ''"> and identify = #{identity}</if>
|
||||
<if test="identify != null and identify != ''"> and identify = #{identify}</if>
|
||||
<if test="deviceId != null and deviceId !=0"> and device_id = #{deviceId}</if>
|
||||
<if test="serialNumber != null and serialNumber !=''"> and serial_number = #{serialNumber}</if>
|
||||
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''"> and create_time between #{beginTime} and #{endTime}</if>
|
||||
@@ -94,6 +94,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
</select>
|
||||
|
||||
<insert id="insertDeviceLog" parameterType="com.fastbee.iot.domain.DeviceLog" useGeneratedKeys="true" keyProperty="logId">
|
||||
insert into iot_device_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="logType != null">log_type,</if>
|
||||
<if test="logValue != null">log_value,</if>
|
||||
<if test="deviceId != null">device_id,</if>
|
||||
<if test="deviceName != null and deviceName != ''">device_name,</if>
|
||||
<if test="serialNumber != null and serialNumber != ''">serial_number,</if>
|
||||
<if test="identify != null">identify,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="isMonitor != null">is_monitor,</if>
|
||||
<if test="mode != null">mode,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="userName != null and userName != ''">user_name,</if>
|
||||
<if test="tenantId != null">tenant_id,</if>
|
||||
<if test="tenantName != null and tenantName != ''">tenant_name,</if>
|
||||
<if test="modelName != null and modelName != ''">model_name,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="logType != null">#{logType},</if>
|
||||
<if test="logValue != null">#{logValue},</if>
|
||||
<if test="deviceId != null">#{deviceId},</if>
|
||||
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
|
||||
<if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
|
||||
<if test="identify != null">#{identify},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="isMonitor != null">#{isMonitor},</if>
|
||||
<if test="mode != null">#{mode},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="userName != null and userName != ''">#{userName},</if>
|
||||
<if test="tenantId != null">#{tenantId},</if>
|
||||
<if test="tenantName != null and tenantName != ''">#{tenantName},</if>
|
||||
<if test="modelName != null and modelName != ''">#{modelName},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="saveBatch" parameterType="com.fastbee.iot.domain.DeviceLog">
|
||||
insert into iot_device_log (log_type,log_value,device_id,device_name,serial_number,identify,create_by,
|
||||
@@ -101,7 +140,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.logType},#{item.logValue},#{item.deviceId},#{item.deviceName},#{item.serialNumber},
|
||||
#{item.identity},#{item.createBy},#{item.isMonitor},#{item.mode},#{item.createTime},#{item.remark},
|
||||
#{item.identify},#{item.createBy},#{item.isMonitor},#{item.mode},#{item.createTime},#{item.remark},
|
||||
#{item.userId},#{item.userName},#{item.tenantId},#{item.tenantName},#{item.modelName})
|
||||
</foreach>
|
||||
</insert>
|
||||
@@ -114,7 +153,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="deviceId != null">device_id = #{deviceId},</if>
|
||||
<if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
|
||||
<if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
|
||||
<if test="identity != null">identify = #{identity},</if>
|
||||
<if test="identify != null">identify = #{identify},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="isMonitor != null">is_monitor = #{isMonitor},</if>
|
||||
<if test="mode != null">mode = #{mode},</if>
|
||||
@@ -150,7 +189,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="deviceId != null and deviceId !=0"> and device_id = #{deviceId}</if>
|
||||
<if test="serialNumber != null and serialNumber !=''"> and serial_number = #{serialNumber}</if>
|
||||
<if test="logType != null "> and log_type = #{logType}</if>
|
||||
<if test="identity != null and identity != ''"> and identity like concat('%', #{identity}, '%')</if>
|
||||
<if test="identify != null and identify != ''"> and identify like concat('%', #{identify}, '%')</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
@@ -6,7 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<resultMap type="com.fastbee.iot.domain.EventLog" id="EventLogResult">
|
||||
<result property="logId" column="log_id" />
|
||||
<result property="identity" column="identify" />
|
||||
<result property="identify" column="identify" />
|
||||
<result property="modelName" column="model_name" />
|
||||
<result property="logType" column="log_type" />
|
||||
<result property="logValue" column="log_value" />
|
||||
@@ -31,7 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<select id="selectEventLogList" parameterType="com.fastbee.iot.domain.EventLog" resultMap="EventLogResult">
|
||||
<include refid="selectEventLogVo"/>
|
||||
<where>
|
||||
<if test="identity != null and identity != ''"> and identify = #{identity}</if>
|
||||
<if test="identify != null and identify != ''"> and identify = #{identify}</if>
|
||||
<if test="modelName != null and modelName != ''"> and model_name like concat('%', #{modelName}, '%')</if>
|
||||
<if test="logType != null "> and log_type = #{logType}</if>
|
||||
<if test="logValue != null and logValue != ''"> and log_value = #{logValue}</if>
|
||||
@@ -62,7 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<insert id="insertEventLog" parameterType="com.fastbee.iot.domain.EventLog" useGeneratedKeys="true" keyProperty="logId">
|
||||
insert into iot_event_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="identity != null and identity != ''">identify,</if>
|
||||
<if test="identify != null and identify != ''">identify,</if>
|
||||
<if test="modelName != null">model_name,</if>
|
||||
<if test="logType != null">log_type,</if>
|
||||
<if test="logValue != null and logValue != ''">log_value,</if>
|
||||
@@ -80,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="remark != null">remark,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="identity != null and identity != ''">#{identity},</if>
|
||||
<if test="identify != null and identify != ''">#{identify},</if>
|
||||
<if test="modelName != null">#{modelName},</if>
|
||||
<if test="logType != null">#{logType},</if>
|
||||
<if test="logValue != null and logValue != ''">#{logValue},</if>
|
||||
@@ -104,7 +104,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
user_name,tenant_id,tenant_name,create_by,create_time,remark)
|
||||
values
|
||||
<foreach collection="list" separator="," index="index" item="item">
|
||||
(#{item.identity},#{item.modelName},#{item.logType},#{item.logValue},#{item.deviceId},#{item.deviceName},#{item.serialNumber},#{item.isMonitor},
|
||||
(#{item.identify},#{item.modelName},#{item.logType},#{item.logValue},#{item.deviceId},#{item.deviceName},#{item.serialNumber},#{item.isMonitor},
|
||||
#{item.mode},#{item.userId},#{item.userName},#{item.tenantId},#{item.tenantName},#{item.createBy},#{item.createTime},#{item.remark})
|
||||
</foreach>
|
||||
</insert>
|
||||
@@ -112,7 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<update id="updateEventLog" parameterType="com.fastbee.iot.domain.EventLog">
|
||||
update iot_event_log
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="identity != null and identity != ''">identify = #{identity},</if>
|
||||
<if test="identify != null and identify != ''">identify = #{identify},</if>
|
||||
<if test="modelName != null">model_name = #{modelName},</if>
|
||||
<if test="logType != null">log_type = #{logType},</if>
|
||||
<if test="logValue != null and logValue != ''">log_value = #{logValue},</if>
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<?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.fastbee.iot.mapper.IotDbLogMapper">
|
||||
<resultMap type="com.fastbee.iot.model.MonitorModel" id="MonitorResult">
|
||||
<result property="value" column="root.ln.device_log.log_value" />
|
||||
<result property="time" column="Time" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.fastbee.iot.domain.DeviceLog" id="DeviceLogResult">
|
||||
<result property="createTime" column="Time" />
|
||||
<result property="logType" column="root.ln.device_log.log_type" />
|
||||
<result property="logValue" column="root.ln.device_log.log_value" />
|
||||
<result property="deviceId" column="root.ln.device_log.device_id" />
|
||||
<result property="deviceName" column="root.ln.device_log.device_name" />
|
||||
<result property="serialNumber" column="root.ln.device_log.serial_number" />
|
||||
<result property="identify" column="root.ln.device_log.identify" />
|
||||
<result property="createBy" column="root.ln.device_log.create_by" />
|
||||
<result property="isMonitor" column="root.ln.device_log.is_monitor" />
|
||||
<result property="mode" column="root.ln.device_log.mode" />
|
||||
<result property="remark" column="root.ln.device_log.remark" />
|
||||
<result property="tenantId" column="root.ln.device_log.tenant_id" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.fastbee.iot.model.HistoryModel" id="HistoryResult">
|
||||
<result property="time" column="Time" />
|
||||
<result property="value" column="root.ln.device_log.log_value" />
|
||||
<result property="identify" column="root.ln.device_log.identify" />
|
||||
</resultMap>
|
||||
|
||||
<!-- <resultMap type="com.fastbee.iot.model.HistoryBo" id="HistoryResultBo">-->
|
||||
<!-- <result property="value" column="root.ln.device_log.log_value" />-->
|
||||
<!-- <result property="time" column="Time" />-->
|
||||
<!-- <result property="identify" column="root.ln.device_log.identify" />-->
|
||||
<!-- </resultMap>-->
|
||||
|
||||
<!-- <resultMap type="com.fastbee.iot.model.vo.ThingsModelLogCountVO" id="ThingsModelLogCountVO">-->
|
||||
<!-- <result property="identifier" column="root.ln.device_log.identify" />-->
|
||||
<!-- </resultMap>-->
|
||||
|
||||
<update id="createDB">
|
||||
create database ${database}
|
||||
</update>
|
||||
|
||||
<select id="countDB" resultType="Long">
|
||||
count databases ${database}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="save" parameterType="com.fastbee.iot.domain.DeviceLog" useGeneratedKeys="false">
|
||||
INSERT INTO root.ln.device_log (
|
||||
<trim suffixOverrides=",">
|
||||
<if test="logType != null">log_type</if>
|
||||
<if test="logValue != null">, log_value</if>
|
||||
<if test="deviceId != null">, device_id</if>
|
||||
<if test="deviceName != null and deviceName != ''">, device_name</if>
|
||||
<if test="serialNumber != null and serialNumber != ''">,serial_number</if>
|
||||
<if test="identify != null">, identify</if>
|
||||
<if test="createBy != null">, create_by</if>
|
||||
<if test="isMonitor != null">, is_monitor</if>
|
||||
<if test="mode != null">, mode</if>
|
||||
<if test="remark != null">, remark</if>
|
||||
<if test="tenantId != null">, tenant_id</if>
|
||||
</trim>
|
||||
) VALUES (
|
||||
<trim suffixOverrides=",">
|
||||
<if test="logType != null">#{logType}</if>
|
||||
<if test="logValue != null">, #{logValue}</if>
|
||||
<if test="deviceId != null">, #{deviceId}</if>
|
||||
<if test="deviceName != null and deviceName != ''">, #{deviceName}</if>
|
||||
<if test="serialNumber != null and serialNumber != ''">,#{serialNumber}</if>
|
||||
<if test="identify != null">, #{identify}</if>
|
||||
<if test="createBy != null">, #{createBy}</if>
|
||||
<if test="isMonitor != null">, #{isMonitor}</if>
|
||||
<if test="mode != null">, #{mode}</if>
|
||||
<if test="remark != null">, #{remark}</if>
|
||||
<if test="tenantId != null">, #{tenantId}</if>
|
||||
</trim>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteDeviceLogByDeviceNumber" parameterType="String">
|
||||
DELETE FROM root.ln.device_log.**
|
||||
</delete>
|
||||
|
||||
<select id="selectPropertyLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
SELECT COUNT(mode)
|
||||
FROM root.ln.device_log
|
||||
WHERE log_type = 1
|
||||
<if test="device.tenantId != null">AND tenant_id = #{device.tenantId}</if>
|
||||
<if test="device.createBy != null and device.createBy != ''"> AND create_by = #{device.createBy}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectFunctionLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
select count(mode)
|
||||
from root.ln.device_log
|
||||
where log_type=2
|
||||
<if test="device.tenantId != null"> and tenant_id = #{device.tenantId}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectEventLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
select count(mode)
|
||||
from root.ln.device_log
|
||||
where log_type=3
|
||||
<if test="device.tenantId != null"> and tenant_id = #{device.tenantId}</if>
|
||||
<if test="device.createBy != null and device.createBy != ''"> AND create_by = #{device.createBy}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectMonitorLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
select count(mode)
|
||||
from root.ln.device_log
|
||||
where log_type=1 and is_monitor=1
|
||||
<if test="device.tenantId != null"> and tenant_id = #{device.tenantId}</if>
|
||||
<if test="device.createBy != null and device.createBy != ''"> AND create_by = #{device.createBy}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectMonitorList" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="MonitorResult">
|
||||
SELECT log_value FROM root.ln.device_log
|
||||
<where>
|
||||
is_monitor = 1
|
||||
<if test="device.serialNumber != null and device.serialNumber != ''">
|
||||
AND serial_number = '${device.serialNumber}'
|
||||
</if>
|
||||
<if test="device.identify != null and device.identify != ''">
|
||||
AND identify LIKE '${device.identify}'
|
||||
</if>
|
||||
<if test="device.beginTime != null and device.endTime != null">
|
||||
AND time <![CDATA[ >= ]]> ${device.beginTime} and time <![CDATA[ <= ]]> ${device.endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY time DESC
|
||||
LIMIT #{device.total}
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceLogList" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="DeviceLogResult">
|
||||
SELECT log_type, log_value, device_id, device_name, identify, create_by, is_monitor, mode, tenant_id, remark, model_name
|
||||
FROM root.ln.device_log
|
||||
<where>
|
||||
<if test="device.serialNumber != null and device.serialNumber != ''">
|
||||
and serial_number = #{device.serialNumber}
|
||||
</if>
|
||||
<if test="device.isMonitor != null">
|
||||
AND is_monitor = #{device.isMonitor}
|
||||
</if>
|
||||
<if test="device.logType != null">
|
||||
AND log_type = #{device.logType}
|
||||
</if>
|
||||
<if test="device.logType == null">
|
||||
AND log_type != 7
|
||||
</if>
|
||||
<if test="device.identify != null and device.identify != ''">
|
||||
AND identify LIKE '${device.identify}'
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY time DESC limit #{page.pageSize} offset #{page.pageNum}
|
||||
</select>
|
||||
|
||||
<select id="selectEventLogList" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="DeviceLogResult">
|
||||
SELECT log_type, log_value, device_id, device_name, serial_number, identify, create_by, is_monitor, mode, remark, tenant_id FROM root.ln.device_log
|
||||
<where>
|
||||
<if test="device.serialNumber != null and device.serialNumber != ''">
|
||||
and serial_number = '${device.serialNumber}'
|
||||
</if>
|
||||
<if test="device.isMonitor != null"> and is_monitor = #{device.isMonitor}</if>
|
||||
<if test="device.logType != null "> and log_type = #{device.logType}</if>
|
||||
<if test="device.logType == null "> and log_type != 1
|
||||
and log_type != 2
|
||||
and log_type != 4
|
||||
and log_type != 7
|
||||
</if>
|
||||
<if test="device.identify != null and device.identify != ''"> and identify like '${device.identify}' </if>
|
||||
<if test="device.beginTime != null and device.beginTime != '' and device.endTime != null and device.endTime != ''">
|
||||
and time <![CDATA[ >= ]]> ${device.beginTime} and time <![CDATA[ <= ]]> ${device.endTime}
|
||||
</if>
|
||||
</where>
|
||||
order by time desc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,176 @@
|
||||
<?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.fastbee.iot.mapper.TDDeviceLogMapper">
|
||||
|
||||
<resultMap type="com.fastbee.iot.model.MonitorModel" id="MonitorResult">
|
||||
<result property="value" column="log_value" />
|
||||
<result property="time" column="ts" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.fastbee.iot.domain.DeviceLog" id="DeviceLogResult">
|
||||
<result property="logType" column="log_type" />
|
||||
<result property="logValue" column="log_value" />
|
||||
<result property="mode" column="mode" />
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="deviceName" column="device_name" />
|
||||
<result property="serialNumber" column="serial_number" />
|
||||
<result property="identify" column="identify" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="isMonitor" column="is_monitor" />
|
||||
<result property="createTime" column="ts" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="userName" column="user_name" />
|
||||
<result property="tenantId" column="tenant_id" />
|
||||
<result property="tenantName" column="tenant_name" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<!-- <resultMap type="com.fastbee.iot.model.HistoryModel" id="HistoryResult">-->
|
||||
<!-- <result property="time" column="ts" />-->
|
||||
<!-- <result property="value" column="log_value" />-->
|
||||
<!-- <result property="identify" column="identify" />-->
|
||||
<!-- <result property="moderName" column="mode" />-->
|
||||
<!-- </resultMap>-->
|
||||
|
||||
<!-- <resultMap type="com.fastbee.iot.model.HistoryBo" id="HistoryResultBo">-->
|
||||
<!-- <result property="value" column="log_value" />-->
|
||||
<!-- <result property="time" column="ts" />-->
|
||||
<!-- <result property="identify" column="identify" />-->
|
||||
<!-- </resultMap>-->
|
||||
|
||||
<update id="createDB">
|
||||
create database if not exists ${database} vgroups 4;
|
||||
</update>
|
||||
|
||||
<update id="createSTable">
|
||||
create STABLE if not exists ${database}.device_log
|
||||
(ts timestamp,
|
||||
log_value BINARY(100),
|
||||
is_monitor TINYINT,
|
||||
log_type TINYINT,
|
||||
identify BINARY(100),
|
||||
mode TINYINT,
|
||||
remark BINARY(500),
|
||||
tenant_id BIGINT,
|
||||
create_by BINARY(50))
|
||||
TAGS(serial_number BINARY(50));
|
||||
</update>
|
||||
|
||||
<insert id="save" parameterType="com.fastbee.iot.domain.DeviceLog" useGeneratedKeys="false">
|
||||
insert into ${database}.device_${device.serialNumber} using device_log
|
||||
tags (#{device.serialNumber})
|
||||
values (
|
||||
<if test="device.ts != null">
|
||||
#{device.ts},
|
||||
</if>
|
||||
<if test="device.ts == null">
|
||||
now,
|
||||
</if>
|
||||
#{device.logValue},
|
||||
#{device.isMonitor},
|
||||
#{device.logType},
|
||||
#{device.identify},
|
||||
#{device.mode},
|
||||
#{device.remark},
|
||||
#{device.tenantId},
|
||||
#{device.createBy});
|
||||
</insert>
|
||||
|
||||
<insert id="saveBatch" parameterType="com.fastbee.iot.tsdb.model.TdLogDto" useGeneratedKeys="false">
|
||||
insert into ${database}.device_${data.serialNumber} using device_log
|
||||
tags (#{data.serialNumber})
|
||||
values
|
||||
<foreach collection="data.list" separator=" " item="device" index="index">
|
||||
(now,
|
||||
#{device.logValue},
|
||||
#{device.isMonitor},
|
||||
#{device.logType},
|
||||
#{device.identify},
|
||||
#{device.mode},
|
||||
#{device.remark},
|
||||
#{device.tenantId},
|
||||
#{device.createBy})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteDeviceLogByDeviceNumber" parameterType="com.fastbee.iot.domain.DeviceLog">
|
||||
DROP TABLE IF EXISTS ${database}.device_${serialNumber};
|
||||
</delete>
|
||||
|
||||
<select id="selectPropertyLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
select count(mode) as propertyCount
|
||||
from ${database}.device_log
|
||||
where log_type=1
|
||||
<if test="device.tenantId != null"> and tenant_id = #{device.tenantId}</if>
|
||||
<if test="device.createBy != null and device.createBy != ''"> AND create_by = #{device.createBy}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectFunctionLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
select count(mode) as functionCount
|
||||
from ${database}.device_log
|
||||
where log_type=2
|
||||
<if test="device.tenantId != null"> and tenant_id = #{device.tenantId}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectEventLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
select count(mode) as eventCount
|
||||
from ${database}.device_log
|
||||
where log_type=3
|
||||
<if test="device.tenantId != null"> and tenant_id = #{device.tenantId}</if>
|
||||
<if test="device.createBy != null and device.createBy != ''"> AND create_by = #{device.createBy}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectMonitorLogCount" parameterType="com.fastbee.iot.domain.Device" resultType="Long">
|
||||
select count(mode) as monitorCount
|
||||
from ${database}.device_log
|
||||
where log_type=1 and is_monitor=1
|
||||
<if test="device.tenantId != null"> and tenant_id = #{device.tenantId}</if>
|
||||
<if test="device.createBy != null and device.createBy != ''"> AND create_by = #{device.createBy}</if>
|
||||
</select>
|
||||
|
||||
<select id="selectMonitorList" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="MonitorResult">
|
||||
select log_value, ts from ${database}.device_log
|
||||
<where>
|
||||
is_monitor=1
|
||||
<if test="device.serialNumber != null and device.serialNumber !=''"> and serial_number = #{device.serialNumber}</if>
|
||||
<if test="device.identify != null and device.identify != ''"> and identify like #{device.identify}</if>
|
||||
<if test="device.beginTime != null and device.beginTime != '' and device.endTime != null and device.endTime != ''"> and ts between #{device.beginTime} and #{device.endTime}</if>
|
||||
order by ts desc
|
||||
limit #{device.total}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDeviceLogList" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="DeviceLogResult">
|
||||
select * from ${database}.device_log
|
||||
<where>
|
||||
<if test="device.isMonitor != null"> and is_monitor = #{device.isMonitor}</if>
|
||||
<if test="device.serialNumber != null and device.serialNumber !=''"> and serial_number = #{device.serialNumber}</if>
|
||||
<if test="device.logType != null "> and log_type = #{device.logType}</if>
|
||||
<if test="device.logType == null "> and log_type != 7</if>
|
||||
<if test="device.identify != null and device.identify != ''"> and identify like #{device.identify}</if>
|
||||
</where>
|
||||
order by ts desc
|
||||
</select>
|
||||
|
||||
<select id="selectEventLogList" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="DeviceLogResult">
|
||||
select * from ${database}.device_log
|
||||
<where>
|
||||
|
||||
<if test="device.isMonitor != null"> and is_monitor = #{device.isMonitor}</if>
|
||||
<if test="device.logType != null "> and log_type = #{device.logType}</if>
|
||||
<if test="device.logType == null "> and log_type != 1
|
||||
and log_type != 2
|
||||
and log_type != 4
|
||||
and log_type != 7 </if>
|
||||
<if test="device.serialNumber != null and device.serialNumber !=''"> and serial_number = #{device.serialNumber}</if>
|
||||
<if test="device.identify != null and device.identify != ''"> and identify like #{device.identify}</if>
|
||||
<if test="device.beginTime != null and device.beginTime != '' and device.endTime != null and device.endTime != ''">
|
||||
and ts between #{device.beginTime} and #{device.endTime}
|
||||
</if>
|
||||
</where>
|
||||
order by ts desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user