<?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.bowintek.smartsearch.mapper.cquery.DictionaryCQuery">
    <select id="selectCollegeList" resultType="com.bowintek.smartsearch.vo.system.dictionary.DicCollegeModel">
        select collegeID,code,name,recordStatus from cf_college
        order by code
    </select>

    <select id="selectMajorGradeList" resultType="com.bowintek.smartsearch.vo.system.dictionary.DicMajorGradeModel">
        select g.majorGradeID,g.code,g.name,g.schoolYearID,g.majorID
        from cf_major_grade g
        inner join cf_major m on g.MajorID = m.MajorID
        inner join cf_college cl on m.CollegeID = cl.CollegeID
        inner join cf_schoolyear s  on g.schoolYearID = s.schoolYearID
        <where>
            <if test="schoolYearID!='' and schoolYearID!=null">
                and g.schoolYearID = #{schoolYearID}
            </if>
            <if test="collegeID!='' and collegeID!=null">
                and cl.collegeID = #{collegeID}
            </if>
            <if test="majorID!='' and majorID!=null">
                and m.MajorID = #{majorID}
            </if>
        </where>
        order by s.StartYear asc,g.Name desc
    </select>

    <select id="selectMajorClassList" resultType="com.bowintek.smartsearch.vo.system.dictionary.DicMajorClassModel">
        select cs.majorClassID,cs.majorGradeID,cs.code,cs.name
        from cf_major_class cs
        inner join cf_major_grade g on cs.majorGradeID = g.majorGradeID
        inner join cf_major m on g.MajorID = m.MajorID
        inner join cf_college cl on m.CollegeID = cl.CollegeID
        <where>
            <if test="schoolYearID!='' and schoolYearID!=null">
                and g.schoolYearID = #{schoolYearID}
            </if>
            <if test="collegeID!='' and collegeID!=null">
                and cl.collegeID = #{collegeID}
            </if>
            <if test="majorGradeID!='' and majorGradeID!=null">
                and g.majorGradeID = #{majorGradeID}
            </if>
        </where>
        order by cs.code
    </select>

    <select id="selectMajorList" resultType="com.bowintek.smartsearch.vo.system.dictionary.DicMajorModel">
        select cm.CollegeID,cm.MajorID,cm.code,cm.name
        from cf_major cm inner join cf_college cc
        on cm.CollegeID = cc.CollegeID
        <where>
            <if test="collegeID!='' and collegeID!=null">
                and cm.collegeID = #{collegeID}
            </if>
            <if test="code!='' and code!=null">
                and cm.code = #{code}
            </if>
            <if test="name!='' and name!=null">
                and cm.name = #{name}
            </if>
        </where>
        order by cm.code
    </select>

    <select id="selectPositionByMajorGradeIDList" resultType="com.bowintek.smartsearch.model.CfPosition">
        select distinct  p.positionID,p.name
        from  cf_position p
        left join (
            select positionID,sum(useQty) useQty from (select positionID,count(1) as useQty from pm_practice_task_student group by positionID
            union select NextPositionID PositionID,count(1) as useQty from pm_practice_position_change pc where RecordStatus=1
            group by pc.NextPositionID) pu group by pu.PositionID
        ) as pUse on p.positionID = pUse.positionID
        where  p.Qty>ifnull(pUse.useQty,0) and p.MajorGradeID = #{majorGradeID}
        <if test="schoolYearID!='' and schoolYearID!=null">
            and p.schoolYearID = #{schoolYearID}
        </if>
        <if test="practiceBaseID!='' and practiceBaseID!=null">
            and p.practiceBaseID = #{practiceBaseID}
        </if>
        order by p.name
    </select>

</mapper>