<?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.fastbee.deviceInfo.mapper.DeviceInformationWormsMapper">

    <resultMap type="DeviceInformationWorms" id="DeviceInformationWormsResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="deviceBrand"    column="device_brand"    />
        <result property="deviceType"    column="device_type"    />
        <result property="deviceEncoding"    column="device_encoding"    />
        <result property="installationLocation"    column="installation_location"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="nameProject"    column="name_project"    />
        <result property="constructionYear"    column="construction_year"    />
        <result property="dockingMethod"    column="docking_method"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectDeviceInformationWormsVo">
        select id, name, device_brand, device_type, device_encoding, installation_location, longitude, latitude, name_project, construction_year, docking_method, del_flag, create_time, create_by, update_time, update_by from iot_device_information_worms
    </sql>

    <select id="selectDeviceInformationWormsList" parameterType="DeviceInformationWorms" resultMap="DeviceInformationWormsResult">
        <include refid="selectDeviceInformationWormsVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="deviceBrand != null  and deviceBrand != ''"> and device_brand = #{deviceBrand}</if>
            <if test="deviceType != null  and deviceType != ''"> and device_type = #{deviceType}</if>
            <if test="deviceEncoding != null  and deviceEncoding != ''"> and device_encoding = #{deviceEncoding}</if>
            <if test="installationLocation != null  and installationLocation != ''"> and installation_location = #{installationLocation}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="nameProject != null  and nameProject != ''"> and name_project = #{nameProject}</if>
            <if test="constructionYear != null "> and construction_year = #{constructionYear}</if>
            <if test="dockingMethod != null  and dockingMethod != ''"> and docking_method = #{dockingMethod}</if>
        </where>
    </select>

    <select id="selectDeviceInformationWormsById" parameterType="String" resultMap="DeviceInformationWormsResult">
        <include refid="selectDeviceInformationWormsVo"/>
        where device_encoding = #{deviceEncoding}
    </select>

    <insert id="insertDeviceInformationWorms" parameterType="DeviceInformationWorms" useGeneratedKeys="true" keyProperty="id">
        insert into iot_device_information_worms
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="deviceBrand != null">device_brand,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="deviceEncoding != null">device_encoding,</if>
            <if test="installationLocation != null">installation_location,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="nameProject != null">name_project,</if>
            <if test="constructionYear != null">construction_year,</if>
            <if test="dockingMethod != null">docking_method,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="deviceBrand != null">#{deviceBrand},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="deviceEncoding != null">#{deviceEncoding},</if>
            <if test="installationLocation != null">#{installationLocation},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="nameProject != null">#{nameProject},</if>
            <if test="constructionYear != null">#{constructionYear},</if>
            <if test="dockingMethod != null">#{dockingMethod},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateDeviceInformationWorms" parameterType="DeviceInformationWorms">
        update iot_device_information_worms
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="deviceBrand != null">device_brand = #{deviceBrand},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="deviceEncoding != null">device_encoding = #{deviceEncoding},</if>
            <if test="installationLocation != null">installation_location = #{installationLocation},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="nameProject != null">name_project = #{nameProject},</if>
            <if test="constructionYear != null">construction_year = #{constructionYear},</if>
            <if test="dockingMethod != null">docking_method = #{dockingMethod},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeviceInformationWormsById" parameterType="Long">
        delete from iot_device_information_worms where id = #{id}
    </delete>

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