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

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

import com.ym.mec.biz.dal.dto.*;
import org.apache.ibatis.annotations.Param;

import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.IndexBaseMonthData;
import com.ym.mec.biz.dal.entity.Student;
import com.ym.mec.biz.dal.entity.Subject;
import com.ym.mec.biz.dal.enums.GroupType;

public interface StudentDao extends com.ym.mec.common.dal.BaseDAO<Integer, Student> {

    Student getLocked(Integer userId);
	
    int lockUser(@Param("userId") Integer userId);

    List<Student> findByStudentIds(@Param("studentIds") List<Integer> studentIds);

    List<Student> lockStudents(@Param("studentIds") List<Integer> studentIds);

    SysUser lockUserReturnInfo(@Param("userId") Integer userId);

    SysUser getUser(@Param("userId") Integer userId);

    List<SysUser> findStudents(Map<String, Object> params);

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

    List<Student> queryByOperatingTempTag(Integer operatingTag);

    int batchUpdate(@Param("studentList") List<Student> studentList);

    /**
     * 查询运营学生列表
     *
     * @param params
     * @return
     */
    List<Student4operating> getOperatingStudents(Map<String, Object> params);

    /**
     * 查询运营学生总数
     *
     * @param params
     * @return
     */
    Integer countOperatingStudents(Map<String, Object> params);

    /**
     * 批量获取老师体验学生数
     *
     * @param teacherIds
     * @return
     */
    List<Map<Integer, Integer>> getTeacherOperatingStudentsNum(@Param("teacherIds") String teacherIds);

    List<String> getStudentNames(@Param("studentIds") List<Integer> studentIds);

    List<SimpleUserDto> getStudentsWithOrgan(Map<String, Object> params);

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

    /**
     * 根据类型批量获取老师转化
     *
     * @param teacherIds
     * @param groupType
     * @return
     */
    List<Map<Integer, Integer>> getBuyNums(@Param("teacherId") String teacherId, @Param("groupType") GroupType groupType);

    /**
     * 根据同事存在vip和网管的转化
     *
     * @param teacherIds
     * @return
     */
    List<Map<Integer, Integer>> getPracticeAndVipNums(@Param("teacherIds") String teacherIds);

    /**
     * @return java.util.List<com.ym.mec.biz.dal.entity.Student>
     * @describe 获取服务学员列表
     * @author Joburgess
     * @date 2020.04.29
     */

    List<Student> getServiceStudents(Integer tenantId);

    /**
     * @return java.util.List<java.lang.Integer>
     * @describe 获取被服务学员id列表
     * @author Joburgess
     * @date 2020.06.04
     */
    List<Integer> getServeStudentIds(Integer tenantId);

    List<StudentServeCourseDto> getServeStudentCourseStartTimes(@Param("monday") String monday, @Param("tenantId") Integer tenantId);

    List<StudentServeCourseDto> getStudentFutureCourseInfo(@Param("monday") String monday,
                                                           @Param("sunday") String sunday,
                                                           @Param("studentIds") List<Integer> studentIds, @Param("tenantId") Integer tenantId);

    List<StudentServeCourseDto> getNoCourseBeServeStudentInfo(@Param("studentIds") List<Integer> noCourseStudentIds, @Param("tenantId") Integer tenantId);


    List<StudentServeDto> getBeServiceStudentsInfoWithStudents(@Param("monday") String monday,
                                                               @Param("courseExpireDate") Date courseExpireDate,
                                                               @Param("studentIds") List<Integer> studentIds);

    List<StudentServeDto> getBeServiceStudentsInfoWithStudentsForHistory(@Param("monday") String monday,
                                                                         @Param("courseExpireDate") Date courseExpireDate,
                                                                         @Param("studentIds") List<Integer> studentIds);

    /**
     * @param studentId:    学生编号
     * @param serviceTag:   服务指标
     * @param operatingTag: 运营指标
     * @return int
     * @describe 更新指定学员的服务指标或运营指标
     * @author Joburgess
     * @date 2020.05.28
     */
    int updateStudentServiceOrOperatingTag(@Param("studentId") Integer studentId,
                                           @Param("studentIds") List<Integer> studentIds,
                                           @Param("serviceTag") Integer serviceTag,
                                           @Param("operatingTag") Integer operatingTag);

    /**
     * @param studentId:  学生编号
     * @param serviceTag: 服务指标
     * @return int
     * @describe 更新指定学员的服务指标
     * @author Joburgess
     * @date 2020.05.28
     */
    int updateStudentServiceTag(@Param("studentId") Integer studentId,
                                @Param("studentIds") List<Integer> studentIds,
                                @Param("serviceTag") Integer serviceTag);

