package com.srs.comprehensive.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.srs.comprehensive.domain.TeacherEvaluationStatus;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 辅导员综合评价状态Mapper接口
 *
 * @author srs
 * @date 2024-01-20
 */
@Mapper
public interface TeacherEvaluationStatusMapper extends BaseMapper<TeacherEvaluationStatus> {

    /**
     * 查询辅导员综合评价状态列表
     *
     * @param teacherEvaluationStatus 辅导员综合评价状态
     * @return 辅导员综合评价状态集合
     */
    List<TeacherEvaluationStatus> selectTeacherEvaluationStatusList(TeacherEvaluationStatus teacherEvaluationStatus);

    /**
     * 查询辅导员待办事项数量
     *
     * @param teacherId 辅导员ID
     * @param stuYearId 学年ID
     * @return 待办事项数量
     */
    @Select("SELECT COUNT(*) FROM cph_audit_details cad " +
            "LEFT JOIN cph_teacher ct ON cad.reviewed_by_id = ct.teacher_id " +
            "LEFT JOIN srs_stu_year ssy ON ssy.id = #{stuYearId} " +
            "WHERE ct.teacher_id = #{teacherId} " +
            "AND cad.status_code IN (1, 2) " +
            "AND cad.create_time >= ssy.start_time " +
            "AND cad.create_time <= ssy.end_time")
    Integer selectTodoCountByTeacherAndYear(@Param("teacherId") Long teacherId, @Param("stuYearId") Long stuYearId);

    /**
     * 查询综合评价成绩导入状态
     *
     * @param teacherId 辅导员ID
     * @param stuYearId 学年ID
     * @return 是否已导入成绩
     */
    @Select("SELECT COUNT(*) > 0 FROM srs_ce_score scs " +
            "LEFT JOIN srs_student ss ON scs.stu_id = ss.stu_id " +
            "LEFT JOIN srs_class sc ON ss.class_id = sc.class_id " +
            "LEFT JOIN cph_teacher ct ON sc.teacher_id = ct.teacher_id " +
            "WHERE ct.teacher_id = #{teacherId} " +
            "AND scs.stu_year_id = #{stuYearId}")
    Boolean selectScoreImportStatusByTeacherAndYear(@Param("teacherId") Long teacherId, @Param("stuYearId") Long stuYearId);

    /**
     * 获取所有辅导员基本信息
     *
     * @return 辅导员列表
     */
    @Select("SELECT ct.teacher_id, ct.name as teacher_name, ct.employee_id, " +
            "ct.dept_id, sd.dept_name " +
            "FROM cph_teacher ct " +
            "LEFT JOIN sys_dept sd ON ct.dept_id = sd.dept_id ")
    List<TeacherEvaluationStatus> selectAllTeachers();

    /**
     * 根据条件查询辅导员综合评价状态
     *
     * @param deptId 学院ID
     * @param teacherName 辅导员姓名
     * @param employeeId 工号
     * @param stuYearId 学年ID
     * @return 辅导员综合评价状态列表
     */
    List<TeacherEvaluationStatus> selectTeacherEvaluationStatusByCondition(
            @Param("deptId") Long deptId,
            @Param("teacherName") String teacherName,
            @Param("employeeId") String employeeId,
            @Param("stuYearId") Long stuYearId
    );

    /**
     * 查询学院名称列表
     *
     * @return 学院列表
     */
    List<java.util.Map<String, Object>> selectDeptNameList();
}
