<?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.MusicGroupQuestionnaireDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.MusicGroupQuestionnaire" id="MusicGroupQuestionnaire">
		<result column="id_" property="id" />
		<result column="questionnaire_topic_id_" property="questionnaireTopicId" />
		<result column="music_group_id_" property="musicGroupId" />
		<result column="target_" property="target" />
		<result column="operator_id_" property="operatorId" />
		<result column="real_name_" property="operatorName" />
		<result column="question_time_" property="questionTime" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
        <result column="tenant_id_" property="tenantId"/>
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="MusicGroupQuestionnaire" >
		SELECT mgq.*,su.real_name_ FROM music_group_questionnaire mgq
		LEFT JOIN sys_user su ON su.id_ = mgq.operator_id_
		WHERE mgq.id_ = #{id}
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="MusicGroupQuestionnaire">
		SELECT * FROM music_group_questionnaire where tenant_id_ = #{tenantId} ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupQuestionnaire" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO music_group_questionnaire (questionnaire_topic_id_,music_group_id_,target_,operator_id_,question_time_,create_time_,update_time_,tenant_id_)
		VALUES(#{questionnaireTopicId},#{musicGroupId},#{target},#{operatorId},#{questionTime},NOW(),NOW(),#{tenantId})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.MusicGroupQuestionnaire">
		UPDATE music_group_questionnaire <set>
		<if test="operatorId != null">
			operator_id_ = #{operatorId},
		</if>
		<if test="target != null">
			target_ = #{target},
		</if>
		<if test="questionnaireTopicId != null">
			questionnaire_topic_id_ = #{questionnaireTopicId},
		</if>
		<if test="questionTime != null">
			question_time_ = #{questionTime},
		</if>
		<if test="musicGroupId != null">
			music_group_id_ = #{musicGroupId},
		</if>
			update_time_ = NOW()
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM music_group_questionnaire WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="MusicGroupQuestionnaire" parameterType="map">
		SELECT mgq.*,su.real_name_ FROM music_group_questionnaire mgq
		LEFT JOIN sys_user su ON su.id_ = mgq.operator_id_
		<include refid="queryPageSql"/>
		ORDER BY mgq.id_
		<include refid="global.limit"/>
	</select>
	<sql id="queryPageSql">
		<where>
			mgq.tenant_id_ = #{tenantId}
			<if test="search != null and search != ''">
				AND mgq.music_group_id_ = #{search}
			</if>
			<if test="musicGroupId != null and musicGroupId != ''">
				AND mgq.music_group_id_ = #{musicGroupId}
			</if>
		</where>
	</sql>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(mgq.id_) FROM music_group_questionnaire mgq
		<include refid="queryPageSql"/>
	</select>
</mapper>
