<?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.framework.recovery.mapper.WxUserMapper">

    <resultMap type="WxUser" id="WxUserResult">
        <result property="id"    column="id"    />
        <result property="username"    column="username"    />
        <result property="password"    column="password"    />
        <result property="gender"    column="gender"    />
        <result property="birthday"    column="birthday"    />
        <result property="lastLoginTime"    column="last_login_time"    />
        <result property="lastLoginIp"    column="last_login_ip"    />
        <result property="userLevel"    column="user_level"    />
        <result property="nickname"    column="nickname"    />
        <result property="mobile"    column="mobile"    />
        <result property="avatar"    column="avatar"    />
        <result property="wxOpenid"    column="wx_openid"    />
        <result property="status"    column="status"    />
        <result property="addTime"    column="add_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deleted"    column="deleted"    />
        <result property="points"    column="points"    />
        <result property="vipStartTime"    column="vip_start_time"    />
        <result property="vipEndTime"    column="vip_end_time"    />
    </resultMap>

    <sql id="selectWxUserVo">
        select id, username, password, gender, birthday, last_login_time, last_login_ip, user_level, nickname, mobile, avatar, wx_openid, status, add_time, update_time, deleted, points, vip_start_time, vip_end_time from wx_user
    </sql>

    <select id="selectWxUserList" parameterType="WxUser" resultMap="WxUserResult">
        <include refid="selectWxUserVo"/>
        <where>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="gender != null "> and gender = #{gender}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
            <if test="lastLoginTime != null "> and last_login_time = #{lastLoginTime}</if>
            <if test="lastLoginIp != null  and lastLoginIp != ''"> and last_login_ip = #{lastLoginIp}</if>
            <if test="userLevel != null "> and user_level = #{userLevel}</if>
            <if test="nickname != null  and nickname != ''"> and nickname like concat('%', #{nickname}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="wxOpenid != null  and wxOpenid != ''"> and wx_openid = #{wxOpenid}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="addTime != null "> and add_time = #{addTime}</if>
            <if test="deleted != null "> and deleted = #{deleted}</if>
            <if test="points != null "> and points = #{points}</if>
            <if test="vipStartTime != null "> and vip_start_time = #{vipStartTime}</if>
            <if test="vipEndTime != null "> and vip_end_time = #{vipEndTime}</if>
        </where>
    </select>

    <select id="selectWxUserById" parameterType="Long" resultMap="WxUserResult">
        <include refid="selectWxUserVo"/>
        where id = #{id}
    </select>
    <select id="selectWxUserByOpenid" resultMap="WxUserResult">
        <include refid="selectWxUserVo" />
            where wx_openid = #{openid} and status = 0
    </select>

    <insert id="insertWxUser" parameterType="WxUser" useGeneratedKeys="true" keyProperty="id">
        insert into wx_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null and username != ''">username,</if>
            <if test="password != null and password != ''">password,</if>
            <if test="gender != null">gender,</if>
            <if test="birthday != null">birthday,</if>
            <if test="lastLoginTime != null">last_login_time,</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">last_login_ip,</if>
            <if test="userLevel != null">user_level,</if>
            <if test="nickname != null and nickname != ''">nickname,</if>
            <if test="mobile != null and mobile != ''">mobile,</if>
            <if test="avatar != null and avatar != ''">avatar,</if>
            <if test="wxOpenid != null and wxOpenid != ''">wx_openid,</if>
            <if test="status != null">status,</if>
            <if test="addTime != null">add_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleted != null">deleted,</if>
            <if test="points != null">points,</if>
            <if test="vipStartTime != null">vip_start_time,</if>
            <if test="vipEndTime != null">vip_end_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="username != null and username != ''">#{username},</if>
            <if test="password != null and password != ''">#{password},</if>
            <if test="gender != null">#{gender},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="lastLoginTime != null">#{lastLoginTime},</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">#{lastLoginIp},</if>
            <if test="userLevel != null">#{userLevel},</if>
            <if test="nickname != null and nickname != ''">#{nickname},</if>
            <if test="mobile != null and mobile != ''">#{mobile},</if>
            <if test="avatar != null and avatar != ''">#{avatar},</if>
            <if test="wxOpenid != null and wxOpenid != ''">#{wxOpenid},</if>
            <if test="status != null">#{status},</if>
            <if test="addTime != null">#{addTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleted != null">#{deleted},</if>
            <if test="points != null">#{points},</if>
            <if test="vipStartTime != null">#{vipStartTime},</if>
            <if test="vipEndTime != null">#{vipEndTime},</if>
         </trim>
    </insert>

    <update id="updateWxUser" parameterType="WxUser">
        update wx_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="username != null and username != ''">username = #{username},</if>
            <if test="password != null and password != ''">password = #{password},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="lastLoginTime != null">last_login_time = #{lastLoginTime},</if>
            <if test="lastLoginIp != null and lastLoginIp != ''">last_login_ip = #{lastLoginIp},</if>
            <if test="userLevel != null">user_level = #{userLevel},</if>
            <if test="nickname != null and nickname != ''">nickname = #{nickname},</if>
            <if test="mobile != null and mobile != ''">mobile = #{mobile},</if>
            <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
            <if test="wxOpenid != null and wxOpenid != ''">wx_openid = #{wxOpenid},</if>
            <if test="status != null">status = #{status},</if>
            <if test="addTime != null">add_time = #{addTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
            <if test="points != null">points = #{points},</if>
            <if test="vipStartTime != null">vip_start_time = #{vipStartTime},</if>
            <if test="vipEndTime != null">vip_end_time = #{vipEndTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxUserById" parameterType="Long">
        delete from wx_user where id = #{id}
    </delete>

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