<?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.aucma.report.mapper.PerfusionRecordMapper">

    <resultMap type="PerfusionRecord" id="PerfusionRecordResult">
        <result property="objId" column="obj_id"/>
        <result property="perfusionBoxcode" column="perfusion_boxcode"/>
        <result property="perfusionRefrigeranttypeleft" column="perfusion_refrigeranttypeleft"/>
        <result property="perfusionRefrigeranttyperight" column="perfusion_refrigeranttyperight"/>
        <result property="perfusionSetvolume" column="perfusion_setvolume"/>
        <result property="perfusionActualvolume" column="perfusion_actualvolume"/>
        <result property="perfusionR" column="perfusion_r"/>
        <result property="perfusionL" column="perfusion_l"/>
        <result property="perfusionDuration" column="perfusion_duration"/>
        <result property="perfusionSystem" column="perfusion_system"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
        <result property="perfusionResult" column="perfusion_result"/>
        <result property="yield" column="yield"/>
        <result property="finishStatus" column="finish_status"/>
    </resultMap>

    <sql id="selectPerfusionRecordVo">
        select obj_id,
               perfusion_boxcode,
               perfusion_refrigeranttypeleft,
               perfusion_refrigeranttyperight,
               perfusion_setvolume,
               perfusion_actualvolume,
               perfusion_r,
               perfusion_l,
               perfusion_duration,
               perfusion_system,
               created_by,
               created_time,
               updated_by,
               updated_time,
               perfusion_result,
               yield,
               finish_status
        from perfusion_record
    </sql>

    <select id="selectPerfusionRecordList" parameterType="PerfusionRecord" resultMap="PerfusionRecordResult">
        <include refid="selectPerfusionRecordVo"/>
        <where>
            <if test="perfusionBoxcode != null  and perfusionBoxcode != ''">and perfusion_boxcode =
                #{perfusionBoxcode}
            </if>
            <if test="perfusionRefrigeranttypeleft != null  and perfusionRefrigeranttypeleft != ''">and
                perfusion_refrigeranttypeleft = #{perfusionRefrigeranttypeleft}
            </if>
            <if test="perfusionRefrigeranttyperight != null  and perfusionRefrigeranttyperight != ''">and
                perfusion_refrigeranttyperight = #{perfusionRefrigeranttyperight}
            </if>
            <if test="perfusionSetvolume != null  and perfusionSetvolume != ''">and perfusion_setvolume =
                #{perfusionSetvolume}
            </if>
            <if test="perfusionActualvolume != null  and perfusionActualvolume != ''">and perfusion_actualvolume =
                #{perfusionActualvolume}
            </if>
            <if test="perfusionR != null  and perfusionR != ''">and perfusion_r = #{perfusionR}</if>
            <if test="perfusionL != null  and perfusionL != ''">and perfusion_l = #{perfusionL}</if>
            <if test="perfusionDuration != null  and perfusionDuration != ''">and perfusion_duration =
                #{perfusionDuration}
            </if>
            <if test="perfusionSystem != null  and perfusionSystem != ''">and perfusion_system = #{perfusionSystem}</if>
            <if test="createdBy != null  and createdBy != ''">and created_by = #{createdBy}</if>
            <if test="params.beginCreatedTime != null and params.beginCreatedTime != '' and params.endCreatedTime != null and params.endCreatedTime != ''">
                and created_time between to_date(#{params.beginCreatedTime}, 'yyyy-mm-dd hh24:mi:ss') and
                to_date(#{params.endCreatedTime}, 'yyyy-mm-dd hh24:mi:ss')
            </if>
            <if test="updatedBy != null  and updatedBy != ''">and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and updated_time = #{updatedTime}</if>
            <if test="perfusionResult != null ">and perfusion_result = #{perfusionResult}</if>
            <if test="yield != null  and yield != ''">and yield = #{yield}</if>
            <if test="finishStatus != null  and finishStatus != ''">and finish_status = #{finishStatus}</if>
        </where>
        order by created_time desc
    </select>

    <select id="selectPerfusionRecordByObjId" parameterType="Long" resultMap="PerfusionRecordResult">
        <include refid="selectPerfusionRecordVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertPerfusionRecord" parameterType="PerfusionRecord">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_perfusion_record.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into perfusion_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="perfusionBoxcode != null">perfusion_boxcode,</if>
            <if test="perfusionRefrigeranttypeleft != null">perfusion_refrigeranttypeleft,</if>
            <if test="perfusionRefrigeranttyperight != null">perfusion_refrigeranttyperight,</if>
            <if test="perfusionSetvolume != null">perfusion_setvolume,</if>
            <if test="perfusionActualvolume != null">perfusion_actualvolume,</if>
            <if test="perfusionR != null">perfusion_r,</if>
            <if test="perfusionL != null">perfusion_l,</if>
            <if test="perfusionDuration != null">perfusion_duration,</if>
            <if test="perfusionSystem != null">perfusion_system,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="perfusionResult != null">perfusion_result,</if>
            <if test="yield != null">yield,</if>
            <if test="finishStatus != null">finish_status,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="perfusionBoxcode != null">#{perfusionBoxcode},</if>
            <if test="perfusionRefrigeranttypeleft != null">#{perfusionRefrigeranttypeleft},</if>
            <if test="perfusionRefrigeranttyperight != null">#{perfusionRefrigeranttyperight},</if>
            <if test="perfusionSetvolume != null">#{perfusionSetvolume},</if>
            <if test="perfusionActualvolume != null">#{perfusionActualvolume},</if>
            <if test="perfusionR != null">#{perfusionR},</if>
            <if test="perfusionL != null">#{perfusionL},</if>
            <if test="perfusionDuration != null">#{perfusionDuration},</if>
            <if test="perfusionSystem != null">#{perfusionSystem},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="perfusionResult != null">#{perfusionResult},</if>
            <if test="yield != null">#{yield},</if>
            <if test="finishStatus != null">#{finishStatus},</if>
        </trim>
    </insert>

    <update id="updatePerfusionRecord" parameterType="PerfusionRecord">
        update perfusion_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="perfusionBoxcode != null">perfusion_boxcode = #{perfusionBoxcode},</if>
            <if test="perfusionRefrigeranttypeleft != null">perfusion_refrigeranttypeleft =
                #{perfusionRefrigeranttypeleft},
            </if>
            <if test="perfusionRefrigeranttyperight != null">perfusion_refrigeranttyperight =
                #{perfusionRefrigeranttyperight},
            </if>
            <if test="perfusionSetvolume != null">perfusion_setvolume = #{perfusionSetvolume},</if>
            <if test="perfusionActualvolume != null">perfusion_actualvolume = #{perfusionActualvolume},</if>
            <if test="perfusionR != null">perfusion_r = #{perfusionR},</if>
            <if test="perfusionL != null">perfusion_l = #{perfusionL},</if>
            <if test="perfusionDuration != null">perfusion_duration = #{perfusionDuration},</if>
            <if test="perfusionSystem != null">perfusion_system = #{perfusionSystem},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
            <if test="perfusionResult != null">perfusion_result = #{perfusionResult},</if>
            <if test="yield != null">yield = #{yield},</if>
            <if test="finishStatus != null">finish_status = #{finishStatus},</if>
        </trim>
        where obj_id = #{objId}
    </update>

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

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