<?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.sstudy.mapper.resource.GuideGroupStudentMapper">
    <!--已存在的学生预习学生集合-->
    <select id="listStudentByResourceId" resultType="com.xhkjedu.sstudy.model.resource.TGuideGroupStudent">
        SELECT * FROM t_guide_group_student WHERE resourceid=#{resourceid}
    </select>

    <select id="listStudentByGuideid" resultType="com.xhkjedu.sstudy.model.resource.TGuideGroupStudent">
        SELECT * FROM t_guide_group_student WHERE guideid=#{guideid}
    </select>
    <!--更新学生预习学生集合-->
    <update id="batchUpdate">
        UPDATE t_guide_group_student
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="createtime = CASE " suffix="END,">
                <foreach collection="list" index="index" item="item">
                    when rgsid=#{item.rgsid} then #{item.createtime}
                </foreach>
            </trim>
        </trim>
        where
        <foreach collection="list" item="item" index="index" separator="or">
            rgsid=#{item.rgsid}
        </foreach>
    </update>
    <!--更新查看记录-->
    <update id="updateRead">
        update t_guide_group_student set costtime=costtime+#{student.costtime},readtime=#{student.readtime}
        where guideid=#{student.guideid} and studentid=#{student.studentid}
    </update>
    <!--复制学生预习导学信息-->
  <!--  <insert id="copyGuideResource">
        insert into t_guide_group_student(guideid,classid,studentid,createtime)
        select gg.guideid,gg.classid,#{studentid},UNIX_TIMESTAMP(now())
        from t_guide_group gg left join t_guide_group_student ggs on gg.guideid=ggs.guideid
        and gg.classid=ggs.classid and ggs.studentid=#{studentid}
        where gg.classid=#{classid} and ggs.rgsid is null
    </insert>-->

    <!--获取学生预习记录-->
    <select id="listGuideGroupStudent" resultType="com.xhkjedu.sstudy.model.resource.TGuideGroupStudent">
        select * from t_guide_group_student where resourceid=#{resourceid} and studentid=${studentid}
    </select>
</mapper>
