<?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.java2nb.novel.dao.UserFeedbackDao">

	<select id="get" resultType="com.java2nb.novel.domain.UserFeedbackDO">
		select `id`,`user_id`,`content`,`create_time` from user_feedback where id = #{value}
	</select>

	<select id="list" resultType="com.java2nb.novel.domain.UserFeedbackDO">
		select `id`,`user_id`,`content`,`create_time` from user_feedback
        <where>  
		  		  <if test="id != null and id != ''"> and id = #{id} </if>
		  		  <if test="userId != null and userId != ''"> and user_id = #{userId} </if>
		  		  <if test="content != null and content != ''"> and content = #{content} </if>
		  		  <if test="createTime != null and createTime != ''"> and create_time = #{createTime} </if>
		  		</where>
        <choose>
            <when test="sort != null and sort.trim() != ''">
                order by ${sort} ${order}
            </when>
			<otherwise>
                order by id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="count" resultType="int">
		select count(*) from user_feedback
		 <where>  
		  		  <if test="id != null and id != ''"> and id = #{id} </if>
		  		  <if test="userId != null and userId != ''"> and user_id = #{userId} </if>
		  		  <if test="content != null and content != ''"> and content = #{content} </if>
		  		  <if test="createTime != null and createTime != ''"> and create_time = #{createTime} </if>
		  		</where>
	</select>
	 
	<insert id="save" parameterType="com.java2nb.novel.domain.UserFeedbackDO">
		insert into user_feedback
		(
			`id`, 
			`user_id`, 
			`content`, 
			`create_time`
		)
		values
		(
			#{id}, 
			#{userId}, 
			#{content}, 
			#{createTime}
		)
	</insert>

	<insert id="saveSelective" parameterType="com.java2nb.novel.domain.UserFeedbackDO">
		insert into user_feedback
		(
					<if test="id != null"> `id`,  </if>
					<if test="userId != null"> `user_id`,  </if>
					<if test="content != null"> `content`,  </if>
					<if test="createTime != null"> `create_time` </if>
				)
		values
		(
					<if test="id != null"> #{id},  </if>
					<if test="userId != null"> #{userId},  </if>
					<if test="content != null"> #{content},  </if>
					<if test="createTime != null"> #{createTime} </if>
				)
	</insert>
	 
	<update id="update" parameterType="com.java2nb.novel.domain.UserFeedbackDO">
		update user_feedback 
		<set>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="content != null">`content` = #{content}, </if>
			<if test="createTime != null">`create_time` = #{createTime}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="remove">
		delete from user_feedback where id = #{value}
	</delete>
	
	<delete id="batchRemove">
		delete from user_feedback where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>