<?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.ym.mec.biz.dal.dao.ChildrenDayDegreeDetailDao">
    <resultMap id="ChildrenDayDegreeDetail" type="com.ym.mec.biz.dal.entity.ChildrenDayDegreeDetail">
        <!--@mbg.generated-->
        <id column="id_" property="id"/>
        <result column="reserve_id_" property="reserveId"/>
        <result column="user_id_" property="userId"/>
        <result column="type_" property="type"/>
        <result column="subject_id_" property="subjectId"/>
        <result column="level_" property="level"/>
        <result column="price_" property="price"/>
        <result column="status_" property="status"/>
        <result column="order_id_" property="orderId"/>
        <result column="create_time_" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <select id="get" parameterType="java.lang.Integer" resultMap="ChildrenDayDegreeDetail">
        <!--@mbg.generated-->
        select * from children_day_degree_detail
        where id_ = #{id}
    </select>
    <delete id="delete" parameterType="java.lang.Integer">
        <!--@mbg.generated-->
        delete from children_day_degree_detail
        where id_ = #{id}
    </delete>
    <insert id="insert" keyColumn="id_" keyProperty="id"
            parameterType="com.ym.mec.biz.dal.entity.ChildrenDayDegreeDetail" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into children_day_degree_detail (reserve_id_, user_id_, type_, subject_id_, level_, price_,
        status_,order_id_,
        create_time_, update_time)
        values (#{reserveId}, #{userId}, #{type}, #{subjectId}, #{level}, #{price}, #{status},#{orderId},
        #{createTime}, #{updateTime})
    </insert>
    <update id="update" parameterType="com.ym.mec.biz.dal.entity.ChildrenDayDegreeDetail">
        <!--@mbg.generated-->
        update children_day_degree_detail
        <set>
            <if test="reserveId != null">
                reserve_id_ = #{reserveId},
            </if>
            <if test="userId != null">
                user_id_ = #{userId},
            </if>
            <if test="type != null">
                type_ = #{type},
            </if>
            <if test="subjectId != null">
                subject_id_ = #{subjectId},
            </if>
            <if test="level != null">
                level_ = #{level},
            </if>
            <if test="price != null">
                price_ = #{price},
            </if>
            <if test="status != null">
                status_ = #{status},
            </if>
            <if test="orderId != null">
                order_id_ = #{orderId},
            </if>
            <if test="createTime != null">
                create_time_ = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        where id_ = #{id}
    </update>

    <select id="getByUserIdAndStatus" resultMap="ChildrenDayDegreeDetail">
        SELECT *
        FROM children_day_degree_detail
        WHERE user_id_ = #{userId}
          AND status_ = #{status}
    </select>

    <insert id="batchAdd" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id_">
        INSERT INTO children_day_degree_detail
        (reserve_id_, user_id_, type_, subject_id_, level_, price_,status_,order_id_,create_time_,update_time)
        VALUE
        <foreach collection="details" item="detail" separator=",">
            (#{detail.reserveId}, #{detail.userId}, #{detail.type}, #{detail.subjectId}, #{detail.level},
            #{detail.price}, #{detail.status},#{detail.orderId},
            now(),now())
        </foreach>
    </insert>

    <update id="updateStatus">
        UPDATE children_day_degree_detail
        SET status_=#{status},
            update_time = NOW()
        WHERE order_id_ = #{orderId}
    </update>

    <select id="getByOrderId" resultMap="ChildrenDayDegreeDetail">
        SELECT *
        FROM children_day_degree_detail
        WHERE order_id_ = #{orderId}
    </select>
</mapper>
