<?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.iformall.mapper.WxBuserMapper">
	<resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBuser">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
		<result column="open_id" jdbcType="VARCHAR" property="openId"/>
		<result column="union_id" jdbcType="VARCHAR" property="unionId"/>
		<result column="nick_name" jdbcType="VARCHAR" property="nickName"/>
		<result column="gender" jdbcType="INTEGER" property="gender"/>
		<result column="avatar_url" jdbcType="VARCHAR" property="avatarUrl"/>
		<result column="phone" jdbcType="VARCHAR" property="phone"/>
		<result column="pure_phone" jdbcType="VARCHAR" property="purePhone"/>
		<result column="city" jdbcType="VARCHAR" property="city"/>
		<result column="province" jdbcType="VARCHAR" property="province"/>
		<result column="language" jdbcType="VARCHAR" property="language"/>
		<result column="country_code" jdbcType="VARCHAR" property="countryCode"/>
		<result column="register_ip" jdbcType="VARCHAR" property="registerIp"/>
		<result column="verify_code_phone" jdbcType="VARCHAR" property="verifyCodePhone"/>
		<result column="qrcode_source" jdbcType="VARCHAR" property="qrcodeSource"/>
		<result column="scene" jdbcType="VARCHAR" property="scene"/>
		<result column="scene_address" jdbcType="VARCHAR" property="sceneAddress"/>
		<result column="session_key" jdbcType="VARCHAR" property="sessionKey"/>
		<result column="score" jdbcType="INTEGER" property="score"/>
		<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
		<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
		<result column="app_id" jdbcType="VARCHAR" property="appId"/>
		<result column="token" jdbcType="VARCHAR" property="token"/>
		<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime"/>
		<result column="latitude" jdbcType="DECIMAL" property="latitude"/>
		<result column="longitude" jdbcType="DECIMAL" property="longitude"/>
		<result column="login_count" jdbcType="INTEGER" property="loginCount"/>
		<result column="extra_info" jdbcType="VARCHAR" property="extraInfo"/>
		<result column="is_subscribe" jdbcType="TINYINT" property="isSubscribe"/>
		<result column="open_app_id" jdbcType="VARCHAR" property="openAppId"/>
		<result column="mp_open_id" jdbcType="VARCHAR" property="mpOpenId"/>
		<result column="mp_app_id" jdbcType="VARCHAR" property="mpAppId"/>
		<result column="mp_subscribe" jdbcType="TINYINT" property="mpSubscribe"/>
		<result column="mp_subscribe_time" jdbcType="TIMESTAMP" property="mpSubscribeTime"/>
		<result column="mp_subscribe_scene" jdbcType="VARCHAR" property="mpSubscribeScene"/>
		<result column="subs_open_id" jdbcType="VARCHAR" property="subsOpenId"/>
		<result column="subs_app_id" jdbcType="VARCHAR" property="subsAppId"/>
		<result column="subs_subscribe" jdbcType="TINYINT" property="subsSubscribe"/>
		<result column="subs_subscribe_time" jdbcType="TIMESTAMP" property="subsSubscribeTime"/>
		<result column="subs_subscribe_scene" jdbcType="VARCHAR" property="subsSubscribeScene"/>
		<result column="credit" jdbcType="INTEGER" property="credit"/>
		<result column="active_time" jdbcType="TIMESTAMP" property="activeTime"/>
		<result column="user_id" jdbcType="BIGINT" property="userId"/>
	
	</resultMap>
	
	<sql id="allColumns">
	    `id`,`tenant_id`,`open_id`,`union_id`,`nick_name`,`gender`,`avatar_url`,`phone`,`pure_phone`,
	    `city`,`province`,`language`,`country_code`,`register_ip`,`verify_code_phone`,
	    `qrcode_source`,`scene`,`scene_address`,`session_key`,`score`,
	    `update_date`,`create_date`,`app_id`,`token`,`expire_time`,`latitude`, `longitude`,
	    `login_count`, `extra_info`, `is_subscribe`,`open_app_id`,`user_id`,
	    `mp_open_id`,`mp_app_id`,`mp_subscribe`,`mp_subscribe_time`,`mp_subscribe_scene`,
	    `subs_open_id`,`subs_app_id`,`subs_subscribe`,`subs_subscribe_time`,`subs_subscribe_scene`,`credit`,`active_time`
	</sql>
	
	<sql id="dynamicWhereConditions">
		where 1 = 1
		
		<if test=" null != id ">
			and `id` = #{id}
		</if>
		
		<if test=" null != tenantId ">
			and `tenant_id`= #{tenantId}
		</if>
		
		<if test=" null != openId ">
			and `open_id` = #{openId}
		</if>
		
		<if test=" null != unionId ">
			and `union_id` = #{unionId}
		</if>
		
		<if test=" null != nickName ">
			and `nick_name` like concat('%', #{nickName},'%')
		</if>
		
		<if test=" null != gender ">
			and `gender` = #{gender}
		</if>
		
		<if test=" null != avatarUrl ">
			and `avatar_url` like concat('%', #{avatarUrl},'%')
		</if>
		
		<if test=" null != phone ">
			and `phone` like concat('%', #{phone},'%')
		</if>
		
		<if test=" null != purePhone ">
			and `pure_phone` like concat('%', #{purePhone},'%')
		</if>
		
		<if test=" null != city ">
			and `city` like concat('%', #{city},'%')
		</if>
		
		<if test=" null != province ">
			and `province` like concat('%', #{province},'%')
		</if>
		
		<if test=" null != language ">
			and `language` like concat('%', #{language},'%')
		</if>
		
		<if test=" null != countryCode ">
			and `country_code` like concat('%', #{countryCode},'%')
		</if>
		
		<if test=" null != registerIp ">
			and `register_ip` like concat('%', #{registerIp},'%')
		</if>
		
		<if test=" null != verifyCodePhone ">
			and `verify_code_phone` like concat('%', #{verifyCodePhone},'%')
		</if>
		
		<if test=" null != qrcodeSource ">
			and `qrcode_source` like concat('%', #{qrcodeSource},'%')
		</if>
		
		<if test=" null != scene ">
			and `scene` like concat('%', #{scene},'%')
		</if>
		
		<if test=" null != sceneAddress ">
			and `scene_address` like concat('%', #{sceneAddress},'%')
		</if>
		
		<if test=" null != sessionKey ">
			and `session_key` like concat('%', #{sessionKey},'%')
		</if>
		
		<if test=" null != score ">
			and `score` = #{score}
		</if>
		
		<if test=" null != updateDate ">
			and `update_date` = #{updateDate}
		</if>
		
		<if test=" null != createDate ">
			and `create_date` = #{createDate}
		</if>
		
		<if test=" null != appId ">
			and `app_id` like concat('%', #{appId},'%')
		</if>
		
		<if test=" null != token ">
			and `token` like concat('%', #{token},'%')
		</if>
		
		<if test=" null != expireTime ">
			and `expire_time` = #{expireTime}
		</if>
		
		<if test=" null != latitude ">
			and `latitude` = #{latitude}
		</if>
		
		<if test=" null != longitude ">
			and `longitude` = #{longitude}
		</if>
		
		<if test=" null != loginCount ">
			and `login_count` = #{loginCount}
		</if>
		
		<if test=" null != extraInfo ">
			and `extra_info` = #{extraInfo}
		</if>
		
		<if test=" null != isSubscribe ">
			and `is_subscribe` = #{isSubscribe}
		</if>
		
		<if test=" null != openAppId ">
			and `open_app_id` = #{openAppId}
		</if>
		
		<if test=" null != mpOpenId ">
			and `mp_open_id` = #{mpOpenId}
		</if>
		
		<if test=" null != mpAppId ">
			and `mp_app_id` = #{mpAppId}
		</if>
		
		<if test=" null != subsOpenId ">
			and `subs_open_id` = #{subsOpenId}
		</if>
		
		<if test=" null != subsAppId ">
			and `subs_app_id` = #{subsAppId}
		</if>
		
		<if test=" null != credit ">
			and `credit` = #{credit}
		</if>
		
		<if test=" null != userId ">
			and `user_id` = #{userId}
		</if>
		<if test=" null != ids ">
			and id in
			<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
				#{idItem}
			</foreach>
		</if>
		<if test=" null != sortColumns">order by ${sortColumns}</if>
	</sql>
	
	<select id="findList" parameterType="com.iformall.domain.po.WxBuser" resultMap="BaseResultMap">
		select
		<include refid="allColumns"/>
		from wx_buser
		<include refid="dynamicWhereConditions"/>
	</select>
	
	<select id="findByOpenId" parameterType="com.iformall.domain.po.WxBuser" resultMap="BaseResultMap">
		select * from wx_buser
		where `app_id` = #{appId} and `open_id` =  #{openId}
	</select>
	
	<select id="findByUnionId" parameterType="com.iformall.domain.po.WxBuser" resultMap="BaseResultMap">
		select * from wx_buser
		where `open_app_id` = #{openAppId} and `union_id` =  #{unionId}
	</select>
	
	
	<select id="findByToken" resultMap="BaseResultMap">
		select * from wx_buser
		where `token` = #{token}
	</select>


</mapper>
