<?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.EmsRecordSteamInstantMapper">

    <resultMap type="EmsRecordSteamInstant" id="EmsRecordSteamInstantResult">
        <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="steamFlow" column="steam_flow"/>
        <result property="heatInstantValue" column="heat_instant_value"/>
        <result property="heatTotalValue" column="heat_total_value"/>
        <result property="temperature" column="temperature"/>
        <result property="press" column="press"/>
        <result property="density" column="density"/>
        <result property="differencePress" column="difference_press"/>
        <result property="recordTime" column="record_time"/>
    </resultMap>

    <sql id="selectEmsRecordSteamInstantVo">
        select ersi.obj_id,
               ersi.monitor_code,
               ebmi.monitor_name,
               ersi.collect_time,
               ersi.flux_flow,
               ersi.steam_flow,
               ersi.heat_instant_value,
               ersi.heat_total_value,
               ersi.temperature,
               ersi.press,
               ersi.density,
               ersi.difference_press,
               ersi.record_time
        from ems_record_steam_instant ersi
                 left join ems_base_monitor_info ebmi on ersi.monitor_code = ebmi.monitor_code
    </sql>

    <select id="selectEmsRecordSteamInstantList" parameterType="EmsRecordSteamInstant"
            resultMap="EmsRecordSteamInstantResult">
        <include refid="selectEmsRecordSteamInstantVo"/>
        <where>
            <if test="monitorCode != null  and monitorCode != ''">and ersi.monitor_code = #{monitorCode}</if>
            <if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''">
                and ersi.collect_time between #{params.beginCollectTime} and #{params.endCollectTime}
            </if>
            <if test="fluxFlow != null ">and ersi.flux_flow = #{fluxFlow}</if>
            <if test="steamFlow != null ">and ersi.steam_flow = #{steamFlow}</if>
            <if test="heatInstantValue != null ">and ersi.heat_instant_value = #{heatInstantValue}</if>
            <if test="heatTotalValue != null ">and ersi.heat_total_value = #{heatTotalValue}</if>
            <if test="temperature != null ">and ersi.temperature = #{temperature}</if>
            <if test="press != null ">and ersi.press = #{press}</if>
            <if test="density != null ">and ersi.density = #{density}</if>
            <if test="differencePress != null ">and ersi.difference_press = #{differencePress}</if>
            <if test="params.beginRecordTime != null and params.beginRecordTime != '' and params.endRecordTime != null and params.endRecordTime != ''">
                and ersi.record_time between #{params.beginRecordTime} and #{params.endRecordTime}
            </if>
        </where>
    </select>

    <select id="selectEmsRecordSteamInstantByObjId" parameterType="Long" resultMap="EmsRecordSteamInstantResult">
        <include refid="selectEmsRecordSteamInstantVo"/>
        where ersi.obj_id = #{objId}
    </select>

    <insert id="insertEmsRecordSteamInstant" parameterType="EmsRecordSteamInstant" useGeneratedKeys="true"
            keyProperty="objId">
        insert into ems_record_steam_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="steamFlow != null">steam_flow,</if>
            <if test="heatInstantValue != null">heat_instant_value,</if>
            <if test="heatTotalValue != null">heat_total_value,</if>
            <if test="temperature != null">temperature,</if>
            <if test="press != null">press,</if>
            <if test="density != null">density,</if>
            <if test="differencePress != null">difference_press,</if>
            <if test="recordTime != null">record_time,</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="steamFlow != null">#{steamFlow},</if>
            <if test="heatInstantValue != null">#{heatInstantValue},</if>
            <if test="heatTotalValue != null">#{heatTotalValue},</if>
            <if test="temperature != null">#{temperature},</if>
            <if test="press != null">#{press},</if>
            <if test="density != null">#{density},</if>
            <if test="differencePress != null">#{differencePress},</if>
            <if test="recordTime != null">#{recordTime},</if>
        </trim>
    </insert>

    <update id="updateEmsRecordSteamInstant" parameterType="EmsRecordSteamInstant">
        update ems_record_steam_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="steamFlow != null">steam_flow = #{steamFlow},</if>
            <if test="heatInstantValue != null">heat_instant_value = #{heatInstantValue},</if>
            <if test="heatTotalValue != null">heat_total_value = #{heatTotalValue},</if>
            <if test="temperature != null">temperature = #{temperature},</if>
            <if test="press != null">press = #{press},</if>
            <if test="density != null">density = #{density},</if>
            <if test="differencePress != null">difference_press = #{differencePress},</if>
            <if test="recordTime != null">record_time = #{recordTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

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

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