<?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.suser.mapper.subjectbook.TeacherPowersbMapper">
    <!-- 根据用户id删除用户教材 -->
    <delete id="deleteByUserid">
        delete from t_teacher_powersb where teacherid=#{userid}
    </delete>
    <!-- 用户id获取教材集合 -->
    <select id="listLsbsByUserid" resultType="java.util.Map">
        SELECT tsb.lsbid,sb.subjectid,s.subjectname,sb.lsbname,sb.coverpath,sb.versionid,v.versionname
        FROM t_teacher_powersb tsb LEFT JOIN t_subject_book sb ON tsb.lsbid=sb.lsbid
        LEFT JOIN t_subject s ON sb.subjectid=s.subjectid
        LEFT JOIN t_version v ON sb.versionid=v.versionid
        WHERE tsb.teacherid=#{userid} and (sb.belong=1 or sb.schoolid=tsb.schoolid)
        ORDER BY s.subjectorder,v.versionorder,sb.lsborder
    </select>
    <!--教师权限科目-->
    <select id="listSubject" resultType="java.util.Map">
        SELECT sb.subjectid,s.subjectname,s.level
        FROM t_teacher_powersb tsb LEFT JOIN t_subject_book sb ON tsb.lsbid=sb.lsbid
        LEFT JOIN t_subject s ON sb.subjectid=s.subjectid
        WHERE tsb.teacherid=#{teacherid} and (sb.belong=1 or sb.schoolid=tsb.schoolid)
        GROUP BY s.subjectid ORDER BY s.subjectorder
    </select>

    <select id="listBookBySubjectid" resultType="java.util.Map">
        SELECT tsb.lsbid,sb.lsbname,sb.versionid,v.versionname
         FROM t_teacher_powersb tsb LEFT JOIN t_subject_book sb ON tsb.lsbid=sb.lsbid
         LEFT JOIN t_version v ON sb.versionid=v.versionid
         WHERE tsb.teacherid=#{teacherid} AND sb.subjectid=#{subjectid} and (sb.belong=1 or sb.schoolid=tsb.schoolid)
         GROUP BY sb.lsbid ORDER BY v.versionorder,sb.lsborder
    </select>

    <!--根据教材id获取科目id-->
    <select id="getSubjectidBylsbid" resultType="java.lang.String">
        select subjectid from  t_subject_book where lsbid=#{lsbid}
    </select>
</mapper>
