<?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.sv.mapper.MemberRefundMapper">

    <resultMap id="MemberRefundMap" type="com.sv.entity.MemberRefund">
		<id column="id" property="id" jdbcType="INTEGER"/>
		<result column="member_id" property="memberId"  jdbcType="INTEGER" />
		<result column="lesson_id" property="lessonId"  jdbcType="INTEGER" />
		<result column="money" property="money"  jdbcType="DECIMAL" />
		<result column="refund_status" property="refundStatus"  jdbcType="VARCHAR" />
		<result column="success_time" property="successTime"  jdbcType="TIMESTAMP" />
		<result column="order_sn" property="orderSn"  jdbcType="VARCHAR" />
		<result column="transaction_id" property="transactionId"  jdbcType="VARCHAR" />
		<result column="order_id" property="orderId"  jdbcType="INTEGER" />
		<result column="refund_id" property="refundId"  jdbcType="VARCHAR" />
		<result column="out_refund_no" property="outRefundNo"  jdbcType="VARCHAR" />
        <result column="platform_id" property="platformId"  jdbcType="INTEGER" />
		<result column="created_id" property="createdId"  jdbcType="INTEGER" />
		<result column="modified_id" property="modifiedId"  jdbcType="INTEGER" />
		<result column="created_time" property="createdTime"  jdbcType="TIMESTAMP" />
		<result column="modified_time" property="modifiedTime"  jdbcType="TIMESTAMP" />
		<result column="deleted" property="deleted"  jdbcType="TINYINT" />
    </resultMap>

    <resultMap id="MemberRefundDtoMap" type="com.sv.dto.api.MemberRefundDTO">
		<id column="id" property="id" jdbcType="INTEGER"/>
		<result column="member_id" property="memberId" jdbcType="INTEGER" />
		<result column="lesson_id" property="lessonId" jdbcType="INTEGER" />
		<result column="money" property="money" jdbcType="DECIMAL" />
		<result column="refund_status" property="refundStatus" jdbcType="VARCHAR" />
		<result column="success_time" property="successTime" jdbcType="TIMESTAMP" />
		<result column="order_sn" property="orderSn" jdbcType="VARCHAR" />
		<result column="transaction_id" property="transactionId" jdbcType="VARCHAR" />
		<result column="order_id" property="orderId" jdbcType="INTEGER" />
		<result column="refund_id" property="refundId" jdbcType="VARCHAR" />
		<result column="out_refund_no" property="outRefundNo"  jdbcType="VARCHAR" />
        <result column="platform_id" property="platformId"  jdbcType="INTEGER" />
		<result column="created_id" property="createdId" jdbcType="INTEGER" />
		<result column="modified_id" property="modifiedId" jdbcType="INTEGER" />
		<result column="created_time" property="createdTime" jdbcType="TIMESTAMP" />
		<result column="modified_time" property="modifiedTime" jdbcType="TIMESTAMP" />
		<result column="deleted" property="deleted" jdbcType="TINYINT" />
    </resultMap>
	
	<!--表名 -->
	<sql id="tableName">
		sv_member_refund
	</sql>
	
	<!-- 字段 -->
	<sql id="Field">
		id,
		member_id,
		lesson_id,
		money,
		refund_status,
		success_time,
		order_sn,
		transaction_id,
		order_id,
		refund_id,
		out_refund_no,
		created_id,
		modified_id,
		created_time,
		modified_time,
		deleted,
		platform_id
	</sql>
	
	<!-- 字段值 -->
	<sql id="FieldValue">
		#{id, jdbcType=INTEGER},
		#{memberId, jdbcType=INTEGER},
		#{lessonId, jdbcType=INTEGER},
		#{money, jdbcType=DECIMAL},
		#{refundStatus, jdbcType=VARCHAR},
		#{successTime, jdbcType=TIMESTAMP},
		#{orderSn, jdbcType=VARCHAR},
		#{transactionId, jdbcType=VARCHAR},
		#{orderId, jdbcType=INTEGER},
		#{refundId, jdbcType=VARCHAR},
		#{outRefundNo, jdbcType=VARCHAR},
		#{createdId, jdbcType=INTEGER},
		#{modifiedId, jdbcType=INTEGER},
		#{createdTime, jdbcType=TIMESTAMP},
		#{modifiedTime, jdbcType=TIMESTAMP},
		#{deleted, jdbcType=TINYINT}
		#{platform_id, jdbcType=TINYINT}
	</sql>

	<!-- 查询全部记录 -->
    <select id="findAll" resultMap="MemberRefundMap">
        SELECT
        	<include refid="Field"></include>
        FROM
        	<include refid="tableName"></include>
		WHERE
			deleted = 0
    </select>
	
	<!-- 新增-->
	<insert id="insert" parameterType="com.sv.entity.MemberRefund" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO
			<include refid="tableName"></include>
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
				id,
            </if>
            <if test="memberId != null">
				member_id,
            </if>
            <if test="lessonId != null">
				lesson_id,
            </if>
            <if test="money != null">
				money,
            </if>
            <if test="refundStatus != null">
				refund_status,
            </if>
            <if test="successTime != null">
				success_time,
            </if>
            <if test="orderSn != null">
				order_sn,
            </if>
            <if test="transactionId != null">
				transaction_id,
            </if>
            <if test="orderId != null">
				order_id,
            </if>
            <if test="refundId != null">
				refund_id,
            </if>
            <if test="outRefundNo != null">
				out_refund_no,
            </if>
            <if test="createdId != null">
				created_id,
            </if>
            <if test="modifiedId != null">
				modified_id,
            </if>
            <if test="createdTime != null">
				created_time,
            </if>
            <if test="modifiedTime != null">
				modified_time,
            </if>
            <if test="deleted != null">
				deleted,
            </if>
            <if test="platformId != null">
                platform_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
				#{id},
            </if>
            <if test="memberId != null">
				#{memberId},
            </if>
            <if test="lessonId != null">
				#{lessonId},
            </if>
            <if test="money != null">
				#{money},
            </if>
            <if test="refundStatus != null">
				#{refundStatus},
            </if>
            <if test="successTime != null">
				#{successTime},
            </if>
            <if test="orderSn != null">
				#{orderSn},
            </if>
            <if test="transactionId != null">
				#{transactionId},
            </if>
            <if test="orderId != null">
				#{orderId},
            </if>
            <if test="refundId != null">
				#{refundId},
            </if>
            <if test="outRefundNo != null">
				#{outRefundNo},
            </if>
            <if test="createdId != null">
				#{createdId},
            </if>
            <if test="modifiedId != null">
				#{modifiedId},
            </if>
            <if test="createdTime != null">
				#{createdTime},
            </if>
            <if test="modifiedTime != null">
				#{modifiedTime},
            </if>
            <if test="deleted != null">
				#{deleted},
            </if>
            <if test="platformId != null">
                #{platformId},
            </if>
        </trim>
	</insert>
	
	<!-- 删除-->
	<delete id="delete" parameterType="java.lang.Integer">
		UPDATE
			<include refid="tableName"></include>
		SET
			deleted = 1
		WHERE
			id = #{id}
	</delete>

    <!-- 批量删除 -->
    <delete id="deleteByIds">
        UPDATE
        	<include refid="tableName"></include>
		SET
			deleted = 1
        WHERE
			id IN
			<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
				#{item}
			</foreach>
    </delete>
	
	<!-- 更新记录 -->
	<update id="update" parameterType="com.sv.entity.MemberRefund">
		UPDATE
			<include refid="tableName"></include>
        <set>
			<if test="memberId != null">
				member_id = #{memberId},
			</if>
			<if test="lessonId != null">
				lesson_id = #{lessonId},
			</if>
			<if test="money != null">
				money = #{money},
			</if>
			<if test="refundStatus != null">
				refund_status = #{refundStatus},
			</if>
			<if test="successTime != null">
				success_time = #{successTime},
			</if>
			<if test="orderSn != null">
				order_sn = #{orderSn},
			</if>
			<if test="transactionId != null">
				transaction_id = #{transactionId},
			</if>
			<if test="orderId != null">
				order_id = #{orderId},
			</if>
			<if test="refundId != null">
				refund_id = #{refundId},
			</if>
			<if test="outRefundNo != null">
				out_refund_no = #{outRefundNo},
			</if>
			<if test="createdId != null">
				created_id = #{createdId},
			</if>
			<if test="modifiedId != null">
				modified_id = #{modifiedId},
			</if>
			<if test="createdTime != null">
				created_time = #{createdTime},
			</if>
			<if test="modifiedTime != null">
				modified_time = #{modifiedTime},
			</if>
			<if test="deleted != null">
				deleted = #{deleted},
			</if>
            <if test="platformId != null">
                platform_id = #{platformId},
            </if>
        </set>
        WHERE id = #{id}
	</update>
	
	<!-- 通过编号查询 -->
	<select id="findById" parameterType="java.lang.Integer" resultMap="MemberRefundMap">
		SELECT
			<include refid="Field"></include>
		FROM
			<include refid="tableName"></include>
		WHERE id = #{id}
	</select>

	<!-- api 通过订单号查找用户退款记录表 -->
	<select id="findByOrderSn" resultMap="MemberRefundMap">
		select
			<include refid="Field"></include>
		FROM
			<include refid="tableName"></include>
		WHERE
			order_sn = #{outTradeNo}
	</select>
</mapper>