<?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.community.huiju.dao.TaUserVerifyMapper">

    <select id="selectAllByPhoneAndUserNameAndIdCard" resultType="com.community.huiju.model.TaUserVerify" >
        select
            tav.*,
            tu.user_name as userName,
            tu.login_name as phone,
            tu.id_card as idCard,
            tu.gender as gender
        from
          ta_user_verify tav LEFT JOIN ta_user tu on tav.user_id = tu.id
        <where>
            <trim suffixOverrides="and | or">
                tav.verify_status = 0
                <if test="phone != null and phone != ''">
                    and tu.login_name like CONCAT('%',#{phone},'%')
                </if>
                <if test="userName != null and userName != ''">
                    and tu.user_name like CONCAT('%',#{userName},'%')
                </if>
                <if test="idCard != null and idCard != ''">
                    and tu.id_card like CONCAT('%',#{idCard},'%')
                </if>
                <if test="communityId != null and communityId != ''">
                    and tav.community_id = #{communityId,jdbcType=INTEGER}
                </if>
            </trim>
        </where>
    </select>


    <select id="selectCommunityAndAddress" resultType="com.community.huiju.model.TaUserVerify">
        select
        *
        from ta_user_verify
        where community_id = #{communityId,jdbcType=INTEGER}
        and phase_id = #{phaseId,jdbcType=INTEGER}
        and building_id = #{buildingId,jdbcType=INTEGER}
        and unit_id = #{unitId,jdbcType=INTEGER}
        and level_id = #{levelId,jdbcType=INTEGER}
        and room_no_id = #{roomNoId,jdbcType=INTEGER}
        and verify_status = 1
        and role_id = 1
    </select>

    <select id="selectCommunityAndAddressAndRoleId" resultType="com.community.huiju.model.TaUserVerify">
        select
        *
        from ta_user_verify
        where community_id = #{communityId,jdbcType=INTEGER}
        and phase_id = #{phaseId,jdbcType=INTEGER}
        and building_id = #{buildingId,jdbcType=INTEGER}
        and unit_id = #{unitId,jdbcType=INTEGER}
        and level_id = #{levelId,jdbcType=INTEGER}
        and room_no_id = #{roomNoId,jdbcType=INTEGER}
        and verify_status = 1
        and user_id = #{userId}
        and role_id = #{roleId}
    </select>

    <select id="selectUserVerifyCommunityAndAddress" resultType="com.community.huiju.model.TaUserVerify">
        select
          *
        from ta_user_verify
        where community_id = #{communityId,jdbcType=INTEGER}
        and user_id = #{userId,jdbcType=INTEGER}
        and phase_id = #{phaseId,jdbcType=INTEGER}
        and building_id = #{buildingId,jdbcType=INTEGER}
        and unit_id = #{unitId,jdbcType=INTEGER}
        and level_id = #{levelId,jdbcType=INTEGER}
        and room_no_id = #{roomNoId,jdbcType=INTEGER}
        <if test="verifyStatus != null and verifyStatus != ''">
            and verify_status = #{verifyStatus}
        </if>
    </select>
</mapper>
