<?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="cn.iocoder.yudao.module.system.dal.mysql.biz.ElderlyCcbPayOrderRecordMapper">

    <select id="selectPageWithElderInfo"
            resultType="cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyCcbPayOrderRecordDO">
        select ecpor.*, ei.elder_name as elderName
        from elderly_ccb_pay_order_record ecpor
                 left join elderly_expense_order eeo on eeo.id = ecpor.expense_order_id
                 left join elderly_info ei on ei.id = eeo.elder_id
        <where>
            1 = 1
            <if test="reqVO.elderName != null and reqVO.elderName != ''">
                and ei.elder_name like concat('%', #{reqVO.elderName}, '%')
            </if>
            <if test="reqVO.beginBillingMonth != null and reqVO.beginBillingMonth != ''">
                and ecpor.billing_month <![CDATA[ >= ]]> #{reqVO.beginBillingMonth}
            </if>
            <if test="reqVO.endBillingMonth != null and reqVO.endBillingMonth != ''">
                and ecpor.billing_month <![CDATA[ <= ]]> #{reqVO.endBillingMonth}
            </if>
            <if test="reqVO.tenantIds != null and reqVO.tenantIds.length > 0">
                and ecpor.tenant_id in
                <foreach collection="reqVO.tenantIds" item="tenantId" open="(" separator="," close=")">
                    #{tenantId}
                </foreach>
            </if>
        </where>
        order by ecpor.pay_time desc, ecpor.id desc
    </select>

</mapper>
