<?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.sclass.mapper.classroom.ClassroomVoteMapper">

  <!--获取课堂投票-->
  <select id="listVoteByRoomid" resultType="java.util.Map">
    select voteid,votetitle,duration,votetype from t_classroom_vote where roomid=#{roomid} order by createtime desc
  </select>

  <!--投票参与学生-->
  <select id="listVoteStus" resultType="com.xhkjedu.sclass.model.classroom.TClassroomVoteStudent">
    select s.stuvote,s.createtime,s.studentid,u.username from t_classroom_vote_student s
    left join t_user u on s.studentid=u.userid
    where s.voteid=#{voteid} order by s.createtime
  </select>

  <!--课堂信息投票-->
  <select id="listVoteStuByRoomAndStuid" resultType="java.util.Map">
    select v.voteid,v.votetitle,v.duration,v.options,
    v.selectnum,v.votetype,vs.stuvote,vs.createtime from t_classroom_vote v
    left join t_classroom_vote_student vs on vs.voteid=v.voteid and vs.studentid=#{studentid}
    where v.roomid=#{roomid} group by v.voteid order by v.voteid
  </select>


  <!--批量保存-->
  <insert id="insertBatch">
    insert into t_classroom_vote
    (voteid,roomid,votetitle,duration,options,selectnum,votetype,createid,createtime,schoolid)
    values
    <foreach collection="votes" item="v" separator=",">
      (#{v.voteid},#{v.roomid},#{v.votetitle},#{v.duration},#{v.options},#{v.selectnum},#{v.votetype},#{v.createid},#{v.createtime},#{v.schoolid})
    </foreach>
  </insert>
</mapper>