<?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.ruoyi.ems.record.mapper.EmsVibrationInstantMapper">
    
    <resultMap type="EmsVibrationInstant" id="EmsVibrationInstantResult">
        <result property="objId"    column="objId"    />
        <result property="collectTime"    column="collectTime"    />
        <result property="sensorId"    column="sensor_id"    />
        <result property="speed"    column="speed"    />
        <result property="displacement"    column="displacement"    />
        <result property="acceleration"    column="acceleration"    />
        <result property="temperature"    column="temperature"    />
        <result property="recodeTime"    column="recodeTime"    />
        <result property="remark"    column="remark"    />
        <result property="monitorName"    column="monitor_name"    />
    </resultMap>

    <sql id="selectEmsVibrationInstantVo">
        select rdi.objId,
               rdi.collectTime,
               rdi.sensor_id,
               rdi.speed,
               rdi.displacement,
               rdi.acceleration,
               rdi.temperature,
               rdi.recodeTime,
               rdi.remark,
               bmi.monitor_name
        from T_VibrationSensor_Data rdi
                 left join ems_base_monitor_info bmi on rdi.sensor_id = bmi.monitor_code
    </sql>

    <select id="selectVibrationInstantList" parameterType="EmsVibrationInstant" resultMap="EmsVibrationInstantResult">
        <include refid="selectEmsVibrationInstantVo"/>
        <where>
            <if test="objId != null  and objId != ''">and rdi.objId = #{objId}</if>
            <if test="sensorId != null  and sensorId != ''">and rdi.sensor_id = #{sensorId}</if>
            <if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''">
                and rdi.collectTime between #{params.beginCollectTime} and #{params.endCollectTime}</if>
            <if test="params.beginRecordTime != null and params.beginRecordTime != '' and params.endRecordTime != null and params.endRecordTime != ''">
                and rdi.collectTime between #{params.beginRecordTime} and #{params.endRecordTime}</if>
        </where>
        order by rdi.collectTime
    </select>



    <select id="selectEmsVibrationInstantList" parameterType="EmsVibrationInstant" resultMap="EmsVibrationInstantResult">
        <include refid="selectEmsVibrationInstantVo"/>
        <where>  
            <if test="params.beginCollectTime != null and params.beginCollectTime != '' and params.endCollectTime != null and params.endCollectTime != ''"> and collectTime between #{params.beginCollectTime} and #{params.endCollectTime}</if>
            <if test="sensorId != null  and sensorId != ''"> and rdi.sensor_id = #{sensorId}</if>
            <if test="speed != null "> and rdi.speed = #{speed}</if>
            <if test="displacement != null "> and rdi.displacement = #{displacement}</if>
            <if test="acceleration != null "> and rdi.acceleration = #{acceleration}</if>
            <if test="temperature != null "> and rdi.temperature = #{temperature}</if>
            <if test="params.beginRecodeTime != null and params.beginRecodeTime != '' and params.endRecodeTime != null and params.endRecodeTime != ''"> and recodeTime between #{params.beginRecodeTime} and #{params.endRecodeTime}</if>
        </where>
    </select>
    
    <select id="selectEmsVibrationInstantByObjId" parameterType="Long" resultMap="EmsVibrationInstantResult">
        <include refid="selectEmsVibrationInstantVo"/>
        where rdi.objId = #{objId}
    </select>
        
    <insert id="insertEmsVibrationInstant" parameterType="EmsVibrationInstant" useGeneratedKeys="true" keyProperty="objId">
        insert into T_VibrationSensor_Data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="collectTime != null">collectTime,</if>
            <if test="sensorId != null">sensor_id,</if>
            <if test="speed != null">speed,</if>
            <if test="displacement != null">displacement,</if>
            <if test="acceleration != null">acceleration,</if>
            <if test="temperature != null">temperature,</if>
            <if test="recodeTime != null">recodeTime,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="collectTime != null">#{collectTime},</if>
            <if test="sensorId != null">#{sensorId},</if>
            <if test="speed != null">#{speed},</if>
            <if test="displacement != null">#{displacement},</if>
            <if test="acceleration != null">#{acceleration},</if>
            <if test="temperature != null">#{temperature},</if>
            <if test="recodeTime != null">#{recodeTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateEmsVibrationInstant" parameterType="EmsVibrationInstant">
        update T_VibrationSensor_Data
        <trim prefix="SET" suffixOverrides=",">
            <if test="collectTime != null">collectTime = #{collectTime},</if>
            <if test="sensorId != null">sensor_id = #{sensorId},</if>
            <if test="speed != null">speed = #{speed},</if>
            <if test="displacement != null">displacement = #{displacement},</if>
            <if test="acceleration != null">acceleration = #{acceleration},</if>
            <if test="temperature != null">temperature = #{temperature},</if>
            <if test="recodeTime != null">recodeTime = #{recodeTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where objId = #{objId}
    </update>

    <delete id="deleteEmsVibrationInstantByObjId" parameterType="Long">
        delete from T_VibrationSensor_Data where objId = #{objId}
    </delete>

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