<?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.tourism.webadmin.back.dao.TourUserMapper">
    <resultMap id="BaseResultMap" type="com.tourism.webadmin.back.model.TourUser">
        <id column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="login_name" jdbcType="VARCHAR" property="loginName"/>
        <result column="password" jdbcType="VARCHAR" property="password"/>
        <result column="show_name" jdbcType="VARCHAR" property="showName"/>
        <result column="head_image_url" jdbcType="VARCHAR" property="headImageUrl"/>
        <result column="user_status" jdbcType="INTEGER" property="userStatus"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
        <result column="sex" jdbcType="CHAR" property="sex"/>
        <result column="birthday" jdbcType="DATE" property="birthday"/>
        <result column="create_user_id" jdbcType="BIGINT" property="createUserId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_user_id" jdbcType="BIGINT" property="updateUserId"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="deleted_flag" jdbcType="INTEGER" property="deletedFlag"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="job" jdbcType="VARCHAR" property="job"/>
        <result column="personal_sign" jdbcType="VARCHAR" property="personalSign"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO tour_user
            (user_id,
            login_name,
            password,
            show_name,
            head_image_url,
            user_status,
            email,
            mobile,
            sex,
            birthday,
            create_user_id,
            create_time,
            update_user_id,
            update_time,
            deleted_flag,
            address,
            job,
            personal_sign)
        VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.userId},
            #{item.loginName},
            #{item.password},
            #{item.showName},
            #{item.headImageUrl},
            #{item.userStatus},
            #{item.email},
            #{item.mobile},
            #{item.sex},
            #{item.birthday},
            #{item.createUserId},
            #{item.createTime},
            #{item.updateUserId},
            #{item.updateTime},
            #{item.deletedFlag},
            #{item.address},
            #{item.job}),
            #{item.personalSign}
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.webadmin.back.dao.TourUserMapper.inputFilterRef"/>
        AND tour_user.deleted_flag = ${@com.tourism.common.core.constant.GlobalDeletedFlag@NORMAL}
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="tourUserFilter != null">
            <if test="tourUserFilter.loginName != null and tourUserFilter.loginName != ''">
                <bind name = "safeTourUserLoginName" value = "'%' + tourUserFilter.loginName + '%'" />
                AND tour_user.login_name LIKE #{safeTourUserLoginName}
            </if>
            <if test="tourUserFilter.showName != null and tourUserFilter.showName != ''">
                <bind name = "safeTourUserShowName" value = "'%' + tourUserFilter.showName + '%'" />
                AND tour_user.show_name LIKE #{safeTourUserShowName}
            </if>
            <if test="tourUserFilter.userStatus != null">
                AND tour_user.user_status = #{tourUserFilter.userStatus}
            </if>
            <if test="tourUserFilter.email != null and tourUserFilter.email != ''">
                <bind name = "safeTourUserEmail" value = "'%' + tourUserFilter.email + '%'" />
                AND tour_user.email LIKE #{safeTourUserEmail}
            </if>
            <if test="tourUserFilter.mobile != null and tourUserFilter.mobile != ''">
                <bind name = "safeTourUserMobile" value = "'%' + tourUserFilter.mobile + '%'" />
                AND tour_user.mobile LIKE #{safeTourUserMobile}
            </if>
            <if test="tourUserFilter.sex != null and tourUserFilter.sex != ''">
                AND tour_user.sex = #{tourUserFilter.sex}
            </if>
            <if test="tourUserFilter.searchString != null and tourUserFilter.searchString != ''">
                <bind name = "safeTourUserSearchString" value = "'%' + tourUserFilter.searchString + '%'" />
                AND CONCAT(IFNULL(tour_user.login_name,''), IFNULL(tour_user.show_name,''), IFNULL(tour_user.email,''), IFNULL(tour_user.mobile,'')) LIKE #{safeTourUserSearchString}
            </if>
        </if>
    </sql>

    <select id="getTourUserList" resultMap="BaseResultMap" parameterType="com.tourism.webadmin.back.model.TourUser">
        SELECT * FROM tour_user
        <where>
            <include refid="filterRef"/>
        </where>
        <if test="orderBy != null and orderBy != ''">
            ORDER BY ${orderBy}
        </if>
    </select>
</mapper>
