<?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="cn.pluss.platform.mapper.QuestionsAnswersMapper">

	   	<insert id="saveQuestionsAnswers" parameterType="cn.pluss.platform.entity.QuestionsAnswers">
        	insert into tb_pluss_questions_answers(question,answer,createDt,seq,status)VALUES(#{question},#{answer},NOW(),#{seq},#{status})
    	</insert>

	   	<insert id="saveQuestionsAnswersBatch">
        	insert into tb_pluss_questions_answers(question,answer,createDt,seq,status) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{question},#{answer},#{createDt},#{seq},#{status}		)
				</foreach>
    	</insert>

		<select id="queryQuestionsAnswers" parameterType="cn.pluss.platform.entity.QuestionsAnswers" resultType="cn.pluss.platform.entity.QuestionsAnswers">
			SELECT * from tb_pluss_questions_answers 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="question!= null"> 
					 	and question = #{question}
					 </if> 
					<if test="answer!= null"> 
					 	and answer = #{answer}
					 </if> 
					<if test="createDt!= null"> 
					 	and createDt = #{createDt}
					 </if> 
					<if test="seq!= null"> 
					 	and seq = #{seq}
					 </if> 
					<if test="status!= null"> 
					 	and status = #{status}
					 </if> 
				 </where> 
		</select>

		<select id="queryQuestionsAnswersList" parameterType="cn.pluss.platform.entity.QuestionsAnswers" resultType="cn.pluss.platform.entity.QuestionsAnswers">
			SELECT * from tb_pluss_questions_answers 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="question!= null"> 
					 and 	question = #{question}
					 </if> 
					<if test="answer!= null"> 
					 and 	answer = #{answer}
					 </if> 
					<if test="createDt!= null"> 
					 and 	createDt = #{createDt}
					 </if> 
					<if test="seq!= null"> 
					 and 	seq = #{seq}
					 </if> 
					<if test="status!= null"> 
					 and 	status = #{status}
					 </if> 
				 </where> 
		</select>

		<update id="updateQuestionsAnswers" parameterType="cn.pluss.platform.entity.QuestionsAnswers" >
			update tb_pluss_questions_answers 
				  <set> 
					<if test="question!= null"> 
					 	question = #{question},
					 </if> 
					<if test="answer!= null"> 
					 	answer = #{answer},
					 </if> 
					<if test="createDt!= null"> 
					 	createDt = #{createDt},
					 </if> 
					<if test="seq!= null"> 
					 	seq = #{seq},
					 </if> 
					<if test="status!= null"> 
					 	status = #{status}
					 </if> 
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteQuestionsAnswers" parameterType="cn.pluss.platform.entity.QuestionsAnswers" >
			DELETE FROM tb_pluss_questions_answers where id=#{id}
		</delete>

		<select id="queryQuestionsAnswersPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.QuestionsAnswers">
			SELECT * from tb_pluss_questions_answers 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="question!= null"> 
					and question like CONCAT("%",#{question},"%") 
					 </if> 
					<if test="answer!= null"> 
					and answer = #{answer}
					 </if> 
					<if test="createDt!= null"> 
					and createDt = #{createDt}
					 </if> 
					<if test="seq!= null"> 
					and seq = #{seq}
					 </if> 
					<if test="status!= null"> 
					and status = #{status}
					 </if> 
				 </where> 
			order by seq asc  limit #{pageSize}  offset  #{offset}  
		</select>
		
		<!--根据ID倒序  -->
		<select id="queryQuestionsAnswersOrderByIDPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.QuestionsAnswers">
			SELECT * from tb_pluss_questions_answers 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="question!= null"> 
					and question like CONCAT("%",#{question},"%") 
					 </if> 
					<if test="answer!= null"> 
					and answer = #{answer}
					 </if> 
					<if test="createDt!= null"> 
					and createDt = #{createDt}
					 </if> 
					<if test="seq!= null"> 
					and seq = #{seq}
					 </if> 
					<if test="status!= null"> 
					and status = #{status}
					 </if> 
				 </where> 
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>

		<select id="queryQuestionsAnswersPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_questions_answers 
					<where> 
					<if test="id!= null"> 
					 and id = #{id}
					 </if> 
					<if test="question!= null"> 
					 and question like CONCAT("%",#{question},"%")
					 </if> 
					<if test="answer!= null"> 
					 and answer = #{answer}
					 </if> 
					<if test="createDt!= null"> 
					 and createDt = #{createDt}
					 </if> 
					<if test="seq!= null"> 
					 and seq = #{seq}
					 </if> 
					<if test="status!= null"> 
					 and status = #{status}
					 </if> 
				</where>
		</select>

</mapper>
