<?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( SUM( t1.amount ), 0 ), "-", IFNULL(t2.currency,"¥") ) 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;= 30
        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
        FROM ehsd_purchase_product t1
                 LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id
        WHERE t1.contract_id = #{contractId}
    </select>
</mapper>
