<?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.trade.service.business.payableaccounts.mapper.PayableAccountsMapper">

    <resultMap id="BaseResultMap" type="com.trade.service.business.payableaccounts.domain.PayableAccounts">
        <id column="id" property="id"/>
        <id column="customer_user_id" property="customerUserId"/>
        <id column="billing_income_id" property="billingIncomeId"/>
        <id column="payment_type" property="paymentType"/>
        <id column="payment_amount" property="paymentAmount"/>
        <id column="payment_currency" property="paymentCurrency"/>
        <id column="apply_no" property="applyNo"/>
        <id column="sales_contract_no" property="salesContractNo"/>
        <id column="contract_name" property="contractName"/>
        <id column="payment_deadline" property="paymentDeadline"/>
        <id column="payment_time" property="paymentTime"/>
        <id column="voucher_no" property="voucherNo"/>
        <id column="payee_type" property="payeeType"/>
        <id column="payee_name" property="payeeName"/>
        <id column="contact_file_id" property="contactFileId"/>
        <id column="status" property="status"/>
        <id column="source" property="source"/>
        <id column="deleted" property="deleted"/>
        <id column="gmt_create" property="gmtCreate"/>
        <id column="gmt_modified" property="gmtModified"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
        , payee_type, payee_name, contact_file_id
        , customer_user_id, billing_income_id, payment_type, payment_amount, payment_currency, apply_no, sales_contract_no, contract_name, payment_deadline, payment_time, voucher_no, status, source, deleted, gmt_create, gmt_modified
    </sql>
    <select id="selectByPage"
            parameterType="com.trade.service.business.payableaccounts.dto.PayableAccountsSearchDto"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from payable_accounts
        where deleted = 0
        <if test="customerUserId != null">
            and customer_user_id = #{customerUserId}
        </if>
        <if test="applyNo != null and applyNo != ''">
            and apply_no = #{applyNo}
        </if>
        <if test="salesContractNo != null and salesContractNo != ''">
            and sales_contract_no = #{salesContractNo}
        </if>
        <if test="paymentType != null and paymentType != ''">
            and payment_type = #{paymentType}
        </if>
        <if test="status != null and status != ''">
            and status = #{status}
        </if>
        <if test="voucherNo != null and voucherNo != ''">
            and voucher_no = #{voucherNo}
        </if>
        <if test="deadlineStartTime != null">
            AND payment_deadline <![CDATA[ >= ]]> #{deadlineStartTime}
        </if>
        <if test="deadlineEndTime != null">
            AND payment_deadline <![CDATA[ <= ]]> #{deadlineEndTime}
        </if>
        <if test="paymentStartTime != null">
            AND payment_time <![CDATA[ >= ]]> #{paymentStartTime}
        </if>
        <if test="paymentEndTime != null">
            AND payment_time <![CDATA[ <= ]]> #{paymentEndTime}
        </if>
        <if test="gmtCreateStartTime != null">
            AND gmt_create <![CDATA[ >= ]]> #{gmtCreateStartTime}
        </if>
        <if test="gmtCreatEndTime != null">
            AND gmt_create <![CDATA[ <= ]]> #{gmtCreatEndTime}
        </if>
        order by payment_deadline asc
    </select>

</mapper>