<?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.timer.api.dao.insure.InsureApplicantMapper">

    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="cn.timer.api.bean.insure.InsureApplicant" id="insureApplicantMap">
        <result property="id" column="id"/>
        <result property="applicantEName" column="applicant_e_name"/>
        <result property="applicantEAddress" column="applicant_e_address"/>
        <result property="applicantEmployeeList" column="applicant_employee_list"/>
        <result property="applicantEContacts" column="applicant_e_contacts"/>
        <result property="applicantEPhone" column="applicant_e_phone"/>
        <result property="applicantENoType" column="applicant_e_no_type"/>
        <result property="applicantENo" column="applicant_e_no"/>
        <result property="applicantEMail" column="applicant_e_mail"/>
        <result property="applicantProvinceCity" column="applicant_province_city"/>
        <result property="applicantInvoiceReceivingAddress" column="applicant_invoice_receiving_address"/>
        <result property="applicantInvoiceBillingPhone" column="applicant_invoice_billing_phone"/>
        <result property="applicantBusinessBankName" column="applicant_business_bank_name"/>
        <result property="policyNo" column="policy_no"/>
        <result property="applicantType" column="applicant_type"/>
        <result property="transId" column="trans_id"/>
        <result property="currency" column="currency"/>
        <result property="applicantInvoicedAmount" column="applicant_invoiced_amount"/>
        <result property="applicantCorporateBankAccount" column="applicant_corporate_bank_account"/>
    </resultMap>

    <select id="queryObject" resultType="cn.timer.api.bean.insure.InsureApplicant">
        select *
        from insure_applicant
        where id = #{value}
    </select>

    <select id="queryList" resultType="cn.timer.api.bean.insure.InsureApplicant">
        select * from insure_applicant
        <where>
            <if test="applicantEName != null and applicantEName != ''">AND `applicant_e_name` = #{applicantEName}</if>
            <if test="applicantEAddress != null and applicantEAddress != ''">AND `applicant_e_address` =
                #{applicantEAddress}
            </if>
            <if test="applicantEmployeeList != null and applicantEmployeeList != ''">AND `applicant_employee_list` =
                #{applicantEmployeeList}
            </if>
            <if test="applicantEContacts != null and applicantEContacts != ''">AND `applicant_e_contacts` =
                #{applicantEContacts}
            </if>
            <if test="applicantEPhone != null and applicantEPhone != ''">AND `applicant_e_phone` = #{applicantEPhone}
            </if>
            <if test="applicantENoType != null and applicantENoType != ''">AND `applicant_e_no_type` =
                #{applicantENoType}
            </if>
            <if test="applicantENo != null and applicantENo != ''">AND `applicant_e_no` = #{applicantENo}</if>
            <if test="applicantEMail != null and applicantEMail != ''">AND `applicant_e_mail` = #{applicantEMail}</if>
            <if test="applicantProvinceCity != null and applicantProvinceCity != ''">AND `applicant_province_city` =
                #{applicantProvinceCity}
            </if>
            <if test="applicantInvoiceReceivingAddress != null and applicantInvoiceReceivingAddress != ''">AND
                `applicant_invoice_receiving_address` = #{applicantInvoiceReceivingAddress}
            </if>
            <if test="applicantInvoiceBillingPhone != null and applicantInvoiceBillingPhone != ''">AND
                `applicant_invoice_billing_phone` = #{applicantInvoiceBillingPhone}
            </if>
            <if test="applicantBusinessBankName != null and applicantBusinessBankName != ''">AND
                `applicant_business_bank_name` = #{applicantBusinessBankName}
            </if>
            <if test="policyNo != null and policyNo != ''">AND `policy_no` = #{policyNo}</if>
            <if test="applicantType != null and applicantType != ''">AND `applicant_type` = #{applicantType}</if>
            <if test="transId != null and transId != ''">AND `trans_id` = #{transId}</if>
            <if test="currency != null and currency != ''">AND `currency` = #{currency}</if>
            <if test="applicantInvoicedAmount != null and applicantInvoicedAmount != ''">AND `applicant_invoiced_amount`
                = #{applicantInvoicedAmount}
            </if>
        </where>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
        select count(*) from insure_applicant
        <where>
            <if test="applicantEName != null and applicantEName != ''">AND `applicant_e_name` = #{applicantEName}</if>
            <if test="applicantEAddress != null and applicantEAddress != ''">AND `applicant_e_address` =
                #{applicantEAddress}
            </if>
            <if test="applicantEmployeeList != null and applicantEmployeeList != ''">AND `applicant_employee_list` =
                #{applicantEmployeeList}
            </if>
            <if test="applicantEContacts != null and applicantEContacts != ''">AND `applicant_e_contacts` =
                #{applicantEContacts}
            </if>
            <if test="applicantEPhone != null and applicantEPhone != ''">AND `applicant_e_phone` = #{applicantEPhone}
            </if>
            <if test="applicantENoType != null and applicantENoType != ''">AND `applicant_e_no_type` =
                #{applicantENoType}
            </if>
            <if test="applicantENo != null and applicantENo != ''">AND `applicant_e_no` = #{applicantENo}</if>
            <if test="applicantEMail != null and applicantEMail != ''">AND `applicant_e_mail` = #{applicantEMail}</if>
            <if test="applicantProvinceCity != null and applicantProvinceCity != ''">AND `applicant_province_city` =
                #{applicantProvinceCity}
            </if>
            <if test="applicantInvoiceReceivingAddress != null and applicantInvoiceReceivingAddress != ''">AND
                `applicant_invoice_receiving_address` = #{applicantInvoiceReceivingAddress}
            </if>
            <if test="applicantInvoiceBillingPhone != null and applicantInvoiceBillingPhone != ''">AND
                `applicant_invoice_billing_phone` = #{applicantInvoiceBillingPhone}
            </if>
            <if test="applicantBusinessBankName != null and applicantBusinessBankName != ''">AND
                `applicant_business_bank_name` = #{applicantBusinessBankName}
            </if>
            <if test="policyNo != null and policyNo != ''">AND `policy_no` = #{policyNo}</if>
            <if test="applicantType != null and applicantType != ''">AND `applicant_type` = #{applicantType}</if>
            <if test="transId != null and transId != ''">AND `trans_id` = #{transId}</if>
            <if test="currency != null and currency != ''">AND `currency` = #{currency}</if>
            <if test="applicantInvoicedAmount != null and applicantInvoicedAmount != ''">AND `applicant_invoiced_amount`
                = #{applicantInvoicedAmount}
            </if>
        </where>
    </select>

    <insert id="save" parameterType="cn.timer.api.bean.insure.InsureApplicant" useGeneratedKeys="true"
            keyProperty="id">
        insert into insure_applicant
        (`applicant_e_name`,
         `applicant_e_address`,
         `applicant_employee_list`,
         `applicant_e_contacts`,
         `applicant_e_phone`,
         `applicant_e_no_type`,
         `applicant_e_no`,
         `applicant_e_mail`,
         `applicant_province_city`,
         `applicant_invoice_receiving_address`,
         `applicant_invoice_billing_phone`,
         `applicant_business_bank_name`,
         `policy_no`,
         `applicant_type`,
         `trans_id`,
         `currency`,
         `applicant_invoiced_amount`,
         `applicant_corporate_bank_account`)
        values (#{applicantEName},
                #{applicantEAddress},
                #{applicantEmployeeList},
                #{applicantEContacts},
                #{applicantEPhone},
                #{applicantENoType},
                #{applicantENo},
                #{applicantEMail},
                #{applicantProvinceCity},
                #{applicantInvoiceReceivingAddress},
                #{applicantInvoiceBillingPhone},
                #{applicantBusinessBankName},
                #{policyNo},
                #{applicantType},
                #{transId},
                #{currency},
                #{applicantCorporateBankAccount})
    </insert>

    <insert id="saveSelective" parameterType="cn.timer.api.bean.insure.InsureApplicant" useGeneratedKeys="true"
            keyProperty="id">
        insert into insure_applicant
        (
        <if test="applicantEName != null">,`applicant_e_name`</if>
        <if test="applicantEAddress != null">,`applicant_e_address`</if>
        <if test="applicantEmployeeList != null">,`applicant_employee_list`</if>
        <if test="applicantEContacts != null">,`applicant_e_contacts`</if>
        <if test="applicantEPhone != null">,`applicant_e_phone`</if>
        <if test="applicantENoType != null">,`applicant_e_no_type`</if>
        <if test="applicantENo != null">,`applicant_e_no`</if>
        <if test="applicantEMail != null">,`applicant_e_mail`</if>
        <if test="applicantProvinceCity != null">,`applicant_province_city`</if>
        <if test="applicantInvoiceReceivingAddress != null">,`applicant_invoice_receiving_address`</if>
        <if test="applicantInvoiceBillingPhone != null">,`applicant_invoice_billing_phone`</if>
        <if test="applicantBusinessBankName != null">,`applicant_business_bank_name`</if>
        <if test="policyNo != null">,`policy_no`</if>
        <if test="applicantType != null">,`applicant_type`</if>
        <if test="transId != null">,`trans_id`</if>
        <if test="currency != null">,`currency`</if>
        <if test="applicantInvoicedAmount != null">,`applicant_invoiced_amount`</if>
        <if test="applicantCorporateBankAccount != null">,`applicant_corporate_bank_account`</if>
        )
        values
        (
        <if test="applicantEName != null">,#{applicantEName}</if>
        <if test="applicantEAddress != null">,#{applicantEAddress}</if>
        <if test="applicantEmployeeList != null">,#{applicantEmployeeList}</if>
        <if test="applicantEContacts != null">,#{applicantEContacts}</if>
        <if test="applicantEPhone != null">,#{applicantEPhone}</if>
        <if test="applicantENoType != null">,#{applicantENoType}</if>
        <if test="applicantENo != null">,#{applicantENo}</if>
        <if test="applicantEMail != null">,#{applicantEMail}</if>
        <if test="applicantProvinceCity != null">,#{applicantProvinceCity}</if>
        <if test="applicantInvoiceReceivingAddress != null">,#{applicantInvoiceReceivingAddress}</if>
        <if test="applicantInvoiceBillingPhone != null">,#{applicantInvoiceBillingPhone}</if>
        <if test="applicantBusinessBankName != null">,#{applicantBusinessBankName}</if>
        <if test="policyNo != null">,#{policyNo}</if>
        <if test="applicantType != null">,#{applicantType}</if>
        <if test="transId != null">,#{transId}</if>
        <if test="currency != null">,#{currency}</if>
        <if test="applicantCorporateBankAccount != null">,#{applicantCorporateBankAccount}</if>
        )
    </insert>


    <insert id="saveList" parameterType="cn.timer.api.bean.insure.InsureApplicant" useGeneratedKeys="true"
            keyProperty="id">
        insert into insure_applicant
        (
        `applicant_e_name`,
        `applicant_e_address`,
        `applicant_employee_list`,
        `applicant_e_contacts`,
        `applicant_e_phone`,
        `applicant_e_no_type`,
        `applicant_e_no`,
        `applicant_e_mail`,
        `applicant_province_city`,
        `applicant_invoice_receiving_address`,
        `applicant_invoice_billing_phone`,
        `applicant_business_bank_name`,
        `policy_no`,
        `applicant_type`,
        `trans_id`,
        `currency`,
        `applicant_invoiced_amount`
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.applicantEName},
            #{item.applicantEAddress},
            #{item.applicantEmployeeList},
            #{item.applicantEContacts},
            #{item.applicantEPhone},
            #{item.applicantENoType},
            #{item.applicantENo},
            #{item.applicantEMail},
            #{item.applicantProvinceCity},
            #{item.applicantInvoiceReceivingAddress},
            #{item.applicantInvoiceBillingPhone},
            #{item.applicantBusinessBankName},
            #{item.policyNo},
            #{item.applicantType},
            #{item.transId},
            #{item.currency},
            #{item.applicantInvoicedAmount}
            )
        </foreach>
    </insert>

    <delete id="deleteBatch">
        delete from insure_applicant where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>