<?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.xhkjedu.sapi.mapper.gradeclass.ClassMapper">
    <!--获取班级当前年份-->
    <select id="getYearById" resultType="java.lang.Integer">
        select year from t_class where classid=#{classid}
    </select>
    <!--根据班级名称获取班级id-->
    <select id="getClassIdByName" resultType="java.lang.Integer">
        select c.classid from t_class c where c.schoolid=#{schoolid} and c.gradeid=#{gradeid} and c.classtype=1 and
        c.classstate=1 and c.classname=#{classname} and c.year=#{year}
    </select>

    <!--修改班级状态-->
    <update id="updateClassState">
       update t_class set classstate=#{classstate} where classid in (${classids})
    </update>

    <!--要升级的班级列表-->
    <select id="listClassBySchoolId" resultType="com.xhkjedu.sapi.model.gradeclass.TClass">
        select * from t_class where schoolid=#{schoolid} and year=#{year} and classtype in(1,2) and classstate=1 and gradeid in(1,2,3,4,5,7,8,10,11)
    </select>
    <!--升级时要毕业的班级列表-->
    <select id="listClassBiyeBySchoolId" resultType="com.xhkjedu.sapi.model.gradeclass.TClass">
        select classid,classtype,gradeid from t_class where schoolid=#{schoolid} and year=#{year} and classtype in(1,2) and classstate=#{classstate} and gradeid in(6,9,12)
    </select>

    <!--获取要升级的学生列表-->
    <select id="listStudentByClassIds" resultType="com.xhkjedu.sapi.model.gradeclass.TClassStudent">
        select * from t_class_student where classid in(${classIds}) order by classid;
    </select>
    <!--要升级的教师列表-->
    <select id="listTeacherByClassIds" resultType="com.xhkjedu.sapi.model.gradeclass.TClassTeacher">
        select * from t_class_teacher where classid in(${classIds}) order by classid;
    </select>
    <!--要升级的全体分组列表-->
    <select id="listGroupByClassIds" resultType="com.xhkjedu.sapi.model.gradeclass.TGroup">
        select g.* from t_group g where g.classid in(${classIds}) and g.grouptype=1 order by classid
    </select>
    <!--获取要升级的学生列表-->
    <select id="listStudentByGroupIds" resultType="com.xhkjedu.sapi.model.gradeclass.TGroupStudent">
        select * from t_group_student where groupid in(${groupIds}) order by groupid;
    </select>
    <!--班级学生id列表-->
    <select id="listStudentIdByClassIds" resultType="java.lang.Integer">
        select distinct studentid from t_class_student where classid in(${classIds})
    </select>

    <!--教师权限班级id集合-->
    <select id="listTeacherClassids" resultType="java.lang.String">
        select group_concat(distinct c.classid)
        from t_class_teacher ct left join  t_class c on ct.classid=c.classid
        left join t_school s on ct.schoolid=s.schoolid
        where ct.teacherid=#{teacherid} and c.year=s.year and c.classstate=1
          and c.classtype in(1,2) and c.schoolid=#{schoolid}
    </select>

    <!--获取教师权限班级-->
    <select id="listTeacherClass" resultType="com.xhkjedu.sapi.vo.gradeclass.ClassVo">
        select c.classid,c.gradeid,c.classname
        from t_class_teacher ct left join  t_class c on ct.classid=c.classid
        left join t_school s on ct.schoolid=s.schoolid
        where ct.teacherid=#{teacherid} and c.year=s.year and c.classstate=1
          and c.classtype in(1,2) and c.schoolid=#{schoolid} order by c.classtype,c.classorder
    </select>
</mapper>
