<?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.iocoder.yudao.module.system.dal.mysql.biz.RefundSettlementOrderItemMapper">

    <select id="selectRetreatRefundDeductGrouped" resultType="java.util.Map">
        SELECT
            rso.elder_id AS "elderId",
            eei.type AS "expenseItemType",
            SUM(rsoi.actual_refund_amount) AS "totalDeduct"
        FROM
            elderly_refund_settlement_order rso
        JOIN
            elderly_refund_settlement_order_item rsoi ON rso.id = rsoi.refund_settlement_order_id
        JOIN
            elderly_expense_item eei ON rsoi.source_item_id = eei.id
        WHERE
            rso.tenant_id = #{tenantId}
            AND rso.elder_id IN
            <foreach item="elderId" collection="elderIds" open="(" separator="," close=")">
                #{elderId}
            </foreach>
            AND rso.status = 1
        GROUP BY
            rso.elder_id, eei.type
    </select>

</mapper>

