LearnStudentController.java 8.19 KB
package com.jevon.controller;

import com.jevon.enums.DifficultEnums;
import com.jevon.enums.DimensionalEnums;
import com.jevon.model.Analyse;
import com.jevon.model.AnalyseDimensional;
import com.jevon.model.Dimensional;
import com.jevon.model.Student;
import com.jevon.service.*;
import com.jevon.vo.req.StudentReqVo;
import com.jevon.vo.school.Form6;
import com.jevon.vo.student.Form1;
import com.jevon.vo.student.Form2;
import com.jevon.vo.student.Form3;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author chen
 * @version 1.0
 * @date 2019/11/1 0001 10:38
 */
@RestController
@RequestMapping(value = "/getStudent")
@Api(value = "学生报告")
public class LearnStudentController {

    @Autowired
    AnalyseService analyseService;

    @Autowired
    DimensionalService dimensionalService;

    @Autowired
    AnalyseDimensionalService analyseDimensionalService;

    @Autowired
    AnalyseDetailService analyseDetailService;

    @Autowired
    StudentDetailService studentDetailService;

    @Autowired
    StudentService studentService;

    @Autowired
    LeagueService leagueService;

    @Autowired
    ChapterService chapterService;

    @ApiOperation("getForm1")
    @RequestMapping(value = "getForm1", method = RequestMethod.POST)
    public Form1 getStudent1(@RequestBody StudentReqVo studentReqVo){
        Form1 form1 = new Form1();
        Analyse analyse = analyseService.selectById(studentReqVo.getAnalyseId());
        Student student = studentService.selectStudent(analyse.getId(),studentReqVo.getSchoolName(),studentReqVo.getStudentNumber());
        List<Student> schoolStudent = studentService.selectByClassName(analyse.getId(),studentReqVo.getSchoolName(),null);
        List<Student> classStudent = studentService.selectByClassName(analyse.getId(),studentReqVo.getSchoolName(),student.getClassName());
        Double highestScore = studentService.selectClassMaxScore(analyse.getId(),student.getSchoolName(),student.getClassName());
        int schoolRank = 0 , classRank = 0 ;
        for (int i = 0; i < schoolStudent.size() ; i++) {
            if(schoolStudent.get(i).getStudentNumber().equals(student.getStudentNumber())){
                schoolRank = i+1 ;
            }
        }
        for (int i = 0; i < classStudent.size() ; i++) {
            if(classStudent.get(i).getStudentNumber().equals(student.getStudentNumber())){
                classRank = i+1 ;
            }
        }
        Double rank = new Double(classStudent.size()-classRank) / new Double(classStudent.size()) ;
        form1.setClassName(student.getClassName());
        form1.setMaxScore(highestScore);
        form1.setScore(student.getScore());
        form1.setRank(rank);
        form1.setClassRank(classRank);
        form1.setSchoolRank(schoolRank);
        return form1;
    }

