<?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.pay.PayDetailMapper">
    <select id="getPage" resultType="com.fjhx.purchase.entity.pay.vo.PayDetailVo">
        select
            pd.id,
            pd.purchase_id,
            pd.money,
            pd.remark,
            pd.create_user,
            pd.create_time,
            pd.update_user,
            pd.update_time
        from pay_detail pd
            ${ew.customSqlSegment}
    </select>

    <select id="getSumMoneyByPurchaseIds" resultType="com.fjhx.purchase.entity.pay.vo.PayDetailVo">
        SELECT
            purchase_id,
            IFNULL( SUM( money ), 0 ) AS sumMoney
        FROM
            pay_detail
        <where>
            <if test="purchaseIds neq null and purchaseIds.size() > 0">
                <foreach collection="purchaseIds" item="purchaseId" open="purchase_id IN (" separator="," close=")">
                    #{purchaseId}
                </foreach>
            </if>
        </where>
        GROUP BY
        purchase_id
    </select>

    <select id="getPayMoneyCountByPurchaseId" resultType="com.fjhx.purchase.entity.pay.po.PayDetail">
        select pd.money, pd.purchase_id
        from pay p
                 inner join pay_detail pd on p.id = pd.pay_id
            ${ew.customSqlSegment}
    </select>

    <select id="getSumMoney" resultType="java.math.BigDecimal">
        SELECT
            IFNULL(SUM(t1.money),0) AS money
        FROM
            pay_detail t1
        LEFT JOIN pay t2 ON t1.pay_id = t2.id
        <where>
            <if test="purchaseIds neq null and purchaseIds.size() > 0">
                <foreach collection="purchaseIds" item="purchaseId" open="purchase_id IN (" separator="," close=")">
                    #{purchaseId}
                </foreach>
            </if>
        </where>
    </select>
</mapper>
