<?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.yonge.cooleshow.biz.dal.dao.VideoLessonGroupLogDao">

	<resultMap type="com.yonge.cooleshow.biz.dal.entity.VideoLessonGroupLog"
		id="BaseResultMap">
		<result column="id_" property="id" />
		<result column="video_lesson_group_id_" property="videoLessonGroupId" />
		<result column="lesson_name_" property="lessonName" />
		<result column="lesson_subject_" property="lessonSubject" />
		<result column="lesson_desc_" property="lessonDesc" />
		<result column="lesson_price_" property="lessonPrice" />
		<result column="pay_type_" property="payType" />
		<result column="lesson_cover_url_" property="lessonCoverUrl" />
		<result column="teacher_id_" property="teacherId" />
		<result column="lesson_count_" property="lessonCount" />
		<result column="sort_number_" property="sortNumber" />
		<result column="lesson_tag_" property="lessonTag" />
		<result column="top_flag_" property="topFlag" />
		<result column="hot_flag_" property="hotFlag" />
		<result column="shelves_flag_" property="shelvesFlag" />
		<result column="shelves_time_" property="shelvesTime" />
		<result column="shelves_reason_" property="shelvesReason" />
		<result column="shelves_id_" property="shelvesId" />
		<result column="modifier_id_" property="modifierId" />
		<result column="remarks" property="remarks" />
		<result column="audit_version_" property="auditVersion" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="version_" property="version" />
		<result column="video_detail_json_" property="videoDetailJson" />
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="BaseResultMap">
		SELECT * FROM
		video_lesson_group_log WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="BaseResultMap">
		SELECT * FROM
		video_lesson_group_log ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert"
		parameterType="com.yonge.cooleshow.biz.dal.entity.VideoLessonGroupLog"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO
		video_lesson_group_log
		(id_,video_lesson_group_id_,lesson_name_,lesson_subject_,pay_type_,lesson_desc_,lesson_price_,lesson_cover_url_,teacher_id_,lesson_count_,sort_number_,lesson_tag_,top_flag_,hot_flag_,shelves_flag_,shelves_time_,shelves_reason_,shelves_id_,modifier_id_,remarks,audit_version_,create_time_,update_time_,version_,video_detail_json_,draft_flag_,relation_type_)
		VALUES(#{id},#{videoLessonGroupId},#{lessonName},#{lessonSubject},#{payType},#{lessonDesc},#{lessonPrice},#{lessonCoverUrl},#{teacherId},#{lessonCount},#{sortNumber},#{lessonTag},#{topFlag},#{hotFlag},#{shelvesFlag},#{shelvesTime},#{shelvesReason},#{shelvesId},#{modifierId},#{remarks},#{auditVersion},#{createTime},#{updateTime},#{version},#{videoDetailJson},#{draftFlag},#{relationType})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update"
		parameterType="com.yonge.cooleshow.biz.dal.entity.VideoLessonGroupLog">
		UPDATE video_lesson_group_log
		<set>
			<if test="lessonCount != null">
				lesson_count_ = #{lessonCount},
			</if>
			<if test="lessonSubject != null">
				lesson_subject_ = #{lessonSubject},
			</if>
			<if test="lessonDesc != null">
				lesson_desc_ = #{lessonDesc},
			</if>
			<if test="payType != null">
				pay_type_ = #{payType},
			</if>
			<if test="modifierId != null">
				modifier_id_ = #{modifierId},
			</if>
			<if test="topFlag != null">
				top_flag_ = #{topFlag},
			</if>
			<if test="shelvesFlag != null">
				shelves_flag_ = #{shelvesFlag},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="shelvesId != null">
				shelves_id_ = #{shelvesId},
			</if>
			<if test="lessonCoverUrl != null">
				lesson_cover_url_ = #{lessonCoverUrl},
			</if>
			<if test="shelvesTime != null">
				shelves_time_ = #{shelvesTime},
			</if>
			<if test="shelvesReason != null">
				shelves_reason_ = #{shelvesReason},
			</if>
			<if test="sortNumber != null">
				sort_number_ = #{sortNumber},
			</if>
			<if test="hotFlag != null">
				hot_flag_ = #{hotFlag},
			</if>
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
			<if test="auditVersion != null">
				audit_version_ = #{auditVersion},
			</if>
			<if test="teacherId != null">
				teacher_id_ = #{teacherId},
			</if>
			<if test="lessonPrice != null">
				lesson_price_ = #{lessonPrice},
			</if>
			<if test="updateTime != null">
				update_time_ = #{updateTime},
			</if>
			<if test="lessonName != null">
				lesson_name_ = #{lessonName},
			</if>
			<if test="remarks != null">
				remarks = #{remarks},
			</if>
			<if test="lessonTag != null">
				lesson_tag_ = #{lessonTag},
			</if>
			<if test="videoLessonGroupId != null">
				video_lesson_group_id_ = #{videoLessonGroupId},
			</if>
			<if test="version != null">
				version_ = #{version},
			</if>
			<if test="videoDetailJson != null">
				video_detail_json_ = #{videoDetailJson},
			</if>
		</set>
		WHERE id_ = #{id}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete">
		DELETE FROM video_lesson_group_log WHERE id_
		= #{id}
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="BaseResultMap" parameterType="map">
		SELECT * FROM video_lesson_group_log ORDER BY id_
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM video_lesson_group_log
	</select>
	
	<select id="queryMaxVersion" resultType="long">
		SELECT ifnull(max(version_),0) FROM video_lesson_group_log where video_lesson_group_id_ = #{videoLessonGroupId}
	</select>
	
	<select id="queryByVideoLessonGroupId" resultMap="BaseResultMap">
		SELECT * FROM video_lesson_group_log where video_lesson_group_id_ = #{videoLessonGroupId} and version_ = #{version}
	</select>
	
	<select id="queryLastestShelvesInfo" resultMap="BaseResultMap">
		SELECT gg.* FROM video_lesson_auth_record ar left join video_lesson_group_log gg on ar.video_group_id_ = gg.video_lesson_group_id_ and ar.version_ = gg.version_
		where ar.video_group_id_ = #{videoLessonGroupId} and ar.audit_status_ = 'PASS' order by ar.version_ desc limit 1
	</select>
</mapper>
