<?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.PropertyFeeMapper">
    
    <resultMap type="PropertyFee" id="PropertyFeeResult">
        <result property="propertyId"    column="property_id"    />
        <result property="houseId"    column="house_id"    />
        <result property="ownerName"    column="owner_name"    />
        <result property="location"    column="location"    />
        <result property="area"    column="area"    />
        <result property="propertyUnitNumber"    column="property_unit_number"    />
        <result property="detailedAddress"    column="detailed_address"    />
        <result property="hasParkingSpace"    column="has_parking_space"    />
        <result property="parkingNumber"    column="parking_number"    />
        <result property="communityName"    column="community_name"    />
        <result property="year"    column="year"    />
        <result property="time"    column="time"    />
        <result property="tenementExpense"    column="tenement_expense"    />
        <result property="parkingExpense"    column="parking_expense"    />
        <result property="energyExpense"    column="energy_expense"    />
        <result property="totalExpense"    column="total_expense"    />
        <result property="isExpense"    column="is_expense"    />
        <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="selectPropertyFeeVo">
        select property_id, house_id, owner_name, location, area, property_unit_number, detailed_address, has_parking_space, parking_number, community_name, year, time, tenement_expense, parking_expense, energy_expense, total_expense, is_expense, create_by, create_time, update_by, update_time, remark from property_fee
    </sql>

    <select id="selectPropertyFeeList" parameterType="PropertyFee" resultMap="PropertyFeeResult">
        <include refid="selectPropertyFeeVo"/>
        <where>  
            <if test="houseId != null "> and house_id = #{houseId}</if>
            <if test="ownerName != null  and ownerName != ''"> and owner_name like concat('%', #{ownerName}, '%')</if>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="area != null "> and area = #{area}</if>
            <if test="propertyUnitNumber != null  and propertyUnitNumber != ''"> and property_unit_number = #{propertyUnitNumber}</if>
            <if test="detailedAddress != null  and detailedAddress != ''"> and detailed_address = #{detailedAddress}</if>
            <if test="hasParkingSpace != null  and hasParkingSpace != ''"> and has_parking_space = #{hasParkingSpace}</if>
            <if test="parkingNumber != null  and parkingNumber != ''"> and parking_number = #{parkingNumber}</if>
            <if test="communityName != null  and communityName != ''"> and community_name like concat('%', #{communityName}, '%')</if>
            <if test="year != null  and year != ''"> and year = #{year}</if>
            <if test="time != null  and time != ''"> and time = #{time}</if>
            <if test="tenementExpense != null "> and tenement_expense = #{tenementExpense}</if>
            <if test="parkingExpense != null "> and parking_expense = #{parkingExpense}</if>
            <if test="energyExpense != null "> and energy_expense = #{energyExpense}</if>
            <if test="totalExpense != null "> and total_expense = #{totalExpense}</if>
            <if test="isExpense != null  and isExpense != ''"> and is_expense = #{isExpense}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectPropertyFeeByPropertyId" parameterType="Long" resultMap="PropertyFeeResult">
        <include refid="selectPropertyFeeVo"/>
        where property_id = #{propertyId}
    </select>

    <insert id="insertPropertyFee" parameterType="PropertyFee" useGeneratedKeys="true" keyProperty="propertyId">
        insert into property_fee
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="houseId != null">house_id,</if>
            <if test="ownerName != null">owner_name,</if>
            <if test="location != null">location,</if>
            <if test="area != null">area,</if>
            <if test="propertyUnitNumber != null">property_unit_number,</if>
            <if test="detailedAddress != null">detailed_address,</if>
            <if test="hasParkingSpace != null">has_parking_space,</if>
            <if test="parkingNumber != null">parking_number,</if>
            <if test="communityName != null">community_name,</if>
            <if test="year != null">year,</if>
            <if test="time != null">time,</if>
            <if test="tenementExpense != null">tenement_expense,</if>
            <if test="parkingExpense != null">parking_expense,</if>
            <if test="energyExpense != null">energy_expense,</if>
            <if test="totalExpense != null">total_expense,</if>
            <if test="isExpense != null">is_expense,</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="houseId != null">#{houseId},</if>
            <if test="ownerName != null">#{ownerName},</if>
            <if test="location != null">#{location},</if>
            <if test="area != null">#{area},</if>
            <if test="propertyUnitNumber != null">#{propertyUnitNumber},</if>
            <if test="detailedAddress != null">#{detailedAddress},</if>
            <if test="hasParkingSpace != null">#{hasParkingSpace},</if>
            <if test="parkingNumber != null">#{parkingNumber},</if>
            <if test="communityName != null">#{communityName},</if>
            <if test="year != null">#{year},</if>
            <if test="time != null">#{time},</if>
            <if test="tenementExpense != null">#{tenementExpense},</if>
            <if test="parkingExpense != null">#{parkingExpense},</if>
            <if test="energyExpense != null">#{energyExpense},</if>
            <if test="totalExpense != null">#{totalExpense},</if>
            <if test="isExpense != null">#{isExpense},</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="updatePropertyFee" parameterType="PropertyFee">
        update property_fee
        <trim prefix="SET" suffixOverrides=",">
            <if test="houseId != null">house_id = #{houseId},</if>
            <if test="ownerName != null">owner_name = #{ownerName},</if>
            <if test="location != null">location = #{location},</if>
            <if test="area != null">area = #{area},</if>
            <if test="propertyUnitNumber != null">property_unit_number = #{propertyUnitNumber},</if>
            <if test="detailedAddress != null">detailed_address = #{detailedAddress},</if>
            <if test="hasParkingSpace != null">has_parking_space = #{hasParkingSpace},</if>
            <if test="parkingNumber != null">parking_number = #{parkingNumber},</if>
            <if test="communityName != null">community_name = #{communityName},</if>
            <if test="year != null">year = #{year},</if>
            <if test="time != null">time = #{time},</if>
            <if test="tenementExpense != null">tenement_expense = #{tenementExpense},</if>
            <if test="parkingExpense != null">parking_expense = #{parkingExpense},</if>
            <if test="energyExpense != null">energy_expense = #{energyExpense},</if>
            <if test="totalExpense != null">total_expense = #{totalExpense},</if>
            <if test="isExpense != null">is_expense = #{isExpense},</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 property_id = #{propertyId}
    </update>

    <delete id="deletePropertyFeeByPropertyId" parameterType="Long">
        delete from property_fee where property_id = #{propertyId}
    </delete>

    <delete id="deletePropertyFeeByPropertyIds" parameterType="String">
        delete from property_fee where property_id in 
        <foreach item="propertyId" collection="array" open="(" separator="," close=")">
            #{propertyId}
        </foreach>
    </delete>
</mapper>