<?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="org.springblade.modules.finance.mapper.OrderExceptionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="orderExceptionResultMap" type="org.springblade.modules.finance.entity.OrderException">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="order_id" property="orderId"/>
        <result column="error_message" property="errorMessage"/>
        <result column="error_type" property="errorType"/>
        <result column="is_process" property="isProcess"/>
        <result column="process_time" property="processTime"/>
        <result column="is_delete" property="isDelete"/>
        <result column="create_user_id" property="createUserId"/>
        <result column="update_user_id" property="updateUserId"/>
    </resultMap>


    <select id="selectOrderExceptionPage" resultType="org.springblade.modules.finance.vo.OrderExceptionVO">
        SELECT
            oe.*,
            o.out_trade_no orderNo,
            o.pay_code payCode,
            gi.source
        FROM
            t_order_exception oe
            JOIN t_order o ON oe.order_id = o.id
            JOIN t_order_goods og ON o.out_trade_no = og.out_trade_no
            JOIN re_goods_info gi ON og.goods_id = gi.id
        WHERE
            1 = 1
            <if test="@cn.hutool.core.util.StrUtil@isNotBlank(p.orderNo)">
                AND INSTR( o.out_trade_no, #{p.orderNo} ) > 0
            </if>
            <if test="p.isProcess != null">
                AND oe.is_process = #{p.isProcess}
            </if>
            <if test="p.errorType != null">
                AND oe.error_type = #{p.errorType}
            </if>
            order by oe.create_time desc
    </select>

</mapper>
