<?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.system.mapper.BusDeviceMapper">
    
    <resultMap type="BusDevice" id="BusDeviceResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="area"    column="area"    />
        <result property="bed"    column="bed"    />
        <result property="brandName"    column="brand_name"    />
        <result property="model"    column="model"    />
        <result property="manufactureId"    column="manufacture_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="price"    column="price"    />
        <result property="warranty"    column="warranty"    />
        <result property="updateTime"    column="update_time"    />
        <result property="enable"    column="enable"    />
        <result property="status"    column="status"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="infection"    column="infection"    />
    </resultMap>

    <sql id="selectBusDeviceVo">
        select id, device_id, area, bed, brand_name, model, manufacture_id, create_time, price, warranty, update_time, enable, status, is_delete, infection from bus_device
    </sql>

    <select id="selectBusDeviceList" parameterType="BusDevice" resultMap="BusDeviceResult">
        <include refid="selectBusDeviceVo"/>
        <where>  
            <if test="deviceId != null  and deviceId != ''"> and device_id like concat('%', #{deviceId}, '%')</if>
            <if test="area != null  and area != ''"> and area like concat('%', #{area}, '%')</if>
            <if test="bed != null  and bed != ''"> and bed = #{bed}</if>
            <if test="brandName != null  and brandName != ''"> and brand_name like concat('%', #{brandName}, '%')</if>
            <if test="model != null  and model != ''"> and model like concat('%', #{model}, '%')</if>
            <if test="manufactureId != null  and manufactureId != ''"> and manufacture_id like concat('%', #{manufactureId}, '%')</if>
            <if test="price != null  and price != ''"> and price = #{price}</if>
            <if test="warranty != null  and warranty != ''"> and warranty = #{warranty}</if>
            <if test="enable != null "> and enable = #{enable}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
            <if test="infection != null "> and infection = #{infection}</if>
        </where>
    </select>
    
    <select id="selectBusDeviceById" parameterType="Long" resultMap="BusDeviceResult">
        <include refid="selectBusDeviceVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBusDevice" parameterType="BusDevice">
        insert into bus_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="area != null">area,</if>
            <if test="bed != null">bed,</if>
            <if test="brandName != null">brand_name,</if>
            <if test="model != null">model,</if>
            <if test="manufactureId != null">manufacture_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="price != null">price,</if>
            <if test="warranty != null">warranty,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="enable != null">enable,</if>
            <if test="status != null">status,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="infection != null">infection,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="area != null">#{area},</if>
            <if test="bed != null">#{bed},</if>
            <if test="brandName != null">#{brandName},</if>
            <if test="model != null">#{model},</if>
            <if test="manufactureId != null">#{manufactureId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="price != null">#{price},</if>
            <if test="warranty != null">#{warranty},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="enable != null">#{enable},</if>
            <if test="status != null">#{status},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="infection != null">#{infection},</if>
         </trim>
    </insert>

    <update id="updateBusDevice" parameterType="BusDevice">
        update bus_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="area != null">area = #{area},</if>
            <if test="bed != null">bed = #{bed},</if>
            <if test="brandName != null">brand_name = #{brandName},</if>
            <if test="model != null">model = #{model},</if>
            <if test="manufactureId != null">manufacture_id = #{manufactureId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="price != null">price = #{price},</if>
            <if test="warranty != null">warranty = #{warranty},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="enable != null">enable = #{enable},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="infection != null">infection = #{infection},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBusDeviceById" parameterType="Long">
        delete from bus_device where id = #{id}
    </delete>

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

    <update id="updateStatusByIds">
        update bus_device_history
        <trim prefix="SET" suffixOverrides=",">
            <if test="status != null">status = #{status},</if>
        </trim>
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>