<?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.com.xingxi.store.data.mapper.WxaStoreInvoiceMapper">

    <resultMap id="selectInvoiceOrderListByUserIdInvoiceOrderResult" type="InvoiceOrderDTO" >
        <result property="id"    column="id"    />
        <result property="orderId"    column="orderId"    />
        <result property="orderNo"    column="orderNo"    />
        <result property="orderDetailId"    column="orderDetailId"    />
        <result property="buyerId"    column="buyerId"    />
        <result property="buyerRole"    column="buyerRole"    />
        <result property="tradeType"    column="tradeType"    />
        <result property="sellerId"    column="sellerId"    />
        <result property="sellerRole"    column="sellerRole"    />
        <result property="payeeId"    column="payeeId"    />
        <result property="payeeRole"    column="payeeRole"    />
        <result property="suiteId"    column="suiteId"    />
        <result property="prodId"    column="prodId"    />
        <result property="prodName"    column="prodName"    />
        <result property="pprId"    column="pprId"    />
        <result property="pprName"    column="pprName"    />
        <result property="mateId"    column="mateId"    />
        <result property="mateName"    column="mateName"    />
        <result property="prodType"    column="prodType"    />
        <result property="orgProdId"    column="orgProdId"    />
        <result property="surfaceQty"    column="surfaceQty"    />
        <result property="unitQty"    column="unitQty"    />
        <result property="orderQty"    column="orderQty"    />
        <result property="price"    column="price"    />
        <result property="returnQty"    column="returnQty"    />
        <result property="finishTime"    column="finishTime"    />
        <result property="orderStatus"    column="orderStatus"    />
        <result property="invoiceTime"    column="invoiceTime"    />
        <result property="invoiceStatus"    column="invoiceStatus"    />
        <result property="invoiceBatchNo"    column="invoiceBatchNo"    />
        <result property="invoiceBillNo"    column="invoiceBillNo"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
        <association property="prodImageDTOS" select="selectProductImageByProdId" column="prodcutId=prodId"/>
    </resultMap>

    <resultMap id="ProductImageDTOResult" type="ImageDTO" >
        <result property="imageId"    column="fileId"    />
        <result property="imageUrl"    column="fileUrl"    />
    </resultMap>

    <select id="selectProductImageByProdId"  resultMap="ProductImageDTOResult">
        SELECT t_attch_file.fileId, t_attch_file.fileUrl
        FROM m_prod_picture
        INNER JOIN t_attch_file ON m_prod_picture.picImgId = t_attch_file.fileId
        WHERE m_prod_picture.delFlag = '0'
          AND m_prod_picture.prodId = #{prodcutId}
    </select>

    <select id="selectInvoiceOrderListByUserId" resultMap="selectInvoiceOrderListByUserIdInvoiceOrderResult">
        SELECT t_invoice_order.*
        FROM t_invoice_order
        WHERE t_invoice_order.delFlag = '0'
          AND t_invoice_order.sellerId = #{mercId}
          AND t_invoice_order.buyerId = #{userId}
    </select>

    <select id="selectUserInvoiceListByUserId" resultType="UserInvoiceDTO">
        SELECT t_invoice.*,t_invoice.xhf_nsrsbh as xhfNsrsbh, t_invoice.ghf_nsrsbh as ghfNsrsbh
        FROM t_invoice
        WHERE t_invoice.delFlag = '0'
          AND t_invoice.sellerId = #{mercId}
          AND t_invoice.buyerId = #{userId}
    </select>


    <select id="selectInvoiceOrderListByOrderIds"  resultType="InvoiceOrderDTO">
        select i.*
        from t_invoice_order i
        where i.delFlag = '0'
        <if test="list != null">
            AND i.orderId IN
            <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>
