package com.yida.data.user.controller.in;

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.extension.plugins.pagination.Page;
import com.yida.data.common.core.annotation.ControllerLog;
import com.yida.data.common.core.common.ResultBean;
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.user.EduStaff;
import com.yida.data.common.core.entity.user.EduStaffDept;
import com.yida.data.common.core.entity.user.EduStudent;
import com.yida.data.common.core.entity.user.EduTeacherDept;
import com.yida.data.common.core.entity.user.EduUserDept;
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.system.feign.RemoteDeptService;
import com.yida.data.user.dto.ListStaffDTO;
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.StaStaffDistributeVO;
import com.yida.data.user.vo.StaffPageVO;
import com.yida.data.user.vo.StaffWithDeptVO;
import com.yida.data.user.vo.TeacherClassAndGradeVO;
import com.yida.data.user.vo.TeacherClassVO;
import com.yida.data.user.vo.TeacherCourseInfoVO;
import com.yida.data.user.vo.TeacherDetailVO;
import com.yida.data.user.vo.TeacherListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

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


    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("根据根据部门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("/getStaffDeptByStaffIds")
    public ResultBean<List<EduStaffDept>> getStaffDeptByStaffIds(@ApiParam("职工id") @RequestBody List<Long> staffIds) {
        return ResultBean.buildSuccess(eduStaffDeptService.getStaffDeptByStaffIds(staffIds));
    }

    @ApiOperation("更新教职工信息缓存")
    @GetMapping("/updateStaffCache")
    public ResultBean updateStaffCache() {
        eduStaffService.updateStaffCache();
        return ResultBean.buildSuccess();
    }
}
