<?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.TpBuildingOwnerInfoMapper">
    <select id="selectUserApprove" parameterType="map" resultType="com.community.huiju.model.TpBuildingOwnerInfo" >
        SELECT
        id,
        phase,
        owner_name,
        owner_tel,
        building,
        gender,
        id_card,
        unit,
        LEVEL ,
        room_no,
        create_date,
        verify_status
        FROM
        tp_building_owner_info
        <where>
            <if test="ownerName != null and ownerName != ''" >
                AND owner_name like concat('%',#{ownerName,jdbcType=VARCHAR},'%')

            </if>
            <if test="ownerTel != null and ownerTel != ''" >
                AND owner_tel like concat('%',#{ownerTel,jdbcType=VARCHAR},'%')
            </if>
            <if test="VerifyStatus != null and VerifyStatus != ''" >
                AND  verify_status = #{VerifyStatus,jdbcType=VARCHAR}
            </if>
            <if test="VerifyStatus == null or VerifyStatus == ''" >
                and	(verify_status = 1 or verify_status = 2)
            </if>
            and community_id=#{CommunityId,jdbcType=INTEGER}
            order by create_date desc
        </where>
    </select>

    <insert id="batchInsert" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.ArrayList">
        insert into tp_building_owner_info(community_id,id_card, phase, building,unit, `level`,
        room_no,owner_name,owner_tel,gender,pair_status,verify_status,create_user,create_date,update_user,update_date)
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.communityId},#{item.idCard},#{item.phase},#{item.building},#{item.unit}, #{item.level},#{item.roomNo},#{item.ownerName},
            #{item.ownerTel},#{item.gender},#{item.pairStatus},#{item.verifyStatus},#{item.createUser},#{item.createDate},#{item.updateUser},#{item.updateDate})
        </foreach>
    </insert>

    <update id="batchUpdate" parameterType="java.util.ArrayList">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update tp_building_owner_info
            <set>
                owner_name = #{item.ownerName},
                owner_tel = #{item.ownerTel},
                owner_status = #{item.ownerStatus}
            </set>
            where id = #{item.id}
        </foreach>
    </update>

    <select id="selectListByParams" resultType="com.community.huiju.model.TpBuildingOwnerInfo">
        SELECT
            u.id,
            u.phase_name,
            u.building_name,
            u.unit_name,
            u.level_name,
            u.room_no_name,
            u.id AS userVerifyId,
            u.community_id AS communityId,
            t.login_name AS ownerTel,
            t.user_name AS ownerName,
            t.id_card AS idCard,
            r.description AS roleName,
            u.verify_status AS verifyStatus,
            u.verify_name AS updateName,
            u.create_date AS createDate
        FROM
            ta_user_verify u
            LEFT JOIN ta_user t ON t.id = u.user_id
            LEFT JOIN ta_sys_role r ON u.role_id = r.id
        WHERE

        u.community_id=#{tpBuildingOwnerInfo.communityId,jdbcType=INTEGER}
        <if test="tpBuildingOwnerInfo.phaseId != null and tpBuildingOwnerInfo.phaseId != ''">
            and u.phase_id = #{tpBuildingOwnerInfo.phaseId,jdbcType=INTEGER}
        </if>
        <if test="tpBuildingOwnerInfo.buildingId != null and tpBuildingOwnerInfo.buildingId != ''">
            and u.building_id = #{tpBuildingOwnerInfo.buildingId,jdbcType=INTEGER}
        </if>
        <if test="tpBuildingOwnerInfo.unitId != null and tpBuildingOwnerInfo.unitId != ''">
            and u.unit_id = #{tpBuildingOwnerInfo.unitId,jdbcType=INTEGER}
        </if>
        <if test="tpBuildingOwnerInfo.levelId != null and tpBuildingOwnerInfo.levelId != ''">
            and u.level_id = #{tpBuildingOwnerInfo.levelId,jdbcType=INTEGER}
        </if>
        <if test="tpBuildingOwnerInfo.roomNoId != null and tpBuildingOwnerInfo.roomNoId != ''">
            and u.room_no_id = #{tpBuildingOwnerInfo.roomNoId,jdbcType=INTEGER}
        </if>
        <if test="tpBuildingOwnerInfo.ownerName != null and tpBuildingOwnerInfo.ownerName != ''">
            and t.user_name like concat('%',#{tpBuildingOwnerInfo.ownerName,jdbcType=VARCHAR},'%')
        </if>
        <if test="tpBuildingOwnerInfo.ownerTel != null and tpBuildingOwnerInfo.ownerTel != ''">
            and t.login_name like concat('%',#{tpBuildingOwnerInfo.ownerTel,jdbcType=VARCHAR},'%')
        </if>
        <if test="tpBuildingOwnerInfo.idCard != null and tpBuildingOwnerInfo.idCard != ''">
            and t.id_card like concat('%',#{tpBuildingOwnerInfo.idCard,jdbcType=VARCHAR},'%')
        </if>
        order by u.create_date desc
    </select>
</mapper>
