<?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.meas.system.mapper.MeasDataResultsMapper">

    <resultMap type="MeasDataResults" id="MeasDataResultsResult">
        <result property="id" column="id"/>
        <result property="measurementBatchId" column="measurement_batch_id"/>
        <result property="model" column="model"/>
        <result property="geometryFiles" column="geometry_files"/>
        <result property="geometryImage" column="geometry_image"/>
        <result property="measurementBatch" column="measurement_batch"/>
        <result property="engineStatus" column="measurement_batch"/>
        <result property="angle" column="angle"/>
        <result property="specIrr1" column="spec_irr_1"/>
        <result property="specIrr2" column="spec_irr_2"/>
        <result property="specBandIrr1" column="spec_band_irr_1"/>
        <result property="specBandIrr2" column="spec_band_irr_2"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMeasDataResultsVo">
        SELECT
            mdr.id,
            med.id measurement_batch_id,
            mem.model,
            mem.geometry_files,
            mem.geometry_image,
            mb.measurement_batch,
            med.engine_status,
            med.angle,
            mdr.spec_irr_1,
            mdr.spec_irr_2,
            mdr.spec_band_irr_1,
            mdr.spec_band_irr_2,
            mdr.create_by,
            mdr.create_time,
            mdr.update_by,
            mdr.update_time
        FROM
            meas_env_data med
        LEFT JOIN meas_data_results mdr ON mdr.measurement_batch_id = med.id
        LEFT JOIN meas_batch mb ON med.measurement_batch_id = mb.id
        LEFT JOIN meas_engine_model mem ON mb.engine_id = mem.id
    </sql>

    <select id="selectMeasDataResultsList" parameterType="MeasDataResults" resultMap="MeasDataResultsResult">
        <include refid="selectMeasDataResultsVo"/>
        <where>
            <if test="measurementBatch != null  and measurementBatch != ''">and mdr.measurement_batch = #{measurementBatch}</if>
            <if test="model != null  and model != ''">and med.model =
                #{model}
            </if>
            <if test="engineStatus != null  and engineStatus != ''">and mdr.engine_status = #{engineStatus}</if>
            <if test="angle != null  and angle != ''">and mdr.angle = #{angle}</if>
            <if test="specIrr2 != null  and specIrr2 != ''">and mdr.spec_irr_2 = #{specIrr2}</if>
            <if test="specBandIrr1 != null ">and mdr.spec_band_irr_1 = #{specBandIrr1}</if>
            <if test="specBandIrr2 != null ">and mdr.spec_band_irr_2 = #{specBandIrr2}</if>
        </where>
    </select>

    <select id="selectMeasDataResultsById" parameterType="Long" resultMap="MeasDataResultsResult">
        <include refid="selectMeasDataResultsVo"/>
        where mdr.id = #{id}
    </select>

    <insert id="insertMeasDataResults" parameterType="MeasDataResults">
        insert into meas_data_results
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="measurementBatchId != null and measurementBatchId != ''">measurement_batch_id,</if>
            <if test="specIrr1 != null">spec_irr_1,</if>
            <if test="specIrr2 != null">spec_irr_2,</if>
            <if test="specBandIrr1 != null">spec_band_irr_1,</if>
            <if test="specBandIrr2 != null">spec_band_irr_2,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="measurementBatchId != null and measurementBatchId != ''">#{measurementBatchId},</if>
            <if test="specIrr1 != null">#{specIrr1},</if>
            <if test="specIrr2 != null">#{specIrr2},</if>
            <if test="specBandIrr1 != null">#{specBandIrr1},</if>
            <if test="specBandIrr2 != null">#{specBandIrr2},</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>
        </trim>
    </insert>

    <update id="updateMeasDataResults" parameterType="MeasDataResults">
        update meas_data_results
        <trim prefix="SET" suffixOverrides=",">
            <if test="measurementBatchId != null and measurementBatchId != ''">measurement_batch_id =
                #{measurementBatchId},
            </if>
            <if test="specIrr1 != null">spec_irr_1 = #{specIrr1},</if>
            <if test="specIrr2 != null">spec_irr_2 = #{specIrr2},</if>
            <if test="specBandIrr1 != null">spec_band_irr_1 = #{specBandIrr1},</if>
            <if test="specBandIrr2 != null">spec_band_irr_2 = #{specBandIrr2},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMeasDataResultsById" parameterType="Long">
        delete from meas_data_results where id = #{id}
    </delete>

    <delete id="deleteMeasDataResultsByIds" parameterType="String">
        delete from meas_data_results where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectMeasDataResultsByEnvDataId" parameterType="Long" resultMap="MeasDataResultsResult">
        <include refid="selectMeasDataResultsVo"/>
        where med.id = #{id}
    </select>
</mapper>