<?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.education.business.mapper.education.CustomizeModelMapper">

    <!-- 自定义环节模板列表 -->
    <select id="selectPageList" resultType="customizeModelDto">
        select * from customize_model
        <where>
            <if test="customizeModel.name != null and customizeModel.name != ''">
                <bind name="name" value="'%' + customizeModel.name + '%'"/>
                and name like #{name}
            </if>
            <if test="customizeModel.gradeInfoId != null">
                and grade_info_id = #{customizeModel.gradeInfoId}
            </if>
            <if test="customizeModel.schoolType != null">
                and school_type = #{customizeModel.schoolType}
            </if>
            <if test="customizeModel.subjectId != null">
                and subject_id = #{customizeModel.subjectId}
            </if>
            <if test="customizeModel.courseId != null">
                and course_id = #{customizeModel.courseId}
            </if>
            <if test="customizeModel.sectionId != null">
                and section_id = #{customizeModel.sectionId}
            </if>
        </where>
        order by id desc
    </select>

    <!-- 根据 ID 查询自定义环节模板 -->
    <select id="selectCustomizeModelById" parameterType="int" resultType="com.education.model.entity.CustomizeModel">
        SELECT * FROM customize_model WHERE id = #{id}
    </select>

    <!-- 根据 ID 更新自定义环节模板 -->
    <update id="updateCustomizeModelById" parameterType="com.education.model.entity.CustomizeModel">
        UPDATE customize_model
        SET name = #{name},
            grade_info_id = #{gradeInfoId},
            school_type = #{schoolType},
            subject_id = #{subjectId},
            course_id = #{courseId},
            section_id = #{sectionId},
            prompt = #{prompt},
            reserve = #{reserve},
            create_date = #{createDate},
            update_date = #{updateDate}
        WHERE id = #{id}
    </update>

    <!-- 根据 ID 删除自定义环节模板 -->
    <delete id="deleteCustomizeModelById" parameterType="int">
        DELETE FROM customize_model WHERE id = #{id}
    </delete>

</mapper>