<?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.tamguo.admin.dao.CourseMapper">

	<resultMap id="BaseResultMap" type="com.tamguo.admin.model.CourseEntity" >
	    <id column="uid" property="uid" jdbcType="VARCHAR" />
	    <result column="name" property="name" jdbcType="VARCHAR" />
	    <result column="subject_id" property="subjectId" jdbcType="INTEGER" />
	    <result column="point_num" property="pointNum" jdbcType="INTEGER" />
	    <result column="question_num" property="questionNum" jdbcType="INTEGER" />
	    <result column="orders" property="orders" jdbcType="INTEGER" />
	    <result column="seo_title" property="seoTitle" jdbcType="VARCHAR" />
	    <result column="seo_keywords" property="seoKeywords" jdbcType="VARCHAR" />
	    <result column="seo_description" property="seoDescription" jdbcType="VARCHAR" />
	    <result column="subject_name" property="subjectName" jdbcType="VARCHAR" />
	</resultMap>

	<select id="findBySubjectId" resultType="CourseEntity">
		SELECT
			c.uid,
			c.`name`,
			c.orders,
			c.point_num,
			c.question_num,
			c.subject_id
		FROM
			tiku_course c
		WHERE
			c.subject_id = #{subjectId}
		ORDER BY orders ASC
	</select>
	
	<select id="queryPageByName" resultType="CourseEntity">
		SELECT
			c.`name`,
			c.orders,
			c.point_num,
			c.question_num,
			c.subject_id,
			c.uid,
			(select s.name from tiku_subject s where s.uid = c.subject_id) as subject_name
		FROM
			tiku_course c
		<where>
			<if test="name != null and name != ''">
				c.name like #{name}
			</if>
		</where>
	</select>
	
</mapper>