<?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.cclotus.register.mapper.WXUserMapper">

    <resultMap type="com.cclotus.register.domain.WXUser" id="WXUserResult">
        <result property="userId" column="user_id"/>
        <result property="name" column="name"/>
        <result property="photo" column="photo"/>
        <result property="phone" column="phone"/>
        <result property="birthday" column="birthday"/>
        <result property="openid" column="openid"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleted" column="deleted"/>
    </resultMap>

    <sql id="selectWXUserVo">
        select u.user_id,
               u.name,
               u.photo,
               u.phone,
               u.birthday,
               u.openid,
               u.create_time,
               u.update_time,
               u.deleted
        from wx_user u
    </sql>

    <select id="selectWXUserList" parameterType="com.cclotus.register.domain.WXUser" resultMap="WXUserResult">
        <include refid="selectWXUserVo"/>
        where u.deleted = 0
        <if test="name != null  and name != ''">and u.name like concat('%', #{name}, '%')</if>
        <if test="photo != null  and photo != ''">and u.photo = #{photo}</if>
        <if test="phone != null  and phone != ''">and u.phone like concat('%', #{phone}, '%')</if>
        <if test="params.beginBirthday != null and params.beginBirthday != '' and params.endBirthday != null and params.endBirthday != ''">
            and u.birthday between #{params.beginBirthday} and #{params.endBirthday}
        </if>
        <if test="openid != null  and openid != ''">and u.openid = #{openid}</if>
        <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
            and date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
        </if>
        <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
            and date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
        </if>
    </select>

    <select id="selectWXUserByUserId" parameterType="String" resultMap="WXUserResult">
        <include refid="selectWXUserVo"/>
        where u.user_id = #{userId} and u.deleted = 0
    </select>

</mapper>
