<?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.zksy.property.mapper.AReceiptInfoMapper">

    <resultMap id="BaseResultMap" type="com.zksy.property.domain.AReceiptInfo">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="contractId" column="contract_id" jdbcType="VARCHAR"/>
            <result property="receiptNumber" column="receipt_number" jdbcType="VARCHAR"/>
            <result property="payer" column="payer" jdbcType="VARCHAR"/>
            <result property="paymentMethod" column="payment_method" jdbcType="VARCHAR"/>
            <result property="totalAmount" column="total_amount" jdbcType="DECIMAL"/>
            <result property="rent" column="rent" jdbcType="DECIMAL"/>
            <result property="propertyFee" column="property_fee" jdbcType="DECIMAL"/>
            <result property="deposit" column="deposit" jdbcType="DECIMAL"/>
            <result property="waterFee" column="water_fee" jdbcType="DECIMAL"/>
            <result property="attachmentUrl" column="attachment_url" jdbcType="VARCHAR"/>
            <result property="receiptReason" column="receipt_reason" jdbcType="VARCHAR"/>
            <result property="generationDate" column="generation_date" javaType="DATE"/>
            <result property="accountingDate" column="accounting_date" jdbcType="DATE"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <resultMap id="VoResultMap" type="com.zksy.property.domain.vo.AReceiptInfoVo">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="contractId" column="contract_id" jdbcType="VARCHAR"/>
        <result property="receiptNumber" column="receipt_number" jdbcType="VARCHAR"/>
        <result property="payer" column="payer" jdbcType="VARCHAR"/>
        <result property="paymentMethod" column="payment_method" jdbcType="VARCHAR"/>
        <result property="totalAmount" column="total_amount" jdbcType="DECIMAL"/>
        <result property="rent" column="rent" jdbcType="DECIMAL"/>
        <result property="propertyFee" column="property_fee" jdbcType="DECIMAL"/>
        <result property="deposit" column="deposit" jdbcType="DECIMAL"/>
        <result property="waterFee" column="water_fee" jdbcType="DECIMAL"/>
        <result property="attachmentUrl" column="attachment_url" jdbcType="VARCHAR"/>
        <result property="receiptReason" column="receipt_reason" jdbcType="VARCHAR"/>
        <result property="generationDate" column="generation_date" jdbcType="DATE" javaType="java.time.LocalDate"/>
        <result property="accountingDate" column="accounting_date" jdbcType="DATE" javaType="java.time.LocalDate"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP" javaType="java.time.LocalDateTime"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP" javaType="java.time.LocalDateTime"/>
        <result property="contactNumber" column="contract_number" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,contract_id,receipt_number,payer,
        payment_method,total_amount,rent,
        property_fee,deposit,water_fee,
        receipt_reason,attachment_url,accounting_date,
        generation_date,create_time,update_time
    </sql>
    <select id="selectReceiptWithContractByPage" resultMap="VoResultMap">
        SELECT
        r.id,
        r.contract_id,
        r.receipt_number,
        r.payer,
        r.payment_method,
        r.total_amount,
        r.rent,
        r.property_fee,
        r.deposit,
        r.water_fee,
        r.receipt_reason,
        r.attachment_url,
        r.accounting_date,
        r.generation_date,
        r.create_time,
        r.update_time,
        c.contract_number
        FROM a_receipt_info r
        LEFT JOIN a_contract_info c ON r.contract_id = c.id
        <where>
            <if test="receiptNumber != null and receiptNumber != ''">
                AND r.receipt_number LIKE CONCAT('%', #{receiptNumber}, '%')
            </if>
            <if test="payer != null and payer != ''">
                AND r.payer LIKE CONCAT('%', #{payer}, '%')
            </if>
            <if test="paymentMethod != null and paymentMethod != ''">
                AND r.payment_method LIKE CONCAT('%', #{paymentMethod}, '%')
            </if>
            <if test="contractNumber != null and contractNumber != ''">
                AND c.contract_number LIKE CONCAT('%', #{contractNumber}, '%')
            </if>
        </where>
        ORDER BY r.create_time DESC
    </select>
</mapper>
