<?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.deviceData.mapper.DeviceManufacturersMapper">

    <resultMap type="DeviceManufacturers" id="DeviceManufacturersResult">
        <result property="id"    column="id"    />
        <result property="endpoint"    column="endpoint"    />
        <result property="manufacturerName"    column="manufacturer_name"    />
        <result property="account"    column="account"    />
        <result property="password"    column="password"    />
        <result property="interfaceDocumentation"    column="interface_documentation"    />
        <result property="apiKey"    column="api_key"    />
        <result property="authid"    column="authId"    />
        <result property="secretKey"    column="secret_key"    />
        <result property="tokenendpoint"    column="tokenEndpoint"    />
        <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"    />
        <result property="manufacturerType"    column="manufacturer_type"    />
        <result property="code"    column="code"    />
    </resultMap>

    <sql id="selectDeviceManufacturersVo">
        select id, endpoint, manufacturer_name, account, password, interface_documentation, api_key, authId, secret_key, tokenEndpoint, del_flag, create_time, create_by, update_time, update_by, manufacturer_type, code from iot_device_manufacturers
    </sql>

    <select id="selectDeviceManufacturersList" parameterType="DeviceManufacturers" resultMap="DeviceManufacturersResult">
        <include refid="selectDeviceManufacturersVo"/>
        <where>
            <if test="endpoint != null  and endpoint != ''"> and endpoint = #{endpoint}</if>
            <if test="manufacturerName != null  and manufacturerName != ''"> and manufacturer_name like concat('%', #{manufacturerName}, '%')</if>
            <if test="account != null  and account != ''"> and account = #{account}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="interfaceDocumentation != null  and interfaceDocumentation != ''"> and interface_documentation = #{interfaceDocumentation}</if>
            <if test="apiKey != null  and apiKey != ''"> and api_key = #{apiKey}</if>
            <if test="authid != null  and authid != ''"> and authId = #{authid}</if>
            <if test="secretKey != null  and secretKey != ''"> and secret_key = #{secretKey}</if>
            <if test="tokenendpoint != null  and tokenendpoint != ''"> and tokenEndpoint = #{tokenendpoint}</if>
            <if test="manufacturerType != null  and manufacturerType != ''"> and manufacturer_type = #{manufacturerType}</if>
            <if test="code != null "> and code = #{code}</if>
        </where>
    </select>

    <select id="selectDeviceManufacturersById" parameterType="Long" resultMap="DeviceManufacturersResult">
        <include refid="selectDeviceManufacturersVo"/>
        where id = #{id}
    </select>

    <insert id="insertDeviceManufacturers" parameterType="DeviceManufacturers" useGeneratedKeys="true" keyProperty="id">
        insert into iot_device_manufacturers
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="endpoint != null">endpoint,</if>
            <if test="manufacturerName != null">manufacturer_name,</if>
            <if test="account != null">account,</if>
            <if test="password != null">password,</if>
            <if test="interfaceDocumentation != null">interface_documentation,</if>
            <if test="apiKey != null">api_key,</if>
            <if test="authid != null">authId,</if>
            <if test="secretKey != null">secret_key,</if>
            <if test="tokenendpoint != null">tokenEndpoint,</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>
            <if test="manufacturerType != null">manufacturer_type,</if>
            <if test="code != null">code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="endpoint != null">#{endpoint},</if>
            <if test="manufacturerName != null">#{manufacturerName},</if>
            <if test="account != null">#{account},</if>
            <if test="password != null">#{password},</if>
            <if test="interfaceDocumentation != null">#{interfaceDocumentation},</if>
            <if test="apiKey != null">#{apiKey},</if>
            <if test="authid != null">#{authid},</if>
            <if test="secretKey != null">#{secretKey},</if>
            <if test="tokenendpoint != null">#{tokenendpoint},</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>
            <if test="manufacturerType != null">#{manufacturerType},</if>
            <if test="code != null">#{code},</if>
        </trim>
    </insert>

    <update id="updateDeviceManufacturers" parameterType="DeviceManufacturers">
        update iot_device_manufacturers
        <trim prefix="SET" suffixOverrides=",">
            <if test="endpoint != null">endpoint = #{endpoint},</if>
            <if test="manufacturerName != null">manufacturer_name = #{manufacturerName},</if>
            <if test="account != null">account = #{account},</if>
            <if test="password != null">password = #{password},</if>
            <if test="interfaceDocumentation != null">interface_documentation = #{interfaceDocumentation},</if>
            <if test="apiKey != null">api_key = #{apiKey},</if>
            <if test="authid != null">authId = #{authid},</if>
            <if test="secretKey != null">secret_key = #{secretKey},</if>
            <if test="tokenendpoint != null">tokenEndpoint = #{tokenendpoint},</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>
            <if test="manufacturerType != null">manufacturer_type = #{manufacturerType},</if>
            <if test="code != null">code = #{code},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeviceManufacturersById" parameterType="Long">
        delete from iot_device_manufacturers where id = #{id}
    </delete>

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