<?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.ssj.mapper.problem.ProblemMapper">
    <!--查询老师的难题列表，只查三天-->
    <select id="findProblemListByTeacherId" resultType="com.ssj.bean.sys.problem.dto.ProblemPictureListDto">
        select pp.id problem_picture_id, pp.subject, vip.child_name, vip.img_url child_img, pp.create_time, pp.manual_edit_type type,
        pp.file_key problem_picture_path, psp.task_status, psp.deal_flag,pp.is_feedback isFeedback from  scon_problem_picture  pp
        left join  tb_lib_vip vip on vip.id=pp.vip_id
        left join tb_class_student cs on vip.id=cs.vip_id and cs.status = 1
        left join scon_problem_similar_predeal psp on pp.id=psp.problem_picture_id
        where cs.class_id = #{classId}
        <if test="subjects != null">
            and pp.subject in
            <foreach collection="subjects" open="(" item="subject" separator="," close=")">
                #{subject}
            </foreach>
        </if>
        <if test="libId != null and libId != ''">
            and vip.lib_id=#{libId}
                </if>
        and pp.create_time > #{beginTime} and pp.is_delete=0
        and vip.user_id is not null
        order by pp.create_time desc
    </select>

    <!--查询学生某科难题-->
    <select id="findProblemListByVipIdAndSubject" resultType="com.ssj.bean.sys.problem.dto.ProblemPictureListDto">
        select pp.id problem_picture_id, pp.subject, pp.create_time, pp.file_key problem_picture_path,
        pp.manual_edit_type type, pp.teacher_message teacherComment,
            psp.task_status, psp.deal_flag,is_feedback isFeedback
        from scon_problem_picture pp
        left join scon_problem_similar_predeal psp on pp.id=psp.problem_picture_id
        where pp.vip_id=#{vipId}
        <if test="subjects != null">
            and pp.subject in
            <foreach collection="subjects" open="(" item="subject" separator="," close=")">
                #{subject}
            </foreach>
        </if>
        and pp.is_delete = 0
        order by pp.create_time desc
    </select>

    <!--查询学生某科所有难题-->
    <select id="findAllProblemListByVipIdAndSubject" resultType="com.ssj.bean.sys.problem.dto.ProblemPictureListDto">
        select pp.id problem_picture_id, pp.subject, pp.create_time, pp.file_key problem_picture_path,
        pp.manual_edit_type type, psp.task_status, psp.deal_flag,pp.is_feedback isFeedback from scon_problem_picture pp
        left join scon_problem_similar_predeal psp on pp.id=psp.problem_picture_id
        where pp.vip_id=#{vipId}
        <if test="subject != null and subject !='' ">
            and pp.subject=#{subject}
        </if>
        and pp.is_delete = 0
        order by pp.create_time desc
    </select>

    <select id="findOrgTeacherIdByVipIdAndSubject" resultType="java.lang.String">
        select distinct tb_lib_manager.user_id
        from (select tb_class_teacher.teacher_id
              from (select class_id
                    from tb_class_student
                    where vip_id = #{vipId} and status = 1) classStudent
                  join tb_class_teacher
                      on classStudent.class_id = tb_class_teacher.class_id and tb_class_teacher.status = 1 and tb_class_teacher.lib_id=#{libId}) classTeacher
            join tb_lib_manager
                on classTeacher.teacher_id = tb_lib_manager.user_id and tb_lib_manager.type = 10 and tb_lib_manager.state = 1 and
                   tb_lib_manager.course_name regexp #{subject} and tb_lib_manager.lib_id regexp #{libId}
    </select>
</mapper>