派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package com.qxueyou.scc.admin.score.action;
 
import com.qxueyou.scc.admin.classes.model.ClsClassReSubject;
import com.qxueyou.scc.admin.score.model.Score;
import com.qxueyou.scc.admin.score.service.impl.ScoreService;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QBeanUtils;
import com.qxueyou.scc.exam.model.ExamBatchInfo;
import com.qxueyou.scc.exam.model.ExamInfo;
import com.qxueyou.scc.exam.model.ExamReExamPaper;
import com.qxueyou.scc.exam.model.ExamResultV;
import com.qxueyou.scc.exercise.model.ExerciseRecord;
import com.qxueyou.scc.exercise.model.ExerciseResultV;
import com.qxueyou.scc.teach.subject.model.Subject;
import com.qxueyou.scc.teach.subject.model.SubjectUtils;
import com.qxueyou.scc.teach.subject.model.view.MyLectureV;
import com.qxueyou.scc.teach.subject.model.view.MySubjectV;
import com.qxueyou.scc.teach.subject.service.ILectureService;
import com.qxueyou.scc.teach.subject.service.impl.SubjectService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Api(tags = "成绩管理接口")
@Controller
@CrossOrigin(origins="*",maxAge=3600)
@RequestMapping(value = "admin/score")
public class ScoreController {
 
    // 分页查询中,默认记录条数和页数
    private static final int DEFAULT_PAGE_SIZE = 10;
    private static final int DEFAULT_PAGE_NUM = 1;
 
    @Autowired
    ScoreService scoreService;
 
    @Autowired
    ILectureService lectureService;
 
    @Autowired
    SubjectService subjectService;
 
    @RequestMapping(value = "lstScore", method = RequestMethod.GET)
    public @ResponseBody
    Result list(String classId,Integer pageSize, Integer pageNum) {
        pageSize = pageSize != null && pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
        pageNum = pageNum != null && pageNum > 0 ? pageNum : DEFAULT_PAGE_NUM;
        Pager pager = new Pager(pageSize,pageNum);
        if(classId == null){
            classId = "%";
        }else {
            classId += "%";
        }
        List<Map<String,Object>> mapList = new ArrayList<>();
        List<ExamResultV> examResultVS =  scoreService.allExamResultV(classId);
        List<ExerciseResultV> exerciseResultVS = scoreService.allExerciseResultV(classId);
        //总成绩数量
        int totalCount = scoreService.findCount("from ExamResultV where class_Id Like ? and score != null and score != 0",CollectionUtils.newList(classId));
        if (examResultVS.size() < exerciseResultVS.size()){
            totalCount = exerciseResultVS.size();
        }
        int totalPage = totalCount % pageSize > 0 ? totalCount/pageSize + 1 : totalCount/pageSize;
        int currentPage = pageNum < totalPage? pageNum : totalPage;
        int pageStart = (currentPage-1) * pageSize < 0 ? 0 :  (currentPage-1) * pageSize;
        int pageEnd = pageSize * currentPage > totalCount ? totalCount : pageSize * currentPage;
        pager.setTotalCount(totalCount);
 
        if(examResultVS.size() > exerciseResultVS.size()) {
            for (ExamResultV e : examResultVS) {
 
                Map<String, Object> map = new HashMap<>();
                boolean esisNull = true;
                BigDecimal examScore;
                if (e.getScore() == null) {
                    examScore = BigDecimal.ZERO;
                    System.out.println(examScore);
                } else {
                    examScore = e.getScore();
                }
                for (ExerciseResultV es : exerciseResultVS) {
                    if (e.getId().getStudentNo().equals(es.getStudentNo())) {
                        esisNull = false;
                        Double exerciseInfoScore = es.getScore() == null ? 0.0 : es.getScore().doubleValue();
                        map.put("studentName", es.getStudentName());
                        map.put("studentNumber", es.getStudentNo());
                        map.put("sex", es.getSex());
                        map.put("status", e.getStatus());
                        map.put("studyTime", 0);
                        map.put("subjectScore", 0);
                        map.put("exerciseInfoScore", exerciseInfoScore);
                        map.put("examScore", examScore);
                        map.put("totalScore", exerciseInfoScore + examScore.doubleValue());
                    }
                }
                if (esisNull) {
                    map.put("studentName", e.getStudentName());
                    map.put("studentNumber", e.getId().getStudentNo());
                    map.put("sex", e.getSex());
                    map.put("status", e.getStatus());
                    map.put("studyTime", 0);
                    map.put("subjectScore", 0);
                    map.put("exerciseInfoScore", 0);
                    map.put("examScore", examScore);
                    map.put("totalScore", examScore);
                }
                mapList.add(map);
            }
        }else {
            for (ExerciseResultV es : exerciseResultVS) {
                Map<String, Object> map = new HashMap<>();
                boolean esisNull = true;
                BigDecimal exerciseInfoScore;
                if (es.getScore() == null) {
                    exerciseInfoScore = BigDecimal.ZERO;
                } else {
                    exerciseInfoScore = es.getScore();
                }
                for (ExamResultV e : examResultVS) {
                    if (e.getId().getStudentNo().equals(es.getStudentNo())) {
                        esisNull = false;
                        Double examScore = e.getScore() == null ? 0.0 : e.getScore().doubleValue();
                        map.put("studentName", es.getStudentName());
                        map.put("studentNumber", es.getStudentNo());
                        map.put("sex", es.getSex());
                        map.put("status", e.getStatus());
                        map.put("studyTime", 0);
                        map.put("subjectScore", 0);
                        map.put("exerciseInfoScore", exerciseInfoScore);
                        map.put("examScore", examScore);
                        map.put("totalScore", examScore + exerciseInfoScore.doubleValue());
                    }
                }
                if (esisNull) {
                    map.put("studentName", es.getStudentName());
                    map.put("studentNumber", es.getStudentNo());
                    map.put("sex", es.getSex());
                    map.put("status", 0);
                    map.put("studyTime", 0);
                    map.put("subjectScore", 0);
                    map.put("exerciseInfoScore", exerciseInfoScore);
                    map.put("examScore", 0);
                    map.put("totalScore", exerciseInfoScore);
                }
                mapList.add(map);
            }
        }
        return new Result(true,"success",CollectionUtils.newObjectMap("data", mapList.subList(pageStart,pageEnd), "scoreCount", totalCount));
    }
 
