<?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.ruoyi.ss.wifi.mapper.WifiMapper">

    <resultMap type="WifiVO" id="WifiResult" autoMapping="true" />

    <sql id="selectWifiVo">
        select
            w.wifi_id,
            w.wifi,
            w.password,
            w.store_id,
            w.merchant_id,
            w.create_by,
            w.create_time,
            m.user_name merchantName
        from ss_wifi w
        left join ss_user m on w.merchant_id = m.user_id
    </sql>

    <sql id="searchCondition">
        <if test="query.wifi != null  and query.wifi != ''"> and w.wifi = #{query.wifi}</if>
        <if test="query.password != null  and query.password != ''"> and w.password = #{query.password}</if>
        <if test="query.storeId != null "> and w.store_id = #{query.storeId}</if>
        <if test="query.merchantId != null "> and w.merchant_id = #{query.merchantId}</if>
    </sql>

    <select id="selectWifiList" parameterType="WifiQuery" resultMap="WifiResult">
        <include refid="selectWifiVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectWifiByWifiId" parameterType="Long" resultMap="WifiResult">
        <include refid="selectWifiVo"/>
        where w.wifi_id = #{wifiId}
    </select>

    <insert id="insertWifi" parameterType="Wifi">
        insert into ss_wifi
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="wifiId != null">wifi_id,</if>
            <if test="wifi != null">wifi,</if>
            <if test="password != null">password,</if>
            <if test="storeId != null">store_id,</if>
            <if test="merchantId != null">merchant_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="wifiId != null">#{wifiId},</if>
            <if test="wifi != null">#{wifi},</if>
            <if test="password != null">#{password},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="merchantId != null">#{merchantId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateWifi" parameterType="Wifi">
        update ss_wifi
        <trim prefix="SET" suffixOverrides=",">
            <include refid="updateColumns"/>
        </trim>
        where wifi_id = #{data.wifiId}
    </update>

    <sql id="updateColumns">
        <if test="data.wifi != null">wifi = #{data.wifi},</if>
        <if test="data.password != null">password = #{data.password},</if>
        <if test="data.storeId != null">store_id = #{data.storeId},</if>
        <if test="data.merchantId != null">merchant_id = #{data.merchantId},</if>
        <if test="data.createBy != null">create_by = #{data.createBy},</if>
        <if test="data.createTime != null">create_time = #{data.createTime},</if>
    </sql>

    <delete id="deleteWifiByWifiId" parameterType="Long">
        delete from ss_wifi where wifi_id = #{wifiId}
    </delete>

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