<?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.CloudTeacherFreeCourseDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.CloudTeacherFreeCourse" id="CloudTeacherFreeCourse">
		<result column="id_" property="id" />
		<result column="course_id_" property="courseId" />
		<result column="calender_id_" property="calenderId" />
		<result column="cost_" property="cost" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="CloudTeacherFreeCourse" >
		SELECT * FROM cloud_teacher_free_course WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="CloudTeacherFreeCourse">
		SELECT * FROM cloud_teacher_free_course ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.CloudTeacherFreeCourse" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO cloud_teacher_free_course (id_,course_id_,cost_,calender_id_,create_time_,update_time_)
		VALUES(#{id},#{courseId},#{cost},#{calenderId},NOW(),NOW())
	</insert>
    <insert id="batchInsert">
		insert into cloud_teacher_free_course (course_id_, cost_,calender_id_, create_time_, update_time_)
		SELECT cs.id_,CASE WHEN oct.id_ IS NULL THEN oct1.price_ ELSE oct.price_ END cost_,#{calenderId},NOW(),NOW() FROM course_schedule cs
		left join organ_course_type_original_cost oct ON oct.course_type_ = cs.type_ AND oct.organ_id_ = cs.organ_id_
		left join organ_course_type_original_cost oct1 ON oct1.course_type_ = cs.type_ AND oct1.organ_id_ = 0
		where FIND_IN_SET(cs.id_,#{scheduleIdList})
		GROUP BY cs.id_
	</insert>

    <!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.CloudTeacherFreeCourse">
		UPDATE cloud_teacher_free_course <set>
		<if test="cost != null">
		cost_ = #{cost},
		</if>
		<if test="updateTime != null">
		update_time_ = #{updateTime},
		</if>
		<if test="courseId != null">
		course_id_ = #{courseId},
		</if>
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM cloud_teacher_free_course WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="CloudTeacherFreeCourse" parameterType="map">
		SELECT * FROM cloud_teacher_free_course ORDER BY id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM cloud_teacher_free_course
	</select>
</mapper>
