<?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.TDDeviceLogDAO">
|
|
<resultMap type="com.ruoyi.iot.model.MonitorModel" id="MonitorResult">
|
<result property="value" column="log_value" />
|
<result property="time" column="ts" />
|
</resultMap>
|
|
<resultMap type="com.ruoyi.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="identity" column="identity" />
|
<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>
|
|
<update id="createDB">
|
create database if not exists ${database};
|
</update>
|
|
<update id="createSTable">
|
create STABLE if not exists ${database}.device_log
|
(ts timestamp,
|
`log_value` BINARY(100),
|
is_monitor TINYINT,
|
log_type TINYINT,
|
`identity` BINARY(100),
|
mode TINYINT,
|
remark BINARY(500))
|
|
TAGS(
|
device_id BIGINT,
|
serial_number BINARY(50),
|
user_id BIGINT,
|
tenant_Id BIGINT,
|
user_name BINARY(100),
|
tenant_name BINARY(100),
|
device_name BINARY(100));
|
</update>
|
|
<insert id="save" parameterType="com.ruoyi.iot.domain.DeviceLog">
|
INSERT INTO ${database}.device_${device.serialNumber} USING device_log
|
TAGS (#{device.deviceId},
|
#{device.serialNumber},
|
#{device.userId},
|
#{device.tenantId},
|
#{device.userName},
|
#{device.tenantName},
|
#{device.deviceName})
|
VALUES (now,
|
#{device.logValue},
|
#{device.isMonitor},
|
#{device.logType},
|
#{device.identity},
|
#{device.mode},
|
#{device.remark});
|
</insert>
|
|
<delete id="deleteDeviceLogByDeviceNumber" parameterType="com.ruoyi.iot.domain.DeviceLog">
|
DROP TABLE IF EXISTS ${database}.device_${serialNumber};
|
</delete>
|
|
<select id="selectPropertyLogCount" parameterType="com.ruoyi.iot.domain.Device" resultType="Long">
|
select count(mode) as propertyCount
|
from ${database}.device_log
|
<where>
|
<if test="1==1"> and log_type=1</if>
|
<if test="device.userId != null and device.userId != 0"> and user_id = #{device.userId}</if>
|
<if test="device.tenantId != null and device.tenantId != 0"> and tenant_id = #{device.tenantId}</if>
|
</where>
|
</select>
|
|
<select id="selectFunctionLogCount" parameterType="com.ruoyi.iot.domain.Device" resultType="Long">
|
select count(mode) as functionCount
|
from ${database}.device_log
|
<where>
|
<if test="1==1"> and log_type=2</if>
|
<if test="device.userId != null and device.userId != 0"> and user_id = #{device.userId}</if>
|
<if test="device.tenantId != null and device.tenantId != 0"> and tenant_id = #{device.tenantId}</if>
|
</where>
|
</select>
|
|
<select id="selectEventLogCount" parameterType="com.ruoyi.iot.domain.Device" resultType="Long">
|
select count(mode) as eventCount
|
from ${database}.device_log
|
<where>
|
<if test="1==1"> and log_type=3</if>
|
<if test="device.userId != null and device.userId != 0"> and user_id = #{device.userId}</if>
|
<if test="device.tenantId != null and device.tenantId != 0"> and tenant_id = #{device.tenantId}</if>
|
</where>
|
</select>
|
|
<select id="selectMonitorLogCount" parameterType="com.ruoyi.iot.domain.Device" resultType="Long">
|
select count(mode) as monitorCount
|
from ${database}.device_log
|
<where>
|
<if test="1==1"> and log_type=1 and is_monitor=1</if>
|
<if test="device.userId != null and device.userId != 0"> and user_id = #{device.userId}</if>
|
<if test="device.tenantId != null and device.tenantId != 0"> and tenant_id = #{device.tenantId}</if>
|
</where>
|
</select>
|
|
<select id="selectMonitorList" parameterType="com.ruoyi.iot.domain.DeviceLog" resultMap="MonitorResult">
|
select log_value, ts 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 #{device.identity}</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.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 #{device.identity}</if>
|
</where>
|
order by ts desc
|
</select>
|
|
</mapper>
|