<?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.order.mapper.AfterSalesServiceMapper">


    <!-- 定义结果映射：将数据库字段与 VO 属性一一对应 -->
    <resultMap id="AfterSalesServiceDetailVOMap" type="com.ylx.order.domain.vo.AfterSalesServiceDetailVO">
        <!-- 售后单信息 (after_sales_service) -->
        <id property="id" column="ass_id"/>
        <result property="serviceNo" column="service_no"/>
        <result property="orderId" column="order_id"/>
        <result property="status" column="ass_status"/>
        <result property="actualRefundAmount" column="actual_refund_amount"/>
        <result property="refundDesc" column="refund_desc"/>
        <result property="auditTime" column="audit_time"/>
        <result property="rejectReason" column="reject_reason"/>
        <result property="auditRemark" column="audit_remark"/>
        <result property="refundSuccessTime" column="refund_success_time"/>

        <!-- 订单/商户/项目信息 (t_order) -->
        <result property="merchantId" column="merchant_id"/>
        <result property="merchantNickName" column="merchant_nick_name"/>
        <result property="projectId" column="project_id"/>
        <result property="projectName" column="project_name"/>
        <result property="projectCover" column="project_cover"/>
        <result property="contactAddressInfo" column="contact_address_info"/>
        <result property="basePrice" column="base_price"/>
        <result property="finalAmount" column="final_amount"/>
        <result property="orderStatus" column="order_status"/>
    </resultMap>

    <!-- 根据售后单ID查询详情 -->
    <select id="getDetailById" parameterType="java.lang.Long" resultMap="AfterSalesServiceDetailVOMap">
        SELECT
            -- 1. 售后单核心字段
            ass.id AS ass_id,
            ass.service_no,
            ass.order_id,
            ass.status AS ass_status,
            ass.actual_refund_amount,
            ass.refund_desc,
            ass.audit_time,
            ass.reject_reason,
            ass.audit_remark,
            ass.refund_success_time,

            -- 2. 关联订单、商户及项目冗余字段
            o.merchant_id,
            o.merchant_nick_name,
            o.project_id,
            o.project_name,
            o.project_cover,
            o.contact_address_info,
            o.base_price,
            o.final_amount,
            o.status AS order_status

        FROM after_sales_service ass
                 LEFT JOIN t_order o ON ass.order_id = o.id
        WHERE ass.id = #{id}
          AND ass.is_delete = 0
    </select>

</mapper>
