<?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="beilv.system.mapper.SysMemberMapper">
    
    <resultMap type="SysMember" id="SysMemberResult">
        <result property="id"    column="id"    />
        <result property="username"    column="username"    />
        <result property="password"    column="password"    />
        <result property="realName"    column="real_name"    />
        <result property="mobile"    column="mobile"    />
        <result property="loginDate"    column="login_date"    />
        <result property="loginIp"    column="login_ip"    />
        <result property="registerIp"    column="register_ip"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="integral"    column="integral"    />
        <result property="wxProfile"    column="wx_profile"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="openId"    column="open_id"    />
    </resultMap>

    <sql id="selectSysMemberVo">
        select id, username, password, real_name, mobile, login_date, login_ip, register_ip, create_by, create_time, update_by, update_time, integral, wx_profile, del_flag, open_id from sys_member
    </sql>

    <select id="selectSysMemberList" parameterType="SysMember" resultMap="SysMemberResult">
        <include refid="selectSysMemberVo"/>
        <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="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="loginDate != null "> and login_date = #{loginDate}</if>
            <if test="loginIp != null  and loginIp != ''"> and login_ip = #{loginIp}</if>
            <if test="registerIp != null  and registerIp != ''"> and register_ip = #{registerIp}</if>
            <if test="integral != null "> and integral = #{integral}</if>
            <if test="wxProfile != null  and wxProfile != ''"> and wx_profile = #{wxProfile}</if>
            <if test="openId != null  and openId != ''"> and open_id = #{openId}</if>
        </where>
    </select>
    
    <select id="selectSysMemberById" parameterType="Long" resultMap="SysMemberResult">
        <include refid="selectSysMemberVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysMember" parameterType="SysMember" useGeneratedKeys="true" keyProperty="id">
        insert into sys_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="realName != null">real_name,</if>
            <if test="mobile != null">mobile,</if>
            <if test="loginDate != null">login_date,</if>
            <if test="loginIp != null">login_ip,</if>
            <if test="registerIp != null">register_ip,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="integral != null">integral,</if>
            <if test="wxProfile != null">wx_profile,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="openId != null">open_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="realName != null">#{realName},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="loginDate != null">#{loginDate},</if>
            <if test="loginIp != null">#{loginIp},</if>
            <if test="registerIp != null">#{registerIp},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="integral != null">#{integral},</if>
            <if test="wxProfile != null">#{wxProfile},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="openId != null">#{openId},</if>
         </trim>
    </insert>

    <update id="updateSysMember" parameterType="SysMember">
        update sys_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="realName != null">real_name = #{realName},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="loginDate != null">login_date = #{loginDate},</if>
            <if test="loginIp != null">login_ip = #{loginIp},</if>
            <if test="registerIp != null">register_ip = #{registerIp},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="wxProfile != null">wx_profile = #{wxProfile},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="openId != null">open_id = #{openId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysMemberById" parameterType="Long">
        delete from sys_member where id = #{id}
    </delete>

    <delete id="deleteSysMemberByIds" parameterType="String">
        delete from sys_member where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectByMobile" parameterType="SysMember" resultMap="SysMemberResult">
        <include refid="selectSysMemberVo"/>
        where mobile = #{mobile} and del_flag = 0
    </select>
</mapper>