<?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.ylx.massage.mapper.AfterSaleOrderMapper">

    <!-- 费用VO映射 -->
    <resultMap id="AfterSaleFeeResultMap" type="com.ylx.massage.domain.vo.AfterSaleOrderFeeVo">
        <id column="id" property="id"/>
        <result column="type" property="type"/>
        <result column="fee" property="fee"/>
        <result column="remark" property="remark"/>
    </resultMap>

    <!-- 主VO映射 + 集合自动封装 feeList -->
    <resultMap id="AfterSaleVoResultMap" type="com.ylx.massage.domain.vo.OrderAfterSaleVo">
        <id column="afterSaleOrderId" property="afterSaleOrderId"/>
        <result column="after_sale_type" property="afterSaleType"/>
        <result column="create_time" property="createTime"/>
        <result column="apply_reason" property="applyReason"/>
        <result column="after_sale_status" property="afterSaleStatus"/>
        <result column="logistics_no" property="logisticsNo"/>

        <!-- 关键：自动封装 List<feeList> -->
        <collection
                property="feeList"
                javaType="ArrayList"
                ofType="com.ylx.massage.domain.vo.AfterSaleOrderFeeVo"
                resultMap="AfterSaleFeeResultMap"/>
    </resultMap>

    <select id="selectAfterSaleVoByOrderId" resultMap="AfterSaleVoResultMap">
        SELECT
            a.id as afterSaleOrderId,
            a.after_sale_type,
            a.create_time,
            a.apply_reason,
            a.after_sale_status,
            a.logistics_no,
            f.id,
            f.type,
            f.fee,
            f.remark
        FROM
            after_sale_order a
        LEFT JOIN after_sale_order_fee f ON a.id = f.after_sale_order_id
        WHERE
            a.order_id = #{orderId}
        AND a.after_sale_status != 7
    </select>

</mapper>