<?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="mobile"    column="mobile"    />
        <result property="sex"    column="sex"    />
        <result property="address"    column="address"    />
        <result property="city"    column="city"    />
        <result property="email"    column="email"    />
        <result property="birthday"    column="birthday"    />
        <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="delFlag"    column="del_flag"    />
        <result property="openId"    column="open_id"    />
    </resultMap>

    <sql id="selectSysMemberVo">
        select id,
               username,
               mobile,
               sex,
               address,
               city,
               email,
               birthday,
               create_by,
               create_time,
               update_by,
               update_time,
               integral,
               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="mobile != null  and mobile != ''"> and mobile like concat('%', #{mobile}, '%')</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="mobile != null">mobile,</if>
            <if test="sex != null">sex,</if>
            <if test="address != null">address,</if>
            <if test="city != null">city,</if>
            <if test="email != null">email,</if>
            <if test="birthday != null">birthday,</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="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="mobile != null">#{mobile},</if>
            <if test="sex != null">#{sex},</if>
            <if test="address != null">addressmobile},</if>
            <if test="city != null">#{city},</if>
            <if test="email != null">#{email},</if>
            <if test="birthday != null">#{birthday},</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="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="mobile != null">mobile = #{mobile},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="address != null">address = #{address},</if>
            <if test="city != null">city = #{city},</if>
            <if test="email != null">email = #{email},</if>
            <if test="birthday != null">birthday = #{birthday},</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="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 open_id = #{openId} and del_flag = 0
    </select>

    <insert id="createUserIfAbsent" parameterType="SysMember" useGeneratedKeys="true" keyProperty="id">
        insert into sys_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="username != null">username,</if>
            <if test="mobile != null">mobile,</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="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="mobile != null">#{mobile},</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="delFlag != null">#{delFlag},</if>
            <if test="openId != null">#{openId},</if>
        </trim>
    </insert>
</mapper>