LearnController.java
13.9 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
package com.jevon.controller;
import com.jevon.enums.DifficultEnums;
import com.jevon.enums.DimensionalEnums;
import com.jevon.model.*;
import com.jevon.service.*;
import com.jevon.vo.BaseVo;
import com.jevon.vo.excel.ExamExcelVo;
import com.jevon.vo.excel.ScoreExcelVo;
import com.jevon.vo.req.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
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.io.File;
import java.io.FileInputStream;
import java.util.*;
/**
* @author chen
* @version 1.0
* @date 2019/10/17 0017 13:33
*/
@RestController
@RequestMapping(value = "/learn")
@Api(value = "学情分析")
public class LearnController {
@Autowired
AnalyseService analyseService;
@Autowired
DimensionalService dimensionalService;
@Autowired
AnalyseDimensionalService analyseDimensionalService;
@Autowired
AnalyseDetailService analyseDetailService;
@Autowired
StudentDetailService studentDetailService;
@Autowired
StudentService studentService;
@Autowired
LeagueService leagueService;
@ApiOperation("获取列表")
@RequestMapping(value = "getList", method = RequestMethod.POST)
public List<Analyse> getList(){
List<Analyse> list = analyseService.select(new Analyse());
return list;
}
@ApiOperation("创建考试")
@RequestMapping(value = "createExam", method = RequestMethod.POST)
public BaseVo createExam(@RequestBody CreateExamReqVo createExamReqVo){
BaseVo baseVo = new BaseVo();
Analyse analyse = new Analyse();
analyse.setCourseName(createExamReqVo.getCourseName());
analyse.setExamName(createExamReqVo.getExamName());
analyse.setExamTime(createExamReqVo.getExamTime());
analyse.setCreateTime(new Date());
analyseService.insert(analyse);
baseVo.setMessage(analyse.getId()+"");
return baseVo;
}
@ApiOperation("更新考试信息")
@RequestMapping(value = "updateExam", method = RequestMethod.POST)
public BaseVo updateExam(@RequestBody UpdateExamReqVo updateExamReqVo){
BaseVo baseVo = new BaseVo();
Analyse analyse = analyseService.selectById(updateExamReqVo.getAnalyseId());
if(analyse == null){
baseVo.setMessage("考试不存在");
baseVo.setSuccess(false);
return baseVo;
}
analyse.setExamTime(updateExamReqVo.getExamTime());
analyse.setExamName(updateExamReqVo.getExamName());
analyse.setCourseName(updateExamReqVo.getCourseName());
return baseVo;
}
@ApiOperation("试卷信息导入")
@RequestMapping(value = "initAnalyse", method = RequestMethod.POST)
public BaseVo initAnalyse(@RequestBody InitAnalyseReqVo initAnalyseReqVo){
BaseVo baseVo = new BaseVo();
analysisExcel(initAnalyseReqVo);
return baseVo;
}
private void analysisExcel(InitAnalyseReqVo initAnalyseReqVo){
try{
List<AnalyseDetail> analyseDetails = new ArrayList<>();
List<AnalyseDimensional> analyseDimensionals = new ArrayList<>();
Float maxScore = 0f;
Analyse analyse = analyseService.selectById(initAnalyseReqVo.getAnalyseId());
String fileUrl = initAnalyseReqVo.getUrl();
File excelFile = new File(fileUrl);
// 获得工作簿
String file = excelFile.getName();
Workbook workbook = null;
if (file.endsWith("xls")) {
workbook = new HSSFWorkbook(new FileInputStream(excelFile));
} else {
workbook = new XSSFWorkbook(new FileInputStream(excelFile));
}
// 获得工作表
Sheet sheet = workbook.getSheetAt(0);
Date date = new Date();
int rows = sheet.getPhysicalNumberOfRows();
for (int i = 0; i < rows; i++) {
// 获取第i行数据
Row sheetRow = sheet.getRow(i);
if (i == 0) {
//获取标题
String title = sheetRow.getCell(0).getStringCellValue().trim();
}else if(i == 1){
//获取表头
} else {
ExamExcelVo examExcelVo = new ExamExcelVo(sheetRow);
maxScore = maxScore + new Float(examExcelVo.getScore());
AnalyseDetail analyseDetail = new AnalyseDetail();
String questionNumber = null ;
if(StringUtils.isNotBlank(examExcelVo.getQuestionSmallNumber())){
questionNumber = examExcelVo.getQuestionNumber()+"("+examExcelVo.getQuestionSmallNumber()+")";
}else {
questionNumber = examExcelVo.getQuestionNumber() ;
}
analyseDetail.setQuestionNumber(questionNumber);
analyseDetail.setAnalyseId(analyse.getId());
analyseDetail.setQuestionType(examExcelVo.getQuestionType());
analyseDetail.setDifficult(DifficultEnums.getDifficultType(examExcelVo.getDifficult()));
analyseDetail.setScore(new Double(examExcelVo.getScore()));
analyseDetail.setCreateTime(date);
analyseDetails.add(analyseDetail);
initAnalyseDimensional(analyse,questionNumber,examExcelVo.getScore(),examExcelVo.getKnowledge(),DimensionalEnums.knowledge.getDimensionalType(),analyseDimensionals);
initAnalyseDimensional(analyse,questionNumber,examExcelVo.getScore(),examExcelVo.getAbility(),DimensionalEnums.ability.getDimensionalType(),analyseDimensionals);
initAnalyseDimensional(analyse,questionNumber,examExcelVo.getScore(),examExcelVo.getSkill(),DimensionalEnums.skill.getDimensionalType(),analyseDimensionals);
initAnalyseDimensional(analyse,questionNumber,examExcelVo.getScore(),examExcelVo.getThink(),DimensionalEnums.think.getDimensionalType(),analyseDimensionals);
}
}
analyseDetailService.insertBatch(analyseDetails);
analyseDimensionalService.insertBatch(analyseDimensionals);
analyse.setMaxScore(new Double(maxScore));
analyseService.update(analyse);
}catch (Exception e){
System.out.println(e);
}
}
private void initAnalyseDimensional(Analyse analyse ,String questionNumber , String score , String dimensionalMessage , int dimensionalType , List<AnalyseDimensional> analyseDimensionals){
if(StringUtils.isNotBlank(dimensionalMessage)){
String[] message =dimensionalMessage.split("、");
for (int j = 0; j < message.length ; j++) {
if(StringUtils.isNotBlank(message[j])){
Dimensional dimensional = new Dimensional();
dimensional.setDimensionalType(dimensionalType);
dimensional.setDimensionalName(message[j]);
//查数据库是否已存在该四维诊断 不存在则导入
Dimensional result = dimensionalService.selectByTypeAndName(dimensionalType,message[j]);
int dimensionalId = 0 ;
if(result == null || result.getId() == 0){
dimensional.setCreateTime(new Date());
dimensionalService.insert(dimensional);
dimensionalId = dimensional.getId();
}else{
dimensionalId = result.getId();
}
AnalyseDimensional analyseDimensional = new AnalyseDimensional();
analyseDimensional.setAnalyseId(analyse.getId());
analyseDimensional.setDimensionalId(dimensionalId);
analyseDimensional.setQuestionNumber(questionNumber);
analyseDimensional.setScore(new Double(score));
analyseDimensional.setCreateTime(new Date());
analyseDimensionals.add(analyseDimensional);
}
}
}
}
@ApiOperation("考生成绩导入")
@RequestMapping(value = "initScore", method = RequestMethod.POST)
public BaseVo initScore(@RequestBody InitAnalyseReqVo initAnalyseReqVo){
BaseVo baseVo = new BaseVo();
analysisScoreExcel(initAnalyseReqVo);
return baseVo;
}
private void analysisScoreExcel(InitAnalyseReqVo initAnalyseReqVo){
try{
Analyse analyse = analyseService.selectById(initAnalyseReqVo.getAnalyseId());
List<AnalyseDetail> analyseDetails = analyseDetailService.selectByAnalyseId(analyse.getId());
Map<String , Double> scoreMap = new HashMap<>();
for(AnalyseDetail analyseDetail : analyseDetails){
scoreMap.put(analyseDetail.getQuestionNumber(),analyseDetail.getScore());
}
String fileUrl = initAnalyseReqVo.getUrl();
File excelFile = new File(fileUrl);
// 获得工作簿
String file = excelFile.getName();
Workbook workbook = null;
if (file.endsWith("xls")) {
workbook = new HSSFWorkbook(new FileInputStream(excelFile));
} else {
workbook = new XSSFWorkbook(new FileInputStream(excelFile));
}
// 获得工作表
for(int number = 0 ; number < workbook.getNumberOfSheets() ; number++){
Sheet sheet = workbook.getSheetAt(number);
List<StudentDetail> studentDetails = new ArrayList<>();
List<Student> students = new ArrayList<>();
Date date = new Date();
int rows = sheet.getPhysicalNumberOfRows();
Map<Integer , String> map = new HashMap<>();
int column = 0 ;
for (int i = 0; i < rows; i++) {
// 获取第i行数据
Row sheetRow = sheet.getRow(i);
if (i == 0) {
//获取标题
}else if(i == 1){
//获取表头
int j = 7 ;
while (sheetRow.getCell(j) != null){
Cell cell = sheetRow.getCell(j);
cell.setCellType(CellType.STRING);
map.put(j,cell.getStringCellValue().trim());
j++;
}
column = j ;
} else {
ScoreExcelVo scoreExcelVo = new ScoreExcelVo(sheetRow);
if(StringUtils.isNotBlank(scoreExcelVo.getStudentName())){
Student student = new Student(scoreExcelVo);
student.setAnalyseId(analyse.getId());
student.setCreateTime(date);
students.add(student);
for(int j = 7 ; j < column ; j++){
Cell cell = sheetRow.getCell(j);
StudentDetail studentDetail = new StudentDetail(scoreExcelVo);
studentDetail.setAnalyseId(analyse.getId());
studentDetail.setExamNumber(map.get(j));
studentDetail.setScore(new Double(cell.getNumericCellValue()));
Double score = scoreMap.get((map.get(j))) ;
Double studentScore = studentDetail.getScore() ;
if(Double.doubleToLongBits(score) == Double.doubleToLongBits(studentScore) ){
studentDetail.setCorrect(1);
}else {
studentDetail.setCorrect(0);
}
studentDetail.setCreateTime(date);
studentDetails.add(studentDetail);
}
}
}
}
studentService.insertBatch(students);
studentDetailService.insertBatch(studentDetails);
}
}catch (Exception e){
e.printStackTrace();
System.out.println(e.toString());
}
}
@ApiOperation("获取导入的学校列表")
@RequestMapping(value = "getSchoolName", method = RequestMethod.GET)
public List<String> getSchoolName(int analyseId){
return studentService.selectSchoolNameByAnalyse(analyseId);
}
@ApiOperation("定义这次考试的联盟校")
@RequestMapping(value = "initLeague", method = RequestMethod.POST)
public BaseVo initLeague(@RequestBody InitLeagueReqVo initLeagueReqVo){
BaseVo baseVo = new BaseVo();
Analyse analyse = analyseService.selectById(initLeagueReqVo.getAnalyseId());
if(analyse == null){
baseVo.setMessage("请先创建考试");
baseVo.setSuccess(false);
return baseVo;
}
List<League> leagues = new ArrayList<>();
for(InitLeague initLeague : initLeagueReqVo.getData()){
for(String schoolName : initLeague.getSchoolNames()){
League league = new League();
league.setAnalyseId(analyse.getId());
league.setLeague(initLeague.getLeague());
league.setSchoolName(schoolName);
leagues.add(league);
}
}
leagueService.insertBatch(leagues);
return baseVo;
}
}