<?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.ProprietorHouseMapper">
    
    <resultMap type="ProprietorHouse" id="ProprietorHouseResult">
        <result property="proprietorId"    column="proprietor_id"    />
        <result property="userId"    column="user_id"    />
        <result property="proprietorHouseAddress"    column="proprietor_house_address"    />
        <result property="userName"    column="user_name"    />
        <result property="master"    column="master"    />
        <result property="floorage"    column="floorage"    />
        <result property="roomType"    column="room_type"    />
        <result property="tenementType"    column="tenement_type"    />
        <result property="isMaster"    column="is_master"    />
        <result property="masterRelation"    column="master_relation"    />
        <result property="tenementQuantity"    column="tenement_quantity"    />
        <result property="isPark"    column="is_park"    />
        <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="selectProprietorHouseVo">
        select proprietor_id, user_id, proprietor_house_address, user_name, master, floorage, room_type, tenement_type, is_master, master_relation, tenement_quantity, is_park, create_by, create_time, update_by, update_time, remark from proprietor_house
    </sql>

    <select id="selectProprietorHouseList" parameterType="ProprietorHouse" resultMap="ProprietorHouseResult">
        <include refid="selectProprietorHouseVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="proprietorHouseAddress != null  and proprietorHouseAddress != ''"> and proprietor_house_address = #{proprietorHouseAddress}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="master != null  and master != ''"> and master = #{master}</if>
            <if test="floorage != null  and floorage != ''"> and floorage = #{floorage}</if>
            <if test="roomType != null  and roomType != ''"> and room_type = #{roomType}</if>
            <if test="tenementType != null  and tenementType != ''"> and tenement_type = #{tenementType}</if>
            <if test="isMaster != null  and isMaster != ''"> and is_master = #{isMaster}</if>
            <if test="masterRelation != null  and masterRelation != ''"> and master_relation = #{masterRelation}</if>
            <if test="tenementQuantity != null  and tenementQuantity != ''"> and tenement_quantity = #{tenementQuantity}</if>
            <if test="isPark != null  and isPark != ''"> and is_park = #{isPark}</if>
        </where>
    </select>
    
    <select id="selectProprietorHouseByProprietorId" parameterType="Long" resultMap="ProprietorHouseResult">
        <include refid="selectProprietorHouseVo"/>
        where proprietor_id = #{proprietorId}
    </select>

    <insert id="insertProprietorHouse" parameterType="ProprietorHouse" useGeneratedKeys="true" keyProperty="proprietorId">
        insert into proprietor_house
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="proprietorHouseAddress != null">proprietor_house_address,</if>
            <if test="userName != null">user_name,</if>
            <if test="master != null">master,</if>
            <if test="floorage != null">floorage,</if>
            <if test="roomType != null">room_type,</if>
            <if test="tenementType != null">tenement_type,</if>
            <if test="isMaster != null">is_master,</if>
            <if test="masterRelation != null">master_relation,</if>
            <if test="tenementQuantity != null">tenement_quantity,</if>
            <if test="isPark != null">is_park,</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="userId != null">#{userId},</if>
            <if test="proprietorHouseAddress != null">#{proprietorHouseAddress},</if>
            <if test="userName != null">#{userName},</if>
            <if test="master != null">#{master},</if>
            <if test="floorage != null">#{floorage},</if>
            <if test="roomType != null">#{roomType},</if>
            <if test="tenementType != null">#{tenementType},</if>
            <if test="isMaster != null">#{isMaster},</if>
            <if test="masterRelation != null">#{masterRelation},</if>
            <if test="tenementQuantity != null">#{tenementQuantity},</if>
            <if test="isPark != null">#{isPark},</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="updateProprietorHouse" parameterType="ProprietorHouse">
        update proprietor_house
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="proprietorHouseAddress != null">proprietor_house_address = #{proprietorHouseAddress},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="master != null">master = #{master},</if>
            <if test="floorage != null">floorage = #{floorage},</if>
            <if test="roomType != null">room_type = #{roomType},</if>
            <if test="tenementType != null">tenement_type = #{tenementType},</if>
            <if test="isMaster != null">is_master = #{isMaster},</if>
            <if test="masterRelation != null">master_relation = #{masterRelation},</if>
            <if test="tenementQuantity != null">tenement_quantity = #{tenementQuantity},</if>
            <if test="isPark != null">is_park = #{isPark},</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 proprietor_id = #{proprietorId}
    </update>

    <delete id="deleteProprietorHouseByProprietorId" parameterType="Long">
        delete from proprietor_house where proprietor_id = #{proprietorId}
    </delete>

    <delete id="deleteProprietorHouseByProprietorIds" parameterType="String">
        delete from proprietor_house where proprietor_id in 
        <foreach item="proprietorId" collection="array" open="(" separator="," close=")">
            #{proprietorId}
        </foreach>
    </delete>
</mapper>