<?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.xzzn.ems.mapper.EmsDhDataMapper">

    <resultMap type="EmsDhData" id="EmsDhDataResult">
        <result property="id"    column="id"    />
        <result property="dataUpdateTime"    column="data_update_time"    />
        <result property="humidity"    column="humidity"    />
        <result property="temperature"    column="temperature"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="siteId"    column="site_id"    />
        <result property="deviceId"    column="device_id"    />
    </resultMap>

    <sql id="selectEmsDhDataVo">
        select id, data_update_time，humidity, temperature, create_by, create_time, update_by, update_time, remark, site_id, device_id from ems_dh_data
    </sql>

    <select id="selectEmsDhDataList" parameterType="EmsDhData" resultMap="EmsDhDataResult">
        <include refid="selectEmsDhDataVo"/>
        <where>
            <if test="dataUpdateTime != null "> and data_update_time = #{dataUpdateTime}</if>
            <if test="humidity != null "> and humidity = #{humidity}</if>
            <if test="temperature != null "> and temperature = #{temperature}</if>
            <if test="siteId != null  and siteId != ''"> and site_id = #{siteId}</if>
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
        </where>
    </select>

    <select id="selectEmsDhDataById" parameterType="Long" resultMap="EmsDhDataResult">
        <include refid="selectEmsDhDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmsDhData" parameterType="EmsDhData" useGeneratedKeys="true" keyProperty="id">
        insert into ems_dh_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataUpdateTime != null">data_update_time,</if>
            <if test="humidity != null">humidity,</if>
            <if test="temperature != null">temperature,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="siteId != null">site_id,</if>
            <if test="deviceId != null and deviceId != ''">device_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataUpdateTime != null">#{dataUpdateTime},</if>
            <if test="humidity != null">#{humidity},</if>
            <if test="temperature != null">#{temperature},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="siteId != null">#{siteId},</if>
            <if test="deviceId != null and deviceId != ''">#{deviceId},</if>
        </trim>
    </insert>

    <update id="updateEmsDhData" parameterType="EmsDhData">
        update ems_dh_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="dataUpdateTime != null">data_update_time = #{dataUpdateTime},</if>
            <if test="humidity != null">humidity = #{humidity},</if>
            <if test="temperature != null">temperature = #{temperature},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="siteId != null">site_id = #{siteId},</if>
            <if test="deviceId != null and deviceId != ''">device_id = #{deviceId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsDhDataById" parameterType="Long">
        delete from ems_dh_data where id = #{id}
    </delete>

    <delete id="deleteEmsDhDataByIds" parameterType="String">
        delete from ems_dh_data where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>