package com.ssj.service.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssj.bean.weixin.libmy.domain.TbLibManager;
import com.ssj.service.conch.curator.dto.SchoolmasterInfoDTO;
import com.ssj.service.kmt.exercisesys.dto.*;
import com.ssj.service.kmt.exercisesys.request.ExerciseTeacherDetailReq;
import com.ssj.service.kmt.exercisesys.request.ExerciseTeacherListReq;
import com.ssj.service.weixin.library.dto.SelfCorrectTeacherInfoDTO;
import com.ssj.service.weixin.library.dto.SubjectMyInfoDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

/**
 * @author yrf
 * @time 2019/12/11 17:36
 */
@Mapper
public interface LibManagerMapper {

    /**
     * 查询机构自批改老师的资料
     * @param teacherId 老师id
     * @param type 类型
     * @return 老师资料
     */
    SelfCorrectTeacherInfoDTO findOrgMyInfo(@Param("teacherId") String teacherId, @Param("type") int type);

    /**
     * 查询机构自批改老师的资料多校区
     * @param teacherId 老师id
     * @param type 类型
     * @return 老师资料
     */
    List<SelfCorrectTeacherInfoDTO> findOrgMyInfoV1(@Param("teacherId") String teacherId, @Param("type") int type);

    /**
     * 查询校长个人资料
     * @param schoolmasterUserId 校长用户id
     * @return 校长个人资料
     */
    SchoolmasterInfoDTO findSchoolmasterInfo(@Param("schoolmasterUserId") String schoolmasterUserId);


    /**
     * 查询学科老师我的信息
     * @param teacherId
     * @param type
     * @return
     */
    List<SubjectMyInfoDto> findSubjectMyInfo(@Param("teacherId") String teacherId, @Param("type") int type);

    /**
     * 查询学科老师
     * @param teacherId 老师id
     * @param classId 班级id
     * @return 老师
     */
    @Select("select tlm.*\n" +
            "from (select lib_id from tb_class_teacher where class_id = #{classId} and status = 1 and teacher_id = #{teacherId}) tct\n" +
            "         join tb_lib_manager tlm on tlm.user_id = #{teacherId} and tlm.type = 10 and tlm.state = 1 and tct.lib_id = tlm.lib_id")
    TbLibManager findOrgTeacher(@Param("teacherId") String teacherId, @Param("classId") String classId);

    /**
     * 分页查询练习册老师
     * @param page 分页
     * @param req 入参
     * @return 查询练习册老师
     */
    List<ExerciseTeacherDTO> findExerciseTeacherList(@Param("page") Page page,
                                                      @Param("req") ExerciseTeacherListReq req);

    /**
     * 分页查询kmt老师列表, tb_lib_manager,
     * @param subject 科目
     * @param authority 老师类型
     * @param type 数据类型:1练习册老师汇总数据，2kmt老师汇总数据，3练习册老师下练习册汇总数据，4KMT老师下知识点汇总数据，5题库录入老师汇总数据，6题库录入老师下知识点汇总数据
     * @param teacherName 老师名称
     * @param page 分页
     * @return
     */
    List<ExerciseTeacherDTO> findKmtTeacherList(@Param("subject") String subject,
                                                @Param("authority") String authority,
                                                @Param("type") int type,
                                                @Param("teacherName") String teacherName,
                                                Page page);

    /**
     * 分页查询练习册老师详情
     * @param page 分页
     * @param req 入参
     * @return 练习册老师详情
     */
    IPage<ExerciseTeacherDetailDTO> findExerciseTeacherDetails(IPage<ExerciseTeacherDetailDTO> page,
                                                               @Param("req") ExerciseTeacherDetailReq req);

    /**
     * 查询老师信息状态详情
     * @param teacherId 老师id
     * @return 老师信息状态详情
     */
    TeacherInfoStatusDetailDTO findTeacherStatusDetail(@Param("teacherId") String teacherId);

    /**
     * 查询用户信息 tb_lib_manager
     * @param userIds
     * @param types
     * @return
     */
    List<TbLibManager> findTbLibManagerByUserIdsAndType(@Param("userIds") List<String> userIds,
                                                        @Param("types") List<Integer> types);

    /**
     * 查找相同名字的老师
     * @param name
     * @return
     */
    String findExerciseTeacherByName(@Param("name") String name);

    /**
     * 模糊查询用户角色记录
     * @param name
     * @param type
     * @return
     */
    List<TbLibManager> findManagerByNameAndType(@Param("name") String name,
                                                @Param("type") int type);

    /**
     * 查询老师的馆id
     * @param teacherId 老师id
     * @param type 老师类型
     * @return 馆id
     */
    @Select("select lib_id from tb_lib_manager where user_id = #{teacherId} and type = #{type} and state = 1")
    List<String> findLibIdByUserIdType(@Param("teacherId") String teacherId, @Param("type") int type);

    /**
     * 随机获取以为题目审核老师
     * @param subject
     * @return
     */
    TbLibManager findRandManagerByTypeAndSubject(@Param("subject") String subject);

    List<FindCheckTeacherListDto>  findCheckTeacherList(@Param("teacherName") String teacherName, Page page);

    List<Map<String,Object>> findCheckTeacherDetailsList(@Param("teacherId") String teacherId,@Param("maxCreateTime") String maxCreateTime, Page page);

    /**
     * 查询已校对和未校对总本数
     */
    Map<String,Object> findCheckTeacherDetails(@Param("teacherId")String teacherId,@Param("maxCreateTime")String maxCreateTime);
    List<FindCheckTeacherListDto>  findCheckTeacherList(@Param("teacherName") String teacherName,
                                                        @Param("authorityType") int authorityType,
                                                        @Param("subjects") List<String> subjects,
                                                        Page page);

    /**
     * 查询符合条件的老师
     */
    List<TbLibManager> findTbLibManagersByCreateTime(@Param("page") Page page,@Param("req") ExerciseTeacherListReq req);

    Map<String,Object> findKmtTeacherLists(@Param("userId") String userId);
}
