<?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.AdminDao">

    <select id="getAdmins" resultType="com.yx.face.model.vo.AdminVO">
        SELECT
        a.id AS adminId,
        a.nickname AS name,
        a.username AS username,
        a.avatar AS avatar,
        a.phone AS phone,
        a.email AS email,
        a.gender AS gender,
        a.type AS type,
        a.create_time AS createTime,
        a.province_id as provinceId,
        a.province_name as provinceName,
        a.city_id as cityId,
        a.city_name as cityName,
        a.area_id as areaId,
        a.area_name as areaName,
        a.street_id as streetId,
        a.street_name as streetName,
        a.address as address,
        a.police_station_code as policeStationCode,
        a.police_station_name as policeStationName,
        a.tag_id as tagId,
        at.name as tagName,
        a.is_out as isOut,
        a.is_hide_important as isHideImportant,
        a.is_control_early_warning as isControlEarlyWarning
        FROM admin a left join admin_tag at on at.id = a.tag_id
        <where>
            <if test="type == 1">
                and a.type != 1
            </if>
            <if test="type == 2">
                and a.province_id = #{adminVo.provinceId}
                and a.type in (3 ,4 ,5)
            </if>
            <if test="type == 3">
                and a.province_id = #{adminVo.provinceId}
                and a.type in (4 ,5)
                and a.tag_id = #{adminVo.tagId}
            </if>
            <if test="type == 4">
                and a.city_id = #{adminVo.cityId}
                and a.type = 5
                and a.tag_id = #{adminVo.tagId}
            </if>
            <if test="type == 5">
                and a.id = #{adminVo.adminId}
            </if>
            <if test="ads.username != null and ads.username !=''">
                and a.username = #{ads.username}
            </if>
            <if test="ads.name != null and ads.name !=''">
                and a.nickname LIKE CONCAT('%',#{ads.name},'%')
            </if>
            <if test="ads.phone != null and ads.phone !=''">
                and a.phone = #{ads.phone}
            </if>
            <if test="ads.provinceId != null">
                and a.province_id =#{ads.provinceId}
            </if>
            <if test="ads.cityId != null">
                and a.city_id =#{ads.cityId}
            </if>
            <if test="ads.areaId != null">
                and a.area_id =#{ads.areaId}
            </if>
            <if test="ads.type != null">
                and a.type =#{ads.type}
            </if>
            <if test="ads.tagId != null">
                and a.tag_id =#{ads.tagId}
            </if>

        </where>
        order by a.create_time desc
    </select>

    <select id="getAuthInfo" resultType="com.yx.face.model.vo.AdminVO">
        SELECT id       AS adminId,
               nickname AS name,
               type     AS type,
               password AS password
        FROM admin
        WHERE id = #{id}
    </select>
    <select id="getAdminlist" resultType="com.yx.face.model.vo.AdminVO">
        select
        a.id AS adminId,
        a.username AS username
        FROM admin a
        <where>
            <if test="type == 1">
                and a.type != 1
            </if>
            <if test="type == 2">
                and a.province_id = #{provinceId}
                and a.type in (3 ,4 ,5)
            </if>
            <if test="type == 3">
                and a.province_id = #{provinceId}
                and a.type in (4 ,5)
                and a.tag_id = #{tagId}
            </if>
            <if test="type == 4">
                and a.city_id = #{cityId}
                and a.type = 5
                and a.tag_id = #{tagId}
            </if>
            <if test="type == 5">
                and a.id = #{adminId}
            </if>
        </where>
    </select>
    <select id="getAdminLsit" resultType="com.yx.face.model.vo.AdminVO">
        select
            a.id AS adminId,
            a.username AS username
        FROM admin a
        where a.type = #{type}
    </select>
    <select id="getAdminListSearch" resultType="java.lang.Long">
        SELECT
            id
        from admin a
        <where>
            <if test="adminVo.type == 1">

            </if>
            <if test="adminVo.type == 2">
                and a.province_id = #{adminVo.provinceId}
                and a.type =5
            </if>
            <if test="adminVo.type == 3">
                and a.province_id = #{adminVo.provinceId}
                and a.type =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="query.username != null and query.username !=''">
                and a.username = #{query.username}
            </if>
            <if test="query.provinceId != null">
                and a.province_id =#{query.provinceId}
            </if>
            <if test="query.cityId != null">
                and a.city_id =#{query.cityId}
            </if>
            <if test="query.areaId != null">
                and a.area_id =#{query.areaId}
            </if>
        </where>
    </select>
    <select id="getByAdminlist" resultType="com.yx.face.model.vo.AdminVO">
        select
        id as adminId,
        username
        from admin
        <where>
            <if test="list !=null and list.size()>0">
            and id in
                <foreach collection="list" index="index" item="adminId" open="(" close=")" separator=",">
                    #{adminId}
                </foreach>
            </if>
        </where>
    </select>

</mapper>

