Files
fastbee/springboot/wumei-iot/src/main/resources/mapper/tdengine/TDDeviceLogMapper.xml

139 lines
5.5 KiB
XML

<?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 &lt;= #{beginDate}</if>
<if test="endDate != null "> and create_time &gt;= #{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>