<?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.fs.course.mapper.FsUserCourseOrderMapper">

    <resultMap type="FsUserCourseOrder" id="FsUserCourseOrderResult">
        <result property="orderId"    column="order_id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="courseId"    column="course_id"    />
        <result property="courseName"    column="course_name"    />
        <result property="courseVideoId"    column="course_video_id"    />
        <result property="userId"    column="user_id"    />
        <result property="mobile"    column="mobile"    />
        <result property="integral"    column="integral"    />
        <result property="payPrice"    column="pay_price"    />
        <result property="discountPrice"    column="discount_price"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="payType"    column="pay_type"    />
        <result property="createType"    column="create_type"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="payTime"    column="pay_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="refundReason"    column="refund_reason"    />
    </resultMap>

    <sql id="selectFsUserCourseOrderVo">
        select order_id, order_code, course_id,create_type, course_name, course_video_id, user_id, mobile, integral, pay_price, discount_price, pay_money, pay_type, status, remark, pay_time, create_time, update_time, refund_reason from fs_user_course_order
    </sql>

    <select id="selectFsUserCourseOrderList" parameterType="FsUserCourseOrder" resultMap="FsUserCourseOrderResult">
        <include refid="selectFsUserCourseOrderVo"/>
        <where>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="courseName != null  and courseName != ''"> and course_name like concat('%', #{courseName}, '%')</if>
            <if test="courseVideoId != null "> and course_video_id = #{courseVideoId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="payType != null "> and pay_type = #{payType}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
        </where>
    </select>

    <select id="selectFsUserCourseOrderByOrderId" parameterType="Long" resultMap="FsUserCourseOrderResult">
        <include refid="selectFsUserCourseOrderVo"/>
        where order_id = #{orderId}
    </select>

    <insert id="insertFsUserCourseOrder" parameterType="FsUserCourseOrder" useGeneratedKeys="true" keyProperty="orderId">
        insert into fs_user_course_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderCode != null and orderCode != ''">order_code,</if>
            <if test="courseId != null">course_id,</if>
            <if test="courseName != null">course_name,</if>
            <if test="courseVideoId != null">course_video_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="mobile != null">mobile,</if>
            <if test="integral != null">integral,</if>
            <if test="payPrice != null">pay_price,</if>
            <if test="discountPrice != null">discount_price,</if>
            <if test="payMoney != null">pay_money,</if>
            <if test="payType != null">pay_type,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="refundReason != null">refund_reason,</if>
            <if test="createType != null">create_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderCode != null and orderCode != ''">#{orderCode},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="courseName != null">#{courseName},</if>
            <if test="courseVideoId != null">#{courseVideoId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="integral != null">#{integral},</if>
            <if test="payPrice != null">#{payPrice},</if>
            <if test="discountPrice != null">#{discountPrice},</if>
            <if test="payMoney != null">#{payMoney},</if>
            <if test="payType != null">#{payType},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="refundReason != null">#{refundReason},</if>
            <if test="createType != null">#{createType},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseOrder" parameterType="FsUserCourseOrder">
        update fs_user_course_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderCode != null and orderCode != ''">order_code = #{orderCode},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="courseName != null">course_name = #{courseName},</if>
            <if test="courseVideoId != null">course_video_id = #{courseVideoId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="integral != null">integral = #{integral},</if>
            <if test="payPrice != null">pay_price = #{payPrice},</if>
            <if test="discountPrice != null">discount_price = #{discountPrice},</if>
            <if test="payMoney != null">pay_money = #{payMoney},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="refundReason != null">refund_reason = #{refundReason},</if>
            <if test="createType != null">create_type = #{createType},</if>
        </trim>
        where order_id = #{orderId}
    </update>

    <delete id="deleteFsUserCourseOrderByOrderId" parameterType="Long">
        delete from fs_user_course_order where order_id = #{orderId}
    </delete>

    <delete id="deleteFsUserCourseOrderByOrderIds" parameterType="String">
        delete from fs_user_course_order where order_id in
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </delete>
</mapper>
