<?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.book.dao.impl.SeriesBookDaoImpl">

	<resultMap id="BaseResultMap" type="com.pcloud.book.book.entity.SeriesBook">
		<id column="id" property="id" jdbcType="BIGINT" />
		<result column="agent_id" property="agentId" jdbcType="BIGINT" />
		<result column="series_book_keyword" property="seriesBookKeyword" jdbcType="VARCHAR" />
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
		<result column="serial_number" property="serialNumber" jdbcType="VARCHAR" />
	</resultMap>

	<sql id="Base_Column_List">
		id,agent_id,series_book_keyword, create_time, serial_number
	</sql>

	<insert id="insert" parameterType="com.pcloud.book.book.entity.HotBook" useGeneratedKeys="true"
			keyProperty="id">
		insert into series_book
		<trim prefix="(" suffix=")" suffixOverrides=",">
			agent_id,
			series_book_keyword,
			create_time,
			serial_number
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			#{agentId,jdbcType=BIGINT},
			#{seriesBookKeyword,jdbcType=INTEGER},
			NOW(),
			#{serialNumber}
		</trim>
	</insert>

	<delete id="deleteById" parameterType="long">
		delete from series_book
		where id=#{id}
	</delete>

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

	<select id="getSeriesBookByAgent" resultMap="BaseResultMap" parameterType="long">
		SELECT <include refid="Base_Column_List"/>
		FROM series_book
		WHERE agent_id=#{agentId}
		ORDER BY LENGTH(series_book_keyword) DESC
	</select>
</mapper>