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

    <resultMap type="com.zhongzheng.modules.course.domain.CourseBusiness" id="CourseBusinessResult">
        <result property="id" column="id"/>
        <result property="businessName" column="business_name"/>
        <result property="remark" column="remark"/>
        <result property="projectId" column="project_id"/>
        <result property="schoolYear" column="school_year"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="goodsLearningOrder" column="goods_learning_order"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseBusinessVo" id="CourseBusinessVoResult">
        <result property="id" column="id"/>
        <result property="businessName" column="business_name"/>
        <result property="remark" column="remark"/>
        <result property="projectId" column="project_id"/>
        <result property="schoolYear" column="school_year"/>
        <result property="status" column="status"/>
        <result property="educationName" column="education_name"/>
        <result property="projectName" column="project_name"/>
        <result property="educationId" column="education_id"/>
        <result property="templateStatus" column="template_status"/>
        <result property="templateName" column="template_name"/>
        <result property="goodsLearningOrder" column="goods_learning_order"/>
    </resultMap>

    <select id="queryList" parameterType="com.zhongzheng.modules.course.bo.CourseBusinessQueryBo"  resultMap="CourseBusinessVoResult">
        SELECT
            b.*,
            e.education_name,
            e.id as education_id,
            p.project_name,
            t.name as template_name
        FROM
            course_business b
                LEFT JOIN course_project_type p on b.project_id =p.id
                LEFT JOIN course_education_type e ON p.education_id = e.id
                LEFT JOIN order_input_template t ON b.template_status = t.id
        where 1=1
        and p.status != -1
        and e.status != -1
        <if test="status != null and status.size()!=0 ">
            AND b.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="businessName != null and businessName != ''">
            AND b.business_name = #{businessName}
        </if>
        <if test="encoder != null and encoder != ''">
            AND b.encoder = #{encoder}
        </if>
        <if test="projectId != null and projectId != ''">
            AND p.id = #{projectId}
        </if>
        <if test="educationId != null and educationId != ''">
            AND e.id = #{educationId}
        </if>
        <if test="id != null and id != ''">
            AND b.id = #{id}
        </if>
        order by b.create_time desc
    </select>

</mapper>
