<?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.user.mapper.SchoolMapper">

    <resultMap type="com.zhongzheng.modules.user.domain.School" id="SchoolResult">
        <result property="id" column="id"/>
        <result property="schoolName" column="school_name"/>
        <result property="encoder" column="encoder"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="schoolProvinceId" column="school_province_id"/>
        <result property="schoolCityId" column="school_city_id"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.vo.CourseProjectTypeVo" id="CourseProjectTypeVoResult">
        <result property="id" column="id"/>
        <result property="projectName" column="project_name"/>
        <result property="encoder" column="encoder"/>
        <result property="remark" column="remark"/>
        <result property="educationId" column="education_id"/>
        <result property="educationName" column="education_name"/>
        <result property="status" column="status"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.user.vo.SchoolVo" id="SchoolVoResult">
        <result property="id" column="id"/>
        <result property="schoolName" column="school_name"/>
        <result property="encoder" column="encoder"/>
        <result property="status" column="status"/>
        <result property="schoolProvinceId" column="school_province_id"/>
        <result property="schoolCityId" column="school_city_id"/>
        <result property="schoolProvinceFull" column="school_province_full"/>
        <result property="schoolProvince" column="school_province"/>
        <result property="schoolCityFull" column="school_city_full"/>
        <result property="schoolCityId" column="school_city_id"/>
        <result property="remark" column="remark"/>
    </resultMap>


    <select id="selectProject" parameterType="com.zhongzheng.modules.course.bo.CourseProjectTypeQueryBo"  resultMap="CourseProjectTypeVoResult">
        SELECT
        p.*,
        e.education_name
        FROM
        school_project j
        LEFT JOIN course_project_type p on p.id=j.project_id
        LEFT JOIN course_education_type e ON p.education_id = e.id
        where 1=1
        <if test="status != null and status.size()!=0 ">
            AND p.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="id != null and id != ''">
            and j.school_id = #{id}
        </if>
    </select>


    <select id="queryList" parameterType="com.zhongzheng.modules.user.bo.SchoolQueryBo"  resultMap="SchoolVoResult">
        SELECT
        s.* ,
        v.area_name as school_province,
        v.area_full_name school_province_full,
        a.area_name as school_city,
        a.area_full_name as school_city_full
        FROM
        school s
        LEFT JOIN apply_areas a ON s.school_city_id=a.area_id
        LEFT JOIN apply_areas v ON s.school_province_id=v.area_id
        LEFT JOIN school_project p ON p.school_id = s.id
        LEFT JOIN course_business b on b.project_id =p.project_id
        LEFT JOIN course_project_type t on p.project_id=t.id
        LEFT JOIN course_education_type e on t.education_id = e.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="id != null and id != ''">
            and s.id = #{id}
        </if>
        <if test="schoolProvinceId != null and schoolProvinceId != ''">
            and s.school_province_id = #{schoolProvinceId}
        </if>
        <if test="schoolCityId != null and schoolCityId != ''">
            and s.school_city_id = #{schoolCityId}
        </if>

        <if test="encoder != null and encoder != ''">
            and s.encoder = #{encoder}
        </if>

        <if test="schoolName != null and schoolName != ''">
            and s.school_name like concat('%', #{schoolName}, '%')
        </if>
        <if test="educationId != null and educationId!=0 ">
            AND e.id = #{educationId}
        </if>
        <if test="projectId != null and projectId!=0 ">
            AND t.id = #{projectId}
        </if>
        <if test="businessId != null and businessId!=0 ">
            AND b.id = #{businessId}
        </if>
        GROUP BY s.id
        order by s.update_time desc
    </select>
</mapper>
