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

    <resultMap type="MeasEnvData" id="MeasEnvDataResult">
        <result property="id" column="id"/>
        <result property="measurementBatchId" column="measurement_batch_id"/>
        <result property="measurementBatch" column="measurement_batch"/>
        <result property="model" column="model"/>
        <result property="geometryFiles" column="geometry_files"/>
        <result property="geometryImage" column="geometry_image"/>
        <result property="engineStatus" column="engine_status"/>
        <result property="angle" column="angle"/>
        <result property="turbinePostTemp" column="turbine_post_temp"/>
        <result property="testDistance" column="test_distance"/>
        <result property="time" column="time"/>
        <result property="location" column="location"/>
        <result property="atmosPress" column="atmos_press"/>
        <result property="temperature" column="temperature"/>
        <result property="windSpeed" column="wind_speed"/>
        <result property="humidity" column="humidity"/>
        <result property="concentration" column="concentration"/>
        <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="selectMeasEnvDataVo">
        SELECT
            med.id,
            med.measurement_batch_id,
            mb.measurement_batch,
            mem.model,
            mem.geometry_files,
            mem.geometry_image,
            med.engine_status,
            med.angle,
            med.turbine_post_temp,
            med.test_distance,
            med.time,
            med.location,
            med.atmos_press,
            med.temperature,
            med.wind_speed,
            med.humidity,
            med.concentration,
            med.create_by,
            med.create_time,
            med.update_by,
            med.update_time
        FROM
            meas_env_data med
        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="selectMeasEnvDataList" parameterType="MeasEnvData" resultMap="MeasEnvDataResult">
        <include refid="selectMeasEnvDataVo"/>
        <where>
            <if test="measurementBatchId != null ">and measurement_batch_id = #{measurementBatchId}</if>
            <if test="engineStatus != null  and engineStatus != ''">and engine_status = #{engineStatus}</if>
            <if test="angle != null  and angle != ''">and angle = #{angle}</if>
            <if test="turbinePostTemp != null ">and turbine_post_temp = #{turbinePostTemp}</if>
            <if test="testDistance != null ">and test_distance = #{testDistance}</if>
            <if test="time != null ">and time = #{time}</if>
            <if test="location != null  and location != ''">and location = #{location}</if>
            <if test="atmosPress != null ">and atmos_press = #{atmosPress}</if>
            <if test="temperature != null ">and temperature = #{temperature}</if>
            <if test="windSpeed != null ">and wind_speed = #{windSpeed}</if>
            <if test="humidity != null ">and humidity = #{humidity}</if>
            <if test="concentration != null ">and concentration = #{concentration}</if>
        </where>
    </select>

    <select id="selectMeasEnvDataById" parameterType="Long" resultMap="MeasEnvDataResult">
        <include refid="selectMeasEnvDataVo"/>
        where med.id = #{id}
    </select>

    <insert id="insertMeasEnvData" parameterType="MeasEnvData">
        insert into meas_env_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="measurementBatchId != null">measurement_batch_id,</if>
            <if test="engineStatus != null and engineStatus != ''">engine_status,</if>
            <if test="angle != null">angle,</if>
            <if test="turbinePostTemp != null">turbine_post_temp,</if>
            <if test="testDistance != null">test_distance,</if>
            <if test="time != null">time,</if>
            <if test="location != null and location != ''">location,</if>
            <if test="atmosPress != null">atmos_press,</if>
            <if test="temperature != null">temperature,</if>
            <if test="windSpeed != null">wind_speed,</if>
            <if test="humidity != null">humidity,</if>
            <if test="concentration != null">concentration,</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="engineStatus != null and engineStatus != ''">#{engineStatus},</if>
            <if test="angle != null">#{angle},</if>
            <if test="turbinePostTemp != null">#{turbinePostTemp},</if>
            <if test="testDistance != null">#{testDistance},</if>
            <if test="time != null">#{time},</if>
            <if test="location != null and location != ''">#{location},</if>
            <if test="atmosPress != null">#{atmosPress},</if>
            <if test="temperature != null">#{temperature},</if>
            <if test="windSpeed != null">#{windSpeed},</if>
            <if test="humidity != null">#{humidity},</if>
            <if test="concentration != null">#{concentration},</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="updateMeasEnvData" parameterType="MeasEnvData">
        update meas_env_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="measurementBatchId != null">measurement_batch_id = #{measurementBatchId},</if>
            <if test="engineStatus != null and engineStatus != ''">engine_status = #{engineStatus},</if>
            <if test="angle != null">angle = #{angle},</if>
            <if test="turbinePostTemp != null">turbine_post_temp = #{turbinePostTemp},</if>
            <if test="testDistance != null">test_distance = #{testDistance},</if>
            <if test="time != null">time = #{time},</if>
            <if test="location != null and location != ''">location = #{location},</if>
            <if test="atmosPress != null">atmos_press = #{atmosPress},</if>
            <if test="temperature != null">temperature = #{temperature},</if>
            <if test="windSpeed != null">wind_speed = #{windSpeed},</if>
            <if test="humidity != null">humidity = #{humidity},</if>
            <if test="concentration != null">concentration = #{concentration},</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="deleteMeasEnvDataById" parameterType="Long">
        delete from meas_env_data where id = #{id}
    </delete>

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