LearnController.java
21.6 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
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.utils.HttpClientUtils;
import com.jevon.utils.RedisUtils;
import com.jevon.vo.BaseVo;
import com.jevon.vo.excel.ExamExcelVo;
import com.jevon.vo.excel.ScoreExcelVo;
import com.jevon.vo.rep.GetLeague;
import com.jevon.vo.rep.GetLeagueRepVo;
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.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.InputStream;
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;
@Autowired
ChapterService chapterService;
@Autowired
KnowledgeService knowledgeService;
@ApiOperation("获取列表")
@RequestMapping(value = "getList", method = RequestMethod.POST)
public List<Analyse> getList(){
List<Analyse> list = analyseService.select(new Analyse());
return list;
}
@ApiOperation("获取详情,微信入口")
@RequestMapping(value = "getDetail", method = RequestMethod.GET)
public Analyse getAnalyseId(String grade , String schoolName){
Analyse result = null ;
Analyse search = new Analyse();
search.setGrade(initGrade(grade,schoolName));
List<Analyse> analyseList = analyseService.select(search);
if(analyseList != null && analyseList.size() > 0){
List<League> leagues = leagueService.selectByAnalyseId(analyseList.get(0).getId());
for(League league : leagues){
if(league.getSchoolName().equals(schoolName)){
result = analyseList.get(0);
break;
}
}
}
if(result == null){
Analyse searchAnalyse = new Analyse();
searchAnalyse.setExamName("顺治中学模板考试");
analyseList = analyseService.select(searchAnalyse);
if(analyseList != null && analyseList.size() > 0){
result = analyseList.get(0);
}
}
return result ;
}
private String initGrade(String grade , String schoolName){
String result = null ;
if(schoolName.equals("皋埠中学")){
if(grade.equals("初中一年级")){
result = "七年级" ;
}
if(grade.equals("2017级")){
result = "九年级" ;
}
}
if(schoolName.equals("建功中学")){
if(grade.equals("2019届")){
result = "七年级" ;
}
if(grade.equals("2017届")){
result = "九年级" ;
}
}
if(schoolName.equals("绍兴长城中学")){
if(grade.equals("2019级初中一年级")){
result = "七年级" ;
}
if(grade.equals("2017级初中三年级")){
result = "九年级" ;
}
}
if(schoolName.equals("绍兴市文澜中学")){
if(grade.equals("2019级初中一年级")){
result = "七年级" ;
}
if(grade.equals("2017级初中三年级")){
result = "九年级" ;
}
}
if(schoolName.equals("绍兴文理学院附属中学(慧)")){
if(grade.equals("2019级初中一年级")){
result = "七年级" ;
}
if(grade.equals("2017级初中三年级")){
result = "九年级" ;
}
}
if(result == null){
result = grade ;
}
return result ;
}
@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());
analyse.setGrade(createExamReqVo.getGrade());
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());
analyse.setGrade(updateExamReqVo.getGrade());
analyseService.update(analyse);
return baseVo;
}
@ApiOperation("试卷信息导入")
@RequestMapping(value = "initAnalyse", method = RequestMethod.POST)
public BaseVo initAnalyse(@RequestBody InitAnalyseReqVo initAnalyseReqVo){
BaseVo baseVo = new BaseVo();
Analyse analyse = analyseService.selectById(initAnalyseReqVo.getAnalyseId());
List<AnalyseDetail> analyseDetails = analyseDetailService.selectByAnalyseId(analyse.getId());
if(analyseDetails != null & analyseDetails.size() > 0){
baseVo.setMessage("已经导入");
baseVo.setSuccess(false);
}else {
RedisUtils.flushAll();
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());
File excelFile = new File(initAnalyseReqVo.getUrl());
// 获得工作簿
String file = excelFile.getName();
Workbook workbook = null;
InputStream inputStream = HttpClientUtils.GetFileInputStream(initAnalyseReqVo.getUrl());
if(inputStream == null){
return;
}
if (file.endsWith("xls")) {
workbook = new HSSFWorkbook(inputStream);
} else {
workbook = new XSSFWorkbook(inputStream);
}
// 获得工作表
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);
if(examExcelVo.getScore() != null){
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){
e.printStackTrace();
}
}
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 InitScoreReqVo initScoreReqVo){
BaseVo baseVo = new BaseVo();
boolean success = analysisScoreExcel(initScoreReqVo);
if(!success){
baseVo.setSuccess(false);
baseVo.setMessage("一个学校不能在两个联盟下");
}
return baseVo;
}
private boolean analysisScoreExcel(InitScoreReqVo initScoreReqVo){
try{
Analyse analyse = analyseService.selectById(initScoreReqVo.getAnalyseId());
List<AnalyseDetail> analyseDetails = analyseDetailService.selectByAnalyseId(analyse.getId());
Map<String , Double> scoreMap = new HashMap<>();
for(AnalyseDetail analyseDetail : analyseDetails){
scoreMap.put(analyseDetail.getQuestionNumber(),analyseDetail.getScore());
}
File excelFile = new File(initScoreReqVo.getUrl());
// 获得工作簿
String file = excelFile.getName();
Workbook workbook = null;
InputStream inputStream = HttpClientUtils.GetFileInputStream(initScoreReqVo.getUrl());
if(inputStream == null){
return false ;
}
if (file.endsWith("xls")) {
workbook = new HSSFWorkbook(inputStream);
} else {
workbook = new XSSFWorkbook(inputStream);
}
// 获得工作表
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().replace("(","(").replace(")",")"));
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);
}
}
}
}
int i = leagueService.initLeagueSchool(initScoreReqVo.getLeagueId(),students.get(0).getSchoolName());
if(i > 0){
studentService.insertBatch(students);
studentDetailService.insertBatch(studentDetails);
return true ;
}else {
return false ;
}
}
}catch (Exception e){
e.printStackTrace();
System.out.println(e.toString());
}
return false ;
}
@ApiOperation("获取该次考试联盟学校信息")
@RequestMapping(value = "getLeague", method = RequestMethod.GET)
public GetLeagueRepVo getLeague(int analyseId){
GetLeagueRepVo getLeagueRepVo = new GetLeagueRepVo();
List<League> leagues = leagueService.selectByAnalyseId(analyseId);
List<GetLeague> getLeagues = new ArrayList<>();
for(League league : leagues){
boolean isExist = false ;
for(GetLeague getLeague : getLeagues){
if(getLeague.getLeagueName().equals(league.getLeague())){
isExist = true ;
List<League> list = getLeague.getLeagues();
list.add(league);
getLeague.setLeagues(list);
}
}
if(!isExist){
GetLeague getLeague = new GetLeague();
getLeague.setLeagueName(league.getLeague());
List<League> list = new ArrayList<>();
list.add(league);
getLeague.setLeagues(list);
getLeagues.add(getLeague);
}
}
getLeagueRepVo.setData(getLeagues);
return getLeagueRepVo;
}
@ApiOperation("创建联盟")
@RequestMapping(value = "createLeague", method = RequestMethod.POST)
public BaseVo createLeague(@RequestBody CreateLeagueReqVo createLeagueReqVo){
BaseVo baseVo = new BaseVo();
League league = new League();
Analyse analyse = analyseService.selectById(createLeagueReqVo.getAnalyseId());
league.setAnalyseId(analyse.getId());
league.setLeague(createLeagueReqVo.getLeague());
leagueService.insert(league);
baseVo.setMessage(league.getId() +"");
return baseVo;
}
@ApiOperation("基础信息输入")
@RequestMapping(value = "createChapter", method = RequestMethod.POST)
public BaseVo createChapter(@RequestBody ChapterReqVo chapterReqVo){
BaseVo baseVo = new BaseVo();
analyseService.updateChapter(chapterReqVo.getAnalyseId(),chapterReqVo.getExamTime(),chapterReqVo.getExamScope());
List<Chapter> list = new ArrayList<>();
for(ChapterReq chapterReq :chapterReqVo.getList()){
Chapter chapter = new Chapter();
chapter.setAnalyseId(chapterReqVo.getAnalyseId());
chapter.setChapterNumber(chapterReq.getChapterNumber());
chapter.setChapterName(chapterReq.getChapterName());
chapter.setChapterScore(chapterReq.getScore());
list.add(chapter);
}
chapterService.insertBatch(list);
return baseVo;
}
@ApiOperation("获取导入的学校列表")
@RequestMapping(value = "getSchoolName", method = RequestMethod.GET)
public List<String> getSchoolName(int analyseId){
return studentService.selectSchoolNameByAnalyse(analyseId);
}
@ApiOperation("导入中考数据")
@RequestMapping(value = "initKnowledge", method = RequestMethod.POST)
public void initKnowledge(@RequestParam("file") MultipartFile file){
InputStream fis = null;
Workbook workBook = null;
try {
fis = file.getInputStream();
String fileName = file.getOriginalFilename();
if (fileName.endsWith("xls")) {
workBook = new HSSFWorkbook(fis);
} else {
workBook = new XSSFWorkbook(fis);
}
List<Knowledge> list = new ArrayList<>();
for(int number = 0 ; number < workBook.getNumberOfSheets() ; number++) {
Sheet sheet = workBook.getSheetAt(number);
Date date = new Date();
int rows = sheet.getPhysicalNumberOfRows();
for (int i = 1; i < rows; i++) {
// 获取第i行数据
Row sheetRow = sheet.getRow(i);
if(sheetRow != null){
Cell cell1 = sheetRow.getCell(0);
Cell cell2 = sheetRow.getCell(1);
Cell cell3 = sheetRow.getCell(2);
Cell cell4 = sheetRow.getCell(3);
if(cell1 != null){
Knowledge knowledge = new Knowledge();
knowledge.setKnowledge(cell1.getStringCellValue());
knowledge.setDetail(cell2.getStringCellValue());
cell3.setCellType(CellType.STRING);
cell4.setCellType(CellType.STRING);
knowledge.setRate(cell3.getStringCellValue());
knowledge.setAvg(cell4.getStringCellValue());
knowledge.setUpdateTime(date);
list.add(knowledge);
}
}
}
knowledgeService.insertBatch(list);
}
}catch (Exception e){
e.printStackTrace();
}
}
}