package com.yida.data.user.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.constant.FebsConstant;
import com.yida.data.common.core.entity.system.SystemUser;
import com.yida.data.common.core.entity.user.EduStaff;
import com.yida.data.common.core.entity.user.EduStaffDept;
import com.yida.data.common.core.entity.user.EduTeacherDept;
import com.yida.data.common.core.entity.user.EduUserDept;
import com.yida.data.user.dto.ListStaffDTO;
import com.yida.data.user.dto.PageTeacherDTO;
import com.yida.data.user.dto.StaffImportDTO;
import com.yida.data.user.vo.*;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

public interface EduStaffService extends IService<EduStaff> {

    /**
     * 查询教师列表数据
     */
    IPage<TeacherListVO> listTeacherPage(PageTeacherDTO dto);

    /**
     * 判断该教师手机号是否已经存在
     */
    int checkTeacherTelephone(EduStaff eduStaff);

    /**
     * 保存教师信息
     */
    void saveTeacher(Integer operation, EduStaff eduStaff);

    /**
     * 根据教师id查询教师详细信息
     */
    TeacherDetailVO findTeacher(Long teacherId);

    List<TeacherClassVO> listClassByTeacher(Long teacherId);

    List<TeacherClassVO> listDeptByTeacher(Long teacherId, Integer type);

    List<Long> listClassIdByStaffId();

    List<Integer> listStaffRolesByStaffId(Long staffId);

    List<TeacherDeptVO> listDeptByStaffId(Long staffId);

    /**
     * 批量删除教师信息
     */
    void delStaffBatch(List<Long> staffIds);

    /**
     * 批量删除教师信息
     */
    void delTeacherBatch(List<Long> teacherIds);

    void dealWxTeacherChange(Long schoolId, Long campusId, Long sectionId, Long gradeId,
        Long classId, List<Map> teacherList, Long deptWxId);

    void initStaff(List<EduStaff> teacherList);

    ResultBean<ConcurrentHashMap<Integer, Object>> importStaff(MultipartFile file, Long schoolId, long timestamp);

    //@Async(FebsConstant.ASYNC_POOL)
    //void importTeacher(String path, Long schoolId, CurrentUser currentUser, Long key, String fileName);

    @Async(FebsConstant.ASYNC_POOL)
//    void importStaff(String path, Long schoolId, CurrentUser currentUser, Long key, String fileName);

    Integer importTeacherHeartbeat(String username, Long key);

    Integer importStaffHeartbeat(String username, Long key);

    List<Map<String, String>> listImportKey(String username, Integer type);

    void saveStaffBySchoolAndWx(EduStaff teacher);

    void dealWxUserDelete(String wxId, Long schoolId);

    void downloadTemplate(HttpServletResponse response, Integer type);

    void downloadError(HttpServletResponse response, Integer type, Long noticeId);

    /**
     * 分页查询职工列表数据
     */
    IPage<StaffPageVO> listStaffPage(Page page, CurrentUser currentUser,
        Long areaId, Long schoolId, Long deptId,
        Integer isLeader,
        String position, String name, String mobile, Integer sex,
        Integer collectType);

    /**
     * 添加、修改职工
     */
    void saveStaff(EduStaff staff, CurrentUser currentUser);

    EduStaff getStaffById(Long staffId);


    /**
     * 根据教师id查询教师负责部门
     *
     * @param teacherId
     * @return
     */
    List<TeacherDeptVO> findTeacherRole(Long teacherId);

    /***
     * 根据班级查询关联的老师
     */
    List<EduStaff> listTeacherByClass(List<Long> classIds, String name);

    /**
     * 通过学校查询教师
     */
    List<EduStaff> listTeacherBySchool(Long schoolId, String name);

    List<EduTeacherDept> listTeacherDept(Long teacherId);

    List<EduStaffDept> listStaffDept(Long staffId);

    List<StaffWithDeptVO> listStaffWithDept(Long schoolId);

    List<TeacherCourseInfoVO> listTeacherCourseByGrade(Long gradeId, Long classId);

    List<EduUserDept> listClassByGradeIdAndTeacherId(Long gradeId, Long staffId);

    /**
     * 根据班级和名称查询教师
     *
     * @param classId
     * @param name
     */
    List<EduStaff> listTeacherByClassAndName(Long classId, String name);

    /**
     * 根据部门id或者名字手机号查询员工id
     *
     * @param deptId
     * @param nameOrPhone
     * @return
     */
    List<Long> listStaffByDeptId(Long deptId, String nameOrPhone, Long schoolId);


    /**
     * 根据条件查询教职工列表
     */
    List<EduStaff> listStaff(ListStaffDTO dto);

    /**
     * 同步企业微信职工数据
     */
    @Async(FebsConstant.ASYNC_POOL)
    void syncQywxStaff();


    List<TeacherClassAndGradeVO> listClassAndGradeByTeacher(Long teacherId);

    /**
     * 查询教职工分布情况
     *
     * @return
     */
    StaStaffDistributeVO staStaffDistribute(List<Long> schoolIds);

    StaStaffDistributeVO staStaffNum(List<Long> schoolIds);

    void exportStaff(Long areaId, Long schoolId, Long deptId, Integer isLeader, String position,
        String name, String mobile, Integer sex, Integer collectType,
        HttpServletResponse response);

    SystemUser saveSystemUser(EduStaff eduStaff);

    void getWxIdByStaffId(Long staffId);

    void saveExcelData(ConcurrentHashMap<Integer, StaffImportDTO> concurrentHashMap,
        ConcurrentHashMap<Integer, Object> errorMap,
        Long schoolId,
        long timestamp);

    List<DeptManagetVO> getDeptManager(List<Long> deptIdList, Long ruleId);


    /**
     * 更新学生缓存信息
     */
    @Async
    void updateStaffCache();
}
