<?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.xunhong.erp.turbo.user.infrastructure.mapper.UserMapper">
	<resultMap id="BaseResultMap"
			   type="com.xunhong.erp.turbo.user.infrastructure.entity.UserDO">
		<result property="userId" column="user_id" jdbcType="INTEGER"/>
		<result property="nickname" column="nickname" jdbcType="VARCHAR"/>
		<result property="avatar" column="avatar" jdbcType="VARCHAR"/>
		<result column="name" property="name" jdbcType="VARCHAR"/>
		<result column="birthday" property="birthday" jdbcType="VARCHAR"/>
		<result column="phone" property="phone" jdbcType="VARCHAR"
				typeHandler="com.xunhong.erp.turbo.datasource.handler.AesEncryptTypeHandler"/>
		<result column="gender" property="gender" jdbcType="INTEGER"/>
		<result property="state" column="state" jdbcType="INTEGER"/>
		<result property="remark" column="remark" jdbcType="VARCHAR"/>
		<result property="bindPhoneAt" column="bind_phone_at"/>
		<result property="lastLoginAt" column="last_login_at"/>
		<result property="mpOpenid" column="mp_openid" jdbcType="VARCHAR"/>
		<result property="maOpenid" column="ma_openid" jdbcType="VARCHAR"/>
		<result property="unionid" column="unionid" jdbcType="VARCHAR"/>
		<result property="isAdmin" column="is_admin" jdbcType="BOOLEAN"/>
		<result property="isPartner" column="is_partner" jdbcType="BOOLEAN"/>
		<result property="createdAt" column="created_at"/>
		<result property="updatedAt" column="updated_at"/>
		<result property="isDelete" column="is_delete"/>
		<result property="version" column="version"/>
	</resultMap>

	<select id="selectPage"
			resultType="com.xunhong.erp.turbo.user.infrastructure.entity.UserDO"
			resultMap="BaseResultMap">
		SELECT u.*
		FROM user u
		<where>
			u.is_delete = 0
			<if test="query.userIdList != null and query.userIdList.size() > 0">
				and u.user_id in
				<foreach collection="query.userIdList" item="userId"
						 open="(" separator="," close=")">
					#{userId}
				</foreach>
			</if>
			<if test="query.excludeUserIdList != null and query.excludeUserIdList.size() > 0">
				and u.user_id not in
				<foreach collection="query.excludeUserIdList" item="userId"
						 open="(" separator="," close=")">
					#{userId}
				</foreach>
			</if>
			<if test="ew != null">
				<if test="ew.nonEmptyOfWhere">
					AND
				</if>
				${ew.sqlSegment}
			</if>

		</where>
	</select>
</mapper>
