<!-- 客户结算 - 发票申请 - 查看详情 一般订单类 TODO 要重构 mark by linjinyu 202011121815-->
<select id="findInvoiceApplyDetailNewDim1Unified2Goods" parameterType="java.lang.Long" resultMap="cn.superdesk.uniorder.dao.mapper.invoice.customer.InvoiceApplyMapperEx.ViewDzOrderResultMap">
    SELECT
    auco.id AS id,
    auco.dz_id AS dz_id,

    aucu.accounting_order_sn AS accounting_order_sn,

    auco.order_id AS order_id,
    auco.order_sn AS order_sn,
    auco.parent_order_id AS parent_order_id,
    auco.parent_order_sn AS parent_order_sn,
    auco.create_time AS create_time,
    auco.address_realname AS address_realname,
    auco.address_mobile AS address_mobile,
    auco.address_address AS address_address,
    auco.companyName AS companyName,
    auco.taxpayersIDcode AS taxpayersIDcode,
    auco.send_time AS send_time,
    auco.finish_time AS finish_time,
    auco.`status` AS order_status,
    auco.pay_type AS pay_type,
    auco.merch_name AS merch_name,
    auco.search_field1 AS search_field1,
    auco.search_field2 AS search_field2,
    auco.search_field3 AS search_field3,
    auco.remark AS remark,
    auco.invoice_account AS invoice_account,
    auco.invoice_bank AS invoice_bank,
    auco.examine_id AS examine_id,
    auco.realname_id AS realname_id,
    auco.detail_url AS detail_url,
    auco.organization_id AS organization_id,
    auco.enterprise_id AS enterprise_id,
    auco.invoice_type AS invoice_type,

    auco.dispatchname AS dispatchname,
    auco.sync_time AS sync_time,
    auco.pay_time AS pay_time,

    uog.id AS dz_order_good_id,

    auco.id AS dz_order_id,

    uog.goods_id AS good_id,
    '' AS goodno,
    uog.quantity*uog.price AS price,
    uog.quantity AS total,
    uog.price AS unit_price,
    uog.goods_name AS optionname,
    uog.unit AS unit,
    uog.goods_name AS other_field1,
    uog.goods_params AS other_field2,
    0 AS dispatch_price,
    uog.quantity*uog.price AS total_price,
    uog.tax_code AS tax_code,
    uog.fiscal_code AS fiscal_code,

    real_order_user.realname AS realname,
    examine_order_user.realname AS examine_name,

    auco.price AS order_price,

    invoice_order.back_time as back_time,
    invoice_order.bank_id as bank_id,
    invoice_order.back_status as back_status,

    invoice_bank.count as water_count
    FROM
    (accounting_unified_customer_order auco
    RIGHT JOIN unified_order_goods uog ON auco.order_sn = uog.order_sn)

    LEFT JOIN accounting_unified_customer aucu ON auco.dz_id = aucu.id
    LEFT JOIN invoice_order ON uog.id = invoice_order.dz_good_id
    LEFT JOIN invoice_bank ON invoice_order.bank_id = invoice_bank.id

    LEFT JOIN sys_oder_user AS real_order_user ON auco.realname_id = real_order_user.user_id
    LEFT JOIN sys_oder_user AS examine_order_user ON auco.examine_id = examine_order_user.user_id


    <where>

        <!--
        这个对账单的对账状态为什么要 = 1
        已取消(-1, "已取消"),
        未确认(0, "未确认"),
        已确认(1, "已确认"),
        已拒绝(2, "已拒绝"),
        待提交(3, "待提交"),
        -->
        AND aucu.accounting_status =1
        <if test="id != null ">
            and invoice_order.invoice_apply_id = #{id,jdbcType=BIGINT}
        </if>
    </where>
</select>