<?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.yx.face.dao.UserWhitelistDao">
    <select id="setUserOne" resultType="java.lang.Long">
        SELECT ui.id
        FROM user_whitelist AS uw
                 LEFT JOIN user_info AS ui
                           ON uw.phone = ui.phone
        WHERE uw.id = #{id}
          AND uw.admin_id = #{adminId}
    </select>

    <select id="setUserId" resultType="java.lang.Long">
        SELECT ui.id
        FROM user_whitelist as uw
                 LEFT JOIN user_info as ui
                           on uw.phone = ui.phone
        WHERE uw.id = #{id}
    </select>


    <select id="getByPhoneAndId" resultType="com.yx.face.model.entity.UserWhitelist">
        select id
        from user_whitelist
        <where>
            and phone =#{phone}
            <if test="id != null">
                and id != #{id}
            </if>
            <if test="adminId != null">
                and admin_id = #{adminId}
            </if>
        </where>
    </select>

    <select id="selectListBySearch" resultType="com.yx.face.model.vo.UserWhitelistVO">
        select
        uw.*,
        a.username as username,
        a.province_name as provinceName,
        a.city_name as cityName,
        a.area_name as areaName,
        a.street_name as streetName,
        a.address as address,
        a.police_station_name as policeStationName
        from
        user_whitelist uw left join admin a on a.id =uw.admin_id
        <where>
            <if test="adminVo.type == 1">

            </if>
            <if test="adminVo.type == 2">
                and a.province_id = #{adminVo.provinceId}
                and a.type in (3 ,4 ,5)
            </if>
            <if test="adminVo.type == 3">
                and a.province_id = #{adminVo.provinceId}
                and a.type in (4 , 5)
                and a.tag_id = #{adminVo.tagId}
            </if>
            <if test="adminVo.type == 4">
                and a.city_id = #{adminVo.cityId}
                and a.type = 5
                and a.tag_id = #{adminVo.tagId}
            </if>
            <if test="adminVo.type == 5">
                and a.id =#{adminVo.adminId}
            </if>


            <if test="uws.name != null and uws.name !=''">
                AND uw.name LIKE CONCAT('%',#{uws.name},'%')
            </if>
            <if test="uws.phone != null and uws.phone !=''">
                AND uw.phone = #{uws.phone}
            </if>
            <if test="uws.idNumber != null and uws.idNumber !=''">
                AND uw.id_number = #{uws.idNumber}
            </if>
            <if test="uws.username != null and uws.username !=''">
                AND a.username = #{uws.username}
            </if>
            <if test="uws.provinceId != null">
                and a.province_id =#{uws.provinceId}
            </if>
            <if test="uws.cityId != null">
                and a.city_id =#{uws.cityId}
            </if>
            <if test="uws.areaId != null">
                and a.area_id =#{uws.areaId}
            </if>
        </where>
        order by uw.create_time desc
    </select>
    <select id="selectList" resultType="com.yx.face.model.vo.UserWhitelistVO">
        SELECT ui.id, uw.id as snId, uw.avatar, ui.username as name, ui.id_number as idNumber
        FROM user_whitelist as uw
                 LEFT JOIN user_info as ui
                           on uw.phone = ui.phone
        WHERE uw.`status` = 1
          AND uw.admin_id = #{userId}
    </select>
    <select id="selectListOne" resultType="com.yx.face.model.vo.UserWhitelistVO">
        SELECT ui.id, uw.id as snId, uw.avatar, ui.username as name, ui.id_number as idNumber, uw.admin_id as adminId
        FROM user_whitelist as uw
                 LEFT JOIN user_info as ui
                           on uw.phone = ui.phone
        WHERE uw.id = #{id}
    </select>
    <select id="selectId" resultType="java.lang.Long">
        SELECT uw.id
        FROM user_info AS ui
        LEFT JOIN user_whitelist AS uw
        ON ui.phone = uw.phone
        WHERE uw.admin_id = #{adminId}
        AND ui.id IN
        <foreach collection="userIds" index="index" item="userId" open="(" close=")" separator=",">
            #{userId}
        </foreach>
    </select>
</mapper>

