package com.yida.data.user.controller;

import cc.mrbird.febs.common.redis.service.RedisService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ModuleName;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.common.ResultMsgType;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.constant.CachePrefixConstant;
import com.yida.data.common.core.entity.system.Dept;
import com.yida.data.common.core.entity.system.enums.OperationLogTypeEnum;
import com.yida.data.common.core.entity.user.*;
import com.yida.data.common.core.exception.FebsException;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.common.core.utils.FileUtil;
import com.yida.data.common.core.utils.RedisUtil;
import com.yida.data.log.annotation.OperationLog;
import com.yida.data.system.feign.RemoteDeptService;
import com.yida.data.user.dto.ListStaffDTO;
import com.yida.data.user.dto.ManagerDTO;
import com.yida.data.user.dto.PageTeacherDTO;
import com.yida.data.user.mapper.EduTeacherDeptMapper;
import com.yida.data.user.service.EduStaffDeptService;
import com.yida.data.user.service.EduStaffService;
import com.yida.data.user.service.EduStudentService;
import com.yida.data.user.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.ehcache.impl.internal.concurrent.ConcurrentHashMap;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

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

@Api(tags = "教师管理 仅学校管理员有权限")
@Slf4j
@Validated
@RestController
@RequestMapping("staff")
@RequiredArgsConstructor
public class EduStaffController {


    private final EduStaffService eduStaffService;
    private final RedisService redisService;
    private final EduStudentService eduStudentService;
    private final EduTeacherDeptMapper eduTeacherDeptMapper;
    private final EduStaffDeptService eduStaffDeptService;

    private final RemoteDeptService remoteDeptService;

    @ApiOperation("查询教师列表数据")
    @GetMapping("/listTeacherPage")
    @PreAuthorize("hasAuthority('teacher:view')")
    public ResultBean<IPage<TeacherListVO>> listTeacherPage(PageTeacherDTO dto) {
        dto.setSchoolId(FebsUtil.getTopDeptId());
        IPage<TeacherListVO> list = eduStaffService.listTeacherPage(dto);
        return ResultBean.buildSuccess(list);
    }

