<?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.xhpc.user.mapper.XhpcInvoiceMapper">
    <resultMap id="BaseResultMap" type="com.xhpc.user.pojo.XhpcInvoice">
        <id column="invoice_id" jdbcType="BIGINT" property="invoiceId"/>
        <result column="invoice_type" jdbcType="INTEGER" property="invoiceType"/>
        <result column="receive_email" jdbcType="VARCHAR" property="receiveEmail"/>
        <result column="title_type" jdbcType="INTEGER" property="titleType"/>
        <result column="title_content" jdbcType="VARCHAR" property="titleContent"/>
        <result column="duty_number" jdbcType="VARCHAR" property="dutyNumber"/>
        <result column="invoice_content" jdbcType="VARCHAR" property="invoiceContent"/>
        <result column="invoice_money" jdbcType="DECIMAL" property="invoiceMoney"/>
        <result column="invoice_order_eletric_total_money" jdbcType="DECIMAL" property="invoiceOrderEletricTotalMoney"/>
        <result column="invoice_order_service_total_money" jdbcType="DECIMAL" property="invoiceOrderServiceTotalMoney"/>
        <result column="firm_address" jdbcType="VARCHAR" property="firmAddress"/>
        <result column="firm_phone" jdbcType="VARCHAR" property="firmPhone"/>
        <result column="firm_bank" jdbcType="VARCHAR" property="firmBank"/>
        <result column="firm_bank_account" jdbcType="VARCHAR" property="firmBankAccount"/>
        <result column="is_show_date" jdbcType="INTEGER" property="isShowDate"/>
        <result column="user_notes" jdbcType="VARCHAR" property="userNotes"/>
        <result column="creator_id" jdbcType="BIGINT" property="creatorId"/>
        <result column="creator_type" jdbcType="INTEGER" property="creatorType"/>
        <result column="creator" jdbcType="VARCHAR" property="creator"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="invoicing_time" jdbcType="TIMESTAMP" property="invoicingTime"/>
        <result column="drawer" jdbcType="VARCHAR" property="drawer"/>
        <result column="finance_notes" jdbcType="VARCHAR" property="financeNotes"/>
        <result column="electric_invoice_url" jdbcType="VARCHAR" property="electricInvoiceUrl"/>
        <result column="updator" jdbcType="BIGINT" property="updator"/>
        <result column="update_time" jdbcType="DATE" property="updateTime"/>
        <result column="is_read" jdbcType="TINYINT" property="isRead"/>
        <result column="del_flag" jdbcType="INTEGER" property="delFlag"/>
    </resultMap>

    <sql id="Base_Column_List">
        `invoice_id`
        ,invoice_type,
          `receive_email`,
          `title_type`,
          `title_content`,
          `duty_number`,
          `invoice_content`,
          `invoice_money`,
          `invoice_order_eletric_total_money`,
          `invoice_order_service_total_money`,
          `firm_address`,
          `firm_phone`,
          `firm_bank`,
          `firm_bank_account`,
          `is_show_date`,
          `user_notes`,
          `creator_id`,
          `creator_type`,
          `creator`,
          `create_time`,
          `status`,
          `invoicing_time`,
          `drawer`,
          `finance_notes`,
          `electric_invoice_url`,
          `updator`,
          `update_time`,
          `is_read`,
            tenant_id,
          `del_flag`
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from xhpc_invoice
        where invoice_id = #{invoiceId,jdbcType=BIGINT} and del_flag is null;
    </select>
    <select id="selectAllInvoiceOrdersByCondition" resultMap="BaseResultMap">
        SELECT
        invoice_id,
        invoice_type,
        tenant_id,
        creator,
        creator_type,
        invoice_money,
        status,
        create_time,
        invoicing_time,
        drawer
        FROM
        xhpc_invoice
        <where>
            del_flag IS NULL
            <if test="creator!=null and creator!='' ">
                and creator like concat('%', #{creator}, '%')
            </if>
            <if test="creatorType!=null">
                and creator_type = #{creatorType}
            </if>
            <if test="invoiceType!=null">
                and invoice_type = #{invoiceType}
            </if>
            <if test="tenantId!=null and tenantId !=''">
                and tenant_id = #{tenantId}
            </if>
            <if test="status!=null">
                and status = #{status}
            </if>
            <if test="startCreatorTime!=null">
                and create_time &gt;= #{startCreatorTime}
            </if>
            <if test="endCreatorTime!=null">
                and create_time &lt;= #{endCreatorTime}
            </if>
            <if test="startInvoicingTime!=null">
                and invoicing_time &gt;= #{startInvoicingTime}
            </if>
            <if test="endInvoicingTime!=null">
                and invoicing_time &lt;= #{endInvoicingTime}
            </if>
        </where>
        ORDER BY
        STATUS ASC,
        create_time DESC
        LIMIT #{currentPage},#{items}
    </select>
    <select id="sumItemsInvoice" resultType="java.lang.Long">
        SELECT
        count(invoice_id)
        FROM
        xhpc_invoice
        <where>
            del_flag IS NULL
            <if test="creator!=null">
                and creator = #{creator}
            </if>
            <if test="creatorType!=null">
                and creator_type = #{creatorType}
            </if>
            <if test="invoiceType!=null">
                and invoice_type = #{invoiceType}
            </if>
            <if test="tenantId!=null">
                and tenant_id = #{tenantId}
            </if>
            <if test="status!=null">
                and status = #{status}
            </if>
            <if test="startCreatorTime!=null">
                and create_time &gt;= #{startCreatorTime}
            </if>
            <if test="endCreatorTime!=null">
                and create_time &lt;= #{endCreatorTime}
            </if>
            <if test="startInvoicingTime!=null">
                and invoicing_time &gt;= #{startInvoicingTime}
            </if>
            <if test="endInvoicingTime!=null">
                and invoicing_time &lt;= #{endInvoicingTime}
            </if>
        </where>
    </select>
    <select id="allInvoicedMoney" resultType="java.math.BigDecimal">
        SELECT sum(invoice_money)
        FROM xhpc_invoice
        WHERE del_flag IS NULL
          AND `status` = 1
    </select>
    <select id="allNotInvoicedMoney" resultType="java.math.BigDecimal">
        SELECT sum(invoice_money)
        FROM xhpc_invoice
        WHERE del_flag IS NULL
          AND `status` = 0
    </select>
    <select id="selectInvoiceTitleInfo" resultMap="BaseResultMap">
        SELECT title_content,
               duty_number
        FROM `xhpc_invoice`
        WHERE title_content LIKE concat("%", #{firmName}, "%")
        GROUP BY title_content LIMIT 0,3
    </select>
    <select id="selectUserLastInputInvoiceInfo" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM `xhpc_invoice`
        WHERE creator_id = #{creatorId}
        AND creator_type = #{creatorType}
        ORDER BY invoice_id DESC LIMIT 0,1
    </select>
    <select id="findInvoicesByCreatorIdAndCreatorType" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM xhpc_invoice
        WHERE del_flag IS NULL
        AND creator_id = #{creatorId}
        AND creator_type = #{creatorType}
        ORDER BY create_time DESC
        LIMIT #{currentPage}, #{items}
    </select>
    <select id="getUserInvoiceItemsByCreatorIdAndCreatorType" resultType="java.lang.Long">
        SELECT count(invoice_id)
        FROM xhpc_invoice
        WHERE del_flag IS NULL
          AND creator_id = #{creatorId}
          AND creator_type = #{creatorType}
    </select>
    <select id="findNotReadCount" resultType="java.lang.Long">
        SELECT count(invoice_id)
        FROM xhpc_invoice
        WHERE del_flag IS NULL
          AND is_read = 0
          AND creator_id = #{creatorId}
          AND creator_type = #{creatorType}
    </select>
    <select id="selectExcelInvoiceById" resultType="com.xhpc.user.domain.ExcelInvoiceRow">
        SELECT case i.invoice_type when 0 then '普票' when 1 then '专票' end                as invoiceType,
               i.receive_email                                                          as receiveEmail,
               case i.title_type when 0 THEN '企业' ELSE '个人/非企业' END                     as titleType,
               i.title_content                                                          as titleContent,
               i.duty_number                                                            as dutyNumber,
               i.invoice_content                                                        as invoiceContent,
               i.invoice_money                                                          as invoiceMoney,
               i.invoice_order_service_total_money                                      as invoiceOrderServiceTotalMoney,
               i.invoice_order_eletric_total_money                                      as invoiceOrderElectricTotalMoney,
               i.firm_address                                                           as firmAddress,
               i.firm_phone                                                             as firmPhone,
               i.firm_bank                                                              as firmBank,
               i.firm_bank_account                                                      as firmBankAccount,
               case i.is_show_date when 0 then '开票者要求展示交易日期' ELSE '开票者不要求展示交易日期' END    as isShowDate,
               i.user_notes                                                             as userNotes,
               case i.creator_type
                   when 0 then 'C端用户'
                   when 1 then '流量方'
                   when 2 then '社区用户'
                   when 3
                       then '企业用户' END                                                  as creatorType,
               i.creator                                                                as creator,
               i.create_time                                                            as iCreateTime,
               case i.status when 0 then '未开票' when 1 then '已开票' when 2 then '开票失败' END as status,
               i.invoicing_time                                                         as invoicingTime,
               i.drawer,
               i.finance_notes                                                          as financeNotes,
               i.electric_invoice_url                                                   as electricInvoiceUrl,
               case i.is_read when 1 then '已阅读' when 0 then '未阅读' else '该发票还未处理' END    as isRead,
               h.history_serial_number                                                  as historySerialNumber,
               h.power_price_total                                                      as powerPriceTotal,
               h.service_price_total                                                    as servicePriceTotal,
               h.promotion_discount                                                     as promotionDiscount,
               history_act_price                                                        as historyActPrice,
               h.create_time                                                            as hCreateTime,
               h.charging_mode                                                          as chargingMode
        FROM xhpc_invoice AS i
                 INNER JOIN xhpc_invoice_map_history_order AS h ON i.invoice_id = h.invoice_id
        WHERE i.invoice_id = #{invoiceId}
          AND i.del_flag IS NULL
          AND h.del_flag IS NULL
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from xhpc_invoice
        where invoice_id = #{invoiceId,jdbcType=BIGINT}
    </delete>
    <insert id="insert" keyColumn="invoice_id" keyProperty="invoiceId" parameterType="com.xhpc.user.pojo.XhpcInvoice"
            useGeneratedKeys="true">
        insert into xhpc_invoice (receive_email, title_type, title_content,
                                  duty_number, invoice_content, invoice_money,
                                  invoice_order_eletric_total_money, invoice_order_service_total_money,
                                  firm_address, firm_phone, firm_bank,
                                  firm_bank_account, is_show_date, user_notes,
                                  creator_id, creator_type, creator,
                                  create_time, `status`, invoicing_time,
                                  drawer, finance_notes, electric_invoice_url,
                                  updator, update_time, del_flag, tenant_id)
        values (#{receiveEmail,jdbcType=VARCHAR}, #{titleType,jdbcType=INTEGER}, #{titleContent,jdbcType=VARCHAR},
                #{dutyNumber,jdbcType=VARCHAR}, #{invoiceContent,jdbcType=VARCHAR}, #{invoiceMoney,jdbcType=DECIMAL},
                #{invoiceOrderEletricTotalMoney,jdbcType=DECIMAL}, #{invoiceOrderServiceTotalMoney,jdbcType=DECIMAL},
                #{firmAddress,jdbcType=VARCHAR}, #{firmPhone,jdbcType=VARCHAR}, #{firmBank,jdbcType=VARCHAR},
                #{firmBankAccount,jdbcType=VARCHAR}, #{isShowDate,jdbcType=INTEGER}, #{userNotes,jdbcType=VARCHAR},
                #{creatorId,jdbcType=BIGINT}, #{creatorType,jdbcType=INTEGER}, #{creator,jdbcType=VARCHAR},
                #{createTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, #{invoicingTime,jdbcType=TIMESTAMP},
                #{drawer,jdbcType=VARCHAR}, #{financeNotes,jdbcType=VARCHAR}, #{electricInvoiceUrl,jdbcType=VARCHAR},
                #{updator,jdbcType=BIGINT}, #{updateTime,jdbcType=DATE}, #{delFlag,jdbcType=INTEGER},
                #{tenantId,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" keyColumn="invoice_id" keyProperty="invoiceId"
            parameterType="com.xhpc.user.pojo.XhpcInvoice" useGeneratedKeys="true">
        insert into xhpc_invoice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="receiveEmail != null">
                receive_email,
            </if>
            <if test="titleType != null">
                title_type,
            </if>
            <if test="titleContent != null">
                title_content,
            </if>
            <if test="dutyNumber != null">
                duty_number,
            </if>
            <if test="invoiceContent != null">
                invoice_content,
            </if>
            <if test="invoiceMoney != null">
                invoice_money,
            </if>
            <if test="invoiceOrderEletricTotalMoney != null">
                invoice_order_eletric_total_money,
            </if>
            <if test="invoiceOrderServiceTotalMoney != null">
                invoice_order_service_total_money,
            </if>
            <if test="firmAddress != null">
                firm_address,
            </if>
            <if test="firmPhone != null">
                firm_phone,
            </if>
            <if test="firmBank != null">
                firm_bank,
            </if>
            <if test="firmBankAccount != null">
                firm_bank_account,
            </if>
            <if test="isShowDate != null">
                is_show_date,
            </if>
            <if test="userNotes != null">
                user_notes,
            </if>
            <if test="creatorId != null">
                creator_id,
            </if>
            <if test="creatorType != null">
                creator_type,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="status != null">
                `status`,
            </if>
            <if test="invoicingTime != null">
                invoicing_time,
            </if>
            <if test="drawer != null">
                drawer,
            </if>
            <if test="financeNotes != null">
                finance_notes,
            </if>
            <if test="electricInvoiceUrl != null">
                electric_invoice_url,
            </if>
            <if test="updator != null">
                updator,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="delFlag != null">
                del_flag,
            </if>
            <if test="tenantId != null">
                tenant_id
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="receiveEmail != null">
                #{receiveEmail,jdbcType=VARCHAR},
            </if>
            <if test="titleType != null">
                #{titleType,jdbcType=INTEGER},
            </if>
            <if test="titleContent != null">
                #{titleContent,jdbcType=VARCHAR},
            </if>
            <if test="dutyNumber != null">
                #{dutyNumber,jdbcType=VARCHAR},
            </if>
            <if test="invoiceContent != null">
                #{invoiceContent,jdbcType=VARCHAR},
            </if>
            <if test="invoiceMoney != null">
                #{invoiceMoney,jdbcType=DECIMAL},
            </if>
            <if test="invoiceOrderEletricTotalMoney != null">
                #{invoiceOrderEletricTotalMoney,jdbcType=DECIMAL},
            </if>
            <if test="invoiceOrderServiceTotalMoney != null">
                #{invoiceOrderServiceTotalMoney,jdbcType=DECIMAL},
            </if>
            <if test="firmAddress != null">
                #{firmAddress,jdbcType=VARCHAR},
            </if>
            <if test="firmPhone != null">
                #{firmPhone,jdbcType=VARCHAR},
            </if>
            <if test="firmBank != null">
                #{firmBank,jdbcType=VARCHAR},
            </if>
            <if test="firmBankAccount != null">
                #{firmBankAccount,jdbcType=VARCHAR},
            </if>
            <if test="isShowDate != null">
                #{isShowDate,jdbcType=INTEGER},
            </if>
            <if test="userNotes != null">
                #{userNotes,jdbcType=VARCHAR},
            </if>
            <if test="creatorId != null">
                #{creatorId,jdbcType=BIGINT},
            </if>
            <if test="creatorType != null">
                #{creatorType,jdbcType=INTEGER},
            </if>
            <if test="creator != null">
                #{creator,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="invoicingTime != null">
                #{invoicingTime,jdbcType=TIMESTAMP},
            </if>
            <if test="drawer != null">
                #{drawer,jdbcType=VARCHAR},
            </if>
            <if test="financeNotes != null">
                #{financeNotes,jdbcType=VARCHAR},
            </if>
            <if test="electricInvoiceUrl != null">
                #{electricInvoiceUrl,jdbcType=VARCHAR},
            </if>
            <if test="updator != null">
                #{updator,jdbcType=BIGINT},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=DATE},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=INTEGER},
            </if>
            <if test="tenantId != null">
                #{tenantId,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <insert id="insertSelectiveAndReturnId" parameterType="com.xhpc.user.pojo.XhpcInvoice"
            keyProperty="invoiceId" useGeneratedKeys="true">
        insert into xhpc_invoice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="receiveEmail != null">
                receive_email,
            </if>
            <if test="titleType != null">
                title_type,
            </if>
            <if test="titleContent != null">
                title_content,
            </if>
            <if test="dutyNumber != null">
                duty_number,
            </if>
            <if test="invoiceContent != null">
                invoice_content,
            </if>
            <if test="invoiceMoney != null">
                invoice_money,
            </if>
            <if test="invoiceOrderEletricTotalMoney != null">
                invoice_order_eletric_total_money,
            </if>
            <if test="invoiceOrderServiceTotalMoney != null">
                invoice_order_service_total_money,
            </if>
            <if test="firmAddress != null">
                firm_address,
            </if>
            <if test="firmPhone != null">
                firm_phone,
            </if>
            <if test="firmBank != null">
                firm_bank,
            </if>
            <if test="firmBankAccount != null">
                firm_bank_account,
            </if>
            <if test="isShowDate != null">
                is_show_date,
            </if>
            <if test="userNotes != null">
                user_notes,
            </if>
            <if test="creatorId != null">
                creator_id,
            </if>
            <if test="creatorType != null">
                creator_type,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="status != null">
                `status`,
            </if>
            <if test="invoicingTime != null">
                invoicing_time,
            </if>
            <if test="drawer != null">
                drawer,
            </if>
            <if test="financeNotes != null">
                finance_notes,
            </if>
            <if test="electricInvoiceUrl != null">
                electric_invoice_url,
            </if>
            <if test="updator != null">
                updator,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="delFlag != null">
                del_flag,
            </if>
            <if test="tenantId != null">
                tenant_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="receiveEmail != null">
                #{receiveEmail,jdbcType=VARCHAR},
            </if>
            <if test="titleType != null">
                #{titleType,jdbcType=INTEGER},
            </if>
            <if test="titleContent != null">
                #{titleContent,jdbcType=VARCHAR},
            </if>
            <if test="dutyNumber != null">
                #{dutyNumber,jdbcType=VARCHAR},
            </if>
            <if test="invoiceContent != null">
                #{invoiceContent,jdbcType=VARCHAR},
            </if>
            <if test="invoiceMoney != null">
                #{invoiceMoney,jdbcType=DECIMAL},
            </if>
            <if test="invoiceOrderEletricTotalMoney != null">
                #{invoiceOrderEletricTotalMoney,jdbcType=DECIMAL},
            </if>
            <if test="invoiceOrderServiceTotalMoney != null">
                #{invoiceOrderServiceTotalMoney,jdbcType=DECIMAL},
            </if>
            <if test="firmAddress != null">
                #{firmAddress,jdbcType=VARCHAR},
            </if>
            <if test="firmPhone != null">
                #{firmPhone,jdbcType=VARCHAR},
            </if>
            <if test="firmBank != null">
                #{firmBank,jdbcType=VARCHAR},
            </if>
            <if test="firmBankAccount != null">
                #{firmBankAccount,jdbcType=VARCHAR},
            </if>
            <if test="isShowDate != null">
                #{isShowDate,jdbcType=INTEGER},
            </if>
            <if test="userNotes != null">
                #{userNotes,jdbcType=VARCHAR},
            </if>
            <if test="creatorId != null">
                #{creatorId,jdbcType=BIGINT},
            </if>
            <if test="creatorType != null">
                #{creatorType,jdbcType=INTEGER},
            </if>
            <if test="creator != null">
                #{creator,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="invoicingTime != null">
                #{invoicingTime,jdbcType=TIMESTAMP},
            </if>
            <if test="drawer != null">
                #{drawer,jdbcType=VARCHAR},
            </if>
            <if test="financeNotes != null">
                #{financeNotes,jdbcType=VARCHAR},
            </if>
            <if test="electricInvoiceUrl != null">
                #{electricInvoiceUrl,jdbcType=VARCHAR},
            </if>
            <if test="updator != null">
                #{updator,jdbcType=BIGINT},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=DATE},
            </if>
            <if test="delFlag != null">
                #{delFlag,jdbcType=INTEGER},
            </if>
            <if test="tenantId != null">
                #{tenantId,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.xhpc.user.pojo.XhpcInvoice">
        update xhpc_invoice
        <set>
            <if test="receiveEmail != null">
                receive_email = #{receiveEmail,jdbcType=VARCHAR},
            </if>
            <if test="titleType != null">
                title_type = #{titleType,jdbcType=INTEGER},
            </if>
            <if test="titleContent != null">
                title_content = #{titleContent,jdbcType=VARCHAR},
            </if>
            <if test="dutyNumber != null">
                duty_number = #{dutyNumber,jdbcType=VARCHAR},
            </if>
            <if test="invoiceContent != null">
                invoice_content = #{invoiceContent,jdbcType=VARCHAR},
            </if>
            <if test="invoiceMoney != null">
                invoice_money = #{invoiceMoney,jdbcType=DECIMAL},
            </if>
            <if test="invoiceOrderEletricTotalMoney != null">
                invoice_order_eletric_total_money = #{invoiceOrderEletricTotalMoney,jdbcType=DECIMAL},
            </if>
            <if test="invoiceOrderServiceTotalMoney != null">
                invoice_order_service_total_money = #{invoiceOrderServiceTotalMoney,jdbcType=DECIMAL},
            </if>
            <if test="firmAddress != null">
                firm_address = #{firmAddress,jdbcType=VARCHAR},
            </if>
            <if test="firmPhone != null">
                firm_phone = #{firmPhone,jdbcType=VARCHAR},
            </if>
            <if test="firmBank != null">
                firm_bank = #{firmBank,jdbcType=VARCHAR},
            </if>
            <if test="firmBankAccount != null">
                firm_bank_account = #{firmBankAccount,jdbcType=VARCHAR},
            </if>
            <if test="isShowDate != null">
                is_show_date = #{isShowDate,jdbcType=INTEGER},
            </if>
            <if test="userNotes != null">
                user_notes = #{userNotes,jdbcType=VARCHAR},
            </if>
            <if test="creatorId != null">
                creator_id = #{creatorId,jdbcType=BIGINT},
            </if>
            <if test="creatorType != null">
                creator_type = #{creatorType,jdbcType=INTEGER},
            </if>
            <if test="creator != null">
                creator = #{creator,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="status != null">
                `status` = #{status,jdbcType=INTEGER},
            </if>
            <if test="invoicingTime != null">
                invoicing_time = #{invoicingTime,jdbcType=TIMESTAMP},
            </if>
            <if test="drawer != null">
                drawer = #{drawer,jdbcType=VARCHAR},
            </if>
            <if test="financeNotes != null">
                finance_notes = #{financeNotes,jdbcType=VARCHAR},
            </if>
            <if test="electricInvoiceUrl != null">
                electric_invoice_url = #{electricInvoiceUrl,jdbcType=VARCHAR},
            </if>
            <if test="updator != null">
                updator = #{updator,jdbcType=BIGINT},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=DATE},
            </if>
            <if test="delFlag != null">
                del_flag = #{delFlag,jdbcType=INTEGER},
            </if>
        </set>
        where invoice_id = #{invoiceId,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.xhpc.user.pojo.XhpcInvoice">
        update xhpc_invoice
        set receive_email                     = #{receiveEmail,jdbcType=VARCHAR},
            title_type                        = #{titleType,jdbcType=INTEGER},
            title_content                     = #{titleContent,jdbcType=VARCHAR},
            duty_number                       = #{dutyNumber,jdbcType=VARCHAR},
            invoice_content                   = #{invoiceContent,jdbcType=VARCHAR},
            invoice_money                     = #{invoiceMoney,jdbcType=DECIMAL},
            invoice_order_eletric_total_money = #{invoiceOrderEletricTotalMoney,jdbcType=DECIMAL},
            invoice_order_service_total_money = #{invoiceOrderServiceTotalMoney,jdbcType=DECIMAL},
            firm_address                      = #{firmAddress,jdbcType=VARCHAR},
            firm_phone                        = #{firmPhone,jdbcType=VARCHAR},
            firm_bank                         = #{firmBank,jdbcType=VARCHAR},
            firm_bank_account                 = #{firmBankAccount,jdbcType=VARCHAR},
            is_show_date                      = #{isShowDate,jdbcType=INTEGER},
            user_notes                        = #{userNotes,jdbcType=VARCHAR},
            creator_id                        = #{creatorId,jdbcType=BIGINT},
            creator_type                      = #{creatorType,jdbcType=INTEGER},
            creator                           = #{creator,jdbcType=VARCHAR},
            create_time                       = #{createTime,jdbcType=TIMESTAMP},
            `status`                          = #{status,jdbcType=INTEGER},
            invoicing_time                    = #{invoicingTime,jdbcType=TIMESTAMP},
            drawer                            = #{drawer,jdbcType=VARCHAR},
            finance_notes                     = #{financeNotes,jdbcType=VARCHAR},
            electric_invoice_url              = #{electricInvoiceUrl,jdbcType=VARCHAR},
            updator                           = #{updator,jdbcType=BIGINT},
            update_time                       = #{updateTime,jdbcType=DATE},
            del_flag                          = #{delFlag,jdbcType=INTEGER}
        where invoice_id = #{invoiceId,jdbcType=BIGINT}
    </update>

    <update id="updateInvoiceToUser">
        UPDATE xhpc_invoice
        SET finance_notes        = #{financeNotes},
            invoicing_time       = #{invoicingTime},
            electric_invoice_url = #{eletricInvoiceUrl},
            `status`             = #{status},
            drawer               = #{drawer},
            is_read              = 0
        WHERE invoice_id = #{invoiceId};
    </update>

    <update id="updateFailInvoiceToUser">
        UPDATE xhpc_invoice
        SET finance_notes        = #{financeNotes},
            invoicing_time       = #{invoicingTime},
            electric_invoice_url = #{eletricInvoiceUrl},
            `status`             = #{status},
            drawer               = #{drawer},
            is_read              = 0
        WHERE invoice_id = #{invoiceId}
    </update>
    <update id="updateByInvoiceId">
        UPDATE xhpc_invoice
        SET is_read = 1
        WHERE del_flag IS NULL
          AND invoice_id = #{invoiceId}
    </update>
    <update id="updateElectricAndServiceById">
        UPDATE xhpc_invoice
        SET invoice_order_eletric_total_money = #{invoiceOrderEletricTotalMoney},
            invoice_order_service_total_money = #{invoiceOrderServiceTotalMoney}
        WHERE invoice_id = #{invoiceId};
    </update>

    <select id="getInvoiceInfo" resultType="int">
        select count(invoice_id) from xhpc_invoice where status =0
    </select>
</mapper>
