<?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.sale.mapper.purchase.EhsdPurchaseProductMapper">
    <select id="getPage" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
        select
            epp.id,
            epp.purchase_id,
            epp.product_id,
            epp.product_name,
            epp.product_model,
            epp.quantity,
            epp.price,
            epp.amount,
            epp.remark,
            epp.json,
            epp.create_user,
            epp.create_time,
            epp.update_user,
            epp.update_time
        from ehsd_purchase_product epp
            ${ew.customSqlSegment}
    </select>

    <select id="getGroupSumAmount" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
        SELECT
            CONCAT(
            IFNULL(
            (SELECT IFNULL( SUM( amount ), 0 ) FROM ehsd_purchase_product_mountings WHERE FIND_IN_SET(purchase_product_id,GROUP_CONCAT(t1.id))),
            0
            ),
            "-",
            IFNULL( t2.currency, "¥" ),
            "-",
            IFNULL( t2.rate, 1 )) AS currencyAmount,
            t1.contract_id AS contractId
        FROM
            ehsd_purchase_product t1
        LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id
        WHERE
        t2.`status` &gt;= 10
        AND t2.`status` &lt; 88
        <if test="contractIds neq null and contractIds.size() > 0">
            <foreach collection="contractIds" item="contractId" open="AND t1.contract_id IN (" separator="," close=")">
                #{contractId}
            </foreach>
        </if>
        GROUP BY t1.contract_id
    </select>

    <select id="getListByContractId" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
        SELECT
            t1.*,
            t2.currency,
            t2.rate
        FROM
            ehsd_purchase_product t1
                LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id
        WHERE
            t1.contract_id = #{contractId}
    </select>
</mapper>