    @ApiOperation("保存教师信息 新增或编辑")
    @PostMapping("/saveTeacher")
    @OperationLog(module = ModuleName.STAFF, methods = "新增、修改教师", type = OperationLogTypeEnum.SAVE)
    @PreAuthorize("hasAuthority('teacher:edit')")
    public ResultBean saveTeacher(@ApiParam("0-添加，1-编辑") @RequestParam("operation") Integer operation,
        @RequestBody EduStaff eduStaff) {
        eduStaffService.saveTeacher(operation, eduStaff);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("根据教师id查询教师详细信息")
    @GetMapping("/getTeacher")
    @PreAuthorize("hasAuthority('teacher:view')")
    public ResultBean<TeacherDetailVO> getTeacher(@ApiParam("教师Id") @RequestParam("teacherId") Long teacherId) {
        return ResultBean.buildSuccess(eduStaffService.findTeacher(teacherId));
    }

    @ApiOperation("查询职工信息")
    @GetMapping("/getStaff")
    public ResultBean<EduStaff> getStaff(@ApiParam("职工id") Long staffId) {
        return ResultBean.buildSuccess(eduStaffService.getStaffById(staffId));
    }

    @ApiOperation("批量删除教师信息")
    @PostMapping("/delTeacherBatch")
    @OperationLog(module = ModuleName.STAFF, methods = "批量删除教师信息", type = OperationLogTypeEnum.DELETE)
    public ResultBean delTeacherBatch(@RequestBody List<Long> teacherIds) {
        eduStaffService.delTeacherBatch(teacherIds);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("批量删除职工信息信息")
    @PostMapping("/delStaff")
    @OperationLog(module = ModuleName.STAFF, methods = "批量删除职工信息信息", type = OperationLogTypeEnum.DELETE)
    @PreAuthorize("hasAuthority('staff:delete')")
    public ResultBean delTeacher(@RequestBody List<Long> staffIds) {
        eduStaffService.delStaffBatch(staffIds);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询教师可见班级")
    @GetMapping("/listClassByTeacher")
    @PreAuthorize("hasAuthority('teacher:view')")
    public ResultBean<List<TeacherClassVO>> listClassByTeacher(@ApiParam("教师id") @RequestParam Long teacherId) {
        return ResultBean.buildSuccess(eduStaffService.listClassByTeacher(teacherId));
    }

    @ApiOperation("查询教师可见班级和年级")
    @GetMapping("/listClassAndGradeByTeacher")
    @PreAuthorize("hasAuthority('teacher:view')")
    public ResultBean<List<TeacherClassAndGradeVO>> listClassAndGradeByTeacher(@ApiParam("教师id") @RequestParam Long teacherId) {
        return ResultBean.buildSuccess(eduStaffService.listClassAndGradeByTeacher(teacherId));
    }

    @ApiOperation("查询教师学校部门信息")
    @GetMapping("/listTeacherDeptByTeacher")
    public ResultBean<List<EduTeacherDept>> listTeacherDeptByTeacher(@ApiParam("教师id") @RequestParam Long teacherId) {
        return ResultBean.buildSuccess(eduStaffService.listTeacherDept(teacherId));
    }

    @ApiOperation("导入教师")
    @PostMapping("/importTeacher")
    public ResultBean importTeacher(MultipartFile file, @RequestParam("schoolId") Long schoolId) {
        CurrentUser currentUser = FebsUtil.getCurrentUser();
        Long key = System.currentTimeMillis();
        Map<Object, Object> map = redisService
            .hmget(CachePrefixConstant.IMPORT_TEACHER_KEY + currentUser.getUsername());
        if (CollUtil.size(map) >= 5) {
            throw new FebsException("导入文件已达上限，请稍后重试");
        }
        redisService.hset(CachePrefixConstant.IMPORT_TEACHER_KEY + currentUser.getUsername(), key.toString(), 0);
        redisService.hset(CachePrefixConstant.IMPORT_TEACHER_FILE + currentUser.getUsername(), key.toString(),
            file.getOriginalFilename());
//        eduStaffService.importTeacher(FileUtil.uploadMultipartFile(file), schoolId, currentUser, System.currentTimeMillis(), file.getName());
        return ResultBean.buildSuccess();
    }

    @ApiOperation("教师导入信息进度")
    @GetMapping("/importTeacherHeartbeat")
    public ResultBean<Integer> importTeacherHeartbeat(Long key) {
        return ResultBean.buildSuccess(eduStaffService.importTeacherHeartbeat(FebsUtil.getCurrentUsername(), key));
    }

    @ApiOperation("下载教师导入表格")
    @PostMapping("/downloadTemplate")
    public void downloadTemplate(HttpServletResponse response,
        @ApiParam("模板类型，0-教师，1-职工") @RequestParam(required = false) Integer type) {
        eduStaffService.downloadTemplate(response, type);
    }

    @ApiOperation("下载错误报告")
    @GetMapping("/downloadError")
    public void downloadError(HttpServletResponse response,
        @ApiParam("模板类型，0-教师，1-职工") Integer type,
        @ApiParam("通知id") Long noticeId) {
        eduStaffService.downloadError(response, type, noticeId);
    }

//    @ApiOperation("导入职工信息")
//    @PostMapping("/importStaffInformation")
//    public ResultBean<Long> importStaffInformation(MultipartFile file, @RequestParam("schoolId") Long schoolId) {
//        CurrentUser currentUser = FebsUtil.getCurrentUser();
//        Long key = System.currentTimeMillis();
//        Map<Object, Object> map = redisService.hmget(CachePrefixConstant.IMPORT_STAFF_FILE + currentUser.getUsername());
//        if (CollUtil.size(map) >= 5) {
//            throw new FebsException("导入文件已达上限，请稍后重试");
//        }
//        redisService.hset(CachePrefixConstant.IMPORT_STAFF_KEY + currentUser.getUsername(), key.toString(),
//            0);
//        redisService.hset(CachePrefixConstant.IMPORT_STAFF_FILE + currentUser.getUsername(), key.toString(),
//            file.getOriginalFilename());
//        eduStaffService.importStaff(FileUtil.uploadMultipartFile(file), schoolId, currentUser
//            , key, file.getName());
//        return ResultBean.buildSuccess();
//    }
//
//    @ApiOperation("导入职工图片")
//    @PostMapping("/importStaffPic")
//    public ResultBean<Long> importStaffPic(MultipartFile file, @RequestParam("schoolId") Long schoolId) {
//        CurrentUser currentUser = FebsUtil.getCurrentUser();
//        Long key = System.currentTimeMillis();
//        Map<Object, Object> map = redisService.hmget(CachePrefixConstant.IMPORT_STAFF_FILE + currentUser.getUsername());
//        if (CollUtil.size(map) >= 5) {
//            throw new FebsException("导入文件已达上限，请稍后重试");
//        }
//        redisService.hset(CachePrefixConstant.IMPORT_STAFF_KEY + currentUser.getUsername(), key.toString(),
//            0);
//        redisService.hset(CachePrefixConstant.IMPORT_STAFF_FILE + currentUser.getUsername(), key.toString(),
//            file.getOriginalFilename());
//        eduStaffService.importStaff(FileUtil.uploadMultipartFile(file), schoolId, currentUser
//            , key, file.getName());
//        return ResultBean.buildSuccess();
//    }

//    @ApiOperation("导入职工")
//    @PostMapping("/importStaff")
//    public ResultBean<Long> importStaff(MultipartFile file, @RequestParam("schoolId") Long schoolId) {
//        CurrentUser currentUser = FebsUtil.getCurrentUser();
//        Long key = System.currentTimeMillis();
//        Map<Object, Object> map = redisService.hmget(CachePrefixConstant.IMPORT_STAFF_FILE + currentUser.getUsername());
//        if (CollUtil.size(map) >= 5) {
//            throw new FebsException("导入文件已达上限，请稍后重试");
//        }
//        redisService.hset(CachePrefixConstant.IMPORT_STAFF_KEY + currentUser.getUsername(), key.toString(),
//            0);
//        redisService.hset(CachePrefixConstant.IMPORT_STAFF_FILE + currentUser.getUsername(), key.toString(),
//            file.getOriginalFilename());
//        eduStaffService.importStaff(FileUtil.uploadMultipartFile(file), schoolId, currentUser
//            , key, file.getName());
//        return ResultBean.buildSuccess();
//    }


    @ApiOperation("职工导入信息进度")
    @GetMapping("/importStaffHeartbeat")
    public ResultBean<Integer> importStaffHeartbeat(Long key) {
        return ResultBean.buildSuccess(eduStaffService.importStaffHeartbeat(FebsUtil.getCurrentUsername(), key));
    }

    @ApiOperation("导入文件列表key值查询,percent,filename")
    @GetMapping("/listImportKey")
    public ResultBean<List<Map<String, String>>> listImportKey(@ApiParam("0-教师，1-职工") Integer type) {
        return ResultBean.buildSuccess(eduStaffService.listImportKey(FebsUtil.getCurrentUsername(), type));
    }

    @ApiOperation("分页查询职工列表数据")
    @GetMapping("/listStaffPage")
    public ResultBean<IPage<StaffPageVO>> listStaffPage(
        @ApiParam("区域id") Long areaId, @ApiParam("学校id") Long schoolId,
        @ApiParam("部门id") Long deptId, @ApiParam("身份，0-普通成员，1-上级") Integer isLeader,
        @ApiParam("职务") String position, @ApiParam("姓名") String name,
        @ApiParam("电话") String mobile, @ApiParam("性别,0-男，1-女") Integer sex,
        @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer pageNum,
        @ApiParam("页面大小") @RequestParam(defaultValue = "10") Integer pageSize,
        @ApiParam("人脸采集状态.0-未采集, 1-已采集") Integer collectType) {
        return ResultBean.buildSuccess(eduStaffService
            .listStaffPage(Page.of(pageNum, pageSize), FebsUtil.getCurrentUser(), areaId, schoolId, deptId, isLeader,
                position, name, mobile, sex, collectType));
    }

    @ApiOperation("导出职工数据")
    @PostMapping("/exportStaff")
    public void exportStaff(
        @ApiParam("区域id") Long areaId, @ApiParam("学校id") Long schoolId,
        @ApiParam("部门id") Long deptId, @ApiParam("身份，0-普通成员，1-上级") Integer isLeader,
        @ApiParam("职务") String position, @ApiParam("姓名") String name,
        @ApiParam("电话") String mobile, @ApiParam("性别,0-男，1-女") Integer sex,
        @ApiParam("人脸采集状态.0-未采集, 1-已采集") Integer collectType, HttpServletResponse response) {
        eduStaffService.exportStaff(areaId, schoolId, deptId, isLeader, position,
            name, mobile, sex, collectType, response);
    }

    @ApiOperation("添加、修改职工")
    @PostMapping("/saveStaff")
    @OperationLog(module = ModuleName.STAFF, methods = "添加、修改职工", type = OperationLogTypeEnum.SAVE)
    public ResultBean saveStaff(@RequestBody EduStaff staff) {
        //判断手机号是否存在
        int number = eduStaffService.checkTeacherTelephone(staff);
        if (number >= 1) {
            return ResultBean.buildError("该手机号已存在");
        }
        eduStaffService.saveStaff(staff, FebsUtil.getCurrentUser());
        return ResultBean.buildSuccess();
    }

    @ApiOperation("根据教师id查询教师详情")
    @GetMapping("/findTeacherRole")
    public ResultBean<List<TeacherDeptVO>> findTeacherRole(@RequestParam Long teacherId, @RequestParam Integer type) {
        return ResultBean.buildSuccess(eduStaffService.findTeacherRole(teacherId));
    }

    @ApiOperation("查询家长孩子关联的教师（班主任、任课老师）")
    @GetMapping("/listTeacherByParent")
    public ResultBean<List<EduStaff>> listTeacherByParent(@RequestParam("parentId") Long parentId,
        @RequestParam(value = "teacherName", required = false) String teacherName) {
        List<EduStudent> studentList = eduStudentService.listStudentByParent(parentId, null);
        List<Long> classIds = studentList.stream().map(x -> x.getClassId()).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(classIds)) {
            return ResultBean.buildSuccess(eduStaffService.listTeacherByClass(classIds, teacherName));
        }
        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询班级关联的教师（班主任、任课老师）")
    @GetMapping("/listTeacherByClassId")
    public ResultBean<List<EduTeacherDept>> listTeacherByStudentId(@ApiParam("班级id") @RequestParam("classId") Long classId) {
        return ResultBean.buildSuccess(eduStudentService.listTeacherByStudentId(classId));
    }

    @ApiModelProperty("查询教师列表")
    @GetMapping("/listTeacherBySchool")
    ResultBean<List<EduStaff>> listTeacherBySchool(@ApiParam("学校id") @RequestParam("schoolId") Long schoolId,
        @ApiParam("教师名称") @RequestParam("name") String name) {
        if (schoolId == null) {
            schoolId = FebsUtil.getCurrentUser().getDeptId();
        }
        return ResultBean.buildSuccess(eduStaffService.listTeacherBySchool(schoolId, name));
    }

    @ApiOperation("获取教师部门")
    @GetMapping("/listStaffDept")
    ResultBean<List<EduStaffDept>> listStaffDept(@RequestParam("staffId") Long staffId) {
        return ResultBean.buildSuccess(eduStaffService.listStaffDept(staffId));
    }

    @ApiOperation("查询教职工列表信息")
    @GetMapping("/listStaffWithDept")
    ResultBean<List<StaffWithDeptVO>> listStaffWithDept(Long schoolId) {
        return ResultBean.buildSuccess(eduStaffService.listStaffWithDept(schoolId));
    }

    @ApiOperation("查询教师可见课程")
    @GetMapping("/findTeacherCourseId")
    ResultBean<List<Long>> findTeacherCourseId(@RequestParam Long teacherId,
        @RequestParam Long schoolId,
        @RequestParam(required = false) Long classId) {
        if (ObjectUtils.isEmpty(classId)) {
            return ResultBean.buildSuccess(eduTeacherDeptMapper.selectCoursetList(null, schoolId, null));
        }
        List<Integer> type = eduTeacherDeptMapper.findType(teacherId);
        if (type.size() == 1 && type.contains(4)) {
            return ResultBean.buildSuccess(eduTeacherDeptMapper.selectCoursetList(teacherId, schoolId, classId));
        }
        if (type.contains(3) && type.size() == 2 && type.contains(4)) {
            List<Long> classId1 = eduTeacherDeptMapper.findClassId(teacherId);
            if (!classId1.contains(classId)) {
                return ResultBean.buildSuccess(eduTeacherDeptMapper.selectCoursetList(teacherId, schoolId, classId));
            }
            return ResultBean.buildSuccess(eduTeacherDeptMapper.selectCoursetList(null, schoolId, null));
        }
        return ResultBean.buildSuccess(eduTeacherDeptMapper.selectCoursetList(null, schoolId, null));
    }


    @ApiOperation("按年级或者班级查询教师任课信息")
    @GetMapping("/listTeacherCourseByGrade")
    ResultBean<List<TeacherCourseInfoVO>> listTeacherCourseByGrade(
        @ApiParam("年级id") @RequestParam(value = "gradeId", required = false) Long gradeId,
        @ApiParam("班级id") @RequestParam(value = "classId", required = false) Long classId) {
        return ResultBean.buildSuccess(eduStaffService.listTeacherCourseByGrade(gradeId, classId));
    }


    @ApiOperation("根据年级ID查询教师管理的班级")
    @GetMapping("/listClassByGradeIdAndTeacherId")
    ResultBean<List<EduUserDept>> listClassByGradeIdAndTeacherId(
        @NotNull(message = "不能为空") @ApiParam("年级id") @RequestParam(value = "gradeId", required = true) Long gradeId,
        @NotNull(message = "不能为空") @ApiParam("教师id") @RequestParam(value = "staffId", required = true) Long staffId) {
        return ResultBean.buildSuccess(eduStaffService.listClassByGradeIdAndTeacherId(gradeId, staffId));
    }


    @ApiOperation("根据班级或名称查询教师")
    @GetMapping("/listTeacherByClassAndName")
    ResultBean<List<EduStaff>> listTeacherByClassAndName(@RequestParam("classId") Long classId,
        @RequestParam("name") String name) {
        return ResultBean.buildSuccess(eduStaffService.listTeacherByClassAndName(classId, name));
    }


    @ApiOperation("根据根据部门id查询对应教职工")
    @GetMapping("/listStaffByDeptId")
    public ResultBean<List<Long>> listStaffByDeptId(@RequestParam(required = false) Long deptId,
        @RequestParam(required = false) String nameOrPhone,
        @RequestParam(required = false) Long schoolId) {

        return ResultBean.buildSuccess(eduStaffService.listStaffByDeptId(deptId, nameOrPhone, schoolId));
    }


    @ApiOperation("根据条件查询教职工列表")
    @PostMapping("/listStaff")
    public ResultBean<List<EduStaff>> listStaff(@RequestBody ListStaffDTO dto) {
        CurrentUser currentUser = FebsUtil.getCurrentUser();
        if (ObjectUtil.equal(currentUser.getDeptType(), 0)) {
            dto.setSchoolId(currentUser.getDeptId());
        }
        return ResultBean.buildSuccess(eduStaffService.listStaff(dto));
    }

    @ApiOperation("查询职工部门信息")
    @PostMapping("/getStaffDeptByStaffIds")
    public ResultBean<List<EduStaffDept>> getStaffDeptByStaffIds(@ApiParam("职工id") @RequestBody List<Long> staffIds) {
        return ResultBean.buildSuccess(eduStaffDeptService.getStaffDeptByStaffIds(staffIds));
    }

    @ApiOperation("查询教职工分布情况--教师分布统计")
    @GetMapping("/staStaffDistribute")
    public ResultBean<StaStaffDistributeVO> staStaffDistribute() {
        List<Long> schoolIds = remoteDeptService.getSchoolByArea(null, null).getData().stream().map(Dept::getDeptId).collect(
            Collectors.toList());
        return ResultBean.buildSuccess(eduStaffService.staStaffDistribute(schoolIds));
    }

    @ApiOperation("查询职工数--职工统计")
    @GetMapping("/staStaffNum")
    public ResultBean<StaStaffDistributeVO> staStaffNum() {
        List<Long> schoolIds = remoteDeptService.getSchoolByArea(null, null).getData().stream().map(Dept::getDeptId).collect(
            Collectors.toList());
        return ResultBean.buildSuccess(eduStaffService.staStaffNum(schoolIds));
    }

    /**
     * @param teacherId 教师ID
     * @param type      1表示校区负责人，2表示年级负责人，3表示班主任，4表示任课老师，5表示学段负责人
     * @return
     */
    @ApiOperation("查询教师可见部门")
    @GetMapping("/listDeptByTeacher")
    public ResultBean<List<TeacherClassVO>> listDeptByTeacher(@ApiParam("教师id") @RequestParam Long teacherId,
        @ApiParam("type") @RequestParam Integer type) {
        return ResultBean.buildSuccess(eduStaffService.listDeptByTeacher(teacherId, type));
    }

    /**
     * @param sysUserId 系统用户Id
     * @param type      1表示校区负责人，2表示年级负责人，3表示班主任，4表示任课老师，5表示学段负责人
     * @return
     */
    @ApiOperation("查询系统用户可见部门")
    @GetMapping("/listDeptBySysUserId")
    public ResultBean<List<TeacherClassVO>> listDeptBySysUserId(@ApiParam("教师id") @RequestParam Long sysUserId,
        @ApiParam("type") @RequestParam Integer type) {
        EduStaff staff = eduStaffService.getOne(Wrappers.lambdaQuery(new EduStaff())
            .eq(EduStaff::getSysUserId, sysUserId)
            .eq(EduStaff::getSchoolId, FebsUtil.getTopDeptId()));
        return ResultBean.buildSuccess(eduStaffService.listDeptByTeacher(staff.getId(), type));
    }

    /**
     * @param teacherId 教师ID
     * @param type      1表示校区负责人，2表示年级负责人，3表示班主任，4表示任课老师，5表示学段负责人
     * @return
     */
    @ApiOperation("查询教师可见部门")
    @GetMapping("/listDeptByStaffId")
    public ResultBean<List<TeacherClassVO>> listDeptByStaffId(@ApiParam("教师id") @RequestParam Long teacherId,
        @ApiParam("type") @RequestParam Integer type) {
        return ResultBean.buildSuccess(eduStaffService.listDeptByTeacher(teacherId, type));
    }

    @ApiOperation("根据职工id集合查询职工信息")
    @PostMapping("/getStaffList")
    public ResultBean<List<EduStaff>> listDeptByStaffId(@RequestBody List<Long> staffIds) {
        return ResultBean.buildSuccess(eduStaffService.list(Wrappers.lambdaQuery(new EduStaff()).in(EduStaff::getId, staffIds)));
    }


    @ApiOperation("导入职工数据-新版")
    @PostMapping(value = "/importStaffDataExcel")
    public ResultBean<ConcurrentHashMap<Integer, Object>> importStaffDataExcel(
        @ApiParam(value = "导入的excel文件", required = true) @RequestParam("file") MultipartFile file,
        @ApiParam(value = "学校id", required = true) @RequestParam("schoolId") Long schoolId) {
        // 当前时间时间戳
        long timestamp = System.currentTimeMillis();
        try {
            // 导入迎新学生数据
            return eduStaffService.importStaff(file, schoolId, timestamp);
        } catch (Exception e) {
            log.error("导入迎新学生数据失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.IMPORT_EXCEL_FAIL.getValue());
        } finally {
            // 清空当前导入的redis学校数据
            redisService.del(RedisUtil.getDeptKey(String.valueOf(timestamp)));
        }
    }


    @ApiOperation("查询dept负责人")
    @PostMapping("/getDeptManager")
    public ResultBean<List<DeptManagetVO>> getDeptManager(@RequestBody ManagerDTO dto) {
        return ResultBean.buildSuccess(eduStaffService.getDeptManager(dto.getDeptIdList(), dto.getRuleId()));
    }
}
