<?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.bonus.canteen.core.device.mapper.DeviceGlobalSettingMapper">
    <resultMap type="com.bonus.canteen.core.device.domain.DeviceGlobalSetting" id="DeviceGlobalSettingResult">
        <result property="id"    column="id"    />
        <result property="siteUrl"    column="site_url"    />
        <result property="mqttAddress"    column="mqtt_address"    />
        <result property="mqttUserName"    column="mqtt_user_name"    />
        <result property="mqttPassWord"    column="mqtt_pass_word"    />
        <result property="appId"    column="app_id"    />
        <result property="appKey"    column="app_key"    />
        <result property="facePassRate"    column="face_pass_rate"    />
        <result property="facePrefix"    column="face_prefix"    />
        <result property="faceVersion"    column="face_version"    />
    </resultMap>

    <sql id="selectDeviceGlobalSettingVo">
        select id, site_url, mqtt_address, mqtt_user_name, mqtt_pass_word, app_id, app_key, face_pass_rate, face_prefix, face_version from device_global_setting
    </sql>

    <select id="selectDeviceGlobalSettingList" parameterType="com.bonus.canteen.core.device.domain.DeviceGlobalSetting" resultMap="DeviceGlobalSettingResult">
        <include refid="selectDeviceGlobalSettingVo"/>
        <where>  
            <if test="siteUrl != null  and siteUrl != ''"> and site_url = #{siteUrl}</if>
            <if test="mqttAddress != null  and mqttAddress != ''"> and mqtt_address = #{mqttAddress}</if>
            <if test="mqttUserName != null  and mqttUserName != ''"> and mqtt_user_name like concat('%', #{mqttUserName}, '%')</if>
            <if test="mqttPassWord != null  and mqttPassWord != ''"> and mqtt_pass_word = #{mqttPassWord}</if>
            <if test="appId != null  and appId != ''"> and app_id = #{appId}</if>
            <if test="appKey != null  and appKey != ''"> and app_key = #{appKey}</if>
            <if test="facePassRate != null  and facePassRate != ''"> and face_pass_rate = #{facePassRate}</if>
            <if test="facePrefix != null  and facePrefix != ''"> and face_prefix = #{facePrefix}</if>
            <if test="faceVersion != null  and faceVersion != ''"> and face_version = #{faceVersion}</if>
        </where>
    </select>
    
    <select id="selectDeviceGlobalSettingById" parameterType="Long" resultMap="DeviceGlobalSettingResult">
        <include refid="selectDeviceGlobalSettingVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDeviceGlobalSetting" parameterType="com.bonus.canteen.core.device.domain.DeviceGlobalSetting" useGeneratedKeys="true" keyProperty="id">
        insert into device_global_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="siteUrl != null">site_url,</if>
            <if test="mqttAddress != null">mqtt_address,</if>
            <if test="mqttUserName != null">mqtt_user_name,</if>
            <if test="mqttPassWord != null">mqtt_pass_word,</if>
            <if test="appId != null">app_id,</if>
            <if test="appKey != null">app_key,</if>
            <if test="facePassRate != null">face_pass_rate,</if>
            <if test="facePrefix != null">face_prefix,</if>
            <if test="faceVersion != null">face_version,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="siteUrl != null">#{siteUrl},</if>
            <if test="mqttAddress != null">#{mqttAddress},</if>
            <if test="mqttUserName != null">#{mqttUserName},</if>
            <if test="mqttPassWord != null">#{mqttPassWord},</if>
            <if test="appId != null">#{appId},</if>
            <if test="appKey != null">#{appKey},</if>
            <if test="facePassRate != null">#{facePassRate},</if>
            <if test="facePrefix != null">#{facePrefix},</if>
            <if test="faceVersion != null">#{faceVersion},</if>
         </trim>
    </insert>

    <update id="updateDeviceGlobalSetting" parameterType="com.bonus.canteen.core.device.domain.DeviceGlobalSetting">
        update device_global_setting
        <trim prefix="SET" suffixOverrides=",">
            <if test="siteUrl != null">site_url = #{siteUrl},</if>
            <if test="mqttAddress != null">mqtt_address = #{mqttAddress},</if>
            <if test="mqttUserName != null">mqtt_user_name = #{mqttUserName},</if>
            <if test="mqttPassWord != null">mqtt_pass_word = #{mqttPassWord},</if>
            <if test="appId != null">app_id = #{appId},</if>
            <if test="appKey != null">app_key = #{appKey},</if>
            <if test="facePassRate != null">face_pass_rate = #{facePassRate},</if>
            <if test="facePrefix != null">face_prefix = #{facePrefix},</if>
            <if test="faceVersion != null">face_version = #{faceVersion},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeviceGlobalSettingById" parameterType="Long">
        delete from device_global_setting where id = #{id}
    </delete>

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