<?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.pcloud.book.riddle.dao.impl.RiddleDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.riddle.entity.Riddle" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="riddle_content" property="riddleContent" jdbcType="VARCHAR" />
    <result column="answer" property="answer" jdbcType="VARCHAR" />
    <result column="other_answer" property="otherAnswer" jdbcType="VARCHAR" />
    <result column="grade" property="grade" jdbcType="TINYINT" />
    <result column="seq" property="seq" jdbcType="TINYINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, riddle_content, answer, other_answer, grade, seq, create_time
  </sql>

  <select id="getRiddleByGradeAndSeq" resultMap="BaseResultMap" parameterType="map">
    SELECT
	<include refid="Base_Column_List"/>
    FROM
        riddle
    WHERE
        grade = #{grade}
    AND seq > #{seq}
    LIMIT 1
  </select>

  <select id="getById" parameterType="Long" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM riddle
    WHERE id = #{id}
  </select>

  <select id="getCount" resultType="integer">
    SELECT
        COUNT(1)
    FROM
        riddle
  </select>

</mapper>