<?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.ems.record.mapper.EmsRecordWaterInstantMapper">

    <resultMap type="EmsRecordWaterInstant" id="EmsRecordWaterInstantResult">
        <result property="objId" column="obj_id"/>
        <result property="monitorCode" column="monitor_code"/>
        <result property="monitorName" column="monitor_name"/>
        <result property="collectTime" column="collect_time"/>
        <result property="fluxFlow" column="flux_flow"/>
        <result property="waterFlow" column="water_flow"/>
        <result property="recordTime" column="record_time"/>
        <result property="collectType" column="collect_type"/>
    </resultMap>

    <sql id="selectEmsRecordWaterInstantVo">
        select RWI.obj_id,
               RWI.monitor_code,
               RWI.collect_time,
               RWI.flux_flow,
               RWI.water_flow,
               RWI.record_time,
               RWI.collect_type,
               BMI.monitor_name
        from ems_record_water_instant RWI
                 left join ems_base_monitor_info BMI on RWI.monitor_code = BMI.monitor_code
    </sql>

    <select id="selectEmsRecordWaterInstantList" parameterType="EmsRecordWaterInstant"
            resultMap="EmsRecordWaterInstantResult">
        <include refid="selectEmsRecordWaterInstantVo"/>
        <where>
            <if test="objId != null  and objId != ''">and RWI.obj_id = #{objId}</if>
            <if test="monitorCode != null  and monitorCode != ''">and RWI.monitor_code = #{monitorCode}</if>
            <if test="fluxFlow != null ">and RWI.flux_flow = #{fluxFlow}</if>
            <if test="waterFlow != null ">and RWI.water_flow = #{waterFlow}</if>
            <if test="collectType != null ">and RWI.collect_type = #{collectType}</if>
            <if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''">
                and RWI.collect_time between #{params.beginCollectTime} and #{params.endCollectTime}</if>
            <if test="params.beginRecordTime != null and params.beginRecordTime != '' and params.endRecordTime != null and params.endRecordTime != ''">
                and RWI.record_time between #{params.beginRecordTime} and #{params.endRecordTime}</if>
        </where>
        order by RWI.collect_time desc
    </select>

    <select id="selectEmsRecordWaterInstantByObjId" parameterType="Long" resultMap="EmsRecordWaterInstantResult">
        <include refid="selectEmsRecordWaterInstantVo"/>
        where RWI.obj_id = #{objId}
    </select>

    <insert id="insertEmsRecordWaterInstant" parameterType="EmsRecordWaterInstant" useGeneratedKeys="true"
            keyProperty="objId">
        insert into ems_record_water_instant
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitorCode != null">monitor_code,</if>
            <if test="collectTime != null">collect_time,</if>
            <if test="fluxFlow != null">flux_flow,</if>
            <if test="waterFlow != null">water_flow,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="collectType != null">collect_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="monitorCode != null">#{monitorCode},</if>
            <if test="collectTime != null">#{collectTime},</if>
            <if test="fluxFlow != null">#{fluxFlow},</if>
            <if test="waterFlow != null">#{waterFlow},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="collectType != null">#{collectType},</if>
        </trim>
    </insert>

    <update id="updateEmsRecordWaterInstant" parameterType="EmsRecordWaterInstant">
        update ems_record_water_instant
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitorCode != null">monitor_code = #{monitorCode},</if>
            <if test="collectTime != null">collect_time = #{collectTime},</if>
            <if test="fluxFlow != null">flux_flow = #{fluxFlow},</if>
            <if test="waterFlow != null">water_flow = #{waterFlow},</if>
            <if test="recordTime != null">record_time = #{recordTime},</if>
            <if test="collectType != null">collect_type = #{collectType},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteEmsRecordWaterInstantByObjId" parameterType="Long">
        delete from ems_record_water_instant where obj_id = #{objId}
    </delete>

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