package com.braisedpanda.shirotest.controller;
import com.braisedpanda.shirotest.Utils.Utils;
import com.braisedpanda.shirotest.bean.*;
import com.braisedpanda.shirotest.service.ClassService;
import com.braisedpanda.shirotest.service.GradesService;
import com.braisedpanda.shirotest.service.NationService;
import com.braisedpanda.shirotest.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.Max;
import java.util.*;
@Controller
public class GradesController {
@Autowired
StudentService studentService;
@Autowired
NationService nationService;
@Autowired
GradesService gradesService;
@Autowired
ClassService classService;
//批量生成学生成绩卡数据
@RequestMapping("addGradesCard")
public String addGradesCard(){
Student_Grades_Card card = new Student_Grades_Card();
List<Student> studentList = studentService.getAllStudent();
for (Student s:
studentList) {
String stu_id = s.getStu_id();
for(int i=1;i<=3;i++){
String time = i+"";
String stu_grades_card_id = "SGC"+time+stu_id;
card.setStu_grades_card_id(stu_grades_card_id);
card.setStu_id(stu_id);
card.setTest_time(time);
if(i==1){
card.setTest_describe("开学考试");
}else if(i==2){
card.setTest_describe("期中考试");
}else {
card.setTest_describe("期末考试");
}
gradesService.add(card);
}
}
return "user/blank";
}
//批量生成学生成绩
@RequestMapping("addGrades")
public String addGrades(){
List<Student> studentList = studentService.getAllStudent();
for (Student s:
studentList) {
String stu_id = s.getStu_id();
List<Student_Grades_Card> student_grades_cardList = gradesService.getGradesCard(stu_id);
Student_Grades student_grades = new Student_Grades();
for (Student_Grades_Card student_grades_card:
student_grades_cardList ) {
String stu_grades_card_id = student_grades_card.getStu_grades_card_id();
student_grades.setStu_grades_id("SGI"+stu_grades_card_id);
student_grades.setStu_grades_card_id(stu_grades_card_id);
Random random = new Random();
double a = 60+random.nextInt(90);
double b = 60+random.nextInt(90);
double c = 60+random.nextInt(90);
double d = 60+random.nextInt(90);
double e = 60+random.nextInt(90);
double f = 60+random.nextInt(90);
double g = 60+random.nextInt(90);
double h = 60+random.nextInt(90);
double i = 60+random.nextInt(90);
double j = 60+random.nextInt(90);
double k = 60+ random.nextInt(90);
double l = 60+random.nextInt(90);
student_grades.setChinese(a);
student_grades.setMathematics(b);
student_grades.setEnglish(c);
student_grades.setPolitics(d);
student_grades.setHistory(e);
student_grades.setGeography(f);
student_grades.setBiology(g);
student_grades.setChemistry(h);
student_grades.setPhysics(i);
student_grades.setMusic(j);
student_grades.setArts(k);
student_grades.setSports(l);
double[] array = new double[]{a,b,c,d,e,f,g,h,i,j,k,l};
double max=array[0];
double min=array[0];
double total=0;
for(int x=0;x<array.length;x++){
if(max<array[x]){
max=array[x];
}
if(min>array[x]){
min=array[x];
}
total = total+array[x];
}
double ave = total/array.length;
student_grades.setMaxscore(max);
student_grades.setMinscore(min);
student_grades.setTotal(total);
student_grades.setAverage(ave);
System.out.println(student_grades);
gradesService.addGrades(student_grades);
}
}
return "user/blank";
}
//查询学生成绩
@ResponseBody
@RequestMapping("grades/sudent/{stu_id}")
public Map<String,Object> getStudentGrades(@PathVariable("stu_id") String stu_id,int page,int limit){
List<StudentGradesCustom> sgcList = new ArrayList<StudentGradesCustom>();
//根据学生id查找学生
Student student = studentService.getStudentById(stu_id);
//成绩卡,根据学生的id在成绩卡中,查询多次考试的成绩单号
Student_Grades_Card gcard = new Student_Grades_Card();
List<Student_Grades_Card> gcardList = gradesService.getGradesCard(stu_id);
for (Student_Grades_Card card:
gcardList) {
//创建前端展示的成绩单
StudentGradesCustom sgc = new StudentGradesCustom();
String cardid = card.getStu_grades_card_id();
//多次成绩单号已经查到
Student_Grades grades = gradesService.getGrades(cardid);
//设置学生id
sgc.setStu_id(stu_id);
//设置学生姓名
sgc.setStu_name(student.getStu_name());
//设置学生班级
sgc.setClass_id(student.getClass_id());
//设置测试的描述信息
sgc.setTest_describe(card.getTest_describe());
//设置总分
sgc.setTotal(grades.getTotal());
//设置平均分
sgc.setAverage(grades.getAverage());
//设置最高分
sgc.setMaxscore(grades.getMaxscore());
//设置最低分
sgc.setMinscore(grades.getMinscore());
//设置语文分数
sgc.setChinese(grades.getChinese());
//设置数学分数
sgc.setMathematics(grades.getMathematics());
//设置英语分数
sgc.setEnglish(grades.getEnglish());
//设置政治分数
sgc.setPolitics(grades.getPolitics());
//设置历史分数
sgc.setHistory(grades.getHistory());
//设置地理分数
sgc.setGeography(grades.getGeography());
//设置生物分数
sgc.setBiology(grades.getBiology());
//设置化学分数
sgc.setChemistry(grades.getChemistry());
//设置物理分数
sgc.setPhysics(grades.getPhysics());
//设置音乐分数
sgc.setMusic(grades.getMusic());
//设置美术分数
sgc.setArts(grades.getArts());
//设置体育分数
sgc.setSports(grades.getSports());
//设置考试的时间
sgc.setTest_time(card.getTest_time());
sgcList.add(sgc);
}
int count = sgcList.size();
PageHelper.startPage(page,limit);
;
PageInfo<StudentGradesCustom> studentGradesPageInfo = new PageInfo<>(sgcList);
List<StudentGradesCustom> studentGradesList = studentGradesPageInfo.getList();