package com.mindskip.xzs.controller.teacher;
|
|
import com.mindskip.xzs.base.BaseApiController;
|
import com.mindskip.xzs.base.RestResponse;
|
import com.mindskip.xzs.domain.other.KeyValue;
|
import com.mindskip.xzs.service.ClassesService;
|
import com.mindskip.xzs.service.ExamPaperService;
|
import com.mindskip.xzs.service.QuestionService;
|
import com.mindskip.xzs.viewmodel.teacher.index.TeacherIndexVM;
|
import lombok.AllArgsConstructor;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.List;
|
|
/**
|
* @version 2.2.0
|
* @description: 主页
|
* Copyright (C), 2020-2021, 武汉思维跳跃科技有限公司
|
* @date 2021 /9/7 9:45
|
*/
|
@RestController("TeacherDashboardController")
|
@RequestMapping(value = "/api/teacher/dashboard")
|
@AllArgsConstructor
|
public class DashboardController extends BaseApiController {
|
|
|
private final ClassesService classesService;
|
private final ExamPaperService examPaperService;
|
private final QuestionService questionService;
|
|
/**
|
* 班级人数、试卷统计
|
*
|
* @return the rest response
|
*/
|
@PostMapping("/index")
|
public RestResponse<TeacherIndexVM> Index() {
|
TeacherIndexVM vm = new TeacherIndexVM();
|
List<Integer> classesIds = classesService.getClassesIdByCreate(getCurrentUser().getId());
|
List<KeyValue> classKeyValue = classesService.getClassCount(classesIds);
|
Integer userCount = classKeyValue.stream().mapToInt(d -> d.getValue()).sum();
|
vm.setClassesCount(classesIds.size());
|
vm.setUserCount(userCount);
|
vm.setClassUserPie(classKeyValue);
|
|
List<KeyValue> paperKeyValue = examPaperService.getPaperClassCount(classesIds);
|
Integer paperCount = paperKeyValue.stream().mapToInt(d -> d.getValue()).sum();
|
vm.setExamPaperCount(paperCount);
|
vm.setClassPaperPie(paperKeyValue);
|
Integer questionCount = questionService.selectAllCountByCreate(getCurrentUser().getId());
|
vm.setQuestionCount(questionCount);
|
return RestResponse.ok(vm);
|
}
|
}
|