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

    <resultMap id="BaseResultMap" type="com.yd.csf.service.model.Policy">
            <id property="id" column="id" />
            <result property="policyBizId" column="policy_biz_id" />
            <result property="policyNo" column="policy_no" />
            <result property="userBizId" column="user_biz_id" />
            <result property="productLaunchBizId" column="product_launch_biz_id" />
            <result property="productCode" column="product_code" />
            <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="region" column="region" />
            <result property="policyHolder" column="policy_holder" />
            <result property="policyHolderAge" column="policy_holder_age" />
            <result property="insured" column="insured" />
            <result property="sumInsured" column="sum_insured" />
            <result property="paymentTerm" column="payment_term" />
            <result property="paymentFrequency" column="payment_frequency" />
            <result property="paymentPremium" column="payment_premium" />
            <result property="status" column="status" />
            <result property="currency" column="currency" />
            <result property="initialPremium" column="initial_premium" />
            <result property="signDate" column="sign_date" />
            <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="isPrepaid" column="is_prepaid" />
            <result property="deductibles" column="deductibles" />
            <result property="prepaidTerm" column="prepaid_term" />
            <result property="initialPaymentMethod" column="initial_payment_method" />
            <result property="renewalPaymentMethod" column="renewal_payment_method" />
            <result property="dividendDistributionMethod" column="dividend_distribution_method" />
            <result property="isBacktrack" column="is_backtrack" />
            <result property="isJoin" column="is_join" />
            <result property="reconciliationCompany" column="reconciliation_company" />
            <result property="reconciliationCompanyCode" column="reconciliation_company_code" />
            <result property="reconciliationCompanyBizId" column="reconciliation_company_biz_id" />
            <result property="policyTransfer" column="policy_transfer" />
            <result property="policyLevy" column="policy_levy" />
            <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,user_biz_id,product_launch_biz_id,product_code,
        product_name,product_cate,insurance_company,insurance_company_biz_id,region,
        policy_holder,policy_holder_age,insured,sum_insured,payment_term,payment_frequency,payment_premium,
        status,currency,initial_premium,sign_date,issue_date,
        effective_date,cooling_off_end_date,cooling_off_days,renewal_date,is_prepaid,deductibles,prepaid_term,
        initial_payment_method,renewal_payment_method,dividend_distribution_method,is_backtrack,is_join,
        reconciliation_company,reconciliation_company_code,reconciliation_company_biz_id,policy_transfer,policy_levy,remark,is_deleted,creator_id,
        updater_id,create_time,update_time
    </sql>

    <select id="queryPolicyBrokerList"
            resultType="com.yd.csf.service.dto.QueryPolicyAndBrokerDto">
        select p.*,
               pb.*,
               p.product_launch_biz_id as planBizId,
               p.cooling_off_end_date as coolingOffEndDate
        from policy p
        left join policy_broker pb on pb.policy_no = p.policy_no and pb.is_deleted = 0
        <where>
            <if test="policyNo != null and policyNo != ''">
                and p.policy_no = #{policyNo}
            </if>
            and p.is_deleted = 0
        </where>
    </select>
</mapper>
