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

    <select id="getPushUrl" resultType="java.lang.String">
        SELECT spc.push_url
        FROM face_device as fd
                 LEFT JOIN system_push_config as spc
                           on fd.admin_id = spc.account_id
        WHERE fd.sn = #{deviceSn}
          and spc.`status` = '1'
          and spc.type = '1'
    </select>
    <select id="getUserVisitorPushUrl" resultType="java.lang.String">
        SELECT spc.push_url
        FROM user_visitor_list as uvl
                 LEFT JOIN system_push_config as spc
                           on uvl.admin_id = spc.account_id
        WHERE spc.`status` = '1'
          and spc.type = '1'
          and uvl.admin_id = #{adminId}
          and uvl.phone = #{phone}
    </select>
    <select id="selectList" resultType="com.yx.face.entity.SystemPushConfig">
        SELECT account_id as accountId, push_url as pushUrl
        FROM system_push_config
        WHERE type = #{type}
          AND `status` = '1'
    </select>
    <select id="getAdmin" resultType="com.yx.face.entity.Admin">
        SELECT province_id as provinceId, city_id as cityId, tag_id as tagId, type as type, id
        FROM admin
        WHERE id = #{id}
    </select>
    <select id="checkSn" resultType="java.lang.String">
        SELECT
        fd.sn
        FROM face_device fd
        left join admin a on a.id = fd.admin_id
        <where>
            <if test="admin.type == 1">

            </if>
            <if test="admin.type == 2">
                and a.province_id = #{admin.provinceId}
                and a.type in (3 ,4 ,5)
            </if>
            <if test="admin.type == 3">
                and a.province_id = #{admin.provinceId}
                and a.type in (4 , 5)
                and a.tag_id = #{admin.tagId}
            </if>
            <if test="admin.type == 4">
                and a.city_id = #{admin.cityId}
                and a.type = 5
                and a.tag_id = #{admin.tagId}
            </if>
            <if test="admin.type == 5">
                and a.id =#{admin.id}
            </if>
            <if test="sn != null and sn !=''">
                and fd.sn = #{sn}
            </if>
        </where>
    </select>
    <select id="checkPhone" resultType="java.lang.String">
        select
        uw.phone
        from
        user_visitor_list uw left join admin a on a.id =uw.admin_id
        <where>
            <if test="admin.type == 2">
                and a.province_id = #{admin.provinceId}
                and a.type in (3 ,4 ,5)
            </if>
            <if test="admin.type == 3">
                and a.province_id = #{admin.provinceId}
                and a.type in (4 , 5)
                and a.tag_id = #{admin.tagId}
            </if>
            <if test="admin.type == 4">
                and a.city_id = #{admin.cityId}
                and a.type = 5
                and a.tag_id = #{admin.tagId}
            </if>
            <if test="admin.type == 5">
                and a.id =#{admin.id}
            </if>
            <if test="phone != null and phone !=''">
                AND uw.phone = #{phone}
            </if>
        </where>
    </select>
</mapper>

