<?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.mofangchuxing.aska.dao.mapper.PayRequestMapper">

    <resultMap id="BaseResultMap" type="com.mofangchuxing.aska.dao.domain.PayRequest">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="requestBody" column="request_body" jdbcType="VARCHAR"/>
            <result property="orderSn" column="order_sn" jdbcType="VARCHAR"/>
            <result property="openId" column="open_id" jdbcType="VARCHAR"/>
            <result property="mobile" column="mobile" jdbcType="VARCHAR"/>
            <result property="orderId" column="order_id" jdbcType="VARCHAR"/>
            <result property="amount" column="amount" jdbcType="INTEGER"/>
            <result property="itemId" column="item_id" jdbcType="VARCHAR"/>
            <result property="itemType" column="item_type" jdbcType="INTEGER"/>
            <result property="itemName" column="item_name" jdbcType="VARCHAR"/>
            <result property="itemChannel" column="item_channel" jdbcType="VARCHAR"/>
            <result property="retailId" column="retail_id" jdbcType="VARCHAR"/>
            <result property="retailName" column="retail_name" jdbcType="VARCHAR"/>
            <result property="useCouponId" column="use_coupon_id" jdbcType="VARCHAR"/>
            <result property="payChannel" column="pay_channel" jdbcType="INTEGER"/>
            <result property="responseBody" column="response_body" jdbcType="VARCHAR"/>
            <result property="payStatus" column="pay_status" jdbcType="INTEGER"/>
            <result property="payTime" column="pay_time" jdbcType="TIMESTAMP"/>
            <result property="transactionId" column="transaction_id" jdbcType="VARCHAR"/>
            <result property="payAmount" column="pay_amount" jdbcType="DECIMAL"/>
            <result property="hasRefund" column="has_refund" jdbcType="INTEGER"/>
            <result property="refundTotal" column="refund_total" jdbcType="DECIMAL"/>
            <result property="clientType" column="client_type" jdbcType="VARCHAR"/>
            <result property="cansplit" column="canSplit" jdbcType="INTEGER"/>
            <result property="callbackUrl" column="callback_url" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="modifiedTime" column="modified_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,request_body,order_sn,
        open_id,mobile,order_id,
        amount,item_id,item_type,
        item_name,item_channel,retail_id,
        retail_name,use_coupon_id,pay_channel,
        response_body,pay_status,pay_time,
        transaction_id,pay_amount,has_refund,
        refund_total,client_type,canSplit,
        callback_url,create_time,modified_time
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from pay_request
        where  id = #{id,jdbcType=INTEGER} 
    </select>

    <select id="selectByOrderSn" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from pay_request
        where order_sn = #{orderSn} limit 1
    </select>
    <select id="selectPaySuccessByOrderId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from pay_request
        where order_id = #{orderId} and pay_status = 1 limit 1
    </select>
    <select id="selectByUser" resultMap="BaseResultMap">
        select order_sn, order_id, item_id, item_name, pay_status
        from pay_request
        where mobile = #{phoneNo} and item_type = #{itemType}
        <if test="payStatus != null">
            and pay_status = #{payStatus}
        </if>
    </select>

    <select id="selectByOrderId" resultMap="BaseResultMap">
        select order_sn, order_id, item_id, item_name, pay_status
        from pay_request
        where mobile = #{phoneNo} and order_id = #{orderId}
    </select>
    <select id="getOrderList" resultType="java.util.Map">
        select pr.*,asr.* from pay_request pr left join aska_splitrecord as asr on pr.id = asr.payId
        where 1=1
        <if test="retailId != null and retailId != ''">
            and pr.retail_id = #{retailId}
        </if>
        <if test="couponNo != null and couponNo != ''">
            and pr.use_coupon_id = #{couponNo}
        </if>
        <if test="orderNo != null and orderNo != ''">
            and pr.order_id = #{orderNo}
        </if>
        <if test="channelId != null and channelId != ''">
            and pr.channel_id = #{channelId}
        </if>
        order by pr.id desc
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from pay_request
        where  id = #{id,jdbcType=INTEGER} 
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.mofangchuxing.aska.dao.domain.PayRequest" useGeneratedKeys="true">
        insert into pay_request
        ( id,request_body,order_sn
        ,open_id,mobile,order_id
        ,amount,item_id,item_type
        ,item_name,item_channel,retail_id
        ,retail_name,use_coupon_id,pay_channel
        ,response_body,pay_status,pay_time
        ,transaction_id,pay_amount,has_refund
        ,refund_total,client_type,canSplit
        ,callback_url,create_time,modified_time
        )
        values (#{id,jdbcType=INTEGER},#{requestBody,jdbcType=VARCHAR},#{orderSn,jdbcType=VARCHAR}
        ,#{openId,jdbcType=VARCHAR},#{mobile,jdbcType=VARCHAR},#{orderId,jdbcType=VARCHAR}
        ,#{amount,jdbcType=DECIMAL},#{itemId,jdbcType=VARCHAR},#{itemType,jdbcType=INTEGER}
        ,#{itemName,jdbcType=VARCHAR},#{itemChannel,jdbcType=VARCHAR},#{retailId,jdbcType=VARCHAR}
        ,#{retailName,jdbcType=VARCHAR},#{useCouponId,jdbcType=VARCHAR},#{payChannel,jdbcType=INTEGER}
        ,#{responseBody,jdbcType=VARCHAR},#{payStatus,jdbcType=INTEGER},#{payTime,jdbcType=TIMESTAMP}
        ,#{transactionId,jdbcType=VARCHAR},#{payAmount,jdbcType=DECIMAL},#{hasRefund,jdbcType=INTEGER}
        ,#{refundTotal,jdbcType=DECIMAL},#{clientType,jdbcType=VARCHAR},#{cansplit,jdbcType=INTEGER}
        ,#{callbackUrl,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{modifiedTime,jdbcType=TIMESTAMP}
        )
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.mofangchuxing.aska.dao.domain.PayRequest" useGeneratedKeys="true">
        insert into pay_request
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="requestBody != null">request_body,</if>
                <if test="orderSn != null">order_sn,</if>
                <if test="openId != null">open_id,</if>
                <if test="mobile != null">mobile,</if>
                <if test="orderId != null">order_id,</if>
                <if test="amount != null">amount,</if>
                <if test="itemId != null">item_id,</if>
                <if test="itemType != null">item_type,</if>
                <if test="itemName != null">item_name,</if>
                <if test="itemChannel != null">item_channel,</if>
                <if test="channelId != null">channel_id,</if>
                <if test="retailId != null">retail_id,</if>
                <if test="retailName != null">retail_name,</if>
                <if test="useCouponId != null">use_coupon_id,</if>
                <if test="payChannel != null">pay_channel,</if>
                <if test="responseBody != null">response_body,</if>
                <if test="payStatus != null">pay_status,</if>
                <if test="payTime != null">pay_time,</if>
                <if test="transactionId != null">transaction_id,</if>
                <if test="payAmount != null">pay_amount,</if>
                <if test="hasRefund != null">has_refund,</if>
                <if test="refundTotal != null">refund_total,</if>
                <if test="clientType != null">client_type,</if>
                <if test="cansplit != null">canSplit,</if>
                <if test="callbackUrl != null">callback_url,</if>
                <if test="createTime != null">create_time,</if>
                <if test="modifiedTime != null">modified_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=INTEGER},</if>
                <if test="requestBody != null">#{requestBody,jdbcType=VARCHAR},</if>
                <if test="orderSn != null">#{orderSn,jdbcType=VARCHAR},</if>
                <if test="openId != null">#{openId,jdbcType=VARCHAR},</if>
                <if test="mobile != null">#{mobile,jdbcType=VARCHAR},</if>
                <if test="orderId != null">#{orderId,jdbcType=VARCHAR},</if>
                <if test="amount != null">#{amount,jdbcType=DECIMAL},</if>
                <if test="itemId != null">#{itemId,jdbcType=VARCHAR},</if>
                <if test="itemType != null">#{itemType,jdbcType=INTEGER},</if>
                <if test="itemName != null">#{itemName,jdbcType=VARCHAR},</if>
                <if test="itemChannel != null">#{itemChannel,jdbcType=VARCHAR},</if>
                <if test="channelId != null">#{channelId,jdbcType=INTEGER},</if>
                <if test="retailId != null">#{retailId,jdbcType=VARCHAR},</if>
                <if test="retailName != null">#{retailName,jdbcType=VARCHAR},</if>
                <if test="useCouponId != null">#{useCouponId,jdbcType=VARCHAR},</if>
                <if test="payChannel != null">#{payChannel,jdbcType=INTEGER},</if>
                <if test="responseBody != null">#{responseBody,jdbcType=VARCHAR},</if>
                <if test="payStatus != null">#{payStatus,jdbcType=INTEGER},</if>
                <if test="payTime != null">#{payTime,jdbcType=TIMESTAMP},</if>
                <if test="transactionId != null">#{transactionId,jdbcType=VARCHAR},</if>
                <if test="payAmount != null">#{payAmount,jdbcType=DECIMAL},</if>
                <if test="hasRefund != null">#{hasRefund,jdbcType=INTEGER},</if>
                <if test="refundTotal != null">#{refundTotal,jdbcType=DECIMAL},</if>
                <if test="clientType != null">#{clientType,jdbcType=VARCHAR},</if>
                <if test="cansplit != null">#{cansplit,jdbcType=INTEGER},</if>
                <if test="callbackUrl != null">#{callbackUrl,jdbcType=VARCHAR},</if>
                <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
                <if test="modifiedTime != null">#{modifiedTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.mofangchuxing.aska.dao.domain.PayRequest">
        update pay_request
        <set>
                <if test="requestBody != null">
                    request_body = #{requestBody,jdbcType=VARCHAR},
                </if>
                <if test="orderSn != null">
                    order_sn = #{orderSn,jdbcType=VARCHAR},
                </if>
                <if test="openId != null">
                    open_id = #{openId,jdbcType=VARCHAR},
                </if>
                <if test="mobile != null">
                    mobile = #{mobile,jdbcType=VARCHAR},
                </if>
                <if test="orderId != null">
                    order_id = #{orderId,jdbcType=VARCHAR},
                </if>
                <if test="amount != null">
                    amount = #{amount,jdbcType=DECIMAL},
                </if>
                <if test="itemId != null">
                    item_id = #{itemId,jdbcType=VARCHAR},
                </if>
                <if test="itemType != null">
                    item_type = #{itemType,jdbcType=INTEGER},
                </if>
                <if test="itemName != null">
                    item_name = #{itemName,jdbcType=VARCHAR},
                </if>
                <if test="itemChannel != null">
                    item_channel = #{itemChannel,jdbcType=VARCHAR},
                </if>
                <if test="retailId != null">
                    retail_id = #{retailId,jdbcType=VARCHAR},
                </if>
                <if test="retailName != null">
                    retail_name = #{retailName,jdbcType=VARCHAR},
                </if>
                <if test="useCouponId != null">
                    use_coupon_id = #{useCouponId,jdbcType=VARCHAR},
                </if>
                <if test="payChannel != null">
                    pay_channel = #{payChannel,jdbcType=INTEGER},
                </if>
                <if test="responseBody != null">
                    response_body = #{responseBody,jdbcType=VARCHAR},
                </if>
                <if test="payStatus != null">
                    pay_status = #{payStatus,jdbcType=INTEGER},
                </if>
                <if test="payTime != null">
                    pay_time = #{payTime,jdbcType=TIMESTAMP},
                </if>
                <if test="transactionId != null">
                    transaction_id = #{transactionId,jdbcType=VARCHAR},
                </if>
                <if test="payAmount != null">
                    pay_amount = #{payAmount,jdbcType=DECIMAL},
                </if>
                <if test="hasRefund != null">
                    has_refund = #{hasRefund,jdbcType=INTEGER},
                </if>
                <if test="refundTotal != null">
                    refund_total = #{refundTotal,jdbcType=DECIMAL},
                </if>
                <if test="clientType != null">
                    client_type = #{clientType,jdbcType=VARCHAR},
                </if>
                <if test="cansplit != null">
                    canSplit = #{cansplit,jdbcType=INTEGER},
                </if>
                <if test="callbackUrl != null">
                    callback_url = #{callbackUrl,jdbcType=VARCHAR},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=TIMESTAMP},
                </if>
                <if test="modifiedTime != null">
                    modified_time = #{modifiedTime,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   id = #{id,jdbcType=INTEGER} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.mofangchuxing.aska.dao.domain.PayRequest">
        update pay_request
        set 
            request_body =  #{requestBody,jdbcType=VARCHAR},
            order_sn =  #{orderSn,jdbcType=VARCHAR},
            open_id =  #{openId,jdbcType=VARCHAR},
            mobile =  #{mobile,jdbcType=VARCHAR},
            order_id =  #{orderId,jdbcType=VARCHAR},
            amount =  #{amount,jdbcType=DECIMAL},
            item_id =  #{itemId,jdbcType=VARCHAR},
            item_type =  #{itemType,jdbcType=INTEGER},
            item_name =  #{itemName,jdbcType=VARCHAR},
            item_channel =  #{itemChannel,jdbcType=VARCHAR},
            retail_id =  #{retailId,jdbcType=VARCHAR},
            retail_name =  #{retailName,jdbcType=VARCHAR},
            use_coupon_id =  #{useCouponId,jdbcType=VARCHAR},
            pay_channel =  #{payChannel,jdbcType=INTEGER},
            response_body =  #{responseBody,jdbcType=VARCHAR},
            pay_status =  #{payStatus,jdbcType=INTEGER},
            pay_time =  #{payTime,jdbcType=TIMESTAMP},
            transaction_id =  #{transactionId,jdbcType=VARCHAR},
            pay_amount =  #{payAmount,jdbcType=DECIMAL},
            has_refund =  #{hasRefund,jdbcType=INTEGER},
            refund_total =  #{refundTotal,jdbcType=DECIMAL},
            client_type =  #{clientType,jdbcType=VARCHAR},
            canSplit =  #{cansplit,jdbcType=INTEGER},
            callback_url =  #{callbackUrl,jdbcType=VARCHAR},
            create_time =  #{createTime,jdbcType=TIMESTAMP},
            modified_time =  #{modifiedTime,jdbcType=TIMESTAMP}
        where   id = #{id,jdbcType=INTEGER} 
    </update>
</mapper>