    /**
     * 修改学员的指导老师
     *
     * @param teacherId
     */
    void batchUpdateAdviser(@Param("teacherId") Integer teacherId, @Param("studentIds") String studentIds);

    /**
     * 获取学生的老师
     * @param studentIds
     * @return
     */
    List<Student> getStudentTeacher(@Param("studentIds") List<Integer> studentIds);

    /**
     * 当前服务指标已开启，但在系统中没有剩余课时，且在乐团中不是在读状态，这种用户需要关闭服务指标
     * @return
     */
    List<Integer> queryCloseServiceTagIds();

    /**
     * 更新用户服务指标
     * @param studentIds
     * @param serviceTag
     */
    void updateServiceTag(@Param("studentIds") List<Integer> studentIds, @Param("serviceTag") Integer serviceTag);

    /**
     * @describe 获取学员声部列表
     * @author Joburgess
     * @date 2021/2/5 0005
     * @param studentIds:
     * @return java.util.List<com.ym.mec.biz.dal.entity.Subject>
     */
    List<Subject> getStudentSubjects(@Param("studentIds") Set<Integer> studentIds);

    List<Student> queryByIds(Map<String, Object> params);
    int countByIds(Map<String, Object> params);

    /**
     * 更新学生班级
     * @return
     */
    int updateGrade();

    /**
     * @describe
     * @author Joburgess
     * @date 2021/3/29 0029
     * @return java.util.List<com.ym.mec.biz.dal.entity.Student>
     */
    List<Student> getNoTeacherOrNoSubjectStudent();

    /**
     * @describe 从新学员中找出有VIP课的学员编号
     * @author Joburgess
     * @date 2021/6/3 0003
     * @return java.util.List<java.lang.Integer>
     */
    List<Integer> getHasVipCourseStudentIdsFromNewStudents();

    /**
     * @describe 将指定学员更新为老学员
     * @author Joburgess
     * @date 2021/6/3 0003
     * @param userIds:
     * @return int
     */
    int updateNewStudentsToOld(@Param("userIds") List<Integer> userIds);

    /**
     * 获取有会员的学员列表
     * @param studentIdsStr
     * @return
     */
    int getMemberNum(@Param("studentIdsStr") String studentIdsStr);

    /**
     * 会员结束前15天提醒学员续费
     * @param pushMemberRenew
     * @return
     */
    List<Integer> queryPushMemberRenew(@Param("pushMemberRenew") String pushMemberRenew,@Param("tenantId") Integer tenantId);

    /**
     * 清空学员会员
     */
    void cleanStudentMember();
    /**
     * 清空学员会员
     */
    void cleanExperienceStudentMember();

    void cleanMember(Integer userId);

    /**
     * 修改学员会员试用
     * @param studentIds
     * @param rankId
     * @param endTime
     */
    int updateMemberExperience(@Param("studentIds") String studentIds,
                                @Param("rankId") Integer rankId,
                                @Param("endTime") Date endTime);

    /**
     * @describe 统计分部会员学员数据
     * @author Joburgess
     * @date 2021/8/16 0016
     * @param organId:
     * @return com.ym.mec.biz.dal.dto.EduOrganStudentDataDto
     */
    int getOrganStudentNum(@Param("organId") Integer organId);
    
    IndexCloudStudyListDto getOrgansCloudTeacherStudent(@Param("organIds") List<Integer> organIds);
    
    List<Map<Integer, Integer>> getOrgansStudentNum(@Param("organIds") List<Integer> organIds);

    List<Map<Integer, Integer>> getOrganTeacherStudentNum(@Param("teacherIds") List<Integer> teacherIds,
                                                          @Param("organId") Integer organId);

    int getOrganNoTeacherStudentNum(@Param("organId") Integer organId);

    /**
     * @describe 统计云教练试用人数
     * @author Joburgess
     * @date 2021/8/17 0017
     * @param organId:
     * @return int
     */
    int getCloudStudyStudentNum(@Param("organId") Integer organId);
    int getOrgansTotalCloudStudyStudentNum(@Param("organIds") List<Integer> organIds);
    List<Map<Integer, Integer>> getOrganCloudStudyStudentNum(@Param("organIds") List<Integer> organIds);

    List<Map<Integer, Integer>> getOrganTeacherCloudStudyStudentNum(@Param("teacherIds") List<Integer> teacherIds,
                                                                    @Param("organId") Integer organId);

    /**
     * @describe 统计云教练今日使用人数
     * @author Joburgess
     * @date 2021/8/18 0018
     * @param organIds:
     * @return int
     */
    int getOrgansTodayTotalCloudStudyStudentNum(@Param("organIds") List<Integer> organIds);


