<?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.fastbee.iot.mapper.NgFlowDeviceDataMapper">

    <resultMap type="NgFlowDeviceData" id="NgFlowDeviceDataResult">
        <result property="id"    column="id"    />
        <result property="inFlow"    column="in_flow"    />
        <result property="sumFlow"    column="sum_flow"    />
        <result property="deviceNumber"    column="device_number"    />
        <result property="realTime"    column="real_time"    />
        <result property="status"    column="status"    />
        <result property="saveTime"    column="save_time"    />
        <result property="deptId"    column="dept_id"    />
    </resultMap>

    <sql id="selectNgFlowDeviceDataVo">
        select id, in_flow, sum_flow, device_number, real_time, status, save_time, dept_id from ng_flow_device_data
    </sql>

    <select id="selectNgFlowDeviceDataList" parameterType="NgFlowDeviceData" resultMap="NgFlowDeviceDataResult">
        <include refid="selectNgFlowDeviceDataVo"/>
        <where>
            <if test="inFlow != null "> and in_flow = #{inFlow}</if>
            <if test="sumFlow != null  and sumFlow != ''"> and sum_flow = #{sumFlow}</if>
            <if test="deviceNumber != null  and deviceNumber != ''"> and device_number = #{deviceNumber}</if>
            <if test="realTime != null "> and real_time = #{realTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="saveTime != null "> and save_time = #{saveTime}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
        order by real_time desc
    </select>

    <select id="selectNgFlowDeviceDataById" parameterType="Long" resultMap="NgFlowDeviceDataResult">
        <include refid="selectNgFlowDeviceDataVo"/>
        where id = #{id}
    </select>

    <insert id="insertNgFlowDeviceData" parameterType="NgFlowDeviceData" useGeneratedKeys="true" keyProperty="id">
        insert into ng_flow_device_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="inFlow != null">in_flow,</if>
            <if test="sumFlow != null">sum_flow,</if>
            <if test="deviceNumber != null">device_number,</if>
            <if test="realTime != null">real_time,</if>
            <if test="status != null">status,</if>
            <if test="saveTime != null">save_time,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="inFlow != null">#{inFlow},</if>
            <if test="sumFlow != null">#{sumFlow},</if>
            <if test="deviceNumber != null">#{deviceNumber},</if>
            <if test="realTime != null">#{realTime},</if>
            <if test="status != null">#{status},</if>
            <if test="saveTime != null">#{saveTime},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateNgFlowDeviceData" parameterType="NgFlowDeviceData">
        update ng_flow_device_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="inFlow != null">in_flow = #{inFlow},</if>
            <if test="sumFlow != null">sum_flow = #{sumFlow},</if>
            <if test="deviceNumber != null">device_number = #{deviceNumber},</if>
            <if test="realTime != null">real_time = #{realTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="saveTime != null">save_time = #{saveTime},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNgFlowDeviceDataById" parameterType="Long">
        delete from ng_flow_device_data where id = #{id}
    </delete>

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