<?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.mirs.biz.mapper.EmiMeasurementMapper">
    
    <resultMap type="EmiMeasurement" id="EmiMeasurementResult">
        <result property="id"    column="id"    />
        <result property="sampleModel"    column="sample_model"    />
        <result property="temperatureK"    column="temperature_k"    />
        <result property="wavelengthUm"    column="wavelength_um"    />
        <result property="emiCorrection1"    column="emi_correction1"    />
        <result property="emiCorrection2"    column="emi_correction2"    />
        <result property="emiCorrection3"    column="emi_correction3"    />
        <result property="emiCorrection4"    column="emi_correction4"    />
        <result property="emiCorrection5"    column="emi_correction5"    />
        <result property="meanValue"    column="mean_value"    />
        <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="selectEmiMeasurementVo">
        select id, sample_model, temperature_k, wavelength_um, emi_correction1, emi_correction2, emi_correction3, emi_correction4, emi_correction5, mean_value, create_by, create_time, update_by, update_time from biz_emi_measurement_t
    </sql>

    <select id="selectEmiMeasurementList" parameterType="EmiMeasurement" resultMap="EmiMeasurementResult">
        <include refid="selectEmiMeasurementVo"/>
        <where>  
            <if test="sampleModel != null  and sampleModel != ''"> and sample_model = #{sampleModel}</if>
            <if test="temperatureK != null "> and temperature_k = #{temperatureK}</if>
            <if test="wavelengthUm != null "> and wavelength_um = #{wavelengthUm}</if>
            <if test="wavelengthUmStr != null and wavelengthUmStr != ''">
                <choose>
                    <!-- 处理3~5范围 -->
                    <when test="wavelengthUmStr == '3~5'">
                        and wavelength_um &gt;= 3 AND wavelength_um &lt;= 5
                    </when>
                    <!-- 处理5~9范围 -->
                    <when test="wavelengthUmStr == '5~9'">
                        and wavelength_um &gt;= 5 AND wavelength_um &lt;= 9
                    </when>
                    <!-- 处理8~16范围（实际查询8~14） -->
                    <when test="wavelengthUmStr == '8~16'">
                        and wavelength_um &gt;= 8 AND wavelength_um &lt;= 14
                    </when>
                    <!-- 处理特定值10.6 -->
                    <when test="wavelengthUmStr == '10.6'">
                        and wavelength_um = 10.6
                    </when>
                    <!-- 如果不是以上预设值，则按实际值查询 -->
                    <otherwise>
                        and wavelength_um = #{wavelengthUmStr}
                    </otherwise>
                </choose>
            </if>
        </where>
    </select>
    
    <select id="selectEmiMeasurementById" parameterType="Long" resultMap="EmiMeasurementResult">
        <include refid="selectEmiMeasurementVo"/>
        where id = #{id}
    </select>

    <insert id="insertEmiMeasurement" parameterType="EmiMeasurement" useGeneratedKeys="true" keyProperty="id">
        insert into biz_emi_measurement_t
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sampleModel != null">sample_model,</if>
            <if test="temperatureK != null">temperature_k,</if>
            <if test="wavelengthUm != null">wavelength_um,</if>
            <if test="emiCorrection1 != null">emi_correction1,</if>
            <if test="emiCorrection2 != null">emi_correction2,</if>
            <if test="emiCorrection3 != null">emi_correction3,</if>
            <if test="emiCorrection4 != null">emi_correction4,</if>
            <if test="emiCorrection5 != null">emi_correction5,</if>
            <if test="meanValue != null">mean_value,</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="sampleModel != null">#{sampleModel},</if>
            <if test="temperatureK != null">#{temperatureK},</if>
            <if test="wavelengthUm != null">#{wavelengthUm},</if>
            <if test="emiCorrection1 != null">#{emiCorrection1},</if>
            <if test="emiCorrection2 != null">#{emiCorrection2},</if>
            <if test="emiCorrection3 != null">#{emiCorrection3},</if>
            <if test="emiCorrection4 != null">#{emiCorrection4},</if>
            <if test="emiCorrection5 != null">#{emiCorrection5},</if>
            <if test="meanValue != null">#{meanValue},</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="updateEmiMeasurement" parameterType="EmiMeasurement">
        update biz_emi_measurement_t
        <trim prefix="SET" suffixOverrides=",">
            <if test="sampleModel != null">sample_model = #{sampleModel},</if>
            <if test="temperatureK != null">temperature_k = #{temperatureK},</if>
            <if test="wavelengthUm != null">wavelength_um = #{wavelengthUm},</if>
            <if test="emiCorrection1 != null">emi_correction1 = #{emiCorrection1},</if>
            <if test="emiCorrection2 != null">emi_correction2 = #{emiCorrection2},</if>
            <if test="emiCorrection3 != null">emi_correction3 = #{emiCorrection3},</if>
            <if test="emiCorrection4 != null">emi_correction4 = #{emiCorrection4},</if>
            <if test="emiCorrection5 != null">emi_correction5 = #{emiCorrection5},</if>
            <if test="meanValue != null">mean_value = #{meanValue},</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="deleteEmiMeasurementById" parameterType="Long">
        delete from biz_emi_measurement_t where id = #{id}
    </delete>

    <delete id="deleteEmiMeasurementByIds" parameterType="String">
        delete from biz_emi_measurement_t where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="getTemperatureK" parameterType="String" resultType="HashMap">
        select distinct temperature_k name, temperature_k value from biz_emi_measurement_t ORDER BY temperature_k asc
    </select>

</mapper>