<?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="fnaBizId" column="fna_biz_id" />
        <result property="appointmentBizId" column="appointment_biz_id" />
        <result property="appointmentNo" column="appointment_no" />
        <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="signer" column="signer" />
        <result property="signerBizId" column="signer_biz_id" />
        <result property="practiceCode" column="practice_code" />
        <result property="signLocation" column="sign_location" />
        <result property="issueDate" column="issue_date" />
        <result property="coolingOffEndDate" column="cooling_off_end_date" />
        <result property="coolingOffDays" column="cooling_off_days" />
        <result property="underwritingDate" column="underwriting_date" />
        <result property="effectiveDate" column="effective_date" />
        <result property="renewalDate" column="renewal_date" />
        <result property="receiptDate" column="receipt_date" />
        <result property="receiptStatus" column="receipt_status" />
        <result property="directPaymentEnabled" column="direct_payment_enabled" />
        <result property="issueNumber" column="issue_number" />
        <result property="guaranteePeriod" column="guarantee_period" />
        <result property="sumInsured" column="sum_insured" />
        <result property="paymentFrequency" column="payment_frequency" />
        <result property="eachIssuePremium" column="each_issue_premium" />
        <result property="isPrepay" column="is_prepay" />
        <result property="isTraceable" column="is_traceable" />
        <result property="retroactiveDate" column="retroactive_date" />
        <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="categoryCode" column="category_code" />
        <result property="insuranceCategoryBizId" column="insurance_category_biz_id" />
        <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="insuredBizId" column="insured_biz_id" />
        <result property="insuredAge" column="insured_age" />
        <result property="gracePeriod" column="grace_period" />
        <result property="isJoin" column="is_join" />
        <result property="policyCurrency" column="policy_currency" />
        <result property="initialPaymentMethod" column="initial_payment_method" />
        <result property="initialPremium" column="initial_premium" />
        <result property="initialPremiumTotal" column="initial_premium_total" />
        <result property="initialPaymentStatus" column="initial_payment_status" />
        <result property="initialPremiumDiscount" column="initial_premium_discount" />
        <result property="mailingMethod" column="mailing_method" />
        <result property="renewalPaymentMethod" column="renewal_payment_method" />
        <result property="dividendDistributionMethod" column="dividend_distribution_method" />
        <result property="deliveryNo" column="delivery_no" />
        <result property="policyLevy" column="policy_levy" />
        <result property="initialPremiumPaid" column="initial_premium_paid" />
        <result property="initialPremiumDue" column="initial_premium_due" />
        <result property="latestPaymentDate" column="latest_payment_date" />
        <result property="brokerSignDate" column="broker_sign_date" />
        <result property="insurerMailingDate" column="insurer_mailing_date" />
        <result property="customerSignDate" column="customer_sign_date" />
        <result property="professionalInvestor" column="professional_investor" />
        <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" />
        <result property="policyType" column="policy_type" />
    </resultMap>

    <sql id="Base_Column_List">
        id,policy_biz_id,policy_no,fna_biz_id,appointment_biz_id,appointment_no,customer_biz_id,
        submit_date,customer_name,sign_date,signer,signer_biz_id,
        practice_code,sign_location,issue_date,cooling_off_end_date,cooling_off_days,
        underwriting_date,effective_date,renewal_date,receipt_date,receipt_status,
        direct_payment_enabled,issue_number,guarantee_period,sum_insured,payment_frequency,
        each_issue_premium,is_prepay,is_traceable,retroactive_date,prepaid_term,
        prepaid_amount,prepaid_amount_after_discount,policy_expiration_date,payment_number,product_launch_biz_id,
        product_name,product_cate,category_code,insurance_company,insurance_company_biz_id,reconciliation_company,insurance_category_biz_id,
        reconciliation_company_biz_id,status,next_status_list,policy_holder,insured,insured_biz_id,
        insured_age,grace_period,is_join,policy_currency,initial_payment_method,
        initial_premium,initial_premium_total,initial_payment_status,initial_premium_discount,
        mailing_method,renewal_payment_method,dividend_distribution_method,delivery_no,
        policy_levy,initial_premium_paid,initial_premium_due,latest_payment_date,broker_sign_date,
        insurer_mailing_date,customer_sign_date,professional_investor,attachments,remark,is_deleted,
        creator_id,updater_id,create_time,update_time,policy_type,is_join
    </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.issue_number            as paymentPeriod,
            t.initial_premium         as annualAmount,
            t.prepaid_amount          as totalPrepayment,
            t.each_issue_premium      as premiumFee,
            t.sign_date               as startTime,
            t.sign_date               as endTime,
            t.signer                  as serviceManager,
            t.sign_location           as location,
            t.policy_holder           as policyHolder,
            t.policy_currency         as currency,
            ifnull(i.name, i.name_en) as insuredPerson,
            t.initial_premium         as initialPremium,
            t.policy_levy             as policyLevy,
            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>
