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

    <resultMap type="MeasSpectralRadiation" id="MeasSpectralRadiationResult">
        <result property="id" column="id"/>
        <result property="measurementBatchId" column="measurement_batch_id"/>
        <result property="engineModel" column="engine_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="model" column="model"/>
        <result property="lensFView" column="lens_f_view"/>
        <result property="gain" column="gain"/>
        <result property="backgroundData" column="background_data"/>
        <result property="calTemp" column="cal_temp"/>
        <result property="calCurve" column="cal_curve"/>
        <result property="rawData" column="raw_data"/>
        <result property="radiance1" column="radiance_1"/>
        <result property="radiance2" column="radiance_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="selectMeasSpectralRadiationVo">
        SELECT
            msr.id,
            med.id measurement_batch_id,
            mem.model engine_model,
            mem.geometry_files,
            mem.geometry_image,
            mb.measurement_batch,
            med.engine_status,
            med.angle,
            msr.model,
            msr.lens_f_view,
            msr.gain,
            msr.background_data,
            msr.cal_temp,
            msr.cal_curve,
            msr.raw_data,
            msr.radiance_1,
            msr.radiance_2,
            msr.create_by,
            msr.create_time,
            msr.update_by,
            msr.update_time
        FROM
            meas_env_data med
        LEFT JOIN meas_spectral_radiation msr ON msr.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="selectMeasSpectralRadiationList" parameterType="MeasSpectralRadiation"
            resultMap="MeasSpectralRadiationResult">
        <include refid="selectMeasSpectralRadiationVo"/>
        <where>

            <if test="measurementBatch != null  and measurementBatch != ''">and mdr.measurement_batch = #{measurementBatch}</if>
            <if test="engineModel != null  and engineModel != ''">and med.model =
                #{engineModel}
            </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="measurementBatchId != null ">and measurement_batch_id = #{measurementBatchId}</if>
            <if test="model != null  and model != ''">and model = #{model}</if>
            <if test="lensFView != null ">and lens_f_view = #{lensFView}</if>
            <if test="gain != null ">and gain = #{gain}</if>
            <if test="backgroundData != null  and backgroundData != ''">and background_data = #{backgroundData}</if>
            <if test="calTemp != null ">and cal_temp = #{calTemp}</if>
            <if test="calCurve != null  and calCurve != ''">and cal_curve = #{calCurve}</if>
            <if test="rawData != null  and rawData != ''">and raw_data = #{rawData}</if>
            <if test="radiance1 != null  and radiance1 != ''">and radiance_1 = #{radiance1}</if>
            <if test="radiance2 != null  and radiance2 != ''">and radiance_2 = #{radiance2}</if>
        </where>
    </select>

    <select id="selectMeasSpectralRadiationById" parameterType="Long" resultMap="MeasSpectralRadiationResult">
        <include refid="selectMeasSpectralRadiationVo"/>
        where msr.id = #{id}
    </select>

    <insert id="insertMeasSpectralRadiation" parameterType="MeasSpectralRadiation">
        insert into meas_spectral_radiation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="measurementBatchId != null">measurement_batch_id,</if>
            <if test="model != null and model != ''">model,</if>
            <if test="lensFView != null">lens_f_view,</if>
            <if test="gain != null">gain,</if>
            <if test="backgroundData != null">background_data,</if>
            <if test="calTemp != null">cal_temp,</if>
            <if test="calCurve != null">cal_curve,</if>
            <if test="rawData != null">raw_data,</if>
            <if test="radiance1 != null">radiance_1,</if>
            <if test="radiance2 != null">radiance_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">#{measurementBatchId},</if>
            <if test="model != null and model != ''">#{model},</if>
            <if test="lensFView != null">#{lensFView},</if>
            <if test="gain != null">#{gain},</if>
            <if test="backgroundData != null">#{backgroundData},</if>
            <if test="calTemp != null">#{calTemp},</if>
            <if test="calCurve != null">#{calCurve},</if>
            <if test="rawData != null">#{rawData},</if>
            <if test="radiance1 != null">#{radiance1},</if>
            <if test="radiance2 != null">#{radiance2},</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="updateMeasSpectralRadiation" parameterType="MeasSpectralRadiation">
        update meas_spectral_radiation
        <trim prefix="SET" suffixOverrides=",">
            <if test="measurementBatchId != null">measurement_batch_id = #{measurementBatchId},</if>
            <if test="model != null and model != ''">model = #{model},</if>
            <if test="lensFView != null">lens_f_view = #{lensFView},</if>
            <if test="gain != null">gain = #{gain},</if>
            <if test="backgroundData != null">background_data = #{backgroundData},</if>
            <if test="calTemp != null">cal_temp = #{calTemp},</if>
            <if test="calCurve != null">cal_curve = #{calCurve},</if>
            <if test="rawData != null">raw_data = #{rawData},</if>
            <if test="radiance1 != null">radiance_1 = #{radiance1},</if>
            <if test="radiance2 != null">radiance_2 = #{radiance2},</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="deleteMeasSpectralRadiationById" parameterType="Long">
        delete from meas_spectral_radiation where id = #{id}
    </delete>

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

    <select id="selectResultsByEnvDataId" parameterType="Long" resultMap="MeasSpectralRadiationResult">
        <include refid="selectMeasSpectralRadiationVo"/>
        where med.id = #{id}
    </select>
</mapper>