<?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.system.mapper.ShopUserMapper">

    <select id="selectShopUserByPhone" resultType="com.ruoyi.common.core.domain.entity.ShopUser">
        SELECT * FROM shop_user where phone = #{phone}
    </select>

    <select id="selectShopUserByUsername" resultType="com.ruoyi.common.core.domain.entity.ShopUser">
        SELECT * FROM shop_user where username = #{username}
    </select>

    <select id="selectShopUserByUsernameAndPass" resultType="com.ruoyi.common.core.domain.entity.ShopUser">
        SELECT * FROM shop_user where username = #{username} and password = #{password}
    </select>

    <!-- Insert -->
    <insert id="insert" parameterType="com.ruoyi.common.core.domain.entity.ShopUser" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO shop_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="phone != null">phone,</if>
            <if test="nickname != null">nickname,</if>
            <if test="sex != null">sex,</if>
            <if test="birthday != null">birthday,</if>
            <if test="addr != null">addr,</if>
            <if test="registerTime != null">register_time,</if>
            <if test="status != null">status,</if>
            <if test="vip != null">vip,</if>
            <if test="online != null">online,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="phone != null">#{phone},</if>
            <if test="nickname != null">#{nickname},</if>
            <if test="sex != null">#{sex},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="addr != null">#{addr},</if>
            <if test="registerTime != null">#{registerTime},</if>
            <if test="status != null">#{status},</if>
            <if test="vip != null">#{vip},</if>
            <if test="online != null">#{online},</if>
        </trim>
    </insert>

    <resultMap type="ShopUser" id="ShopUserResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="username"    column="username"    />
        <result property="password"    column="password"    />
        <result property="phone"    column="phone"    />
        <result property="nickname"    column="nickname"    />
        <result property="sex"    column="sex"    />
        <result property="birthday"    column="birthday"    />
        <result property="addr"    column="addr"    />
        <result property="registerTime"    column="register_time"    />
        <result property="status"    column="status"    />
        <result property="vip"    column="vip"    />
        <result property="online"    column="online"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectShopUserVo">
        select id, user_id, username, password, phone, nickname, sex, birthday, addr, register_time, status, vip, online, create_time, update_time, is_del from shop_user
    </sql>

    <select id="selectShopUserList" parameterType="ShopUser" resultMap="ShopUserResult">
        <include refid="selectShopUserVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="nickname != null  and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="addr != null  and addr != ''"> and addr = #{addr}</if>
            <if test="registerTime != null "> and register_time = #{registerTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="vip != null "> and vip = #{vip}</if>
            <if test="online != null  and online != ''"> and online = #{online}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>

    <select id="selectShopUserById" parameterType="String" resultMap="ShopUserResult">
        <include refid="selectShopUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertShopUser" parameterType="ShopUser" useGeneratedKeys="true" keyProperty="id">
        insert into shop_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="phone != null">phone,</if>
            <if test="nickname != null">nickname,</if>
            <if test="sex != null">sex,</if>
            <if test="birthday != null">birthday,</if>
            <if test="addr != null">addr,</if>
            <if test="registerTime != null">register_time,</if>
            <if test="status != null">status,</if>
            <if test="vip != null">vip,</if>
            <if test="online != null">online,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="phone != null">#{phone},</if>
            <if test="nickname != null">#{nickname},</if>
            <if test="sex != null">#{sex},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="addr != null">#{addr},</if>
            <if test="registerTime != null">#{registerTime},</if>
            <if test="status != null">#{status},</if>
            <if test="vip != null">#{vip},</if>
            <if test="online != null">#{online},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
        </trim>
    </insert>

    <update id="updateShopUser" parameterType="ShopUser">
        update shop_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="nickname != null">nickname = #{nickname},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="addr != null">addr = #{addr},</if>
            <if test="registerTime != null">register_time = #{registerTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="vip != null">vip = #{vip},</if>
            <if test="online != null">online = #{online},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteShopUserById" parameterType="String">
        delete from shop_user where id = #{id}
    </delete>


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