<?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.fjhx.purchase.mapper.purchase.PurchaseDetailMapper">
    <select id="getPage" resultType="com.fjhx.purchase.entity.purchase.vo.PurchaseDetailVo">
        select
            pd.id,
            pd.bussiness_id,
            pd.subscribe_detail_id,
            pd.purchase_id,
            pd.count,
            pd.content,
            pd.status,
            pd.remark,
            pd.create_user,
            pd.create_time,
            pd.update_user,
            pd.update_time
        from purchase_detail pd
            ${ew.customSqlSegment}
    </select>

    <select id="getSumCountInDataResourceId" resultType="com.fjhx.purchase.entity.purchase.vo.PurchaseDetailVo">
        SELECT
            sum( count ) AS sumCount,
            data_resource_id
        FROM
            purchase_detail
        <where>
            data_resource = 1
            <if test="dataResourceIds neq null and dataResourceIds.size() > 0">
                <foreach collection="dataResourceIds" item="dataResourceId" open="AND data_resource_id IN (" separator="," close=")">
                    #{dataResourceId}
                </foreach>
            </if>
        </where>
        GROUP BY
            data_resource_id
    </select>
    <select id="getSumCountInDataResourceIds" resultType="com.fjhx.purchase.entity.purchase.vo.PurchaseDetailVo">
        SELECT
            sum( t1.count ) AS sumCount,
            sum( t1.amount ) AS sumAmount,
            CONCAT( IFNULL( SUM( t1.amount ), 0 ), "-", IFNULL(t2.currency,"¥") ) AS sumAmountCurrency,
            t1.data_resource_id
        FROM
            purchase_detail t1
        LEFT JOIN purchase t2 ON t1.purchase_id = t2.id
        <where>
            t1.data_resource = 1
            AND t2.`purchase_status` &gt;= 30
            AND t2.purchase_status &lt; 88
            <if test="dataResourceIds neq null and dataResourceIds.size() > 0">
                <foreach collection="dataResourceIds" item="dataResourceId" open="AND t1.data_resource_id IN ("
                         separator="," close=")">
                    #{dataResourceId}
                </foreach>
            </if>
        </where>
        GROUP BY
        data_resource_id
    </select>
    <select id="getPurchaseDetailList" resultType="com.fjhx.purchase.entity.purchase.vo.PurchaseDetailVo">
        SELECT
            pd.id,
            pd.quantity AS `count`,
            pd.subscribe_detail_id
        FROM
            bytesailing_sale.ehsd_purchase_product pd
            LEFT JOIN bytesailing_sale.ehsd_purchase p ON pd.purchase_id = p.id
            ${ew.customSqlSegment}
    </select>
</mapper>
