<?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.cultivate.dao.impl.CultivateBookUserDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.cultivate.entity.CultivateBookUser" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT" />
    <result column="book_name" property="bookName" jdbcType="VARCHAR" />
    <result column="read_type" property="readType" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, wechat_user_id, book_name, read_type, create_time
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.cultivate.entity.CultivateBookUser" useGeneratedKeys="true" keyProperty="id">
    insert into cultivate_book_user
    (
      wechat_user_id,
      book_name,
      read_type,
      create_time
      )
    values (
      #{wechatUserId},
      #{bookName},
      #{readType},
      NOW()
      )
  </insert>

  <select id="getById" parameterType="long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/> from
    cultivate_book_user
    where id=#{id}
  </select>

  <select id="getLastCultivateBookUser" parameterType="long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/> from
    cultivate_book_user
    where wechat_user_id=#{wechatUserId}
    order by create_time desc limit 1
  </select>

</mapper>