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

    <resultMap id="BaseResultMap" type="com.yd.csf.service.model.PolicyFollow">
        <id property="id" column="id" />
        <result property="policyBizId" column="policy_biz_id" />
        <result property="policyNo" column="policy_no" />
        <result property="appointmentBizId" column="appointment_biz_id" />
        <result property="appointmentNo" column="appointment_no" />
        <result property="userBizId" column="user_biz_id" />
        <result property="customerBizId" column="customer_biz_id" />
        <result property="submitDate" column="submit_date" />
        <result property="customerName" column="customer_name" />
        <result property="signDate" column="sign_date" />
        <result property="signerList" column="signer_list" />
        <result property="issueDate" column="issue_date" />
        <result property="effectiveDate" column="effective_date" />
        <result property="coolingOffEndDate" column="cooling_off_end_date" />
        <result property="coolingOffDays" column="cooling_off_days" />
        <result property="renewalDate" column="renewal_date" />
        <result property="paymentTerm" column="payment_term" />
        <result property="paymentPremium" column="payment_premium" />
        <result property="isPrepaid" column="is_prepaid" />
        <result property="prepaidTerm" column="prepaid_term" />
        <result property="prepaidAmount" column="prepaid_amount" />
        <result property="prepaidAmountAfterDiscount" column="prepaid_amount_after_discount" />
        <result property="policyExpirationDate" column="policy_expiration_date" />
        <result property="paymentNumber" column="payment_number" />
        <result property="productLaunchBizId" column="product_launch_biz_id" />
        <result property="productName" column="product_name" />
        <result property="productCate" column="product_cate" />
        <result property="insuranceCompany" column="insurance_company" />
        <result property="insuranceCompanyBizId" column="insurance_company_biz_id" />
        <result property="reconciliationCompany" column="reconciliation_company" />
        <result property="reconciliationCompanyBizId" column="reconciliation_company_biz_id" />
        <result property="status" column="status" />
        <result property="nextStatusList" column="next_status_list" />
        <result property="policyHolder" column="policy_holder" />
        <result property="insured" column="insured" />
        <result property="currency" column="currency" />
        <result property="initialPremium" column="initial_premium" />
        <result property="initialPremiumPaid" column="initial_premium_paid" />
        <result property="initialPremiumDue" column="initial_premium_due" />
        <result property="latestPaymentDate" column="latest_payment_date" />
        <result property="policyLevy" column="policy_levy" />
        <result property="mailingMethod" column="mailing_method" />
        <result property="deliveryNo" column="delivery_no" />
        <result property="brokerSignDate" column="broker_sign_date" />
        <result property="insurerMailingDate" column="insurer_mailing_date" />
        <result property="customerSignDate" column="customer_sign_date" />
        <result property="attachments" column="attachments" />
        <result property="remark" column="remark" />
        <result property="isDeleted" column="is_deleted" />
        <result property="creatorId" column="creator_id" />
        <result property="updaterId" column="updater_id" />
        <result property="createTime" column="create_time" />
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="Base_Column_List">
        id,policy_biz_id,policy_no,appointment_biz_id,appointment_no,user_biz_id,
        customer_biz_id,submit_date,customer_name,sign_date,signer_list,
        issue_date,effective_date,cooling_off_end_date,cooling_off_days,renewal_date,payment_term,payment_premium,
        is_prepaid,prepaid_term,prepaid_amount,prepaid_amount_after_discount,policy_expiration_date,
        payment_number,product_launch_biz_id,product_name,product_cate,insurance_company,
        insurance_company_biz_id,reconciliation_company,reconciliation_company_biz_id,status,next_status_list,
        policy_holder,insured,currency,initial_premium,initial_premium_paid,initial_premium_due,latest_payment_date,policy_levy,mailing_method,
        delivery_no,broker_sign_date,insurer_mailing_date,customer_sign_date,attachments,
        remark,is_deleted,creator_id,updater_id,create_time,
        update_time
    </sql>

    <select id="queryPolicyReportData" resultType="com.yd.csf.service.dto.PolicyReportData">
        select
            t.id,
            t.policy_biz_id,
            t.policy_no               as policyNumber,
            t.insurance_company       as insuranceCompany,
            t.product_name            as insurancePlan,
            t.payment_term            as paymentPeriod,
            t.initial_premium         as annualAmount,
            t.prepaid_amount          as totalPrepayment,
            t.payment_premium         as premiumFee,
            t.sign_date               as startTime,
            t.sign_date               as endTime,
            t.signer_list             as serviceManager,
            t.policy_holder           as policyHolder,
            t.currency                as currency,
            ifnull(i.name, i.name_en) as insuredPerson,
            i.age                     as insuredAge

        from policy_follow t
        left join policy_insurant i on t.policy_biz_id = i.policy_biz_id
        where t.policy_biz_id = #{policyBizId}
    </select>
</mapper>
