package com.ym.mec.biz.dal.dao;

import com.ym.mec.biz.dal.dto.CourseHomeworkStudentDetailDto;
import com.ym.mec.biz.dal.dto.StudentCourseHomeworkDto;
import com.ym.mec.biz.dal.dto.StudentHomeworkRecordDto;
import com.ym.mec.biz.dal.dto.StudentServeCourseHomeworkDto;
import com.ym.mec.biz.dal.entity.CourseHomework;
import com.ym.mec.biz.dal.entity.StudentCourseHomework;
import com.ym.mec.common.dal.BaseDAO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface StudentCourseHomeworkDao extends BaseDAO<Long, StudentCourseHomework> {

    /**
     * @Author: Joburgess
     * @Date: 2019/9/18
     * 统计已提交作业的人数
     */
    @Select("SELECT COUNT(*) FROM student_course_homework WHERE course_homework_id_=#{courseHomeworkID} AND attachments_ IS NOT NULL")
    int countCompletedStudentNum(Long courseHomeworkID);

    /**
     * @Author: Joburgess
     * @Date: 2019/9/18
     * 获取学生作业界面详细信息
     */
    CourseHomeworkStudentDetailDto findCourseHomeworkStudentDetail(@Param("courseScheduleID") Long courseScheduleID,
                                                                   @Param("userID") Long userID);

    /**
     * @Author: Joburgess
     * @Date: 2019/9/18
     * 批量插入学生作业提交记录
     */
    int batchInsertStudentCourseHomeworkRecord(List<StudentCourseHomework> studentCourseHomeworks);

    /**
     * @Author: Joburgess
     * @Date: 2019/9/18
     * 构建初始学生作业提交记录
     */
    List<StudentCourseHomework> constructInitialStudentHomeworkRecords(@Param("courseScheduleID") Long courseScheduleID,
                                                                       @Param("courseHomeworkID") Long courseHomeworkID);

    /**
     * @Author: Joburgess
     * @Date: 2019/9/18
     * 构建初始学生作业提交记录
     */
    List<StudentCourseHomework> constructInitialStudentHomeworkRecordsWithPayment(@Param("courseScheduleID") Long courseScheduleID,
                                                                       @Param("courseHomeworkID") Long courseHomeworkID);

    /**
     * @describe 根据作业编号获取需要提交作业的学生
     * @author Joburgess
     * @date 2019/10/20
     * @param courseScheduleId: 作业编号
     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentCourseHomework>
     */
    List<StudentCourseHomework> findByCourseSchedule(@Param("courseScheduleId") Long courseScheduleId,
                                                     @Param("userName") String userName);

    /**
     * @describe 根据作业编号和学生编号查询对应学生作业记录
     * @author Joburgess
     * @date 2019/10/20
     * @param courseHomeworkId: 作业编号
     * @param userId: 用户编号
     * @return com.ym.mec.biz.dal.entity.StudentCourseHomework
     */
    StudentCourseHomework findByStudentAndCourseHomewok(@Param("courseHomeworkId") Long courseHomeworkId,
                                                        @Param("userId") Integer userId);
	
    /**
     * 查询未完成的课程作业
     * @return
     */
    List<StudentCourseHomework> queryNotDoneHomeworkList();

    /**
     * @describe 根据课程查询学生作业记录
     * @author Joburgess
     * @date 2020/3/20
     * @param courseIds:
     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentCourseHomework>
     */
    List<StudentCourseHomework> findByCourses(@Param("courseIds") List<Long> courseIds);

    /**
     * count课程学员作业列表
     * @param params
     * @return
     */
    int countStudentCourseHomeworks(Map<String, Object> params);

    /**
     * 获取课程学员作业列表
     * @param params
     * @return
     */
    List<StudentCourseHomeworkDto> findStudentCourseHomeworks(Map<String, Object> params);

    int delByCourseScheduleId(Long courseScheduleId);
    
    int batchDelByCourseScheduleId(@Param("courseScheduleIdList") List<Long> courseScheduleIdList);

    int countStudentHomeworkRecord(Map<String, Object> params);
    List<StudentHomeworkRecordDto> findStudentHomeworkRecord(Map<String, Object> params);

    /**
     * @describe 根据上课时间区间获取学员课堂作业
     * @author Joburgess
     * @date 2020.05.27
     * @param startDate:
     * @param endDate:
     * @return java.util.List<com.ym.mec.biz.dal.dto.StudentServeCourseHomeworkDto>
     */
    List<StudentServeCourseHomeworkDto> findStudentHomeworkWithCourseDateRange(@Param("startDate") String startDate,
                                                                               @Param("endDate") String endDate,
                                                                               @Param("studentIds") List<Integer> studentIds);

    /**
     * @describe
     * @date 2020.06.15
     * @param startDate:
     * @param endDate:
     * @param studentIds:
     * @return java.util.Set<java.lang.Integer>
     */
    Set<Integer> checkStudentHaveHomeworkInDateRange(@Param("startDate") String startDate,
                                                     @Param("endDate") String endDate,
                                                     @Param("studentIds") List<Integer> studentIds);

    List<StudentCourseHomework> queryAll(Map<String, Object> params);

    int countAll(Map<String, Object> params);

    /**
     * 获取作业的已回复数
     * @param homeWorkIds
     * @return
     */
    List<Map<Long, Long>> queryReplied(@Param("homeWorkIds") List<Long> homeWorkIds);
}
