<?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.mapper.TDeviceRecordMapper">
    <!--  TDeviceRecordVO getStandardByDeviceId(Long deviceId); -->
    <select id="getStandardByDeviceId" resultMap="StandardResultMap">
        SELECT
            <include refid="StandardQueryFields"/>
        FROM
        t_device_record t
        WHERE
        device_id=#{deviceId}
        ORDER BY t.create_time DESC
        limit 1
    </select>

    <sql id="StandardQueryFields">
            JSON_EXTRACT(detail, '$.real_data.dianya') AS dianya,
            JSON_EXTRACT(detail, '$.real_data.dianliu') AS dianliu,
            JSON_EXTRACT(detail, '$.real_data.deviceT') AS deviceT,
            JSON_EXTRACT(detail, '$.real_data.xianT') AS xianT
    </sql>

    <resultMap id="StandardResultMap" type="com.ruoyi.iot.domain.vo.TDeviceRecordVO">
        <result column="dianya" property="dianya" />
        <result column="dianliu" property="dianliu" />
        <result column="deviceT" property="deviceT" />
        <result column="xianT" property="xianT" />
    </resultMap>

</mapper>