<?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.ElderlyConsumerVouchersMapper">

    <select id="selectPageWithElderInfo"
            resultType="cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyConsumerVouchersDO">
        select ecv.*,
               ei.elder_name as elderName,
               ei.id_card as idCard,
               ei.bed_name as bedName
        from elderly_consumer_vouchers ecv
                 left join elderly_info ei on ei.id = ecv.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.billingMonth != null and reqVO.billingMonth != ''">
                and ecv.billing_month = #{reqVO.billingMonth}
            </if>
            <if test="reqVO.status != null">
                and ecv.status = #{reqVO.status}
            </if>
            <if test="reqVO.returnStatus != null">
                and ecv.return_status = #{reqVO.returnStatus}
            </if>
            <if test="reqVO.orderNumber != null and reqVO.orderNumber != ''">
                and ecv.order_number like concat('%', #{reqVO.orderNumber}, '%')
            </if>
            <if test="reqVO.tenantIds != null and reqVO.tenantIds.length > 0">
                and ecv.tenant_id in
                <foreach collection="reqVO.tenantIds" item="tenantId" open="(" separator="," close=")">
                    #{tenantId}
                </foreach>
            </if>
        </where>
        order by ecv.id desc
    </select>

    <select id="selectByIdWithElderInfo"
            resultType="cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyConsumerVouchersDO">
        select ecv.*,
               ei.elder_name as elderName,
               ei.id_card as idCard,
               ei.bed_name as bedName
        from elderly_consumer_vouchers ecv
                 left join elderly_info ei on ei.id = ecv.elder_id
        where ecv.id = #{id}
        limit 1
    </select>

</mapper>
