<?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="again_commit_flag_" property="againCommitFlag" />
		<result column="tenant_id_" property="tenantId" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
        <result column="tenant_id_" property="tenantId"/>
        <result column="login_flag_" property="loginFlag"/>
        <result column="commit_type_" property="commitType"/>
        <result column="template_type_" property="templateType"/>
        <result column="share_title_" property="shareTitle"/>
        <result column="share_describe_" property="shareDescribe"/>
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="QuestionnaireTopic" >
		SELECT * FROM questionnaire_topic WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="QuestionnaireTopic">
		SELECT * FROM questionnaire_topic where tenant_id_ = #{tenantId} 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_,again_commit_flag_,tenant_id_,login_flag_,commit_type_,template_type_,share_title_,share_describe_)
		VALUES(#{title},#{status},#{creatorId},NOW(),NOW(),#{againCommitFlag},#{tenantId},#{loginFlag},#{commitType},#{templateType},#{shareTitle},#{shareDescribe})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.QuestionnaireTopic">
		UPDATE questionnaire_topic <set>
		<if test="templateType != null">
			template_type_ = #{templateType},
		</if>
		<if test="loginFlag != null">
			login_flag_ = #{loginFlag},
		</if>
		<if test="commitType != null">
			commit_type_ = #{commitType},
		</if>
		<if test="tenantId != null">
			tenant_id_ = #{tenantId},
		</if>
		<if test="againCommitFlag != null">
			again_commit_flag_ = #{againCommitFlag},
		</if>
		<if test="status != null">
			status_ = #{status},
		</if>
		<if test="title != null">
			title_ = #{title},
		</if>
		<if test="updateTime != null">
			update_time_ = #{updateTime},
		</if>
		<if test="shareTitle != null">
			share_title_ = #{shareTitle},
		</if>
		<if test="shareDescribe != null">
			share_describe_ = #{shareDescribe},
		</if>
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<update id="delete" >
		DELETE FROM questionnaire_topic WHERE id_ = #{id}
	</update>

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