    @RequestMapping(value = "getScoreDetail", method = RequestMethod.GET)
    @ResponseBody
    public Result getScoreDetail(String studentNo){
        List<ExamResultV> examLst = scoreService.find("from ExamResultV where id.studentNo = ?",CollectionUtils.newList(studentNo),ExamResultV.class);
        List<ExerciseResultV> exerciseInfoLst = scoreService.find("from ExerciseResultV where studentNo = ?",CollectionUtils.newList(studentNo),ExerciseResultV.class);
//        List<MyLectureV> myLectureVList = scoreService .find("from MyLectureV where id.userId = ?",CollectionUtils.newList(examLst.get(0).getUserId()),MyLectureV.class);
        List<Map<String,Object>> mapList = new ArrayList<>();
        List<ClsClassReSubject> clsClassReSubjects = scoreService.find("from ClsClassReSubject where classId = ? and deleteFlag is false",CollectionUtils.newList(examLst.get(0).getId().getClassId()),ClsClassReSubject.class);
        for(ClsClassReSubject c : clsClassReSubjects) {
            Double percent = 0.0;
            Double progressValue = 0.0;
            Double percentAvg = 0.0;
            List<MyLectureV> myLectureVList = lectureService.listLectureVBySubjectId(examLst.get(0).getUserId(), c.getSubjectId(), "", 1000, 1, null);
            if (!myLectureVList.isEmpty()) {
                for (MyLectureV myLectureV : myLectureVList) {
                    if (myLectureV.getPercent() != null && myLectureV.getProgressValue() != null) {
                        percent += myLectureV.getPercent();
                        progressValue += myLectureV.getProgressValue().intValue();
                    }
                }
                if (percentAvg.isNaN()) {
                    percentAvg = 0.0;
                }
                percentAvg = percent / myLectureVList.size() * 100;;
                Map<String, Object> map = new HashMap<>();
                map.put("subjectName", myLectureVList.get(0).getSubjectName());
                map.put("percent", percentAvg.intValue());
                map.put("durationTime", progressValue);
                map.put("endStudyTime", myLectureVList.get(0).getLectureUpdateTime());
                mapList.add(map);
            }else {
                MySubjectV mySubjectV = scoreService.findUnique("from MySubjectV where subjectId = ?",CollectionUtils.newList(c.getSubjectId()),MySubjectV.class);
                Map<String, Object> map = new HashMap<>();
                map.put("subjectName", mySubjectV.getSubjectName());
                map.put("percent", 0);
                map.put("durationTime", 0);
                map.put("endStudyTime", null);
                mapList.add(map);
            }
        }
        return new Result(true,"success",CollectionUtils.newObjectMap("subjectLst",mapList,"examLst",examLst,"exerciseInfoLst",exerciseInfoLst));
    }
}