<?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.srs.system.mapper.StudentMentalRatingMapper">
<!--  添加  知无涯-->
    <select id="selectByStudentId" resultType="com.srs.system.domain.StudentMentalRating">
        SELECT id, student_id, rating, created_time, updated_time
        FROM student_mental_rating
        WHERE student_id = #{studentId}
    </select>

    <insert id="insert" parameterType="com.srs.system.domain.StudentMentalRating"
            useGeneratedKeys="true" keyProperty="id">
        INSERT INTO student_mental_rating(student_id, rating)
        VALUES (#{studentId}, #{rating})
    </insert>

    <update id="updateRatingByStudentId" parameterType="com.srs.system.domain.StudentMentalRating">
        UPDATE student_mental_rating
        SET rating = #{rating}
        WHERE student_id = #{studentId}
    </update>

    <!-- 心理查询全部：知无涯 -->
    <select id="selectAll" resultType="com.srs.system.domain.StudentMentalRating">
        SELECT id,
               student_id AS studentId,
               rating,
               created_time AS createdTime,
               updated_time AS updatedTime
        FROM student_mental_rating
        ORDER BY created_time DESC
    </select>

    <!-- 根据学号查询心理：知无涯 -->
    <select id="selectByStuNo" resultType="com.srs.system.domain.StudentMentalRating">
        SELECT id,
               student_id AS studentId,
               rating,
               created_time AS createdTime,
               updated_time AS updatedTime
        FROM student_mental_rating
        WHERE student_id = #{stuNo}
        ORDER BY created_time DESC
    </select>

    <!-- 查询今天该学生是否已经填写过心理评测 陈冠元 -->
    <select id="countTodayByStudentId" resultType="int">
        SELECT COUNT(*)
        FROM student_mental_rating
        WHERE student_id = #{studentId}
          AND DATE(created_time) = #{today}
    </select>
</mapper>