<?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.hc.business.mapper.OrderRefundLogMapper">

    <resultMap type="com.hc.business.model.OrderRefundLog" id="OrderRefundLogMap">
        <result property="logId" column="log_id" jdbcType="INTEGER"/>
        <result property="refundId" column="refund_id" jdbcType="INTEGER"/>
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        log_id,
        refund_id,
        user_id
    </sql>

    <select id="queryByRefundId" resultType="com.hc.business.dto.OrderRefundLogDto">
        SELECT
            a.log_id,
            a.refund_id,
            a.user_id,
            b.user_nick,
            b.user_name,
            b.user_mobile,
            b.user_email,
            b.user_company,
            b.user_gender
        FROM order_refund_log a join user b on a.user_id=b.user_id
        WHERE refund_id =#{refundId}

    </select>

    <!-- 获取可以退费的用户，并且这些用户没有退费过或者正在退费 -->
    <select id="getWaitingForRefundUser" resultType="com.hc.business.dto.OrderRefundLogDto">
        SELECT
            a.order_log_id as log_id,
            0 as refund_id,
            a.re_user_id as user_id,
            b.user_nick as userNick,
            b.user_name as userName,
            b.user_mobile as userMobile,
            b.user_email as userEmail,
            b.user_company as userCompany,
            b.user_gender as userGender
        FROM order_user_log a join user b on a.re_user_id=b.user_id
        WHERE order_id =#{orderId} and a.re_user_id not in(select user_id from order_refund_log k
            join order_refund o on k.refund_id = o.refund_id and o.status!=1 and o.order_id=#{orderId})
    </select>
</mapper>
