<?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.yonge.cooleshow.biz.dal.dao.StudentStarDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.StudentStar">
            <result column="teacher_id_" property="teacherId" />
	        <result column="student_id_" property="studentId" />
	        <result column="create_time_" property="createTime" />
		</resultMap>  
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.teacher_id_ as "teacherId"
        , t.student_id_ as "studentId"
        , t.create_time_ as "createTime"
        </sql>

	<select id="queryTeacherTotal" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherTotalVo">
		select
			t.teacher_id_ as userId,
			count(1) as fansNum
		from student_star t
<!--		left join sys_user us on t.teacher_id_ = us.id_-->
<!--		left join sys_user ut on t.student_id_ = ut.id_-->
<!--		where us.del_flag_ = 0 and ut.del_flag_ = 0-->
		group by t.teacher_id_
	</select>

    <select id="queryStudentTotal" resultType="com.yonge.cooleshow.biz.dal.vo.StudentTotalVo">
		select
			t.student_id_ as userId,
			count(1) as starTeacherNum
		from student_star t
<!--		left join sys_user us on t.teacher_id_ = us.id_-->
<!--		left join sys_user ut on t.student_id_ = ut.id_-->
<!--		where us.del_flag_ = 0 and ut.del_flag_ = 0-->
		group by t.student_id_
	</select>

    <select id="getByStudentIdAndTeacherId" resultType="com.yonge.cooleshow.biz.dal.entity.StudentStar">
		select
			<include refid="baseColumns"/>
		from student_star t
<!--		left join sys_user us on t.teacher_id_ = us.id_-->
<!--		left join sys_user ut on t.student_id_ = ut.id_-->
<!--		where us.del_flag_ = 0 and ut.del_flag_ = 0-->
        where t.student_id_ = #{studentId} and t.teacher_id_ = #{teacherId}
	</select>
	
	<select id="queryByStudentId" resultMap="BaseResultMap">
		select * from student_star ss where ss.student_id_ = #{studentId}
	</select>

	<delete id="delFans">
        delete from student_star where student_id_ = #{studentId} and teacher_id_ = #{teacherId}
    </delete>
</mapper>