<?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.pm.device.mapper.IbmsDeviceMapper">

    <resultMap type="pd" id="IbmsDeviceResult">
        <result property="id"    column="id"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceType"    column="device_type"    />
        <result property="subsystemType"    column="subsystem_type"    />
        <result property="spaceId"    column="space_id"    />
        <result property="spaceName"    column="space_name"    />
        <result property="brand"    column="brand"    />
        <result property="model"    column="model"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="manufactureDate"    column="manufacture_date"    />
        <result property="installDate"    column="install_date"    />
        <result property="warrantyPeriod"    column="warranty_period"    />
        <result property="status"    column="status"    />
        <result property="isOnline"    column="is_online"    />
        <result property="description"    column="description"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectIbmsDeviceVo">
        select id, device_code, device_name, device_type, subsystem_type, space_id, space_name, brand, model, serial_number, manufacture_date, install_date, warranty_period, status, is_online, description, create_time, update_time from ibms_device
    </sql>

    <select id="selectIbmsDeviceList" parameterType="pd" resultMap="IbmsDeviceResult">
        <include refid="selectIbmsDeviceVo"/>
        <where>
            <if test="deviceCode != null and deviceCode != ''"> and device_code = #{deviceCode}</if>
            <if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="deviceType != null and deviceType != ''"> and device_type = #{deviceType}</if>
        </where>
    </select>

    <select id="selectIbmsDeviceById" parameterType="pd" resultMap="IbmsDeviceResult">
        <include refid="selectIbmsDeviceVo"/>
        where id = #{id}
    </select>

    <insert id="insertIbmsDevice" parameterType="pd" useGeneratedKeys="true" keyProperty="id">
        insert into ibms_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceCode != null and deviceCode != ''">device_code,</if>
            <if test="deviceName != null and deviceName != ''">device_name,</if>
            <if test="deviceType != null and deviceType != ''">device_type,</if>
            <if test="subsystemType != null and subsystemType != ''">subsystem_type,</if>
            <if test="spaceId != null and spaceId != ''">space_id,</if>
            <if test="spaceName != null and spaceName != ''">space_name,</if>
            <if test="brand != null and brand != ''">brand,</if>
            <if test="model != null and model != ''">model,</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number,</if>
            <if test="manufactureDate != null and manufactureDate != ''">manufacture_date,</if>
            <if test="installDate != null and installDate != ''">install_date,</if>
            <if test="warrantyPeriod != null and warrantyPeriod != ''">warranty_period,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="isOnline != null and isOnline != ''">is_online,</if>
            <if test="description != null and description != ''">description,</if>
            <if test="createTime != null and createTime != ''">create_time,</if>
            <if test="updateTime != null and updateTime != ''">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceCode != null and deviceCode != ''">#{deviceCode},</if>
            <if test="deviceName != null and deviceName != ''">#{deviceName},</if>
            <if test="deviceType != null and deviceType != ''">#{deviceType},</if>
            <if test="subsystemType != null and subsystemType != ''">#{subsystemType},</if>
            <if test="spaceId != null and spaceId != ''">#{spaceId},</if>
            <if test="spaceName != null and spaceName != ''">#{spaceName},</if>
            <if test="brand != null and brand != ''">#{brand},</if>
            <if test="model != null and model != ''">#{model},</if>
            <if test="serialNumber != null and serialNumber != ''">#{serialNumber},</if>
            <if test="manufactureDate != null and manufactureDate != ''">#{manufactureDate},</if>
            <if test="installDate != null and installDate != ''">#{installDate},</if>
            <if test="warrantyPeriod != null and warrantyPeriod != ''">#{warrantyPeriod},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="isOnline != null and isOnline != ''">#{isOnline},</if>
            <if test="description != null and description != ''">#{description},</if>
            <if test="createTime != null and createTime != ''">#{createTime},</if>
            <if test="updateTime != null and updateTime != ''">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateIbmsDevice" parameterType="pd">
        update ibms_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceCode != null and deviceCode != ''">device_code = #{deviceCode},</if>
            <if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
            <if test="deviceType != null and deviceType != ''">device_type = #{deviceType},</if>
            <if test="subsystemType != null and subsystemType != ''">subsystem_type = #{subsystemType},</if>
            <if test="spaceId != null and spaceId != ''">space_id = #{spaceId},</if>
            <if test="spaceName != null and spaceName != ''">space_name = #{spaceName},</if>
            <if test="brand != null and brand != ''">brand = #{brand},</if>
            <if test="model != null and model != ''">model = #{model},</if>
            <if test="serialNumber != null and serialNumber != ''">serial_number = #{serialNumber},</if>
            <if test="manufactureDate != null and manufactureDate != ''">manufacture_date = #{manufactureDate},</if>
            <if test="installDate != null and installDate != ''">install_date = #{installDate},</if>
            <if test="warrantyPeriod != null and warrantyPeriod != ''">warranty_period = #{warrantyPeriod},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="isOnline != null and isOnline != ''">is_online = #{isOnline},</if>
            <if test="description != null and description != ''">description = #{description},</if>
            <if test="createTime != null and createTime != ''">create_time = #{createTime},</if>
            <if test="updateTime != null and updateTime != ''">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIbmsDeviceById" parameterType="Long">
        delete from ibms_device where id = #{id}
    </delete>

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