package cn.teammodel.controller.admin.controller;

import cn.teammodel.common.R;
import cn.teammodel.controller.admin.service.TeacherService;
import cn.teammodel.model.dto.admin.teacher.CoreUser;
import cn.teammodel.model.dto.admin.teacher.GpTeacherDto;
import cn.teammodel.model.dto.admin.teacher.GpTeacherRequest;
import cn.teammodel.model.dto.admin.teacher.TeacherDto;
import cn.teammodel.model.entity.school.Teacher;
import cn.teammodel.model.entity.teacher.PtTeacherInfo;
import cn.teammodel.model.vo.admin.GpTeacherVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/teacher")
@Api(tags = "教师相关接口内容")
public class TeacherController {
    @Resource
    private TeacherService teacherService;
    @PostMapping("getCount")
    @ApiOperation("获取教师基础数据统计内容")
    public R<List<Map<String, Integer>>> getCount(@Valid @RequestBody TeacherDto teacherDto) {
        List<Map<String, Integer>> res = teacherService.getTeacherList(teacherDto);
        return R.success(res);
    }
    @PostMapping("getTeacherDetail")
    @ApiOperation("获取教师详细数据")
    public R<Map<String, Object>> getTeacherDetail(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        Map<String, Object> res = teacherService.getTeacherDetail(teacherDto,request);
        return R.success(res);
    }

    @PostMapping("compareData")
    @ApiOperation("比对IES5相关数据")
    public R<Map<String, Object>> compareData(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        Map<String, Object> res = teacherService.compareData(teacherDto,request);
        return R.success(res);
    }

    @PostMapping("getTeacherFromIes")
    @ApiOperation("获取IES5教师基础数据内容")
    public R<List<GpTeacherVo>> getTeacherFromIes(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        List<GpTeacherVo> res = teacherService.getTeacherFromIes(teacherDto,request);
        return R.success(res);
    }

    @PostMapping("getTeacherCountRecordOfWeek")
    @ApiOperation("获取当前学期指定教师每周课程数")
    public R<Map<Long, Integer>> getTeacherCountRecordOfWeek(@Valid @RequestBody TeacherDto teacherDto) {
        Map<Long, Integer> res = teacherService.getTeacherByRecord(teacherDto);
        return R.success(res);
    }
    @PostMapping("getTeacherLearningCategoryCount")
    @ApiOperation("获取指定教师教学法统计")
    public R<Map<String, Object>> getTeacherLearningCategoryCount(@Valid @RequestBody TeacherDto teacherDto) {
        Map<String, Object> res = teacherService.getTeacherLearningCategory(teacherDto);
        return R.success(res);
    }
    @PostMapping("getTeacherGradeCount")
    @ApiOperation("获取年级人数以及分配情况")
    public R<Map<String, Object>> getTeacherGradeCount(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        Map<String, Object> res = teacherService.getTeacherGradeCount(teacherDto,request);
        return R.success(res);
    }
    @PostMapping("getDistributionOfTeachers")
    @ApiOperation("获取教师分布情况")
    public R<List<Map<String,Map<String, Long>>>> getDistributionOfTeachers(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        List<Map<String,Map<String, Long>>> res = teacherService.getDistributionOfTeachers(teacherDto,request);
        return R.success(res);
    }

    @PostMapping("getTeachingAndResearch")
    @ApiOperation("获取教师教研数据")
    public R<Map<String,Object>> getTeachingAndResearch(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        Map<String,Object> res = teacherService.getTeachingAndResearch(teacherDto,request);
        return R.success(res);
    }
    @PostMapping("getTeachingOfTeacher")
    @ApiOperation("获取教师教学法数据")
    public R<List<LinkedHashMap<String, LinkedHashMap<String,Object>>> > getTeachingOfTeacher(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        List<LinkedHashMap<String,LinkedHashMap<String,Object>>>  res = teacherService.getTeachingOfTeacher(teacherDto,request);
        return R.success(res);
    }
    @PostMapping("getTeacherOfCapabilityAssessment")
    @ApiOperation("获取教师能力考核数据")
    public R<Map<String,Object>> getTeacherOfCapabilityAssessment(@Valid @RequestBody TeacherDto teacherDto, HttpServletRequest request) {
        Map<String,Object> res = teacherService.getTeacherOfCapabilityAssessment(teacherDto,request);
        return R.success(res);
    }

    @PostMapping("update")
    @ApiOperation("更新教师信息")
    public R<String> update(@Valid @RequestBody TeacherDto teacherDto) {
        teacherService.update(teacherDto);
        return R.success("更新成功");
    }
    @PostMapping("findIdentityByTmdId")
    @ApiOperation("根据tmdId获取教师身份")
    public R<Map<String, Object>> findIdentityByTmdId(@Valid @RequestBody TeacherDto teacherDto) {
        Map<String, Object> res = teacherService.findIdentityByTmdId(teacherDto);
        return R.success(res);
    }
    @PostMapping("delete")
    @ApiOperation("删除教师信息")
    public R<String> delete(@Valid @RequestBody TeacherDto teacherDto) {
        teacherService.delete(teacherDto);
        return R.success("删除成功");
    }
    @PostMapping("batchImportPtTeachers")
    @ApiOperation("批量导入教师信息")
    public R<List<GpTeacherVo>> batchImportPtTeachers(@Valid @RequestBody List<GpTeacherVo> gpTeacherDtos, HttpServletRequest request) {
        List<GpTeacherVo> res = teacherService.batchImportPtTeachers(gpTeacherDtos,request);
        return R.success(res);
    }
    @PostMapping("findTeachers")
    @ApiOperation("获取教师Base信息")
    public R<List<Map<String, Object>>> findTeachers(@Valid @RequestBody CoreUser dto, HttpServletRequest request) {
        List<Map<String, Object>> res = teacherService.findTeachers(dto,request);
        return R.success(res);
    }
    @PostMapping("saveOrUpdate")
    @ApiOperation("保存或更新教师信息")
    public R<List<PtTeacherInfo>> saveOrUpdate(@Valid @RequestBody GpTeacherRequest gpTeacherDtos, HttpServletRequest request) {
        List<PtTeacherInfo> res = teacherService.saveOrUpdate(gpTeacherDtos,request);
        return R.success(res);
    }
    @PostMapping("dataSync")
    @ApiOperation("同步教师信息")
    public R<String> dataSync(@Valid @RequestBody GpTeacherRequest gpTeacherDtos, HttpServletRequest request) {
        teacherService.dataSync(gpTeacherDtos,request);
        return R.success("同步成功");
    }
}
