<?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.TenantCloudCourseRecordDao">

    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.TenantCloudCourseRecord">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
        <result column="course_id_" jdbcType="INTEGER" property="courseId"/>
        <result column="deduct_state_" jdbcType="INTEGER" property="deductState"/>
        <result column="amount_" jdbcType="VARCHAR" property="amount"/>
        <result column="created_by_" jdbcType="INTEGER" property="createdBy"/>
        <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , tenant_id_,course_id_, deduct_state_, amount_,created_by_, created_time_
    </sql>

    <select id="queryPage" parameterType="map" resultType="com.ym.mec.biz.dal.vo.TenantCloudCourseRecordVo">
        select a.id_ as id,
        b.id_ as courseId,
        o.name_ as organName,
        t.id_ as tenantId,
        t.name_ as tenantName,
        b.type_ as type,
        s.real_name_ as teacherName,
        b.student_num_ as studentNum,
        b.class_date_ as classDate,
        b.start_class_time_ as startClassTime,
        b.end_class_time_ as endClassTime,
        b.status_ as `status`,
        a.deduct_state_ as deductState,
        a.amount_ as amount
        from tenant_info as t
        join tenant_cloud_course_record as a  on t.id_ = a.tenant_id_
        left join course_schedule as b        on a.course_id_ = b.id_
        left join sys_user as s               on b.teacher_id_ = s.id_
        left join organization as o           on o.id_ = b.organ_id_
        <where> 1 = 1
            <if test="param.tenantId != null ">
                AND t.id_ = #{param.tenantId}
            </if>
            <if test="param.search != null ">
                AND (
                b.`id_` LIKE CONCAT('%', #{param.search},'%')
                OR b.`name_` LIKE CONCAT('%', #{param.search},'%')
                )
            </if>
            <if test="param.type != null ">
                AND b.type_ = #{param.type}
            </if>
            <if test="param.orgId != null ">
                AND o.id_= #{param.orgId}
            </if>
            <if test="param.teacherName != null ">
                AND s.real_name_ = #{param.teacherName}
            </if>
            <if test="param.teacherId!= null ">
                AND b.teacher_id_ = #{param.teacherId}
            </if>
            <if test="param.deductState != null ">
                AND a.deduct_state_ = #{param.deductState}
            </if>
            <if test="param.status != null ">
                AND b.status_ = #{param.status}
            </if>
            <if test="param.deductState != null ">
                AND a.deduct_state_ = #{param.deductState}
            </if>
            <if test="param.startDate != null">
                AND b.class_date_ <![CDATA[ >= ]]>  #{param.startDate}
            </if>
            <if test="param.endDate != null ">
                AND b.`class_date_` <![CDATA[ <= ]]>  #{param.endDate}
            </if>
            <if test="param.ids != null ">
               AND a.id_ IN
                <foreach collection="ids" item="id" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>

</mapper>