    int getCloudStudyLivelyStudentNum(@Param("organId") Integer organId);
    int getOrganTotalCloudStudyLivelyStudentNum(@Param("organIds") List<Integer> organIds, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
    List<Map<Integer, Integer>> getOrganCloudStudyLivelyStudentNum(@Param("organIds") List<Integer> organIds);
    
    List<IndexCloudStudyListDto> getCloudStudyStudentOverViewList(@Param("organIds") List<Integer> organIds);
    
    List<Mapper> getOrganActiveCloudStudyStudentNum(@Param("organIds") List<Integer> organIds, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
    
    List<Mapper> getOrganCloudTeacherStudentNum(@Param("organIds") List<Integer> organIds);

    /**
     * @describe 查询云教练学员列表数据
     * @author Joburgess
     * @date 2021/8/17 0017
     * @param params:
     * @return java.util.List<com.ym.mec.biz.dal.dto.EduOrganStudentListDto>
     */
    List<EduOrganStudentListDto> queryCloudStudyStudentData(Map<String, Object> params);
    int countCloudStudyStudentData(Map<String, Object> params);

    List<Map<Integer, String>> getStudentCooperationNameMap(@Param("studentIds") List<Integer> studentIds);

    /**
     * @describe 更新学员云教练连续使用天数
     * @author Joburgess
     * @date 2021/8/17 0017
     * @param userId:
     * @return int
     */
    int addStudentCloudStudySequenceDays(@Param("userId") Integer userId);

    /**
     * @describe 更新学员云教练连续使用天数
     * @author Joburgess
     * @date 2021/8/17 0017
     * @param userId:
     * @param days:
     * @return int
     */
    int updateStudentsCloudStudySequenceDays(@Param("userIds") List<Integer> userId,
                                             @Param("days") Integer days);

    /**
     * @describe 清理学员云教练连续使用天数
     * @author Joburgess
     * @date 2021/8/17 0017
     * @return int
     */
    int cleanStudentCloudStudySequenceDays();

    /**
     * @describe 获取分部下试用会员数
     * @author Joburgess
     * @date 2021/8/17 0017
     * @param organId:
     * @return int
     */
    int getOrganEVipStudentNum(@Param("organId") Integer organId);
    int getOrgansTotalEVipStudentNum(@Param("organIds") List<Integer> organIds);

    List<Map<Integer, Integer>> getTeacherExperienceMemberStudentNum(@Param("teacherIds") List<Integer> teacherIds,
                                                                     @Param("organId") Integer organId);

    List<Map<Integer, String>> getStudentSubjectMapList(@Param("studentIds") List<Integer> studentIds);

    List<IndexBaseMonthData> groupOrganId(@Param("organIds") List<Integer> organIds, @Param("userIds") List<Integer> userIds);

    /**
     * 获取学员分部
     * @param userIdList
     * @return
     */
    List<Map<Integer, String>> queryStudentOrganNameMap(@Param("userIdList") List<Integer> userIdList);

    /**
     * @describe 获取生效中的学员编号
     * @author Joburgess
     * @date 2021/8/27 0027
     * @param :
     * @return java.util.Set<java.lang.Integer>
     */
    Set<Integer> getValidVipStudentIds();

    /**
     * 获取课程中学员会员数量
     * @param courseIds
     * @return
     */
    List<Map<Long, Long>> countCourseStudentMemberNum(@Param("courseIds") List<Long> courseIds);

    /**
     * 获取课程生学员声部名称
     * @param courseIds
     * @return
     */
    List<Map<Long, String>> countCourseStudentSubjectName(@Param("courseIds") List<Long> courseIds);

    /**
     * 获取老师关联的有课的学员列表
     * @param teacherId
     * @return
     */
    List<Integer> getStudentByHasCourse(Integer teacherId);

    /**
     * 清空学员统计标记
     */
    void cleanCountFlag();

    /**
     * 标记进行中乐团在读学员+VIP、网管有课的学员
     */
    void remarkCountFlag();

    /**
    * @description: 更新会员信息
     * @param student
    * @return void
    * @author zx
    * @date 2021/10/13 13:34
    */
    void updateStudentMember(@Param("student") Student student);

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

    List<Student> queryStudent(Map<String, Object> params);

    SysUser getUserByPhone(String phone);

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

    List<SysUserDto> queryStudentBasicInfo(Map<String, Object> params);

    List<BaseMapDto> queryStuSubjectId(@Param("organIds") String organIds);

    List<BaseMapDto> queryStuSubjectIdByTeacherId(@Param("userId") Integer userId);
}
