<?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.miaxis.wx.mapper.WxJsOrderMapper">

    <resultMap type="WxJsOrder" id="WxJsOrderResult">
        <result property="id"    column="id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="outTradeNo"    column="out_trade_no"    />
        <result property="outRefundNo"    column="out_refund_no"    />
        <result property="refundReason"    column="refund_reason"    />
        <result property="transactionId"    column="transaction_id"    />
        <result property="tradeType"    column="trade_type"    />
        <result property="tradeState"    column="trade_state"    />
        <result property="tradeStateDesc"    column="trade_state_desc"    />
        <result property="bankType"    column="bank_type"    />
        <result property="attach"    column="attach"    />
        <result property="successTime"    column="success_time"    />
        <result property="total"    column="total"    />
        <result property="payerTotal"    column="payer_total"    />
        <result property="currency"    column="currency"    />
        <result property="payerCurrency"    column="payer_currency"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectWxJsOrderVo">
        select * from wx_js_order
    </sql>

    <select id="getByOutTradeNo" parameterType="string" resultType="com.miaxis.wx.domain.WxJsOrder">
         select * from wx_js_order where out_trade_no =#{outTradeNo}
    </select>


    <select id="selectWxJsOrderList" parameterType="WxJsOrder" resultMap="WxJsOrderResult">
        select w.*,r.refund,r.status from wx_js_order w left join refund_record r ON w.out_refund_no = r.out_refund_no
        <where>
            <if test="userId!=null"> and user_id = #{userId}</if>
            <if test="userName!=null and userName!=''"> and w.user_name = #{userName}</if>
            <if test="outTradeNo != null and outTradeNo!=''"> and w.out_trade_no = #{outTradeNo}</if>
            <if test="transactionId != null  and transactionId != ''"> and w.transaction_id = #{transactionId}</if>
            <if test="tradeType != null  and tradeType != ''"> and w.trade_type = #{tradeType}</if>
            <if test="tradeState != null  and tradeState != ''"> and w.trade_state = #{tradeState}</if>
            <if test="tradeStateDesc != null  and tradeStateDesc != ''"> and w.trade_state_desc = #{tradeStateDesc}</if>
            <if test="bankType != null  and bankType != ''"> and w.bank_type = #{bankType}</if>
            <if test="attach != null  and attach != ''"> and w.attach = #{attach}</if>
            <if test="successTime != null "> and w.success_time = #{successTime}</if>
            <if test="goodsName != null  and goodsName != ''"> and w.goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="total != null "> and w.total = #{total}</if>
            <if test="payerTotal != null "> and w.payer_total = #{payerTotal}</if>
            <if test="currency != null  and currency != ''"> and w.currency = #{currency}</if>
            <if test="payerCurrency != null  and payerCurrency != ''"> and w.payer_currency = #{payerCurrency}</if>
            <if test="orderStatus != null  and orderStatus != ''"> and w.order_state = #{orderStatus}</if>
        </where>
    </select>




</mapper>
