package com.ruoyi.web.controller.test.teacher;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.test.domain.ClassExamPaper;
import com.ruoyi.test.domain.DO.HomepageDO;
import com.ruoyi.test.domain.TeacherManageClass;
import com.ruoyi.test.seriver.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags = "教师端主页")
@RestController
@RequestMapping("/teacher/homepage")
public class TeacherHomePageController {

    @Autowired
    private ITeacherManageClassService iTeacherManageClassService;

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IStudentClassService iStudentClassService;

    @Autowired
    private IExamPaperService iExamPaperService;

    @Autowired
    private ITeacherSubjectService iTeacherSubjectService;

    @Autowired
    private IExamCreateService iExamCreateService;

    @Autowired
    private IClassExamPaperService iClassExamPaperService;

    @ApiOperation("主页数据")
    @GetMapping("homepagesuju")
    public R<HomepageDO> homepagesuju(){
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        Long zhid = sysUser.getUserId();
        Long teacherid = iUserService.selectByzhid(zhid);
        HomepageDO homepageDO = new HomepageDO();
        Integer total = iTeacherManageClassService.totalClass(teacherid).size();
        homepageDO.setSumclass(total);
        Integer total1 = iStudentClassService.totalStudent(iTeacherManageClassService.totalClass(teacherid));
        homepageDO.setSunnumclass(total1);
        List<TeacherManageClass> list = iTeacherManageClassService.totalClass(teacherid);
        Integer total2 = 0;
        for(TeacherManageClass teacherManageClass : list){
            String grade = teacherManageClass.getGrade();
            String Class = teacherManageClass.getClass1();
            total2 += iClassExamPaperService.selectByGradeAndClass(grade,Class).size();
        }
        homepageDO.setExampapersum(total2);
        List<TeacherManageClass> list2 = iTeacherManageClassService.totalClass(teacherid);
        Integer total3 = 0;
        for(TeacherManageClass teacherManageClass : list2){
            String grade = teacherManageClass.getGrade();
            String Class = teacherManageClass.getClass1();
            List<ClassExamPaper> list1 = iClassExamPaperService.selectByGradeAndClass(grade,Class);
            for(ClassExamPaper classExamPaper : list1){
                total3 += iExamCreateService.total(classExamPaper.getId());
            }
        }
        homepageDO.setSumtimu(total3);
        List<TeacherManageClass> list3 = iTeacherManageClassService.totalClass(teacherid);
        Map<String,Integer> map = new HashMap<>();
        for(TeacherManageClass teacherManageClass : list3){
            String grade = teacherManageClass.getGrade();
            String Class = teacherManageClass.getClass1();
            String s = grade+"年"+Class+"班";
            Integer num = iStudentClassService.selectByGradeAndClass(grade,Class).size();
            map.put(s,num);
        }
        homepageDO.setClasssize(map);
        List<TeacherManageClass> list4 = iTeacherManageClassService.totalClass(teacherid);
        Map<String,Integer> map1 = new HashMap<>();
        for(TeacherManageClass teacherManageClass : list4){
            String grade = teacherManageClass.getGrade();
            String Class = teacherManageClass.getClass1();
            Integer num = iClassExamPaperService.selectByGradeAndClass(grade,Class).size();
            String s = grade+"年"+Class+"班";
            map1.put(s,num);
        }
        homepageDO.setExamPaperSize(map1);
        return R.ok(homepageDO);
    }
//    @ApiOperation("班级总数")
//    @GetMapping("totalClass")
//    public R<Integer> totalClass(){
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        Long zhid = sysUser.getUserId();
//        Long teacherid = iUserService.selectByzhid(zhid);
//        Integer total = iTeacherManageClassService.totalClass(teacherid).size();
//        return R.ok(total);
//    }
//
//    @ApiOperation("班级总人数")
//    @GetMapping("totalStudent")
//    public R<Integer> totalStudent() {
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        Long zhid = sysUser.getUserId();
//        Long teacherid = iUserService.selectByzhid(zhid);
//        Integer total = iStudentClassService.totalStudent(iTeacherManageClassService.totalClass(teacherid));
//        return R.ok(total);
//    }
//
//    @ApiOperation("试卷总数")
//    @GetMapping("totalExamPaper")
//    public R<Integer> totalExamPaper() {
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        Long zhid = sysUser.getUserId();
//        Long teacherid = iUserService.selectByzhid(zhid);
//        List<TeacherManageClass> list = iTeacherManageClassService.totalClass(teacherid);
//        Integer total = 0;
//        for(TeacherManageClass teacherManageClass : list){
//            String grade = teacherManageClass.getGrade();
//            String Class = teacherManageClass.getClass1();
//            total += iClassExamPaperService.selectByGradeAndClass(grade,Class).size();
//        }
//        return R.ok(total);
//    }
//
//    @ApiOperation("题目总数")
//    @GetMapping("totalQuestionbank")
//    public R<Integer> totalQuestionbank() {
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        Long zhid = sysUser.getUserId();
//        Long teacherid = iUserService.selectByzhid(zhid);
//        List<TeacherManageClass> list = iTeacherManageClassService.totalClass(teacherid);
//        Integer total = 0;
//        for(TeacherManageClass teacherManageClass : list){
//            String grade = teacherManageClass.getGrade();
//            String Class = teacherManageClass.getClass1();
//            List<ClassExamPaper> list1 = iClassExamPaperService.selectByGradeAndClass(grade,Class);
//            for(ClassExamPaper classExamPaper : list1){
//                total += iExamCreateService.total(classExamPaper.getId());
//            }
//        }
//        return R.ok(total);
//    }
//
//    @ApiOperation("班级人数分布")
//    @GetMapping("classSize")
//    public R<Map<String,Integer>> classSize(){
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        Long zhid = sysUser.getUserId();
//        Long teacherid = iUserService.selectByzhid(zhid);
//        List<TeacherManageClass> list = iTeacherManageClassService.totalClass(teacherid);
//        Map<String,Integer> map = new HashMap<>();
//        for(TeacherManageClass teacherManageClass : list){
//            String grade = teacherManageClass.getGrade();
//            String Class = teacherManageClass.getClass1();
//            String s = grade+"年"+Class+"班";
//            Integer num = iStudentClassService.selectByGradeAndClass(grade,Class).size();
//            map.put(s,num);
//        }
//        return R.ok(map);
//    }
//
//    @ApiOperation("班级试卷分布")
//    @GetMapping("examPaperSize")
//    public R<Map<String,Integer>> examPaperSize(){
//        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
//        Long zhid = sysUser.getUserId();
//        Long teacherid = iUserService.selectByzhid(zhid);
//        List<TeacherManageClass> list = iTeacherManageClassService.totalClass(teacherid);
//        Map<String,Integer> map = new HashMap<>();
//        for(TeacherManageClass teacherManageClass : list){
//            String grade = teacherManageClass.getGrade();
//            String Class = teacherManageClass.getClass1();
//            Integer num = iClassExamPaperService.selectByGradeAndClass(grade,Class).size();
//            String s = grade+"年"+Class+"班";
//            map.put(s,num);
//        }
//        return R.ok(map);
//    }

}
