<?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.jianshui.invoice.mapper.BillInfoMapper">

    <resultMap type="BillInfo" id="BillInfoResult">
        <result property="id" column="id"/>
        <result property="companyId" column="company_id"/>
        <result property="systemOrderno" column="system_orderno"/>
        <result property="outTradeOrderno" column="out_trade_orderno"/>
        <result property="fpqqlsh" column="fpqqlsh"/>
        <result property="invoiceType" column="invoice_type"/>
        <result property="buyerName" column="buyer_name"/>
        <result property="buyerTaxnum" column="buyer_taxnum"/>
        <result property="buyerAddress" column="buyer_address"/>
        <result property="buyerTelephone" column="buyer_telephone"/>
        <result property="buyerBank" column="buyer_bank"/>
        <result property="buyerAccount" column="buyer_account"/>
        <result property="buyerEmail" column="buyer_email"/>
        <result property="buyerPhone" column="buyer_phone"/>
        <result property="sellerName" column="seller_name"/>
        <result property="sellerTaxnum" column="seller_taxnum"/>
        <result property="sellerAddress" column="seller_address"/>
        <result property="sellerTelephone" column="seller_telephone"/>
        <result property="sellerAccount" column="seller_account"/>
        <result property="message" column="message"/>
        <result property="sellerBank" column="seller_bank"/>
        <result property="clerk" column="clerk"/>
        <result property="payee" column="payee"/>
        <result property="checker" column="checker"/>
        <result property="redInvoiceInfoCode" column="red_invoice_info_code"/>
        <result property="fjh" column="fjh"/>
        <result property="terminalNumber" column="terminal_number"/>
        <result property="remark" column="remark"/>
        <result property="kptype" column="kptype"/>
        <result property="originSystemOrderno" column="origin_system_orderno"/>
        <result property="bmbbh" column="bmbbh"/>
        <result property="originFpdm" column="origin_fpdm"/>
        <result property="originFphm" column="origin_fphm"/>
        <result property="tsfs" column="tsfs"/>
        <result property="qdbz" column="qdbz"/>
        <result property="qdxmmc" column="qdxmmc"/>
        <result property="dkbz" column="dkbz"/>
        <result property="cpybz" column="cpybz"/>
        <result property="state" column="state"/>
        <result property="source" column="source"/>
        <result property="serviceSupplierKey" column="service_supplier_key"/>
        <result property="billType" column="bill_type"/>
        <result property="businessRemark" column="business_remark"/>
        <result property="taxfreeamt" column="taxfreeamt"/>
        <result property="invoicedTime" column="invoiced_time"/>
        <result property="callbackUrl" column="callback_url"/>
        <result property="createBy" column="create_by"/>
        <result property="tax" column="tax"/>
        <result property="createTime" column="create_time"/>
        <result property="taxamt" column="taxamt"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="deletedTime" column="deleted_time"/>
        <result property="jbrxm" column="jbrxm"/>
        <result property="jbrzjhm" column="jbrzjhm"/>
        <result property="jbrzjzldm" column="jbrzjzldm"/>
        <result property="jrznsrsbh" column="jrznsrsbh"/>
        <result property="jshj" column="jshj"/>
        <result property="tdyslxdm" column="tdyslxdm"/>
        <result property="tdywxx" column="tdywxx"/>
        <result property="ext" column="ext"/>
    </resultMap>

    <resultMap id="BillInfoBillDetailResult" type="BillInfo" extends="BillInfoResult">
        <collection property="billDetailList" notNullColumn="sub_id" javaType="java.util.List"
                    resultMap="BillDetailResult"/>
    </resultMap>

    <resultMap type="BillDetail" id="BillDetailResult">
        <result property="id" column="sub_id"/>
        <result property="billInfoId" column="sub_bill_info_id"/>
        <result property="index" column="sub_index"/>
        <result property="goodName" column="sub_good_name"/>
        <result property="num" column="sub_num"/>
        <result property="price" column="sub_price"/>
        <result property="hsbz" column="sub_hsbz"/>
        <result property="taxrate" column="sub_taxrate"/>
        <result property="spec" column="sub_spec"/>
        <result property="unit" column="sub_unit"/>
        <result property="spbm" column="sub_spbm"/>
        <result property="bmbbh" column="sub_bmbbh"/>
        <result property="zsbm" column="sub_zsbm"/>
        <result property="fphxz" column="sub_fphxz"/>
        <result property="yhzcbs" column="sub_yhzcbs"/>
        <result property="zzstsgl" column="sub_zzstsgl"/>
        <result property="lslbs" column="sub_lslbs"/>
        <result property="kce" column="sub_kce"/>
        <result property="taxfreeamt" column="sub_taxfreeamt"/>
        <result property="tax" column="sub_tax"/>
        <result property="taxamt" column="sub_taxamt"/>
        <result property="tspz" column="sub_tspz"/>
        <result property="createBy" column="sub_create_by"/>
        <result property="createTime" column="sub_create_time"/>
        <result property="updateBy" column="sub_update_by"/>
        <result property="updatedTime" column="sub_updated_time"/>
    </resultMap>

    <sql id="selectBillInfoVo">
        select id,
               company_id,
               system_orderno,
               out_trade_orderno,
               fpqqlsh,
               invoice_type,
               buyer_name,
               buyer_taxnum,
               buyer_address,
               buyer_telephone,
               buyer_bank,
               buyer_account,
               buyer_email,
               buyer_phone,
               seller_name,
               seller_taxnum,
               seller_address,
               seller_telephone,
               seller_account,
               message,
               seller_bank,
               clerk,
               payee,
               checker,
               red_invoice_info_code,
               fjh,
               terminal_number,
               remark,
               kptype,
               origin_system_orderno,
               bmbbh,
               origin_fpdm,
               origin_fphm,
               tsfs,
               qdbz,
               qdxmmc,
               dkbz,
               cpybz,
               state,
               source,
               service_supplier_key,
               bill_type,
               business_remark,
               taxfreeamt,
               invoiced_time,
               callback_url,
               create_by,
               tax,
               create_time,
               taxamt,
               update_by,
               update_time,
               deleted_time
        from bill_info
    </sql>

    <select id="selectBillInfoList" parameterType="BillInfo" resultMap="BillInfoResult">
        <include refid="selectBillInfoVo"/>
        <where>
            <if test="companyId != null ">and company_id = #{companyId}</if>
            <if test="systemOrderno != null  and systemOrderno != ''">and system_orderno = #{systemOrderno}</if>
            <if test="outTradeOrderno != null  and outTradeOrderno != ''">and out_trade_orderno = #{outTradeOrderno}
            </if>
            <if test="fpqqlsh != null  and fpqqlsh != ''">and fpqqlsh = #{fpqqlsh}</if>
            <if test="invoiceType != null  and invoiceType != ''">and invoice_type = #{invoiceType}</if>
            <if test="buyerName != null  and buyerName != ''">and buyer_name like concat('%', #{buyerName}, '%')</if>
            <if test="buyerTaxnum != null  and buyerTaxnum != ''">and buyer_taxnum = #{buyerTaxnum}</if>
            <if test="buyerAddress != null  and buyerAddress != ''">and buyer_address = #{buyerAddress}</if>
            <if test="buyerTelephone != null  and buyerTelephone != ''">and buyer_telephone = #{buyerTelephone}</if>
            <if test="buyerBank != null  and buyerBank != ''">and buyer_bank = #{buyerBank}</if>
            <if test="buyerAccount != null  and buyerAccount != ''">and buyer_account = #{buyerAccount}</if>
            <if test="buyerEmail != null  and buyerEmail != ''">and buyer_email = #{buyerEmail}</if>
            <if test="buyerPhone != null  and buyerPhone != ''">and buyer_phone = #{buyerPhone}</if>
            <if test="sellerName != null  and sellerName != ''">and seller_name like concat('%', #{sellerName}, '%')
            </if>
            <if test="sellerTaxnum != null  and sellerTaxnum != ''">and seller_taxnum = #{sellerTaxnum}</if>
            <if test="sellerAddress != null  and sellerAddress != ''">and seller_address = #{sellerAddress}</if>
            <if test="sellerTelephone != null  and sellerTelephone != ''">and seller_telephone = #{sellerTelephone}</if>
            <if test="sellerAccount != null  and sellerAccount != ''">and seller_account = #{sellerAccount}</if>
            <if test="message != null  and message != ''">and message = #{message}</if>
            <if test="sellerBank != null  and sellerBank != ''">and seller_bank = #{sellerBank}</if>
            <if test="clerk != null  and clerk != ''">and clerk = #{clerk}</if>
            <if test="payee != null  and payee != ''">and payee = #{payee}</if>
            <if test="checker != null  and checker != ''">and checker = #{checker}</if>
            <if test="redInvoiceInfoCode != null  and redInvoiceInfoCode != ''">and red_invoice_info_code =
                #{redInvoiceInfoCode}
            </if>
            <if test="fjh != null  and fjh != ''">and fjh = #{fjh}</if>
            <if test="terminalNumber != null  and terminalNumber != ''">and terminal_number = #{terminalNumber}</if>
            <if test="kptype != null  and kptype != ''">and kptype = #{kptype}</if>
            <if test="originSystemOrderno != null  and originSystemOrderno != ''">and origin_system_orderno =
                #{originSystemOrderno}
            </if>
            <if test="bmbbh != null  and bmbbh != ''">and bmbbh = #{bmbbh}</if>
            <if test="originFpdm != null  and originFpdm != ''">and origin_fpdm = #{originFpdm}</if>
            <if test="originFphm != null  and originFphm != ''">and origin_fphm = #{originFphm}</if>
            <if test="tsfs != null  and tsfs != ''">and tsfs = #{tsfs}</if>
            <if test="qdbz != null  and qdbz != ''">and qdbz = #{qdbz}</if>
            <if test="qdxmmc != null  and qdxmmc != ''">and qdxmmc = #{qdxmmc}</if>
            <if test="dkbz != null  and dkbz != ''">and dkbz = #{dkbz}</if>
            <if test="cpybz != null  and cpybz != ''">and cpybz = #{cpybz}</if>
            <if test="state != null ">and state = #{state}</if>
            <if test="source != null  and source != ''">and source = #{source}</if>
            <if test="serviceSupplierKey != null  and serviceSupplierKey != ''">and service_supplier_key =
                #{serviceSupplierKey}
            </if>
            <if test="billType != null  and billType != ''">and bill_type = #{billType}</if>
            <if test="businessRemark != null  and businessRemark != ''">and business_remark = #{businessRemark}</if>
            <if test="taxfreeamt != null ">and taxfreeamt = #{taxfreeamt}</if>
            <if test="invoicedTime != null ">and invoiced_time = #{invoicedTime}</if>
            <if test="tax != null ">and tax = #{tax}</if>
            <if test="taxamt != null ">and taxamt = #{taxamt}</if>
            <if test="callbackUrl != null ">and callback_url = #{callbackUrl}</if>
        </where>
    </select>

    <select id="selectBillInfoById" parameterType="Long" resultMap="BillInfoBillDetailResult">
        select a.id,
               a.company_id,
               a.system_orderno,
               a.out_trade_orderno,
               a.fpqqlsh,
               a.invoice_type,
               a.buyer_name,
               a.buyer_taxnum,
               a.buyer_address,
               a.buyer_telephone,
               a.buyer_bank,
               a.buyer_account,
               a.buyer_email,
               a.buyer_phone,
               a.seller_name,
               a.seller_taxnum,
               a.seller_address,
               a.seller_telephone,
               a.seller_account,
               a.message,
               a.seller_bank,
               a.clerk,
               a.payee,
               a.checker,
               a.red_invoice_info_code,
               a.fjh,
               a.terminal_number,
               a.remark,
               a.kptype,
               a.origin_system_orderno,
               a.bmbbh,
               a.origin_fpdm,
               a.origin_fphm,
               a.tsfs,
               a.qdbz,
               a.qdxmmc,
               a.dkbz,
               a.cpybz,
               a.state,
               a.source,
               a.service_supplier_key,
               a.bill_type,
               a.business_remark,
               a.taxfreeamt,
               a.invoiced_time,
               a.create_by,
               a.tax,
               a.taxamt,
               a.callback_url,
               a.create_time,
               a.update_by,
               a.update_time,
               a.deleted_time,
               b.id           as sub_id,
               b.bill_info_id as sub_bill_info_id,
               b.index        as sub_index,
               b.good_name    as sub_good_name,
               b.num          as sub_num,
               b.price        as sub_price,
               b.hsbz         as sub_hsbz,
               b.taxrate      as sub_taxrate,
               b.spec         as sub_spec,
               b.unit         as sub_unit,
               b.spbm         as sub_spbm,
               b.bmbbh        as sub_bmbbh,
               b.zsbm         as sub_zsbm,
               b.fphxz        as sub_fphxz,
               b.yhzcbs       as sub_yhzcbs,
               b.zzstsgl      as sub_zzstsgl,
               b.lslbs        as sub_lslbs,
               b.kce          as sub_kce,
               b.taxfreeamt   as sub_taxfreeamt,
               b.tax          as sub_tax,
               b.taxamt       as sub_taxamt,
               b.tspz         as sub_tspz,
               b.create_by    as sub_create_by,
               b.create_time  as sub_create_time,
               b.update_by    as sub_update_by,
               b.updated_time as sub_updated_time
        from bill_info a
                 left join bill_detail b on b.bill_info_id = a.id
        where a.id = #{id}
    </select>


    <select id="selectBySystemOrderNo" resultMap="BillInfoBillDetailResult">
        select a.id,
               a.company_id,
               a.system_orderno,
               a.out_trade_orderno,
               a.fpqqlsh,
               a.invoice_type,
               a.buyer_name,
               a.buyer_taxnum,
               a.buyer_address,
               a.buyer_telephone,
               a.buyer_bank,
               a.buyer_account,
               a.buyer_email,
               a.buyer_phone,
               a.seller_name,
               a.seller_taxnum,
               a.seller_address,
               a.seller_telephone,
               a.seller_account,
               a.message,
               a.seller_bank,
               a.clerk,
               a.payee,
               a.checker,
               a.red_invoice_info_code,
               a.fjh,
               a.terminal_number,
               a.remark,
               a.kptype,
               a.origin_system_orderno,
               a.bmbbh,
               a.origin_fpdm,
               a.origin_fphm,
               a.tsfs,
               a.qdbz,
               a.qdxmmc,
               a.dkbz,
               a.cpybz,
               a.state,
               a.source,
               a.service_supplier_key,
               a.bill_type,
               a.business_remark,
               a.taxfreeamt,
               a.invoiced_time,
               a.create_by,
               a.tax,
               a.callback_url,
               a.create_time,
               a.taxamt,
               a.update_by,
               a.update_time,
               a.deleted_time,
               b.id           as sub_id,
               b.bill_info_id as sub_bill_info_id,
               b.index        as sub_index,
               b.good_name    as sub_good_name,
               b.num          as sub_num,
               b.price        as sub_price,
               b.hsbz         as sub_hsbz,
               b.taxrate      as sub_taxrate,
               b.spec         as sub_spec,
               b.unit         as sub_unit,
               b.spbm         as sub_spbm,
               b.bmbbh        as sub_bmbbh,
               b.zsbm         as sub_zsbm,
               b.fphxz        as sub_fphxz,
               b.yhzcbs       as sub_yhzcbs,
               b.zzstsgl      as sub_zzstsgl,
               b.lslbs        as sub_lslbs,
               b.kce          as sub_kce,
               b.taxfreeamt   as sub_taxfreeamt,
               b.tax          as sub_tax,
               b.taxamt       as sub_taxamt,
               b.tspz         as sub_tspz,
               b.create_by    as sub_create_by,
               b.create_time  as sub_create_time,
               b.update_by    as sub_update_by,
               b.updated_time as sub_updated_time
        from bill_info a
                 left join bill_detail b on b.bill_info_id = a.id
        where a.company_id = #{companyId}
          and a.system_orderno = #{system_orderno}
    </select>

    <select id="selectByOutTradeOrderno" resultMap="BillInfoBillDetailResult">
        select a.id,
               a.company_id,
               a.system_orderno,
               a.out_trade_orderno,
               a.fpqqlsh,
               a.invoice_type,
               a.buyer_name,
               a.buyer_taxnum,
               a.buyer_address,
               a.buyer_telephone,
               a.buyer_bank,
               a.buyer_account,
               a.buyer_email,
               a.buyer_phone,
               a.seller_name,
               a.seller_taxnum,
               a.seller_address,
               a.seller_telephone,
               a.seller_account,
               a.message,
               a.seller_bank,
               a.clerk,
               a.payee,
               a.checker,
               a.red_invoice_info_code,
               a.fjh,
               a.terminal_number,
               a.remark,
               a.kptype,
               a.origin_system_orderno,
               a.bmbbh,
               a.origin_fpdm,
               a.origin_fphm,
               a.tsfs,
               a.qdbz,
               a.qdxmmc,
               a.dkbz,
               a.cpybz,
               a.state,
               a.source,
               a.service_supplier_key,
               a.bill_type,
               a.business_remark,
               a.taxfreeamt,
               a.invoiced_time,
               a.create_by,
               a.tax,
               a.callback_url,
               a.create_time,
               a.taxamt,
               a.update_by,
               a.update_time,
               a.deleted_time,
               b.id           as sub_id,
               b.bill_info_id as sub_bill_info_id,
               b.index        as sub_index,
               b.good_name    as sub_good_name,
               b.num          as sub_num,
               b.price        as sub_price,
               b.hsbz         as sub_hsbz,
               b.taxrate      as sub_taxrate,
               b.spec         as sub_spec,
               b.unit         as sub_unit,
               b.spbm         as sub_spbm,
               b.bmbbh        as sub_bmbbh,
               b.zsbm         as sub_zsbm,
               b.fphxz        as sub_fphxz,
               b.yhzcbs       as sub_yhzcbs,
               b.zzstsgl      as sub_zzstsgl,
               b.lslbs        as sub_lslbs,
               b.kce          as sub_kce,
               b.taxfreeamt   as sub_taxfreeamt,
               b.tax          as sub_tax,
               b.taxamt       as sub_taxamt,
               b.tspz         as sub_tspz,
               b.create_by    as sub_create_by,
               b.create_time  as sub_create_time,
               b.update_by    as sub_update_by,
               b.updated_time as sub_updated_time
        from bill_info a
                 left join bill_detail b on b.bill_info_id = a.id
        where a.company_id = #{companyId}
          and a.out_trade_orderno = #{out_trade_orderno}
        limit 1
    </select>

    <select id="selectByOutTradeOrdernoNotDel" resultMap="BillInfoBillDetailResult">
        select a.id,
               a.company_id,
               a.system_orderno,
               a.out_trade_orderno,
               a.fpqqlsh,
               a.invoice_type,
               a.buyer_name,
               a.buyer_taxnum,
               a.buyer_address,
               a.buyer_telephone,
               a.buyer_bank,
               a.buyer_account,
               a.buyer_email,
               a.buyer_phone,
               a.seller_name,
               a.seller_taxnum,
               a.seller_address,
               a.seller_telephone,
               a.seller_account,
               a.message,
               a.seller_bank,
               a.clerk,
               a.payee,
               a.checker,
               a.red_invoice_info_code,
               a.fjh,
               a.terminal_number,
               a.remark,
               a.kptype,
               a.origin_system_orderno,
               a.bmbbh,
               a.origin_fpdm,
               a.origin_fphm,
               a.tsfs,
               a.qdbz,
               a.qdxmmc,
               a.dkbz,
               a.cpybz,
               a.state,
               a.source,
               a.service_supplier_key,
               a.bill_type,
               a.business_remark,
               a.taxfreeamt,
               a.invoiced_time,
               a.create_by,
               a.tax,
               a.callback_url,
               a.create_time,
               a.taxamt,
               a.update_by,
               a.update_time,
               a.deleted_time,
               b.id           as sub_id,
               b.bill_info_id as sub_bill_info_id,
               b.index        as sub_index,
               b.good_name    as sub_good_name,
               b.num          as sub_num,
               b.price        as sub_price,
               b.hsbz         as sub_hsbz,
               b.taxrate      as sub_taxrate,
               b.spec         as sub_spec,
               b.unit         as sub_unit,
               b.spbm         as sub_spbm,
               b.bmbbh        as sub_bmbbh,
               b.zsbm         as sub_zsbm,
               b.fphxz        as sub_fphxz,
               b.yhzcbs       as sub_yhzcbs,
               b.zzstsgl      as sub_zzstsgl,
               b.lslbs        as sub_lslbs,
               b.kce          as sub_kce,
               b.taxfreeamt   as sub_taxfreeamt,
               b.tax          as sub_tax,
               b.taxamt       as sub_taxamt,
               b.tspz         as sub_tspz,
               b.create_by    as sub_create_by,
               b.create_time  as sub_create_time,
               b.update_by    as sub_update_by,
               b.updated_time as sub_updated_time
        from bill_info a
                 left join bill_detail b on b.bill_info_id = a.id
        where a.company_id = #{companyId}
          and a.out_trade_orderno = #{out_trade_orderno}
            and a.update_by = #{updateBy}
    </select>


    <insert id="insertBillInfo" parameterType="BillInfo" useGeneratedKeys="true" keyProperty="id">
        insert into bill_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="systemOrderno != null">system_orderno,</if>
            <if test="outTradeOrderno != null">out_trade_orderno,</if>
            <if test="fpqqlsh != null">fpqqlsh,</if>
            <if test="invoiceType != null">invoice_type,</if>
            <if test="buyerName != null">buyer_name,</if>
            <if test="buyerTaxnum != null">buyer_taxnum,</if>
            <if test="buyerAddress != null">buyer_address,</if>
            <if test="buyerTelephone != null">buyer_telephone,</if>
            <if test="buyerBank != null">buyer_bank,</if>
            <if test="buyerAccount != null">buyer_account,</if>
            <if test="buyerEmail != null">buyer_email,</if>
            <if test="buyerPhone != null">buyer_phone,</if>
            <if test="sellerName != null">seller_name,</if>
            <if test="sellerTaxnum != null">seller_taxnum,</if>
            <if test="sellerAddress != null">seller_address,</if>
            <if test="sellerTelephone != null">seller_telephone,</if>
            <if test="sellerAccount != null">seller_account,</if>
            <if test="message != null">message,</if>
            <if test="sellerBank != null">seller_bank,</if>
            <if test="clerk != null">clerk,</if>
            <if test="payee != null">payee,</if>
            <if test="checker != null">checker,</if>
            <if test="redInvoiceInfoCode != null">red_invoice_info_code,</if>
            <if test="fjh != null">fjh,</if>
            <if test="terminalNumber != null">terminal_number,</if>
            <if test="remark != null">remark,</if>
            <if test="kptype != null">kptype,</if>
            <if test="originSystemOrderno != null">origin_system_orderno,</if>
            <if test="bmbbh != null and bmbbh != ''">bmbbh,</if>
            <if test="originFpdm != null">origin_fpdm,</if>
            <if test="originFphm != null">origin_fphm,</if>
            <if test="tsfs != null">tsfs,</if>
            <if test="qdbz != null">qdbz,</if>
            <if test="qdxmmc != null">qdxmmc,</if>
            <if test="dkbz != null">dkbz,</if>
            <if test="cpybz != null">cpybz,</if>
            <if test="state != null">state,</if>
            <if test="source != null">source,</if>
            <if test="serviceSupplierKey != null and serviceSupplierKey != ''">service_supplier_key,</if>
            <if test="billType != null">bill_type,</if>
            <if test="businessRemark != null">business_remark,</if>
            <if test="taxfreeamt != null">taxfreeamt,</if>
            <if test="invoicedTime != null">invoiced_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="tax != null">tax,</if>
            <if test="createTime != null">create_time,</if>
            <if test="taxamt != null">taxamt,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deletedTime != null">deleted_time,</if>
            <if test="callbackUrl != null">callback_url,</if>
            <if test="jbrxm != null">jbrxm,</if>
            <if test="jbrzjhm != null">jbrzjhm,</if>
            <if test="jbrzjzldm != null">jbrzjzldm,</if>
            <if test="jrznsrsbh != null">jrznsrsbh,</if>
            <if test="jshj != null">jshj,</if>
            <if test="tdyslxdm != null">tdyslxdm,</if>
            <if test="tdywxx != null">tdywxx,</if>
            <if test="ext != null">ext,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="systemOrderno != null">#{systemOrderno},</if>
            <if test="outTradeOrderno != null">#{outTradeOrderno},</if>
            <if test="fpqqlsh != null">#{fpqqlsh},</if>
            <if test="invoiceType != null">#{invoiceType},</if>
            <if test="buyerName != null">#{buyerName},</if>
            <if test="buyerTaxnum != null">#{buyerTaxnum},</if>
            <if test="buyerAddress != null">#{buyerAddress},</if>
            <if test="buyerTelephone != null">#{buyerTelephone},</if>
            <if test="buyerBank != null">#{buyerBank},</if>
            <if test="buyerAccount != null">#{buyerAccount},</if>
            <if test="buyerEmail != null">#{buyerEmail},</if>
            <if test="buyerPhone != null">#{buyerPhone},</if>
            <if test="sellerName != null">#{sellerName},</if>
            <if test="sellerTaxnum != null">#{sellerTaxnum},</if>
            <if test="sellerAddress != null">#{sellerAddress},</if>
            <if test="sellerTelephone != null">#{sellerTelephone},</if>
            <if test="sellerAccount != null">#{sellerAccount},</if>
            <if test="message != null">#{message},</if>
            <if test="sellerBank != null">#{sellerBank},</if>
            <if test="clerk != null">#{clerk},</if>
            <if test="payee != null">#{payee},</if>
            <if test="checker != null">#{checker},</if>
            <if test="redInvoiceInfoCode != null">#{redInvoiceInfoCode},</if>
            <if test="fjh != null">#{fjh},</if>
            <if test="terminalNumber != null">#{terminalNumber},</if>
            <if test="remark != null">#{remark},</if>
            <if test="kptype != null">#{kptype},</if>
            <if test="originSystemOrderno != null">#{originSystemOrderno},</if>
            <if test="bmbbh != null and bmbbh != ''">#{bmbbh},</if>
            <if test="originFpdm != null">#{originFpdm},</if>
            <if test="originFphm != null">#{originFphm},</if>
            <if test="tsfs != null">#{tsfs},</if>
            <if test="qdbz != null">#{qdbz},</if>
            <if test="qdxmmc != null">#{qdxmmc},</if>
            <if test="dkbz != null">#{dkbz},</if>
            <if test="cpybz != null">#{cpybz},</if>
            <if test="state != null">#{state},</if>
            <if test="source != null">#{source},</if>
            <if test="serviceSupplierKey != null and serviceSupplierKey != ''">#{serviceSupplierKey},</if>
            <if test="billType != null">#{billType},</if>
            <if test="businessRemark != null">#{businessRemark},</if>
            <if test="taxfreeamt != null">#{taxfreeamt},</if>
            <if test="invoicedTime != null">#{invoicedTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="tax != null">#{tax},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="taxamt != null">#{taxamt},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deletedTime != null">#{deletedTime},</if>
            <if test="callbackUrl != null">#{callbackUrl},</if>
            <if test="jbrxm != null">#{jbrxm},</if>
            <if test="jbrzjhm != null">#{jbrzjhm},</if>
            <if test="jbrzjzldm != null">#{jbrzjzldm},</if>
            <if test="jrznsrsbh != null">#{jrznsrsbh},</if>
            <if test="jshj != null">#{jshj},</if>
            <if test="tdyslxdm != null">#{tdyslxdm},</if>
            <if test="tdywxx != null">#{tdywxx},</if>
            <if test="ext != null">#{ext},</if>
        </trim>
    </insert>

    <update id="updateBillInfo" parameterType="BillInfo">
        update bill_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="systemOrderno != null">system_orderno = #{systemOrderno},</if>
            <if test="outTradeOrderno != null">out_trade_orderno = #{outTradeOrderno},</if>
            <if test="fpqqlsh != null">fpqqlsh = #{fpqqlsh},</if>
            <if test="invoiceType != null">invoice_type = #{invoiceType},</if>
            <if test="buyerName != null">buyer_name = #{buyerName},</if>
            <if test="buyerTaxnum != null">buyer_taxnum = #{buyerTaxnum},</if>
            <if test="buyerAddress != null">buyer_address = #{buyerAddress},</if>
            <if test="buyerTelephone != null">buyer_telephone = #{buyerTelephone},</if>
            <if test="buyerBank != null">buyer_bank = #{buyerBank},</if>
            <if test="buyerAccount != null">buyer_account = #{buyerAccount},</if>
            <if test="buyerEmail != null">buyer_email = #{buyerEmail},</if>
            <if test="buyerPhone != null">buyer_phone = #{buyerPhone},</if>
            <if test="sellerName != null">seller_name = #{sellerName},</if>
            <if test="sellerTaxnum != null">seller_taxnum = #{sellerTaxnum},</if>
            <if test="sellerAddress != null">seller_address = #{sellerAddress},</if>
            <if test="sellerTelephone != null">seller_telephone = #{sellerTelephone},</if>
            <if test="sellerAccount != null">seller_account = #{sellerAccount},</if>
            <if test="message != null">message = #{message},</if>
            <if test="sellerBank != null">seller_bank = #{sellerBank},</if>
            <if test="clerk != null">clerk = #{clerk},</if>
            <if test="payee != null">payee = #{payee},</if>
            <if test="checker != null">checker = #{checker},</if>
            <if test="redInvoiceInfoCode != null">red_invoice_info_code = #{redInvoiceInfoCode},</if>
            <if test="fjh != null">fjh = #{fjh},</if>
            <if test="terminalNumber != null">terminal_number = #{terminalNumber},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="kptype != null">kptype = #{kptype},</if>
            <if test="originSystemOrderno != null">origin_system_orderno = #{originSystemOrderno},</if>
            <if test="bmbbh != null and bmbbh != ''">bmbbh = #{bmbbh},</if>
            <if test="originFpdm != null">origin_fpdm = #{originFpdm},</if>
            <if test="originFphm != null">origin_fphm = #{originFphm},</if>
            <if test="tsfs != null">tsfs = #{tsfs},</if>
            <if test="qdbz != null">qdbz = #{qdbz},</if>
            <if test="qdxmmc != null">qdxmmc = #{qdxmmc},</if>
            <if test="dkbz != null">dkbz = #{dkbz},</if>
            <if test="cpybz != null">cpybz = #{cpybz},</if>
            <if test="state != null">state = #{state},</if>
            <if test="source != null">source = #{source},</if>
            <if test="serviceSupplierKey != null and serviceSupplierKey != ''">
                service_supplier_key = #{serviceSupplierKey},
            </if>
            <if test="callbackUrl != null">callback_url = #{callbackUrl},</if>
            <if test="billType != null">bill_type = #{billType},</if>
            <if test="businessRemark != null">business_remark = #{businessRemark},</if>
            <if test="taxfreeamt != null">taxfreeamt = #{taxfreeamt},</if>
            <if test="invoicedTime != null">invoiced_time = #{invoicedTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="tax != null">tax = #{tax},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="taxamt != null">taxamt = #{taxamt},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deletedTime != null">deleted_time = #{deletedTime},</if>
            <if test="jbrxm != null">jbrxm = #{jbrxm},</if>
            <if test="jbrzjhm != null">jbrzjhm = #{jbrzjhm},</if>
            <if test="jbrzjzldm != null">jbrzjzldm = #{jbrzjzldm},</if>
            <if test="jrznsrsbh != null">jrznsrsbh = #{jrznsrsbh},</if>
            <if test="jshj != null">jshj = #{jshj},</if>
            <if test="tdyslxdm != null">tdyslxdm = #{tdyslxdm},</if>
            <if test="tdywxx != null">tdywxx = #{tdywxx},</if>
            <if test="ext != null">ext = #{ext},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBillInfoById" parameterType="Long">
        delete
        from bill_info
        where id = #{id}
    </delete>

    <delete id="deleteBillInfoByIds" parameterType="String">
        delete from bill_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteBillDetailByBillInfoIds" parameterType="String">
        delete from bill_detail where bill_info_id in
        <foreach item="billInfoId" collection="array" open="(" separator="," close=")">
            #{billInfoId}
        </foreach>
    </delete>

    <delete id="deleteBillDetailByBillInfoId" parameterType="Long">
        delete
        from bill_detail
        where bill_info_id = #{billInfoId}
    </delete>

    <insert id="batchBillDetail">
        insert into bill_detail( id, bill_info_id, `index`, good_name, num, price, hsbz, taxrate, spec, unit, spbm,
        bmbbh, zsbm, fphxz, yhzcbs, zzstsgl, lslbs, kce, taxfreeamt, tax, taxamt, tspz, create_by, create_time,
        update_by, updated_time) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.billInfoId}, #{item.index}, #{item.goodName}, #{item.num}, #{item.price}, #{item.hsbz},
            #{item.taxrate}, #{item.spec}, #{item.unit}, #{item.spbm}, #{item.bmbbh}, #{item.zsbm}, #{item.fphxz},
            #{item.yhzcbs}, #{item.zzstsgl}, #{item.lslbs}, #{item.kce}, #{item.taxfreeamt}, #{item.tax},
            #{item.taxamt}, #{item.tspz}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updatedTime})
        </foreach>
    </insert>
</mapper>
