<?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.yd.csf.service.dao.PolicyReceiptMapper">

    <select id="page" resultType="com.yd.csf.feign.response.policyreceipt.ApiPolicyReceiptPageResponse">
        select
        pr.id,pr.policy_receipt_biz_id,pr.policy_no,
        p.insurer,p.policy_holder,
        pr.create_time,pr.receipt_date,pr.receipt_status
        from policy_receipt pr
        inner join policy p on p.policy_no = pr.policy_no and p.is_deleted = 0
        inner join policy_follow pf on pf.policy_no = p.policy_no and pf.is_deleted = 0
        <where>
            <if test="request.appointmentNo != null and request.appointmentNo != ''">
                and pf.appointment_no like concat('%', #{request.appointmentNo}, '%')
            </if>

            <if test="request.policyHolder != null and request.policyHolder != ''">
                and p.policy_holder like concat('%', #{request.policyHolder}, '%')
            </if>

            <if test="request.insurer != null and request.insurer != ''">
                and p.insurer = #{request.insurer}
            </if>

            <if test="request.receiptStatus != null and request.receiptStatus != ''">
                and pr.receipt_status = #{request.receiptStatus}
            </if>

            <if test="request.policyNo != null and request.policyNo != ''">
                and pr.policy_no = #{request.policyNo}
            </if>
            and pr.is_deleted = 0
        </where>
    </select>
</mapper>