    @ApiOperation("getForm2")
    @RequestMapping(value = "getForm2", method = RequestMethod.POST)
    public Form2 getStudent2(@RequestBody StudentReqVo studentReqVo){
        Form2 form2 = new Form2();
        Analyse analyse = analyseService.selectById(studentReqVo.getAnalyseId());
        Student student = studentService.selectStudent(analyse.getId(),studentReqVo.getSchoolName(),studentReqVo.getStudentNumber());
        List<Student> classStudent = studentService.selectByClassName(analyse.getId(),studentReqVo.getSchoolName(),student.getClassName());

        Map<String , List<Double>> typeMap = new HashMap<>();
        List<String> questionTypes = analyseDetailService.selectQuestionType(analyse.getId());
        for(String questionType : questionTypes){
            List<Double> list = new ArrayList<>();
            Double maxScore = analyseDetailService.selectSumType(analyse.getId(),questionType);
            List<String> numberList = analyseDetailService.selectQuestionNumberByType(analyse.getId(),questionType);
            Double score = studentDetailService.selectStudentSumScore(analyse.getId(),student.getSchoolName(),student.getStudentNumber(),numberList);
            Double highestScore = new Double(0);
            for(Student temp : classStudent){
                Double tempScore = studentDetailService.selectStudentSumScore(analyse.getId(),temp.getSchoolName(),temp.getStudentNumber(),numberList);
                if(tempScore > highestScore){
                    highestScore = tempScore ;
                }
            }
            list.add(maxScore);
            list.add(highestScore);
            list.add(score);
            typeMap.put(questionType,list);
        }
        Map<String , List<Double>> difficultMap = new HashMap<>();
        for(DifficultEnums difficultEnum : DifficultEnums.values()){
            List<Double> list = new ArrayList<>();
            Double maxScore = analyseDetailService.selectDifficult(analyse.getId(),difficultEnum.getDifficultType());
            List<String> numberList = analyseDetailService.selectQuestionNumberByDifficult(analyse.getId(),difficultEnum.getDifficultType());
            Double score = studentDetailService.selectStudentSumScore(analyse.getId(),student.getSchoolName(),student.getStudentNumber(),numberList);
            Double highestScore = new Double(0);
            for(Student temp : classStudent){
                Double tempScore = studentDetailService.selectStudentSumScore(analyse.getId(),temp.getSchoolName(),temp.getStudentNumber(),numberList);
                if(tempScore > highestScore){
                    highestScore = tempScore ;
                }
            }
            list.add(maxScore);
            list.add(highestScore);
            list.add(score);
            difficultMap.put(difficultEnum.getDifficultShow(),list);
        }
        form2.setDifficultMap(difficultMap);
        form2.setTypeMap(typeMap);
        return form2;
    }

    @ApiOperation("getForm3")
    @RequestMapping(value = "getForm3", method = RequestMethod.POST)
    public Form3 getStudent3(@RequestBody StudentReqVo studentReqVo){
        Form3 form3 = new Form3();
        Analyse analyse = analyseService.selectById(studentReqVo.getAnalyseId());
        Student student = studentService.selectStudent(analyse.getId(),studentReqVo.getSchoolName(),studentReqVo.getStudentNumber());
        List<Student> classStudent = studentService.selectByClassName(analyse.getId(),studentReqVo.getSchoolName(),student.getClassName());
        List<Dimensional> knowledgeList = dimensionalService.selectByAnalyse(analyse.getId(), DimensionalEnums.knowledge.getDimensionalType());
        List<String> goodList = new ArrayList<>();
        List<String> badList = new ArrayList<>();
        for(Dimensional dimensional : knowledgeList) {
            Form6 form6 = new Form6();
            form6.setDimensional(dimensional.getDimensionalName());
            List<AnalyseDimensional> analyseDimensionals = analyseDimensionalService.selectByDimensional(analyse.getId(), dimensional.getId());
            Double score = 0d;
            List<String> examNumberList = new ArrayList<>();
            for (AnalyseDimensional analyseDimensional : analyseDimensionals) {
                score = score + analyseDimensional.getScore();
                examNumberList.add(analyseDimensional.getQuestionNumber());
            }
            Double sumScore = studentDetailService.selectClassSumScore(analyse.getId(),student.getSchoolName(),student.getClassName(),examNumberList);
            Double classAvg = sumScore / new Double(classStudent.size()) ;
            Double tempScore = studentDetailService.selectStudentSumScore(analyse.getId(),student.getSchoolName(),student.getStudentNumber(),examNumberList);
            if(tempScore / classAvg > 1.1){
                goodList.add(dimensional.getDimensionalName());
            }
            if(tempScore / classAvg < 0.9){
                badList.add(dimensional.getDimensionalName());
            }
        }
        form3.setGoodList(goodList);
        form3.setBadList(badList);
        return form3;
    }




}