<?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.ym.mec.biz.dal.dao.QuestionnaireTopicDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.QuestionnaireTopic" id="QuestionnaireTopic">
		<result column="id_" property="id" />
		<result column="title_" property="title" />
		<result column="status_" property="status"/>
		<result column="creator_id_" property="creatorId" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="QuestionnaireTopic" >
		SELECT * FROM questionnaire_topic WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="QuestionnaireTopic">
		SELECT * FROM questionnaire_topic ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.QuestionnaireTopic" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO questionnaire_topic (title_,status_,creator_id_,create_time_,update_time_)
		VALUES(#{title},#{status},#{creatorId},NOW(),NOW())
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.QuestionnaireTopic">
		UPDATE questionnaire_topic <set>
		<if test="status != null">
			status_ = #{status},
		</if>
		<if test="title != null">
			title_ = #{title},
		</if>
		<if test="updateTime != null">
			update_time_ = #{updateTime},
		</if>
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<update id="delete" >
		DELETE FROM questionnaire_topic WHERE id_ = #{id}
	</update>

	<sql id="queryPageSql">
		<where>
			<if test="search != null and search != ''">
				AND (id_ = #{search} OR title_ LIKE CONCAT('%',#{search},'%'))
			</if>
			<if test="status != null">
				AND status_ = #{status}
			</if>
		</where>
	</sql>
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="QuestionnaireTopic" parameterType="map">
		SELECT * FROM questionnaire_topic
		<include refid="queryPageSql"/>
		ORDER BY id_
		<include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM questionnaire_topic
		<include refid="queryPageSql"/>
	</select>
</mapper>
