<?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.ruoyi.system.mapper.HouseLandlordMapper">
    
    <resultMap type="HouseLandlord" id="HouseLandlordResult">
        <result property="houseLandlordId"    column="house_landlord_id"    />
        <result property="portalId"    column="portal_id"    />
        <result property="houseAddress"    column="house_address"    />
        <result property="idcard"    column="idcard"    />
        <result property="name"    column="name"    />
        <result property="birthday"    column="birthday"    />
        <result property="gender"    column="gender"    />
        <result property="type"    column="type"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="isPatriarch"    column="is_patriarch"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectHouseLandlordVo">
        select house_landlord_id, portal_id, house_address, idcard, name, birthday, gender, type, phone_number, is_patriarch, create_by, create_time, update_by, update_time, remark from house_landlord
    </sql>

    <select id="selectHouseLandlordList" parameterType="HouseLandlord" resultMap="HouseLandlordResult">
        <include refid="selectHouseLandlordVo"/>
        <where>  
            <if test="portalId != null "> and portal_id = #{portalId}</if>
            <if test="houseAddress != null  and houseAddress != ''"> and house_address = #{houseAddress}</if>
            <if test="idcard != null  and idcard != ''"> and idcard = #{idcard}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="birthday != null  and birthday != ''"> and birthday = #{birthday}</if>
            <if test="gender != null  and gender != ''"> and gender = #{gender}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="phoneNumber != null  and phoneNumber != ''"> and phone_number = #{phoneNumber}</if>
            <if test="isPatriarch != null  and isPatriarch != ''"> and is_patriarch = #{isPatriarch}</if>
        </where>
    </select>
    
    <select id="selectHouseLandlordByHouseLandlordId" parameterType="Long" resultMap="HouseLandlordResult">
        <include refid="selectHouseLandlordVo"/>
        where house_landlord_id = #{houseLandlordId}
    </select>

    <insert id="insertHouseLandlord" parameterType="HouseLandlord" useGeneratedKeys="true" keyProperty="houseLandlordId">
        insert into house_landlord
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="portalId != null">portal_id,</if>
            <if test="houseAddress != null and houseAddress != ''">house_address,</if>
            <if test="idcard != null">idcard,</if>
            <if test="name != null">name,</if>
            <if test="birthday != null">birthday,</if>
            <if test="gender != null">gender,</if>
            <if test="type != null">type,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="isPatriarch != null">is_patriarch,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="portalId != null">#{portalId},</if>
            <if test="houseAddress != null and houseAddress != ''">#{houseAddress},</if>
            <if test="idcard != null">#{idcard},</if>
            <if test="name != null">#{name},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="gender != null">#{gender},</if>
            <if test="type != null">#{type},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="isPatriarch != null">#{isPatriarch},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateHouseLandlord" parameterType="HouseLandlord">
        update house_landlord
        <trim prefix="SET" suffixOverrides=",">
            <if test="portalId != null">portal_id = #{portalId},</if>
            <if test="houseAddress != null and houseAddress != ''">house_address = #{houseAddress},</if>
            <if test="idcard != null">idcard = #{idcard},</if>
            <if test="name != null">name = #{name},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="type != null">type = #{type},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="isPatriarch != null">is_patriarch = #{isPatriarch},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where house_landlord_id = #{houseLandlordId}
    </update>

    <delete id="deleteHouseLandlordByHouseLandlordId" parameterType="Long">
        delete from house_landlord where house_landlord_id = #{houseLandlordId}
    </delete>

    <delete id="deleteHouseLandlordByHouseLandlordIds" parameterType="String">
        delete from house_landlord where house_landlord_id in 
        <foreach item="houseLandlordId" collection="array" open="(" separator="," close=")">
            #{houseLandlordId}
        </foreach>
    </delete>
</mapper>