<?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="test05.mapper.CourseMapper">
    <!--suppress Annotator -->
    <select id="selectCourse" resultType="test05.pojo.Course">
        SELECT N_COURSE_ID    AS id,
               VC_COURSE_NAME AS name,
               N_TYPE         AS type,
               F_CREDIT       AS credit,
               N_MAJOR        AS major,
               N_GRADE        AS grade,
               VC_DETAIL      AS detail
        FROM t_course
        WHERE #{course.id} in (N_COURSE_ID, -1)
          AND #{course.type} in (N_TYPE, -1)
          AND #{course.credit} in (F_CREDIT, -1)
          AND #{course.major} in (N_MAJOR, -1)
          AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{course.name}), '%')
        ORDER BY N_COURSE_ID DESC
        LIMIT #{offset},#{pageSize}
    </select>
    <select id="selectCourseCount" resultType="int">
        SELECT COUNT(*)
        FROM t_course
        WHERE #{id} in (N_COURSE_ID, -1)
          AND #{type} in (N_TYPE, -1)
          AND #{credit} in (F_CREDIT, -1)
          AND #{major} in (N_MAJOR, -1)
          AND UPPER(VC_COURSE_NAME) LIKE CONCAT('%', UPPER(#{name}), '%')
    </select>
    <insert id="insertCourse" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO t_course
            (VC_COURSE_NAME, N_TYPE, F_CREDIT, N_GRADE, N_MAJOR, VC_DETAIL)
        VALUES (#{name}, #{type}, #{credit}, #{grade}, #{major}, #{detail})
    </insert>
    <update id="updateCourse">
        UPDATE t_course
        SET VC_COURSE_NAME=#{name},
            N_TYPE=#{type},
            F_CREDIT=#{credit},
            N_GRADE=#{grade},
            N_MAJOR=#{major},
            VC_DETAIL=#{detail}
        WHERE N_COURSE_ID=#{id};
    </update>
    <delete id="deleteCourse">
        DELETE FROM t_course
        WHERE N_COURSE_ID=#{id};
    </delete>
</mapper>