<?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.zhongzheng.modules.course.mapper.CourseHandoutsMapper">

    <resultMap type="com.zhongzheng.modules.course.domain.CourseHandouts" id="CourseHandoutsResult">
        <result property="handoutsId" column="handouts_id"/>
        <result property="handoutsName" column="handouts_name"/>
        <result property="status" column="status"/>
        <result property="handoutsUrl" column="handouts_url"/>
        <result property="encoder" column="encoder"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.domain.CourseHandoutsBusiness" id="CourseHandoutsBusinessResult">
        <result property="id" column="id"/>
        <result property="educationId" column="education_id"/>
        <result property="businessId" column="business_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="handoutsId" column="handouts_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseHandoutsBusinessVo" id="CourseHandoutsBusinessVoResult">
        <result property="id" column="id"/>
        <result property="educationId" column="education_id"/>
        <result property="businessId" column="business_id"/>
        <result property="educationName" column="education_name"/>
        <result property="businessName" column="business_name"/>
        <result property="handoutsId" column="handouts_id"/>
        <result property="subjectName" column="subject_name"/>
        <result property="projectName" column="project_name"/>
        <result property="projectId" column="project_id"/>
    </resultMap>


    <select id="selectEntity" parameterType="Long"  resultMap="CourseHandoutsBusinessVoResult">
        SELECT
        h.*,
        b.business_name,
        e.education_name,
        s.subject_name,
        t.project_name,
        t.id as project_id
        FROM
        course_handouts_business h
        LEFT JOIN course_business b ON h.business_id = b.id
        LEFT JOIN course_education_type e ON h.education_id = e.id
        LEFT JOIN course_subject s on s.id = h.subject_id
        LEFT JOIN course_project_type t on t.id = b.project_id
        where 1=1

        <if test="handoutsId != null and handoutsId != ''">
            AND h.handouts_id = #{handoutsId}
        </if>
    </select>

    <select id="queryList" parameterType="com.zhongzheng.modules.course.bo.CourseHandoutsQueryBo"  resultMap="CourseHandoutsResult">
        SELECT
            s.*
        FROM
            course_handouts s
                LEFT JOIN course_handouts_business h ON s.handouts_id = h.handouts_id
        WHERE
            1 = 1
        <if test="status != null and status.size()!=0 ">
            AND s.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="encoder != null and encoder != ''">
            AND s.encoder = #{encoder}
        </if>
        <if test="businessId != null and businessId != ''">
            AND h.business_id = #{businessId}
        </if>
        <if test="educationId != null and educationId != ''">
            AND h.education_id = #{educationId}
        </if>
        <if test="id != null and id != ''">
            AND s.handouts_id = #{id}
        </if>
        <if test="subjectId != null and subjectId != ''">
            AND h.subject_id = #{subjectId}
        </if>
        <if test="handoutsName != null and handoutsName != ''">
            AND s.handouts_name like (concat('%', #{handoutsName}, '%'))
        </if>
        GROUP BY s.handouts_id
        ORDER BY s.update_time desc
    </select>

</mapper>
