<?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.cmvr.device.mapper.DeDeviceRegistrationMapper">
    
    <resultMap type="DeDeviceRegistration" id="DeDeviceRegistrationResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remake"    column="remake"    />
        <result property="idDeDeviceTerminalConfig"    column="id_de_device_terminal_config"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceModel"    column="device_model"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectDeDeviceRegistrationVo">
        select id, create_by, create_time, update_by, update_time, remake, id_de_device_terminal_config, device_code, device_name, device_model, status from de_device_registration
    </sql>

    <select id="selectDeDeviceRegistrationList" parameterType="DeDeviceRegistration" resultMap="DeDeviceRegistrationResult">
        <include refid="selectDeDeviceRegistrationVo"/>
        <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="deviceModel != null  and deviceModel != ''"> and device_model = #{deviceModel}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectDeDeviceRegistrationById" parameterType="String" resultMap="DeDeviceRegistrationResult">
        <include refid="selectDeDeviceRegistrationVo"/>
        where id = #{id}
    </select>


    <select id="selectDeviceModelById" resultType="java.lang.String">
        select device_model from de_device_registration where id = #{id}
    </select>

    <select id="selectAllDeviceCode" resultType="java.lang.String">
        select device_code from de_device_registration
    </select>

    <insert id="insertDeDeviceRegistration" parameterType="DeDeviceRegistration">
        insert into de_device_registration
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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>
            <if test="remake != null">remake,</if>
            <if test="idDeDeviceTerminalConfig != null">id_de_device_terminal_config,</if>
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="deviceModel != null">device_model,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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>
            <if test="remake != null">#{remake},</if>
            <if test="idDeDeviceTerminalConfig != null">#{idDeDeviceTerminalConfig},</if>
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceModel != null">#{deviceModel},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateDeDeviceRegistration" parameterType="DeDeviceRegistration">
        update de_device_registration
        <trim prefix="SET" suffixOverrides=",">
            <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>
            <if test="remake != null">remake = #{remake},</if>
            <if test="idDeDeviceTerminalConfig != null">id_de_device_terminal_config = #{idDeDeviceTerminalConfig},</if>
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceModel != null">device_model = #{deviceModel},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeDeviceRegistrationById" parameterType="String">
        delete from de_device_registration where id = #{id}
    </delete>

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