xiangpei
2024-03-28 0f431b52e0936456bd165d9553761bfd8a5a0517
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
    }
}