<?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.psdc.mapper.PsdcThermometerHtdataMapper">
    <resultMap type="com.psdc.entity.PsdcThermometerHtdata" id="PsdcThermometerHtdataMap">
        <result property="thermometerHtdataId" column="thermometer_htdata_id" />
        <result property="deviceId" column="device_id" />
        <result property="thermometerValue" column="thermometer_value" />
        <result property="thermometerValueIn" column="thermometer_value_in" />
        <result property="thermometerValueOut" column="thermometer_value_out" />
        <result property="updateTime" column="update_time" />
    </resultMap>

    <!-- 通过ID查询单条数据 -->
    <select id="queryById" resultMap="PsdcThermometerHtdataMap">
        select
            thermometer_htdata_id,device_id,thermometer_value,thermometer_value_in,thermometer_value_out,update_time
        from psdc_thermometer_htdata
        where thermometer_htdata_id = #{thermometerHtdataId}
    </select>

    <!--分页查询指定行数据-->
    <select id="queryAllByLimit" resultMap="PsdcThermometerHtdataMap">
        select
        thermometer_htdata_id,device_id,thermometer_value,thermometer_value_in,thermometer_value_out,update_time
        from psdc_thermometer_htdata
        <where>
            <if test="thermometerHtdataId != null and thermometerHtdataId != ''">
                and thermometer_htdata_id = #{thermometerHtdataId}
            </if>
            <if test="deviceId != null and deviceId != ''">
                and device_id = #{deviceId}
            </if>
            <if test="thermometerValue != null and thermometerValue != ''">
                and thermometer_value = #{thermometerValue}
            </if>
            <if test="thermometerValueIn != null and thermometerValueIn != ''">
                and thermometer_value_in = #{thermometerValueIn}
            </if>
            <if test="thermometerValueOut != null and thermometerValueOut != ''">
                and thermometer_value_out = #{thermometerValueOut}
            </if>
            <if test="updateTime != null and updateTime != ''">
                and update_time = #{updateTime}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from psdc_thermometer_htdata
        <where>
            <if test="thermometerHtdataId != null and thermometerHtdataId != ''">
                and thermometer_htdata_id = #{thermometerHtdataId}
            </if>
            <if test="deviceId != null and deviceId != ''">
                and device_id = #{deviceId}
            </if>
            <if test="thermometerValue != null and thermometerValue != ''">
                and thermometer_value = #{thermometerValue}
            </if>
            <if test="thermometerValueIn != null and thermometerValueIn != ''">
                and thermometer_value_in = #{thermometerValueIn}
            </if>
            <if test="thermometerValueOut != null and thermometerValueOut != ''">
                and thermometer_value_out = #{thermometerValueOut}
            </if>
            <if test="updateTime != null and updateTime != ''">
                and update_time = #{updateTime}
            </if>
        </where>
    </select>

    <!--新增数据-->
    <insert id="insert" >
        insert into psdc_thermometer_htdata(thermometer_htdata_id,device_id,thermometer_value,thermometer_value_in,thermometer_value_out,update_time)
        values (#{thermometerHtdataId},#{deviceId},#{thermometerValue},#{thermometerValueIn},#{thermometerValueOut},#{updateTime})
    </insert>

    <!-- 更新数据 -->
    <update id="update">
        update psdc_thermometer_htdata
        <set>
            <if test="thermometerHtdataId != null and thermometerHtdataId != ''">
                thermometer_htdata_id = #{thermometerHtdataId},
            </if>
            <if test="deviceId != null and deviceId != ''">
                device_id = #{deviceId},
            </if>
            <if test="thermometerValue != null and thermometerValue != ''">
                thermometer_value = #{thermometerValue},
            </if>
            <if test="thermometerValueIn != null and thermometerValueIn != ''">
                thermometer_value_in = #{thermometerValueIn},
            </if>
            <if test="thermometerValueOut != null and thermometerValueOut != ''">
                thermometer_value_out = #{thermometerValueOut},
            </if>
            <if test="updateTime != null and updateTime != ''">
                update_time = #{updateTime},
            </if>
        </set>
        where thermometer_htdata_id = #{thermometerHtdataId}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from psdc_thermometer_htdata where thermometer_htdata_id = #{thermometerHtdataId}
    </delete>
</mapper>